Compare commits
4 Commits
bdb807d3e0
...
Add_xslt_p
| Author | SHA1 | Date | |
|---|---|---|---|
| 75db025d80 | |||
| d33ac7e9f8 | |||
| bbae61da42 | |||
| 1d5038ca51 |
@@ -68,7 +68,7 @@ public class MultipleXMLController implements RestController {
|
|||||||
private XMLResponseBody processData(MultipleXmlJob xmlJob) throws Exception {
|
private XMLResponseBody processData(MultipleXmlJob xmlJob) throws Exception {
|
||||||
XmlEngine engine = xmlJob.getEngine();
|
XmlEngine engine = xmlJob.getEngine();
|
||||||
XMLMultipleFilesBody requestBody = xmlJob.getRequestBody();
|
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());
|
return new XMLResponseBody(result, "OK", requestBody.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,6 +2,8 @@ package com.r11.tools.model;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class XMLMultipleFilesBody {
|
public class XMLMultipleFilesBody {
|
||||||
|
|
||||||
@SerializedName("data")
|
@SerializedName("data")
|
||||||
@@ -12,6 +14,8 @@ public class XMLMultipleFilesBody {
|
|||||||
private String processor;
|
private String processor;
|
||||||
@SerializedName("version")
|
@SerializedName("version")
|
||||||
private String version;
|
private String version;
|
||||||
|
@SerializedName("params")
|
||||||
|
private List<Param> params;
|
||||||
|
|
||||||
|
|
||||||
public String getProcessorData() {
|
public String getProcessorData() {
|
||||||
@@ -29,4 +33,9 @@ public class XMLMultipleFilesBody {
|
|||||||
public XMLMultipleFilesData[] getData() {
|
public XMLMultipleFilesData[] getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Param> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,5 @@ public class XMLRequestBody {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Param {
|
|
||||||
@SerializedName("key")
|
|
||||||
private String key;
|
|
||||||
@SerializedName("value")
|
|
||||||
private String value;
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class XmlTools {
|
|||||||
param.setAttribute(valueAttribute, "'" + paramValue + "'");
|
param.setAttribute(valueAttribute, "'" + paramValue + "'");
|
||||||
doc.getDocumentElement().appendChild(param);
|
doc.getDocumentElement().appendChild(param);
|
||||||
}
|
}
|
||||||
public String addParams(List<XMLRequestBody.Param> params,String processorData) {
|
public String addParams(List<Param> params,String processorData) {
|
||||||
params.forEach(param ->
|
params.forEach(param ->
|
||||||
createdParameters.put(param.getKey(), param.getValue())
|
createdParameters.put(param.getKey(), param.getValue())
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.r11.tools.xml;
|
package com.r11.tools.xml;
|
||||||
|
|
||||||
|
import com.r11.tools.model.Param;
|
||||||
import com.r11.tools.model.XMLMultipleFilesData;
|
import com.r11.tools.model.XMLMultipleFilesData;
|
||||||
import com.r11.tools.model.XMLRequestBody;
|
import com.r11.tools.model.XMLRequestBody;
|
||||||
import com.r11.tools.model.XPathQueryResult;
|
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.
|
* @throws IOException thrown when file does not exist, or cannot be read.
|
||||||
*/
|
*/
|
||||||
XmlTools tools = new XmlTools();
|
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);
|
Processor processor = new Processor(false);
|
||||||
XsltCompiler compiler = processor.newXsltCompiler();
|
XsltCompiler compiler = processor.newXsltCompiler();
|
||||||
|
|
||||||
// transform = tools.addParams(params,transform);
|
transform = tools.addParams(params,transform);
|
||||||
|
|
||||||
String filesPath = "/tmp/"+UUID.randomUUID()+"/";
|
String filesPath = "/tmp/"+UUID.randomUUID()+"/";
|
||||||
try{
|
try{
|
||||||
@@ -91,7 +92,7 @@ public class Saxon implements XmlEngine{
|
|||||||
* @return transformed xml
|
* @return transformed xml
|
||||||
* @throws SaxonApiException thrown on stylesheet or transformation errors
|
* @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);
|
Processor processor = new Processor(false);
|
||||||
XsltCompiler compiler = processor.newXsltCompiler();
|
XsltCompiler compiler = processor.newXsltCompiler();
|
||||||
transform = tools.addParams(params,transform);
|
transform = tools.addParams(params,transform);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.r11.tools.xml;
|
package com.r11.tools.xml;
|
||||||
|
|
||||||
|
import com.r11.tools.model.Param;
|
||||||
import com.r11.tools.model.XMLMultipleFilesData;
|
import com.r11.tools.model.XMLMultipleFilesData;
|
||||||
import com.r11.tools.model.XMLRequestBody;
|
import com.r11.tools.model.XMLRequestBody;
|
||||||
import com.r11.tools.model.XPathQueryResult;
|
import com.r11.tools.model.XPathQueryResult;
|
||||||
@@ -41,7 +42,7 @@ public class Xalan implements XmlEngine{
|
|||||||
* @return transformed xml
|
* @return transformed xml
|
||||||
* @throws Exception thrown on stylesheet or transformation errors
|
* @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();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
Document document = builder.parse(new InputSource(new StringReader(data)));
|
Document document = builder.parse(new InputSource(new StringReader(data)));
|
||||||
@@ -69,7 +70,7 @@ public class Xalan implements XmlEngine{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
throw new UnsupportedOperationException("Xalan does not support multiple files XSLT processing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package com.r11.tools.xml;
|
package com.r11.tools.xml;
|
||||||
|
|
||||||
|
import com.r11.tools.model.Param;
|
||||||
import com.r11.tools.model.XMLMultipleFilesData;
|
import com.r11.tools.model.XMLMultipleFilesData;
|
||||||
import com.r11.tools.model.XMLRequestBody;
|
|
||||||
import com.r11.tools.model.XPathQueryResult;
|
import com.r11.tools.model.XPathQueryResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface XmlEngine {
|
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;
|
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 validate(String data, String xsd) throws Exception;
|
||||||
String executeXQuery(String data, String xquery, String version) throws Exception;
|
String executeXQuery(String data, String xquery, String version) throws Exception;
|
||||||
public String getVersion();
|
public String getVersion();
|
||||||
|
|||||||
@@ -13,99 +13,51 @@ const sendToParent = () => {
|
|||||||
options.value.forEach((value) => {console.log("KID" + value + options.value.indexOf(value))})
|
options.value.forEach((value) => {console.log("KID" + value + options.value.indexOf(value))})
|
||||||
emit('update-value', options.value);
|
emit('update-value', options.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const nameInput = ref('')
|
const nameInput = ref('')
|
||||||
const valueInput = ref('')
|
const valueInput = ref('')
|
||||||
|
|
||||||
|
|
||||||
const selectedOption = ref(options.value[0].name)
|
const selectedOption = ref(options.value[0].name)
|
||||||
|
|
||||||
|
const isNumeric = (string : string) => /^[+-]?\d+(\.\d+)?$/.test(string)
|
||||||
|
|
||||||
const selectedFunction = () => {
|
const selectedFunction = () => {
|
||||||
if (selectOption(selectedOption.value) === 'Add Param') {
|
const action = selectOption(selectedOption.value);
|
||||||
options.value.push({name: nameInput.value + " = " + valueInput.value});
|
const name = nameInput.value.trim();
|
||||||
|
const value = valueInput.value.trim();
|
||||||
|
|
||||||
|
if (action === "Add Param" && name && value && !isNumeric(name)) {
|
||||||
|
options.value.push({ name: `${name} = ${value}` });
|
||||||
|
nameInput.value = valueInput.value = "";
|
||||||
}
|
}
|
||||||
if (selectOption(selectedOption.value) === 'Remove Param') {
|
|
||||||
const foundOption = options.value.find(option => option.name === selectedOption.value);
|
if (action === "Remove Param") {
|
||||||
if (foundOption) {
|
options.value = options.value.filter(option => option.name !== selectedOption.value);
|
||||||
const currentIndex = options.value.indexOf(foundOption);
|
selectedOption.value = options.value.length ? options.value[0].name : "";
|
||||||
if (currentIndex !== -1) {
|
nameInput.value = valueInput.value = "";
|
||||||
options.value.splice(currentIndex, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (options.value.length > 0) {
|
|
||||||
selectedOption.value = options.value[0].name;
|
|
||||||
} else {
|
|
||||||
selectedOption.value = "";
|
|
||||||
}
|
|
||||||
valueInput.value = "";
|
|
||||||
nameInput.value = "";
|
|
||||||
}
|
}
|
||||||
sendToParent()
|
sendToParent();
|
||||||
/*
|
};
|
||||||
|
|
||||||
if(selectedOption.value === "Add Param") {
|
|
||||||
sendRequest("add");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sendRequest("remove");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
const sendRequest = (type:string) => {
|
|
||||||
console.log(type)
|
|
||||||
let request: Request = prepareRequest(type)
|
|
||||||
fetchRequest(request).then((body) => {
|
|
||||||
|
|
||||||
const {status} = body as any;
|
|
||||||
console.log(status)
|
|
||||||
if (status === "OK") {
|
|
||||||
options.value.push({ name: nameInput.value + " = " + valueInput.value });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
function selectOption(option: string): string {
|
function selectOption(option: string): string {
|
||||||
return option == "Add Param" ? "Add Param" : "Remove Param"
|
return option == "Add Param" ? "Add Param" : "Remove Param"
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// function prepareRequest(type :string): Request {
|
|
||||||
// let request = new Request(prepareURL(), {
|
|
||||||
// body: prepareRequestBody(type),
|
|
||||||
// method: "POST"
|
|
||||||
// });
|
|
||||||
// return request
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// function prepareURL(): string {
|
|
||||||
// //const engineEndpoint = engine.value == "libxml" ? "libxml" : "java";
|
|
||||||
// return document.location.protocol + "//" + document.location.hostname + "/" + "java" + "/xslt/param";
|
|
||||||
// //return "http://localhost:8081/xslt/param";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// function prepareRequestBody(type: string): string {
|
|
||||||
// let requestBody = JSON.stringify({
|
|
||||||
// "paramName": nameInput.value,
|
|
||||||
// "paramValue": valueInput.value,
|
|
||||||
// "type": type
|
|
||||||
// });
|
|
||||||
// console.log(requestBody);
|
|
||||||
// return requestBody;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// async function fetchRequest(request: Request): Promise<JSON> {
|
|
||||||
// console.log(request)
|
|
||||||
// let responseBody = await fetch(request)
|
|
||||||
// return await responseBody.json()
|
|
||||||
// }
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<input
|
||||||
|
v-if="selectedOption==='Add Param'"
|
||||||
|
id="NameTextInput"
|
||||||
|
v-model="nameInput"
|
||||||
|
class="text-input h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-48"
|
||||||
|
type="text"
|
||||||
|
placeholder="Name"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
v-if="selectedOption==='Add Param'"
|
||||||
|
id="ValueTextInput"
|
||||||
|
v-model="valueInput"
|
||||||
|
class="text-input h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-48"
|
||||||
|
type="text"
|
||||||
|
placeholder="Value"
|
||||||
|
/>
|
||||||
<select
|
<select
|
||||||
v-model="selectedOption"
|
v-model="selectedOption"
|
||||||
class="flex h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-48"
|
class="flex h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-48"
|
||||||
@@ -114,22 +66,7 @@ function selectOption(option: string): string {
|
|||||||
{{ option.name }}
|
{{ option.name }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<input
|
<button class="tool-button w-24" @click="selectedFunction">{{ selectOption(selectedOption) }}</button>
|
||||||
v-if="selectedOption==='Add Param'"
|
|
||||||
id="NameTextInput"
|
|
||||||
v-model="nameInput"
|
|
||||||
class="text-input h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-1/3"
|
|
||||||
type="text"
|
|
||||||
placeholder="Name"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
v-if="selectedOption==='Add Param'"
|
|
||||||
id="ValueTextInput"
|
|
||||||
v-model="valueInput"
|
|
||||||
class="text-input h-full px-3 rounded-full border border-slate-400 bg-white dark:text-slate-100 dark:bg-gray-600 w-1/3"
|
|
||||||
type="text"
|
|
||||||
placeholder="Value"
|
|
||||||
/>
|
|
||||||
<button class="tool-button" @click="selectedFunction">{{ selectOption(selectedOption) }}</button>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const emit = defineEmits(["update"]);
|
|||||||
const result = ref('');
|
const result = ref('');
|
||||||
|
|
||||||
let enginesForCurrentTool = ref(["saxon", "xalan", "libxml"]);
|
let enginesForCurrentTool = ref(["saxon", "xalan", "libxml"]);
|
||||||
|
const formattedParams = ref();
|
||||||
|
|
||||||
|
|
||||||
const allVersions = ["1.0", "2.0", "3.0", "3.1"];
|
const allVersions = ["1.0", "2.0", "3.0", "3.1"];
|
||||||
let versionsForCurrentEngine = ref([""]);
|
let versionsForCurrentEngine = ref([""]);
|
||||||
@@ -100,6 +102,7 @@ function updateOutputField(data: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function prepareRequest():Request {
|
function prepareRequest():Request {
|
||||||
|
formattedParams.value = formatParams()
|
||||||
let request = new Request(prepareURL(), {
|
let request = new Request(prepareURL(), {
|
||||||
body: selectRequestBodyType(),
|
body: selectRequestBodyType(),
|
||||||
method: "POST"
|
method: "POST"
|
||||||
@@ -135,10 +138,8 @@ function formatParams() {
|
|||||||
|
|
||||||
function prepareRequestBodySingleXml(data: string):string {
|
function prepareRequestBodySingleXml(data: string):string {
|
||||||
|
|
||||||
const formattedParams = formatParams();
|
|
||||||
|
|
||||||
let requestBody = JSON.stringify({
|
let requestBody = JSON.stringify({
|
||||||
"params": formattedParams,
|
"params": formattedParams.value,
|
||||||
"data": data,
|
"data": data,
|
||||||
"processorData": props.query,
|
"processorData": props.query,
|
||||||
"processor": engine.value,
|
"processor": engine.value,
|
||||||
@@ -149,12 +150,14 @@ function prepareRequestBodySingleXml(data: string):string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function prepareRequestBodyMultiXml():string {
|
function prepareRequestBodyMultiXml():string {
|
||||||
if (!Array.isArray(props.xml))
|
|
||||||
|
if (!Array.isArray(props.xml))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
let xmlFilesArray = convertDataArray(props.xml);
|
let xmlFilesArray = convertDataArray(props.xml);
|
||||||
|
|
||||||
let requestBody = JSON.stringify({
|
let requestBody = JSON.stringify({
|
||||||
|
"params": formattedParams.value,
|
||||||
"data": xmlFilesArray,
|
"data": xmlFilesArray,
|
||||||
"processorData": props.query,
|
"processorData": props.query,
|
||||||
"processor": engine.value,
|
"processor": engine.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user