Engines now implement interface

This commit is contained in:
2023-05-09 14:57:51 +02:00
parent 8a68514cd3
commit 498dc82ccd
3 changed files with 18 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ import java.io.StringWriter;
* Handler for Saxon engine
* @author Wojciech Czop
*/
public class Saxon {
public class Saxon implements XmlEngine{
/**
* Transforms string containing xml document via xslt
@@ -20,7 +20,7 @@ public class Saxon {
* @return transformed xml
* @throws SaxonApiException thrown on stylesheet or transformation errors
*/
public static String processXSLT(String data, String transform) throws SaxonApiException {
public String processXSLT(String data, String transform) throws SaxonApiException {
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
XsltExecutable stylesheet = compiler.compile(new StreamSource(new StringReader(transform)));
@@ -34,6 +34,11 @@ public class Saxon {
return sw.toString();
}
@Override
public String validate(String data, String xsd) {
throw new UnsupportedOperationException();
}
/**
* Process xpath and return either node or wrapped atomic value
* @param data xml to be querried
@@ -42,7 +47,7 @@ public class Saxon {
* @return string xml representation of the node
* @throws Exception thrown on node building errors or invalid xpath
*/
public static XPathQueryResult processXPath(String data, String query, String version) throws Exception {
public XPathQueryResult processXPath(String data, String query, String version) throws Exception {
Processor p = new Processor(false);
XPathCompiler compiler = p.newXPathCompiler();
DocumentBuilder builder = p.newDocumentBuilder();
@@ -70,7 +75,7 @@ public class Saxon {
* Returns version of the processor
* @return version of the processor
*/
public static String getVersion() {
public String getVersion() {
return new Processor(false).getSaxonProductVersion();
}
}

View File

@@ -24,7 +24,7 @@ import java.io.*;
* Handler for Xalan engine
* @author Wojciech Czop
*/
public class Xalan {
public class Xalan implements XmlEngine{
/**
* Transforms string containing xml document via xslt
@@ -33,7 +33,7 @@ public class Xalan {
* @return transformed xml
* @throws Exception thrown on stylesheet or transformation errors
*/
public static String processXSLT(String data, String transform) throws Exception{
public String processXSLT(String data, String transform) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(data)));
@@ -51,7 +51,7 @@ public class Xalan {
return sw.toString();
}
private static boolean isTextNode(Node n) {
private boolean isTextNode(Node n) {
if (n == null)
return false;
short nodeType = n.getNodeType();
@@ -65,7 +65,7 @@ public class Xalan {
* @return xml processed using given xpath
* @throws Exception thrown on node building errors or invalid xpath
*/
public static XPathQueryResult processXPath(String data, String transform) throws Exception {
public XPathQueryResult processXPath(String data, String transform, String version) throws Exception {
// Set up a DOM tree to query.
InputSource in = new InputSource(new StringReader(data));
@@ -112,7 +112,7 @@ public class Xalan {
* Returns version of the processor
* @return version of the processor
*/
public static String getVersion(){
public String getVersion(){
return org.apache.xalan.Version.getVersion();
}
@@ -123,7 +123,7 @@ public class Xalan {
* @return statement of validity
* @throws Exception thrown on invalid xsd schema or xml
*/
public static String validate(String data, String xsd) throws Exception{
public String validate(String data, String xsd) throws Exception {
Source dataSource = new StreamSource(new StringReader(data));
Source xsdSource = new StreamSource(new StringReader(xsd));
SchemaFactory schemaFactory = SchemaFactory

View File

@@ -3,9 +3,9 @@ package com.r11.tools.xml;
import com.r11.tools.controller.internal.XPathQueryResult;
public interface XmlEngine {
XPathQueryResult processXPath(String data, String query, String version);
String processXSLT(String data, String transform);
String validate(String data, String xsd);
XPathQueryResult processXPath(String data, String query, String version) throws Exception;
String processXSLT(String data, String transform) throws Exception;
String validate(String data, String xsd) throws Exception;
public String getVersion();