You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2012/06/13 16:02:56 UTC
svn commit: r1349858 - in /uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
Author: schor
Date: Wed Jun 13 14:02:56 2012
New Revision: 1349858
URL: http://svn.apache.org/viewvc?rev=1349858&view=rev
Log:
[UIMA-2408] fix array formatting. Improve test so it verifies auto-indent not used when preserve comments and original infoset is available
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java?rev=1349858&r1=1349857&r2=1349858&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/MetaDataObject_impl.java Wed Jun 13 14:02:56 2012
@@ -691,11 +691,21 @@ public abstract class MetaDataObject_imp
return;
// if XML element name was supplied, write a tag
- Node elementNode = findMatchingSubElement(aContentHandler, aPropInfo.xmlElementName);
- outputStartElement(aContentHandler, elementNode, aNamespace, aPropInfo.xmlElementName, aPropInfo.xmlElementName,
- EMPTY_ATTRIBUTES);
+ String elementName = aPropInfo.xmlElementName;
CharacterValidatingContentHandler cc = (CharacterValidatingContentHandler) aContentHandler;
- cc.lastOutputNodeAddLevel();
+ Node elementNode = null;
+
+ if (null != elementName) { // can be null in this case:
+ // <fixedFlow> <== after outputting this,
+ // there is no <array> conntaining:
+ // <node>A</node>
+ // <node>B</node>
+
+ elementNode = findMatchingSubElement(aContentHandler, aPropInfo.xmlElementName);
+ outputStartElement(aContentHandler, elementNode, aNamespace, aPropInfo.xmlElementName, aPropInfo.xmlElementName,
+ EMPTY_ATTRIBUTES);
+ cc.lastOutputNodeAddLevel();
+ }
// get class of property
Class propClass = getAttributeClass(aPropInfo.propertyName);
@@ -726,11 +736,15 @@ public abstract class MetaDataObject_imp
}
}
} finally {
- cc.lastOutputNodeClearLevel();
+ if (null != elementName) {
+ cc.lastOutputNodeClearLevel();
+ }
}
// if XML element name was supplied, end the element that we started
- outputEndElement(aContentHandler, elementNode, aNamespace, aPropInfo.xmlElementName, aPropInfo.xmlElementName);
+ if (null != elementName) {
+ outputEndElement(aContentHandler, elementNode, aNamespace, aPropInfo.xmlElementName, aPropInfo.xmlElementName);
+ }
}
/**
@@ -754,18 +768,21 @@ public abstract class MetaDataObject_imp
protected void writeArrayPropertyAsElement(String aPropName, Class aPropClass, Object aValue,
String aArrayElementTagName, String aNamespace, ContentHandler aContentHandler)
throws SAXException {
+ CharacterValidatingContentHandler cc = (CharacterValidatingContentHandler) aContentHandler;
+
// if aPropClass is generic Object, reader won't know whether to expect
// an array, so we tell it be writing an "array" element here.
Node arraySubElement = findMatchingSubElement(aContentHandler, "array");
- if (aPropClass == Object.class) {
+
+ if (aPropClass == Object.class) { // skip writting <array> unless the property class (of objects in the array) is "Object"
+ // skipped e.g. in <fixedFlow> values, where aPropClass is String
outputStartElement(aContentHandler, arraySubElement, aNamespace, "array", "array", EMPTY_ATTRIBUTES);
+ cc.lastOutputNodeAddLevel();
}
// iterate through elements of the array (at this point we don't allow
// nested arrays here
int len = ((Object[]) aValue).length;
- CharacterValidatingContentHandler cc = (CharacterValidatingContentHandler) aContentHandler;
- cc.lastOutputNodeAddLevel();
try {
for (int i = 0; i < len; i++) {
Object curElem = Array.get(aValue, i);
@@ -795,7 +812,9 @@ public abstract class MetaDataObject_imp
outputEndElement(aContentHandler, matchingArrayElement, aNamespace, aArrayElementTagName, aArrayElementTagName);
}
} finally {
- cc.lastOutputNodeClearLevel();
+ if (aPropClass == Object.class) {
+ cc.lastOutputNodeClearLevel();
+ }
}
// if we started an "Array" element, end it
@@ -1690,7 +1709,12 @@ public abstract class MetaDataObject_imp
String localname,
String qname,
Attributes attributes) throws SAXException {
- if (null == localname) {
+ if (null == localname) { // happens for <flowConstraints>
+ // <fixedFlow> <== after outputting this,
+ // called writePropertyAsElement
+ // But there is no <array>...
+ // <node>A</node>
+ // <node>B</node>
return;
}
maybeOutputCoIwBeforeStart(aContentHandler, node);
Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java?rev=1349858&r1=1349857&r2=1349858&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/analysis_engine/impl/AnalysisEngine_implTest.java Wed Jun 13 14:02:56 2012
@@ -1505,14 +1505,17 @@ public class AnalysisEngine_implTest ext
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(cloneFile));
XMLSerializer xmlSerializer = new XMLSerializer(true);
xmlSerializer.setOutputStream(os);
- xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ // set the amount to a value which will show up if used
+ // indent should not be used because we're using a parser mode which preserves
+ // comments and ignorable white space.
+ xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
ContentHandler contentHandler = xmlSerializer.getContentHandler();
contentHandler.startDocument();
desc.toXML(contentHandler, true);
contentHandler.endDocument();
os.close();
// Omit test for same-length-file as formatting appears to be platform-dependent
- //assertEquals(inFile.length(), cloneFile.length());
+ assertEquals(inFile.length(), cloneFile.length());
// Initialize all delegates and check the initialization order (should be declaration order)
TestAnnotator2.allContexts = "";