Added params functionalities to multipleXml, bugfix

This commit is contained in:
2025-02-04 17:41:22 +01:00
parent bdb807d3e0
commit 1d5038ca51
8 changed files with 67 additions and 28 deletions

View File

@@ -68,7 +68,7 @@ public class MultipleXMLController implements RestController {
private XMLResponseBody processData(MultipleXmlJob xmlJob) throws Exception {
XmlEngine engine = xmlJob.getEngine();
XMLMultipleFilesBody requestBody = xmlJob.getRequestBody();
String result = engine.processXSLT(requestBody.getData(), requestBody.getProcessorData());
String result = engine.processXSLT(requestBody.getParams(), requestBody.getData(), requestBody.getProcessorData());
return new XMLResponseBody(result, "OK", requestBody.getVersion());
}

View File

@@ -0,0 +1,20 @@
package com.r11.tools.model;
import com.google.gson.annotations.SerializedName;
public class Param {
@SerializedName("key")
private String key;
@SerializedName("value")
private String value;
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}

View File

@@ -2,6 +2,8 @@ package com.r11.tools.model;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class XMLMultipleFilesBody {
@SerializedName("data")
@@ -12,6 +14,8 @@ public class XMLMultipleFilesBody {
private String processor;
@SerializedName("version")
private String version;
@SerializedName("params")
private List<Param> params;
public String getProcessorData() {
@@ -29,4 +33,9 @@ public class XMLMultipleFilesBody {
public XMLMultipleFilesData[] getData() {
return data;
}
public List<Param> getParams() {
return params;
}
}

View File

@@ -1,5 +1,6 @@
package com.r11.tools.xml;
import com.r11.tools.model.Param;
import com.r11.tools.model.XMLMultipleFilesData;
import com.r11.tools.model.XMLRequestBody;
import com.r11.tools.model.XPathQueryResult;
@@ -30,11 +31,11 @@ public class Saxon implements XmlEngine{
* @throws IOException thrown when file does not exist, or cannot be read.
*/
XmlTools tools = new XmlTools();
public String processXSLT(XMLMultipleFilesData[] data, String transform) throws SaxonApiException, IOException{
public String processXSLT(List<Param> params, XMLMultipleFilesData[] data, String transform) throws SaxonApiException, IOException{
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
// transform = tools.addParams(params,transform);
transform = tools.addParams(params,transform);
String filesPath = "/tmp/"+UUID.randomUUID()+"/";
try{
@@ -91,7 +92,7 @@ public class Saxon implements XmlEngine{
* @return transformed xml
* @throws SaxonApiException thrown on stylesheet or transformation errors
*/
public String processXSLT(List<XMLRequestBody.Param> params, String data, String transform) throws SaxonApiException {
public String processXSLT(List<Param> params, String data, String transform) throws SaxonApiException {
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
transform = tools.addParams(params,transform);

View File

@@ -1,5 +1,6 @@
package com.r11.tools.xml;
import com.r11.tools.model.Param;
import com.r11.tools.model.XMLMultipleFilesData;
import com.r11.tools.model.XMLRequestBody;
import com.r11.tools.model.XPathQueryResult;
@@ -41,7 +42,7 @@ public class Xalan implements XmlEngine{
* @return transformed xml
* @throws Exception thrown on stylesheet or transformation errors
*/
public String processXSLT(List<XMLRequestBody.Param> params, String data, String transform) throws Exception {
public String processXSLT(List<Param> params, String data, String transform) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(data)));
@@ -69,7 +70,7 @@ public class Xalan implements XmlEngine{
}
@Override
public String processXSLT(XMLMultipleFilesData[] data, String transform) throws Exception {
public String processXSLT(List<Param> params, XMLMultipleFilesData[] data, String transform) throws Exception {
throw new UnsupportedOperationException("Xalan does not support multiple files XSLT processing");
}

View File

@@ -1,16 +1,16 @@
package com.r11.tools.xml;
import com.r11.tools.model.Param;
import com.r11.tools.model.XMLMultipleFilesData;
import com.r11.tools.model.XMLRequestBody;
import com.r11.tools.model.XPathQueryResult;
import java.util.List;
public interface XmlEngine {
String processXSLT(XMLMultipleFilesData[] data, String transform) throws Exception;
String processXSLT(List<Param> params, XMLMultipleFilesData[] data, String transform) throws Exception;
XPathQueryResult processXPath(String data, String query, String version) throws Exception;
String processXSLT(List<XMLRequestBody.Param> params, String data, String transform) throws Exception;
String processXSLT(List<Param> params, String data, String transform) throws Exception;
String validate(String data, String xsd) throws Exception;
String executeXQuery(String data, String xquery, String version) throws Exception;
public String getVersion();