mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-11592: Post-upgrade differencing bug
Character data now handled correctly in XML parsing logic. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32200 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -49,8 +49,7 @@ public class XMLToSchema extends DefaultHandler
|
|||||||
private InputStream in;
|
private InputStream in;
|
||||||
private Schema schema;
|
private Schema schema;
|
||||||
private Stack<Object> stack = new Stack<Object>();
|
private Stack<Object> stack = new Stack<Object>();
|
||||||
private String lastTag;
|
private StringBuilder lastText = new StringBuilder();
|
||||||
private String lastText;
|
|
||||||
|
|
||||||
|
|
||||||
public XMLToSchema(InputStream in, SAXParserFactory saxParserFactory)
|
public XMLToSchema(InputStream in, SAXParserFactory saxParserFactory)
|
||||||
@@ -140,6 +139,60 @@ public class XMLToSchema extends DefaultHandler
|
|||||||
DbObject dbo = (DbObject) stack.peek();
|
DbObject dbo = (DbObject) stack.peek();
|
||||||
dbo.getValidators().add(validator);
|
dbo.getValidators().add(validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deal with elements that contain text.
|
||||||
|
if (lastText.length() != 0)
|
||||||
|
{
|
||||||
|
if (qName.equals(XML.EL_TYPE))
|
||||||
|
{
|
||||||
|
Column column = (Column) stack.peek();
|
||||||
|
column.setType(lastText.toString());
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_NULLABLE))
|
||||||
|
{
|
||||||
|
Column column = (Column) stack.peek();
|
||||||
|
column.setNullable(Boolean.parseBoolean(lastText.toString()));
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_COLUMN_NAME))
|
||||||
|
{
|
||||||
|
if (stack.peek() instanceof PrimaryKey)
|
||||||
|
{
|
||||||
|
PrimaryKey pk = (PrimaryKey) stack.peek();
|
||||||
|
pk.getColumnNames().add(lastText.toString());
|
||||||
|
}
|
||||||
|
else if (stack.peek() instanceof Index)
|
||||||
|
{
|
||||||
|
Index index = (Index) stack.peek();
|
||||||
|
index.getColumnNames().add(lastText.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_LOCAL_COLUMN))
|
||||||
|
{
|
||||||
|
ForeignKey fk = (ForeignKey) stack.peek();
|
||||||
|
fk.setLocalColumn(lastText.toString());
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_TARGET_TABLE))
|
||||||
|
{
|
||||||
|
ForeignKey fk = (ForeignKey) stack.peek();
|
||||||
|
fk.setTargetTable(lastText.toString());
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_TARGET_COLUMN))
|
||||||
|
{
|
||||||
|
ForeignKey fk = (ForeignKey) stack.peek();
|
||||||
|
fk.setTargetColumn(lastText.toString());
|
||||||
|
}
|
||||||
|
else if (qName.equals(XML.EL_PROPERTY))
|
||||||
|
{
|
||||||
|
String propValue = lastText.toString();
|
||||||
|
String propName = (String) stack.pop();
|
||||||
|
if (stack.peek() instanceof DbValidator)
|
||||||
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
DbValidator validator = (DbValidator) stack.peek();
|
||||||
|
validator.setProperty(propName, propValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -147,7 +200,7 @@ public class XMLToSchema extends DefaultHandler
|
|||||||
public void startElement(String uri, String localName, String qName, Attributes atts)
|
public void startElement(String uri, String localName, String qName, Attributes atts)
|
||||||
throws SAXException
|
throws SAXException
|
||||||
{
|
{
|
||||||
lastTag = qName;
|
lastText.setLength(0);
|
||||||
|
|
||||||
if (qName.equals(XML.EL_SCHEMA))
|
if (qName.equals(XML.EL_SCHEMA))
|
||||||
{
|
{
|
||||||
@@ -205,59 +258,10 @@ public class XMLToSchema extends DefaultHandler
|
|||||||
@Override
|
@Override
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException
|
public void characters(char[] ch, int start, int length) throws SAXException
|
||||||
{
|
{
|
||||||
lastText = new String(ch, start, length).trim();
|
String text = new String(ch, start, length).trim();
|
||||||
|
if (text.length() > 0)
|
||||||
if (lastText.length() != 0)
|
|
||||||
{
|
{
|
||||||
if (lastTag.equals(XML.EL_TYPE))
|
lastText.append(text);
|
||||||
{
|
|
||||||
Column column = (Column) stack.peek();
|
|
||||||
column.setType(lastText);
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_NULLABLE))
|
|
||||||
{
|
|
||||||
Column column = (Column) stack.peek();
|
|
||||||
column.setNullable(Boolean.parseBoolean(lastText));
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_COLUMN_NAME))
|
|
||||||
{
|
|
||||||
if (stack.peek() instanceof PrimaryKey)
|
|
||||||
{
|
|
||||||
PrimaryKey pk = (PrimaryKey) stack.peek();
|
|
||||||
pk.getColumnNames().add(lastText);
|
|
||||||
}
|
|
||||||
else if (stack.peek() instanceof Index)
|
|
||||||
{
|
|
||||||
Index index = (Index) stack.peek();
|
|
||||||
index.getColumnNames().add(lastText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_LOCAL_COLUMN))
|
|
||||||
{
|
|
||||||
ForeignKey fk = (ForeignKey) stack.peek();
|
|
||||||
fk.setLocalColumn(lastText);
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_TARGET_TABLE))
|
|
||||||
{
|
|
||||||
ForeignKey fk = (ForeignKey) stack.peek();
|
|
||||||
fk.setTargetTable(lastText);
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_TARGET_COLUMN))
|
|
||||||
{
|
|
||||||
ForeignKey fk = (ForeignKey) stack.peek();
|
|
||||||
fk.setTargetColumn(lastText);
|
|
||||||
}
|
|
||||||
else if (lastTag.equals(XML.EL_PROPERTY))
|
|
||||||
{
|
|
||||||
String propValue = lastText;
|
|
||||||
String propName = (String) stack.pop();
|
|
||||||
if (stack.peek() instanceof DbValidator)
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
DbValidator validator = (DbValidator) stack.peek();
|
|
||||||
validator.setProperty(propName, propValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,8 @@ import org.alfresco.util.schemacomp.validator.DbValidator;
|
|||||||
import org.alfresco.util.schemacomp.validator.NameValidator;
|
import org.alfresco.util.schemacomp.validator.NameValidator;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the XMLToSchema class.
|
* Tests for the XMLToSchema class.
|
||||||
@@ -52,7 +54,8 @@ public class XMLToSchemaTest
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
in = new BufferedInputStream(getClass().getResourceAsStream("xml_to_schema_test.xml"));
|
Resource testFileResource = new ClassPathResource("schemacomp/xml_to_schema_test.xml");
|
||||||
|
in = new BufferedInputStream(testFileResource.getInputStream());
|
||||||
xmlToSchema = new XMLToSchema(in);
|
xmlToSchema = new XMLToSchema(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user