Merge branch 'master' of gitea.release11.com:R11/release11-tools
This commit is contained in:
@@ -54,12 +54,12 @@ def xpath(source: str, xpath: str) -> str:
|
|||||||
# root.xpath can return 4 types: float, string, bool and list.
|
# root.xpath can return 4 types: float, string, bool and list.
|
||||||
# List is the only one that can't be simply converted to str
|
# List is the only one that can't be simply converted to str
|
||||||
if type(result) is not list:
|
if type(result) is not list:
|
||||||
return str(result)
|
return str(result), type(result).__name__
|
||||||
else:
|
else:
|
||||||
result_string = ""
|
result_string = ""
|
||||||
for e in result:
|
for e in result:
|
||||||
result_string += etree.tostring(e, pretty_print=True).decode() + "\n"
|
result_string += etree.tostring(e, pretty_print=True).decode() + "\n"
|
||||||
return result_string
|
return result_string, "node"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def process_xml(request: request, type: str) -> str:
|
|||||||
elif (type == "xslt"):
|
elif (type == "xslt"):
|
||||||
response_json['result'] = Parser.xslt(data, process)
|
response_json['result'] = Parser.xslt(data, process)
|
||||||
elif (type == "xpath"):
|
elif (type == "xpath"):
|
||||||
response_json['result'] = Parser.xpath(data, process)
|
response_json['result'], response_json['type'] = Parser.xpath(data, process)
|
||||||
elif (type == "prettify"):
|
elif (type == "prettify"):
|
||||||
response_json['result'] = Parser.formatXML(data, True)
|
response_json['result'] = Parser.formatXML(data, True)
|
||||||
elif (type == "minimize"):
|
elif (type == "minimize"):
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ package com.r11.tools.controller;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.r11.tools.controller.internal.GlobalControllerManifest;
|
import com.r11.tools.controller.internal.*;
|
||||||
import com.r11.tools.controller.internal.HandlerType;
|
|
||||||
import com.r11.tools.controller.internal.RestController;
|
|
||||||
import com.r11.tools.controller.internal.ScopedControllerManifest;
|
|
||||||
import com.r11.tools.xml.Saxon;
|
import com.r11.tools.xml.Saxon;
|
||||||
import com.r11.tools.xml.Xalan;
|
import com.r11.tools.xml.Xalan;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -63,7 +60,7 @@ public class XPathController implements RestController {
|
|||||||
timeStart = System.currentTimeMillis();
|
timeStart = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tmp = Saxon.processXPath(data, query, version).trim();
|
tmp = Saxon.processXPath(data, query, version).getData().trim();
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
@@ -92,12 +89,13 @@ public class XPathController implements RestController {
|
|||||||
timeStart = System.currentTimeMillis();
|
timeStart = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tmp = Xalan.processXPath(data, query).trim();
|
XPathQueryResult xPathQueryResult = Xalan.processXPath(data, query);
|
||||||
|
|
||||||
response.status(200);
|
response.status(200);
|
||||||
|
|
||||||
responseJson.addProperty("result", tmp);
|
responseJson.addProperty("result", xPathQueryResult.getData().trim());
|
||||||
responseJson.addProperty("status", "OK");
|
responseJson.addProperty("status", "OK");
|
||||||
|
responseJson.addProperty("type", xPathQueryResult.getType());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
this.logger.error("Error on processing XPath using Xalan. " + ex);
|
this.logger.error("Error on processing XPath using Xalan. " + ex);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.r11.tools.controller.internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used to store data received from parser and type of that data (node, string, etc.)
|
||||||
|
*/
|
||||||
|
public class XPathQueryResult {
|
||||||
|
private String data;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public XPathQueryResult(String data, String type) {
|
||||||
|
this.data = data;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.r11.tools.xml;
|
package com.r11.tools.xml;
|
||||||
|
|
||||||
|
import com.r11.tools.controller.internal.XPathQueryResult;
|
||||||
import net.sf.saxon.s9api.*;
|
import net.sf.saxon.s9api.*;
|
||||||
|
|
||||||
import javax.xml.transform.stream.StreamSource;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
@@ -41,7 +42,7 @@ public class Saxon {
|
|||||||
* @return string xml representation of the node
|
* @return string xml representation of the node
|
||||||
* @throws Exception thrown on node building errors or invalid xpath
|
* @throws Exception thrown on node building errors or invalid xpath
|
||||||
*/
|
*/
|
||||||
public static String processXPath(String data, String query, String version) throws Exception {
|
public static XPathQueryResult processXPath(String data, String query, String version) throws Exception {
|
||||||
Processor p = new Processor(false);
|
Processor p = new Processor(false);
|
||||||
XPathCompiler compiler = p.newXPathCompiler();
|
XPathCompiler compiler = p.newXPathCompiler();
|
||||||
DocumentBuilder builder = p.newDocumentBuilder();
|
DocumentBuilder builder = p.newDocumentBuilder();
|
||||||
@@ -61,7 +62,7 @@ public class Saxon {
|
|||||||
sb.append(xdmItem);
|
sb.append(xdmItem);
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return new XPathQueryResult(sb.toString(), "N/A");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.r11.tools.xml;
|
package com.r11.tools.xml;
|
||||||
|
|
||||||
|
import com.r11.tools.controller.internal.XPathQueryResult;
|
||||||
import org.apache.xpath.XPathAPI;
|
import org.apache.xpath.XPathAPI;
|
||||||
import org.apache.xpath.objects.XObject;
|
import org.apache.xpath.objects.XObject;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -64,7 +65,7 @@ public class Xalan {
|
|||||||
* @return xml processed using given xpath
|
* @return xml processed using given xpath
|
||||||
* @throws Exception thrown on node building errors or invalid xpath
|
* @throws Exception thrown on node building errors or invalid xpath
|
||||||
*/
|
*/
|
||||||
public static String processXPath(String data, String transform) throws Exception {
|
public static XPathQueryResult processXPath(String data, String transform) throws Exception {
|
||||||
|
|
||||||
// Set up a DOM tree to query.
|
// Set up a DOM tree to query.
|
||||||
InputSource in = new InputSource(new StringReader(data));
|
InputSource in = new InputSource(new StringReader(data));
|
||||||
@@ -81,7 +82,7 @@ public class Xalan {
|
|||||||
NodeIterator nl = XPathAPI.selectNodeIterator(doc, transform);
|
NodeIterator nl = XPathAPI.selectNodeIterator(doc, transform);
|
||||||
|
|
||||||
// Serialize the found nodes to result object.
|
// Serialize the found nodes to result object.
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder resultString = new StringBuilder();
|
||||||
Node n;
|
Node n;
|
||||||
while ((n = nl.nextNode())!= null) {
|
while ((n = nl.nextNode())!= null) {
|
||||||
StringBuilder sb;
|
StringBuilder sb;
|
||||||
@@ -90,18 +91,19 @@ public class Xalan {
|
|||||||
// single XPath text node. Coalesce all contiguous text nodes
|
// single XPath text node. Coalesce all contiguous text nodes
|
||||||
// at this level
|
// at this level
|
||||||
for (Node nn = n.getNextSibling(); isTextNode(nn); nn = nn.getNextSibling()) {
|
for (Node nn = n.getNextSibling(); isTextNode(nn); nn = nn.getNextSibling()) {
|
||||||
result.append(nn.getNodeValue());
|
resultString.append(nn.getNodeValue());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
serializer.transform(new DOMSource(n), new StreamResult(new OutputStreamWriter(outputStream)));
|
serializer.transform(new DOMSource(n), new StreamResult(new OutputStreamWriter(outputStream)));
|
||||||
result.append(outputStream);
|
resultString.append(outputStream);
|
||||||
}
|
}
|
||||||
result.append("\n");
|
resultString.append("\n");
|
||||||
}
|
}
|
||||||
return result.toString();
|
return new XPathQueryResult(resultString.toString(), "node");
|
||||||
} catch (TransformerException e) {
|
} catch (TransformerException e) {
|
||||||
return XPathAPI.eval(doc, transform).toString();
|
String returnData = XPathAPI.eval(doc, transform).toString();
|
||||||
|
return new XPathQueryResult(data, "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
Frontend/assets/samples/XSLTTemplate.xslt
Normal file
14
Frontend/assets/samples/XSLTTemplate.xslt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
xmlns:b="http://www.release11.com/book" xmlns:p="http://www.release11.com/person"
|
||||||
|
xmlns:l="http://www.release11.com/library">
|
||||||
|
<xsl:template match="/">
|
||||||
|
<Library>
|
||||||
|
<ReaderCount>
|
||||||
|
<xsl:value-of select="count(//p:person)" />
|
||||||
|
</ReaderCount>
|
||||||
|
<BookCount>
|
||||||
|
<xsl:value-of select="count(/l:library/l:bookList/b:book)" />
|
||||||
|
</BookCount>
|
||||||
|
</Library>
|
||||||
|
</xsl:template>
|
||||||
|
</xsl:stylesheet>
|
||||||
@@ -84,6 +84,24 @@ function fillDefaultXML(element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `fillDefaultXSLT()` function fetches a default XSLT template from the server and sets the value of the element with id "transformArea" to the fetched template.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @name fillDefaultXSLT
|
||||||
|
* @kind function
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function fillDefaultXSLT() {
|
||||||
|
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
|
||||||
|
fetch(serverAddress + "/assets/samples/XSLTTemplate.xslt")
|
||||||
|
.then( response => response.text() )
|
||||||
|
.then( (XSTLTemplate) => {
|
||||||
|
document.getElementById('transformArea').value = XSTLTemplate;
|
||||||
|
} )
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It sets default content for the element an changes it's color to grey
|
* It sets default content for the element an changes it's color to grey
|
||||||
*
|
*
|
||||||
@@ -244,9 +262,12 @@ function performRequest(endpoint, checkXML, checkTransform) {
|
|||||||
if (!empty) {
|
if (!empty) {
|
||||||
restRequest(port, endpoint, xmlData, transformData).then(function (result) {
|
restRequest(port, endpoint, xmlData, transformData).then(function (result) {
|
||||||
document.getElementById("resultArea").value = result.result;
|
document.getElementById("resultArea").value = result.result;
|
||||||
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
|
document.getElementById("procinfo").innerText = ' Computed using ' + result.processor
|
||||||
|
if (result.type)
|
||||||
|
document.getElementById("procinfo").innerText += ". Returned: " + result.type;
|
||||||
|
|
||||||
if (result.status = "OK") {
|
if (result.status = "OK") {
|
||||||
document.getElementById("procinfo").innerText = document.getElementById("procinfo").innerText.concat(" in ", result.time, "ms");
|
document.getElementById("procinfo").innerText += " in " + result.time + "ms";
|
||||||
procinfo.style.color = "#30aa58";
|
procinfo.style.color = "#30aa58";
|
||||||
} else {
|
} else {
|
||||||
procinfo.style.color = "#aa3030";
|
procinfo.style.color = "#aa3030";
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<option value="libxml">libXML</option>
|
<option value="libxml">libXML</option>
|
||||||
</select>
|
</select>
|
||||||
<select name="versions" id="versions" style="display: none;">
|
<select name="versions" id="versions" style="display: none;">
|
||||||
<option class="hideable libxml xalan"value="1.0">1.0</option>
|
<option class="hideable libxml xalan" value="1.0">1.0</option>
|
||||||
<option class="hideable saxon" value="2.0">2.0</option>
|
<option class="hideable saxon" value="2.0">2.0</option>
|
||||||
<option class="hideable saxon" value="3.0">3.0</option>
|
<option class="hideable saxon" value="3.0">3.0</option>
|
||||||
<option class="hideable saxon" value="3.1">3.1</option>
|
<option class="hideable saxon" value="3.1">3.1</option>
|
||||||
@@ -51,7 +51,14 @@
|
|||||||
onfocus="clearDefaultContent(this, 'Insert XML here');"></textarea>
|
onfocus="clearDefaultContent(this, 'Insert XML here');"></textarea>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<label for="transformArea"><b>Insert your XSLT:</b></label>
|
<div class="display-space-between">
|
||||||
|
<label for="transformArea"><b>Insert your XSLT:</b></label>
|
||||||
|
<div>
|
||||||
|
<button class="action-button active" id="defaultXSLTButton" style="padding: 3px 10px;"
|
||||||
|
onclick="fillDefaultXSLT()">Insert default XSLT
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<textarea id="transformArea" name="transformArea" rows="15"
|
<textarea id="transformArea" name="transformArea" rows="15"
|
||||||
class="textarea-300 bordered-field vertically-resizeable max-width"
|
class="textarea-300 bordered-field vertically-resizeable max-width"
|
||||||
onblur="setDefaultContent(this, 'Insert XSLT here');"
|
onblur="setDefaultContent(this, 'Insert XSLT here');"
|
||||||
@@ -1144,7 +1151,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function processTooltip() {
|
function processTooltip() {
|
||||||
|
|
||||||
if (getProcessor() == "xalan" || getProcessor() == "libxml") {
|
if (getProcessor() == "xalan" || getProcessor() == "libxml") {
|
||||||
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0 functions";
|
document.getElementById("tooltipFunctionInfo").innerText = "XSLT 1.0 functions";
|
||||||
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT 1.0";
|
document.getElementById("processorTooltipInfo").innerText = "Supports XSLT 1.0";
|
||||||
@@ -1158,9 +1165,9 @@
|
|||||||
|
|
||||||
var triggerList = document.getElementsByClassName("collapseTrigger");
|
var triggerList = document.getElementsByClassName("collapseTrigger");
|
||||||
for (i = 0; i < triggerList.length; i++) {
|
for (i = 0; i < triggerList.length; i++) {
|
||||||
|
|
||||||
triggerList[i].addEventListener("click", function () {
|
triggerList[i].addEventListener("click", function () {
|
||||||
|
|
||||||
var collapsible = this.parentElement;
|
var collapsible = this.parentElement;
|
||||||
var collapsibleData = this.nextElementSibling;
|
var collapsibleData = this.nextElementSibling;
|
||||||
if (collapsibleData.style.maxHeight > "0px") {
|
if (collapsibleData.style.maxHeight > "0px") {
|
||||||
@@ -1197,7 +1204,7 @@
|
|||||||
//Handle clicks in whole form and set info in tooltip
|
//Handle clicks in whole form and set info in tooltip
|
||||||
setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here');
|
setDefaultContent(document.getElementById("xmlArea"), 'Insert XML here');
|
||||||
setDefaultContent(document.getElementById("transformArea"), 'Insert XSLT here');
|
setDefaultContent(document.getElementById("transformArea"), 'Insert XSLT here');
|
||||||
|
|
||||||
// refreshTooltip();
|
// refreshTooltip();
|
||||||
processTooltip();
|
processTooltip();
|
||||||
tool.addEventListener('click', event => {
|
tool.addEventListener('click', event => {
|
||||||
|
|||||||
Reference in New Issue
Block a user