diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-08-22 10:46:29 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-08-22 10:46:29 +0200 |
| commit | 63f2df4babca2cd2232d6b1f438ddcea1d3f3fa2 (patch) | |
| tree | 2831803fde245c0bbc258a46a2875aba39518ac3 /src/main/java/com/c2kernel/persistency | |
| parent | 1b5c986a41c5a0b31b75d6d92eee4d41904f364b (diff) | |
Replace deprecated Xerces DOM to XML serialisation with DOM3 LS.
Refactor all to use the Outcome.serialize static method.
Diffstat (limited to 'src/main/java/com/c2kernel/persistency')
| -rw-r--r-- | src/main/java/com/c2kernel/persistency/outcome/Outcome.java | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java index d321f69..a0b01ee 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java @@ -1,18 +1,17 @@ package com.c2kernel.persistency.outcome;
import java.io.StringReader;
-import java.io.StringWriter;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.apache.xml.serialize.Method;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.InputSource;
import com.c2kernel.common.PersistencyException;
@@ -27,8 +26,10 @@ public class Outcome implements C2KLocalObject { int mSchemaVersion;
Document dom;
static DocumentBuilder parser;
+ static DOMImplementationLS impl;
static {
+ // Set up parser
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(false);
@@ -36,7 +37,18 @@ public class Outcome implements C2KLocalObject { parser = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
Logger.error(e);
+ Logger.die("Cannot function without XML parser");
}
+
+ // Set up serialiser
+ try {
+ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+ impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
+ } catch (Exception e) {
+ Logger.error(e);
+ Logger.die("Cannot function without XML serialiser");
+ }
+
}
//id is the eventID
@@ -158,20 +170,9 @@ public class Outcome implements C2KLocalObject { static public String serialize(Document doc, boolean prettyPrint)
{
- String serializedDoc = null;
- OutputFormat format = new OutputFormat(Method.XML, null, prettyPrint);
- StringWriter stringOut = new StringWriter();
- XMLSerializer serial = new XMLSerializer(stringOut, format);
- try
- {
- serial.asDOMSerializer();
- serial.serialize(doc);
- }
- catch (java.io.IOException ex)
- {
- Logger.error(ex.toString());
- }
- serializedDoc = stringOut.toString();
- return serializedDoc;
+ LSSerializer writer = impl.createLSSerializer();
+ writer.getDomConfig().setParameter("format-pretty-print", prettyPrint);
+ writer.getDomConfig().setParameter("xml-declaration", false);
+ return writer.writeToString(doc);
}
}
|
