Revision: 13057
http://sourceforge.net/p/foray/code/13057
Author: victormote
Date: 2023-01-12 18:14:40 +0000 (Thu, 12 Jan 2023)
Log Message:
-----------
Add more LS methods, so far used only for testing and experimentation.
Modified Paths:
--------------
trunk/foray/foray-xml/src/main/java/org/foray/xml/DomUtil.java
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/DomUtil.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/DomUtil.java 2023-01-11 22:12:29 UTC (rev 13056)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/DomUtil.java 2023-01-12 18:14:40 UTC (rev 13057)
@@ -34,11 +34,14 @@
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSResourceResolver;
+import org.w3c.dom.ls.LSSerializer;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -138,9 +141,9 @@
/**
* Converts an input stream into an LSInput.
+ * @param inputStream The input stream to attach to the input.
* @param publicId The public ID to attache to the input.
* @param systemId The system ID to attach to the input.
- * @param inputStream The input stream to attach to the input.
* @return The new input.
*/
public static LSInput createLSInput(final InputStream inputStream, final String publicId, final String systemId) {
@@ -157,4 +160,37 @@
return input;
}
+ /**
+ * Converts an output stream into an LSInput.
+ * @param outputStream The output stream to attach to the output.
+ * @param systemId The system ID to attach to the output.
+ * @return The new output.
+ */
+ public static LSOutput createLSOutput(final OutputStream outputStream, final String systemId) {
+ final DOMImplementationLS implementation;
+ try {
+ implementation = DomUtil.getDOMImplementationLS();
+ } catch (final IOException e) {
+ return null;
+ }
+ final LSOutput output = implementation.createLSOutput();
+ output.setByteStream(outputStream);
+ output.setSystemId(systemId);
+ return output;
+ }
+
+ /**
+ * Creates an LS Serializer instance.
+ * @return The new LS Serializer.
+ */
+ public static LSSerializer createLSSerializer() {
+ final DOMImplementationLS implementation;
+ try {
+ implementation = DomUtil.getDOMImplementationLS();
+ } catch (final IOException e) {
+ return null;
+ }
+ return implementation.createLSSerializer();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|