You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2020/03/24 09:25:13 UTC

[uima-uimafit] branch bugfix/UIMA-6206-Parameter-values-with-certain-non-XML-1.0-characters-not-supported created (now 2c5e0cb)

This is an automated email from the ASF dual-hosted git repository.

rec pushed a change to branch bugfix/UIMA-6206-Parameter-values-with-certain-non-XML-1.0-characters-not-supported
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git.


      at 2c5e0cb  [UIMA-6206] Parameter values with certain non-XML 1.0 characters not supported

This branch includes the following new commits:

     new 2c5e0cb  [UIMA-6206] Parameter values with certain non-XML 1.0 characters not supported

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[uima-uimafit] 01/01: [UIMA-6206] Parameter values with certain non-XML 1.0 characters not supported

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch bugfix/UIMA-6206-Parameter-values-with-certain-non-XML-1.0-characters-not-supported
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git

commit 2c5e0cb71bc6d3fb92be3d9a0de34368ef72654e
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Tue Mar 24 10:25:05 2020 +0100

    [UIMA-6206] Parameter values with certain non-XML 1.0 characters not supported
    
    - Materialize descriptors as XML 1.1 to support a wider range of characters in parameters
---
 .../main/java/org/apache/uima/fit/cpe/CpeBuilder.java    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/uimafit-cpe/src/main/java/org/apache/uima/fit/cpe/CpeBuilder.java b/uimafit-cpe/src/main/java/org/apache/uima/fit/cpe/CpeBuilder.java
index 1ba8ce4..a0f9c60 100644
--- a/uimafit-cpe/src/main/java/org/apache/uima/fit/cpe/CpeBuilder.java
+++ b/uimafit-cpe/src/main/java/org/apache/uima/fit/cpe/CpeBuilder.java
@@ -25,12 +25,14 @@ import static org.apache.uima.collection.impl.metadata.cpe.CpeDescriptorFactory.
 import static org.apache.uima.collection.impl.metadata.cpe.CpeDescriptorFactory.produceDescriptor;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.Map;
 
+import javax.xml.transform.OutputKeys;
+
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.metadata.FixedFlow;
 import org.apache.uima.collection.CollectionProcessingEngine;
@@ -48,6 +50,8 @@ import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceManager;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLSerializer;
+import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 /**
@@ -177,8 +181,14 @@ public class CpeBuilder {
     File tempDesc = File.createTempFile("desc", ".xml");
     tempDesc.deleteOnExit();
 
-    try (OutputStream os = new FileOutputStream(tempDesc)) {
-      resource.toXML(os);
+    // Write the descriptor using XML 1.1 to allow a wider range of characters for parameter values
+    try (OutputStream os = Files.newOutputStream(tempDesc.toPath())) {
+      XMLSerializer sax2xml = new XMLSerializer(os, true);
+      sax2xml.setOutputProperty(OutputKeys.VERSION, "1.1");
+      ContentHandler contentHandler = sax2xml.getContentHandler();
+      contentHandler.startDocument();
+      resource.toXML(sax2xml.getContentHandler(), true);
+      contentHandler.endDocument();
     }
 
     return tempDesc;