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:14 UTC
[uima-uimafit] 01/01: [UIMA-6206] Parameter values with certain
non-XML 1.0 characters not supported
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;