Author: schor Date: Fri Jan 20 19:36:44 2012 New Revision: 1234092 URL: http://svn.apache.org/viewvc?rev=1234092&view=rev Log: [UIMA-239] support parsing UIMA descriptors in a mode that preserves comments and formatting whitespace.
Modified: uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java Modified: uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java?rev=1234092&r1=1234091&r2=1234092&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java (original) +++ uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java Fri Jan 20 19:36:44 2012 @@ -154,6 +154,7 @@ import org.eclipse.ui.forms.widgets.Form import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.texteditor.ITextEditor; import org.osgi.framework.Bundle; +import org.w3c.dom.Node; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; @@ -205,6 +206,8 @@ public class MultiPageEditor extends For public final int INITIAL_SIZE_TYPE_COLLECTIONS = 20; public final int INITIAL_SIZE_FEATURE_COLLECTIONS = 40; + + public final boolean PRESERVE_COMMENTS = true; // ****************************** @@ -222,6 +225,7 @@ public class MultiPageEditor extends For private TypeSystemDescription importedTypeSystemDescription = null; + private Node xmlInfoset = null; // captures comments and ignorableWhitespace /** * Key = unique ID of included AE in aggregate Value = AnalysisEngineSpecification or URISpecifier * if remote This value is obtained from aeDescription.getDelegateAnalysisEngineSpecifiers() for @@ -957,7 +961,7 @@ public class MultiPageEditor extends For // leaves isBadXML set, if it can't parse but isn't throwing isContextLoaded = false; try { - parseSource(input, filePathName); + parseSource(input, filePathName, PRESERVE_COMMENTS); } catch (MultilevelCancel e) { throw new PartInitException("Operation Cancelled"); } @@ -974,15 +978,15 @@ public class MultiPageEditor extends For private IUimaEditorExtension extensionEditor; - private void parseSource(XMLInputSource input, String filePathName) throws PartInitException { + private void parseSource(XMLInputSource input, String filePathName, boolean preserveComments) throws PartInitException { extensionEditor = null; - parseSourceInner(input, filePathName); + parseSourceInner(input, filePathName, preserveComments); } - private void parseSourceInner(XMLInputSource input, String filePathName) throws PartInitException { + private void parseSourceInner(XMLInputSource input, String filePathName, boolean preserveComments) throws PartInitException { XMLizable inputDescription = null; try { - inputDescription = AbstractSection.parseDescriptor(input); + inputDescription = AbstractSection.parseDescriptor(input, preserveComments); if (inputDescription instanceof AnalysisEngineDescription) { validateDescriptorType(DESCRIPTOR_AE); setAeDescription((AnalysisEngineDescription) inputDescription); @@ -1039,7 +1043,7 @@ public class MultiPageEditor extends For // exception go away - so try reparsing. try { - parseSourceInner(new XMLInputSource(input.getURL()), filePathName); + parseSourceInner(new XMLInputSource(input.getURL()), filePathName, preserveComments); } catch (IOException e1) { Utility.popMessage( "Internal Error", @@ -1288,7 +1292,7 @@ public class MultiPageEditor extends For TypeSystemDescription oldTsdWithResolvedImports = mergedTypeSystemDescription; try { - parseSource(input, filePathName); // sets isBadXML to false if OK + parseSource(input, filePathName, true); // sets isBadXML to false if OK } catch (PartInitException e1) { // if user switched the kind of descriptor Utility.popMessage(Messages.getString("MultiPageEditor.20"), //$NON-NLS-1$ getMessagesToRootCause(e1), MessageDialog.ERROR); @@ -1411,7 +1415,8 @@ public class MultiPageEditor extends For try { XMLSerializer xmlSerializer = new XMLSerializer(true); xmlSerializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.valueOf( - MultiPageEditorContributor.getXMLindent()).toString()); + MultiPageEditorContributor.getXMLindent()).toString()); + xmlSerializer.setIndent(false); xmlSerializer.setWriter(writer); ContentHandler contentHandler = xmlSerializer.getContentHandler(); contentHandler.startDocument(); @@ -1720,7 +1725,7 @@ public class MultiPageEditor extends For } if (null != input) try { - parseSource(input, contextFile); + parseSource(input, contextFile, !PRESERVE_COMMENTS); } catch (PartInitException e) { showContextLoadFailureMessage(e, contextFile); throw new MultilevelCancel(); Modified: uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java?rev=1234092&r1=1234091&r2=1234092&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java (original) +++ uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/ui/AbstractSection.java Fri Jan 20 19:36:44 2012 @@ -1422,8 +1422,13 @@ implements Listener, StandardStrings { } public static XMLizable parseDescriptor(XMLInputSource input) throws InvalidXMLException { + return parseDescriptor(input, false); + } + + public static XMLizable parseDescriptor(XMLInputSource input, boolean preserveComments) throws InvalidXMLException { // turn off environment variable expansion XMLParser.ParsingOptions parsingOptions = new XMLParser.ParsingOptions(false); + parsingOptions.preserveComments = preserveComments; XMLParser parser = UIMAFramework.getXMLParser(); // disabled - error messages from XML validation not very helpful // parser.enableSchemaValidation(true);