Merge branch 'master' of gitea.release11.com:R11/release11-tools into widlam/refactor/issue#162

This commit is contained in:
2023-05-12 10:07:03 +02:00
34 changed files with 100 additions and 117 deletions

View File

@@ -1,27 +0,0 @@
package com.r11.tools.controller;
import lombok.SneakyThrows;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* Class responsible for returning homepage html
* @author Gabriel Modzelewski
*/
@Controller
@RequestMapping("/")
public class MainController {
/**
* Default path to get the homepage
* @return the view of homepage
*/
@SneakyThrows
@GetMapping
public ModelAndView showHome(){
ModelAndView mov = new ModelAndView();
mov.setViewName("html/mock");
return mov;
}
}

View File

@@ -8,6 +8,9 @@ import com.r11.tools.controller.XPathController;
import com.r11.tools.controller.XsdController;
import com.r11.tools.controller.XsltController;
import com.r11.tools.controller.internal.RestControllerRegistry;
import com.r11.tools.xml.Saxon;
import com.r11.tools.xml.Xalan;
import com.r11.tools.xml.XmlEngine;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import spark.Spark;
@@ -35,12 +38,15 @@ public class SparkApplication {
Gson jsongson = new GsonBuilder()
.disableHtmlEscaping()
.create();
XmlEngine saxon = new Saxon();
XmlEngine xalan = new Xalan();
RestControllerRegistry registry = new RestControllerRegistry();
registry.registerController(new ProcessorInfoController(logger));
registry.registerController(new XsdController(gson, logger));
registry.registerController(new XPathController(gson, logger));
registry.registerController(new XsltController(gson, logger));
registry.registerController(new ProcessorInfoController(logger, saxon, xalan));
registry.registerController(new XsdController(gson, logger, saxon, xalan));
registry.registerController(new XPathController(gson, logger, saxon, xalan));
registry.registerController(new XsltController(gson, logger, saxon, xalan));
registry.registerController(new JsonController(gson, jsongson, logger));
registry.register();

View File

@@ -5,6 +5,7 @@ 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.XmlEngine;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;
@@ -13,9 +14,13 @@ import spark.Response;
public class ProcessorInfoController implements RestController {
private final Logger logger;
private final XmlEngine saxon;
private final XmlEngine xalan;
public ProcessorInfoController(Logger logger) {
public ProcessorInfoController(Logger logger, XmlEngine saxon, XmlEngine xalan) {
this.logger = logger;
this.saxon = saxon;
this.xalan = xalan;
}
/**
@@ -24,8 +29,8 @@ public class ProcessorInfoController implements RestController {
@ScopedControllerManifest(method = HandlerType.GET, path = "/procinfo")
public void processorInfo(Request request, Response response) {
try {
response.header("processor", "Saxon " + Saxon.getVersion() + " over s9api");
response.body(Saxon.getVersion());
response.header("processor", "Saxon " + saxon.getVersion() + " over s9api");
response.body(saxon.getVersion());
} catch (Exception ex) {
this.logger.error("Error on retrieving engine version. " + ex);
response.body(ex.getMessage());

View File

@@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
import com.r11.tools.controller.internal.*;
import com.r11.tools.xml.Saxon;
import com.r11.tools.xml.Xalan;
import com.r11.tools.xml.XmlEngine;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;
@@ -15,9 +16,14 @@ public class XPathController implements RestController {
private final Gson gson;
private final Logger logger;
public XPathController(Gson gson, Logger logger) {
private final XmlEngine saxon;
private final XmlEngine xalan;
public XPathController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
this.gson = gson;
this.logger = logger;
this.saxon = saxon;
this.xalan = xalan;
}
@ScopedControllerManifest(method = HandlerType.POST, path = "/xpath")
@@ -56,11 +62,11 @@ public class XPathController implements RestController {
JsonObject responseJson = new JsonObject();
switch (processor) {
case "saxon":
response.header("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
response.header("processor", "Saxon " + saxon.getVersion() + " " + version + " over s9api");
timeStart = System.currentTimeMillis();
try {
tmp = Saxon.processXPath(data, query, version).getData().trim();
tmp = saxon.processXPath(data, query, version).getData().trim();
response.status(200);
@@ -78,18 +84,18 @@ public class XPathController implements RestController {
duration = System.currentTimeMillis() - timeStart;
this.logger.info("Request (XPath, Saxon) processed in " + duration + " ms.");
responseJson.addProperty("processor", "Saxon " + Saxon.getVersion() + " " + version + " over s9api");
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version + " over s9api");
responseJson.addProperty("time", duration);
response.body(this.gson.toJson(responseJson));
return;
case "xalan":
response.header("processor", Xalan.getVersion());
response.header("processor", xalan.getVersion());
timeStart = System.currentTimeMillis();
try {
XPathQueryResult xPathQueryResult = Xalan.processXPath(data, query);
XPathQueryResult xPathQueryResult = xalan.processXPath(data, query, "");
response.status(200);
@@ -108,7 +114,7 @@ public class XPathController implements RestController {
duration = System.currentTimeMillis() - timeStart;
this.logger.info("Request (XPath, Xalan) processed in " + duration + " ms.");
responseJson.addProperty("processor", Xalan.getVersion());
responseJson.addProperty("processor", xalan.getVersion());
responseJson.addProperty("time", duration);
response.body(this.gson.toJson(responseJson));

View File

@@ -7,6 +7,7 @@ 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.Xalan;
import com.r11.tools.xml.XmlEngine;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;
@@ -17,9 +18,14 @@ public class XsdController implements RestController {
private final Gson gson;
private final Logger logger;
public XsdController(Gson gson, Logger logger) {
private final XmlEngine saxon;
private final XmlEngine xalan;
public XsdController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
this.gson = gson;
this.logger = logger;
this.saxon = saxon;
this.xalan = xalan;
}
@ScopedControllerManifest(method = HandlerType.POST, path = "/xsd")
@@ -44,14 +50,14 @@ public class XsdController implements RestController {
String data = requestJson.get("data").getAsString();
String xsd = requestJson.get("process").getAsString();
response.header("processor", Xalan.getVersion());
response.header("processor", xalan.getVersion());
long timeStart = System.currentTimeMillis();
String tmp;
JsonObject responseJson = new JsonObject();
try {
tmp = Xalan.validate(data, xsd).trim();
tmp = xalan.validate(data, xsd).trim();
response.status(200);
@@ -69,7 +75,7 @@ public class XsdController implements RestController {
long duration = System.currentTimeMillis() - timeStart;
this.logger.info("Request (XSD, Xalan) processed in " + duration + " ms.");
responseJson.addProperty("processor", Xalan.getVersion());
responseJson.addProperty("processor", xalan.getVersion());
responseJson.addProperty("time", duration);
response.body(this.gson.toJson(responseJson));

View File

@@ -8,6 +8,7 @@ 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.Xalan;
import com.r11.tools.xml.XmlEngine;
import org.apache.logging.log4j.Logger;
import spark.Request;
import spark.Response;
@@ -18,9 +19,14 @@ public class XsltController implements RestController {
private final Gson gson;
private final Logger logger;
public XsltController(Gson gson, Logger logger) {
private final XmlEngine saxon;
private final XmlEngine xalan;
public XsltController(Gson gson, Logger logger, XmlEngine saxon, XmlEngine xalan) {
this.gson = gson;
this.logger = logger;
this.saxon = saxon;
this.xalan = xalan;
}
@ScopedControllerManifest(method = HandlerType.POST, path = "/xslt")
@@ -61,7 +67,7 @@ public class XsltController implements RestController {
case "saxon":
timeStart = System.currentTimeMillis();
try {
tmp = Saxon.processXSLT(data, query);
tmp = saxon.processXSLT(data, query);
response.status(200);
@@ -79,7 +85,7 @@ public class XsltController implements RestController {
duration = System.currentTimeMillis() - timeStart;
this.logger.info("Request (XSLT, Saxon) processed in " + duration + " ms.");
responseJson.addProperty("processor", "Saxon " + Saxon.getVersion() + " " + version);
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version);
responseJson.addProperty("time", duration);
response.body(this.gson.toJson(responseJson));
@@ -88,7 +94,7 @@ public class XsltController implements RestController {
case "xalan":
timeStart = System.currentTimeMillis();
try {
tmp = Xalan.processXSLT(data, query);
tmp = xalan.processXSLT(data, query);
response.status(200);
@@ -106,7 +112,7 @@ public class XsltController implements RestController {
duration = System.currentTimeMillis() - timeStart;
this.logger.info("Request (XSLT, Xalan) processed in " + duration + " ms.");
responseJson.addProperty("processor", Xalan.getVersion());
responseJson.addProperty("processor", xalan.getVersion());
responseJson.addProperty("time", duration);
response.body(this.gson.toJson(responseJson));

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

@@ -0,0 +1,12 @@
package com.r11.tools.xml;
import com.r11.tools.controller.internal.XPathQueryResult;
public interface XmlEngine {
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();
}

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -42,7 +42,7 @@ function init() {
tools.set("xslt", "tools/xslt.html");
tools.set("xmlform", "tools/xmlFormatter.html");
tools.set("jsonform", "tools/jsonFormatter.html");
tools.set("mock", getMockHost());
tools.set("mock", "tools/mock.html");
changeActiveTools('XML');
loadLastPage();

View File

@@ -4,7 +4,7 @@ var json = {};
var jsonIndex = 0;
var lastId = 1;
var htable_row = 0;
var host = getDomain();
var host = window.location.protocol + "//" + window.location.hostname + ":8097";
var dataModified = false;
const addMessageName = 'addMessage';
const loadMessageName = 'changeMessage';

View File

@@ -65,28 +65,6 @@ function clearDataField() {
}
/**
* The `escapeHTML` function is used to escape special characters in an HTML element's innerHTML property.
* This is done to prevent these characters from being interpreted as HTML tags or attributes,
* which could potentially cause security vulnerabilities or unintended behavior.
*
* @function
* @name escapeHTML
* @kind function
* @param {any} element
* @returns {void}
*/
function escapeHTML(elementID) {
document.getElementById(elementID).innerHTML = document.getElementById(elementID).innerHTML
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
/**
* It fills the XML area with a sample XML.
*
@@ -111,6 +89,16 @@ function fillDefaultXML(element) {
}
}
/**
* It fills the XSD area with a sample XSD and XML area with matching XML.
*
* @function
* @name fillDefaultXSD
* @kind function
* @param {any} element
* @returns {void}
*/
function fillDefaultXSD(){
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
fetch(serverAddress + "/assets/samples/sampleXSD.xsd")

View File

@@ -5,7 +5,6 @@
<link rel="stylesheet" href="assets/css/frame.css">
<script src="assets/scripts/common/jquery-3.6.0.slim.min.js"></script>
<script src="assets/scripts/frame.js"></script>
<!-- <link rel="stylesheet" href="common.css"> -->
<link rel="shortcut icon" href="assets/images/favicon.ico" type="image/x-icon">
<!-- Meta tags for SEO and SEM -->
<title>Release11 Web Tools</title>

View File

@@ -3,12 +3,10 @@
<head>
<title>R11 MockedServices</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/fontello.css" type="text/css">
<link rel="stylesheet" href="../css/main.css" type="text/css">
<!-- <link rel="stylesheet" href="css/common.css" type="text/css"> -->
<link rel="stylesheet" href="../css/common.css" type="text/css">
<link rel="stylesheet" href="../assets/css/tools/mock/fontello.css" type="text/css">
<link rel="stylesheet" href="../assets/css/tools/mock/main.css" type="text/css">
<link rel="stylesheet" href="../assets/css/tools/mock/common.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- <script src="../js/dyn_host.js"></script> -->
</head>
<body>
<div class="container">
@@ -155,14 +153,6 @@
</tr>
</thead>
<tbody>
<!-- <tr class="even">
<td>2021-01-01T10:57:26</td>
<td>Client request</td>
</tr>
<tr>
<td>2021-01-01T10:57:26</td>
<td>Client request</td>
</tr> -->
</tbody>
</table>
</div>
@@ -179,19 +169,6 @@
</div>
<!-- tile list -->
<div id="listItems">
<!-- <div class="tile">
<div class="content">
<div class="display-space-between">
<div class="centered-vertically">
<p>Id: 2</p>
<p>Status: 200</p>
</div>
<div>
<button id="test1" class="modification-button btn-tile"><i class="icon-cancel"></i></button>
</div>
</div>
</div>
</div> -->
</div>
<div id="new-tile" class="max-width centered-content small-vertical-margin">
<button id="btn-newtile" class="modification-button btn-addtile"><i class="icon-plus"></i></button>
@@ -302,7 +279,7 @@
<div>Message saved<i class="r-exclamation"></i></div>
<button>&times;</button>
</div>
<div class="body">Your message has been successfuly saved.<br>You might view it under the link.</div>
<div class="body">Your message has been successfully saved.<br>You might view it under the link.</div>
</div>
<div id="modal-query" class="modal">
<div class="header">
@@ -317,10 +294,10 @@
<button>No</button>
</div>
</div>
<script type="text/javascript" src="../js/modal.js"></script>
<script type="text/javascript" src="../js/uianimation.js"></script>
<script type="text/javascript" src="../js/datatransfer.js"></script>
<script type="text/javascript" src="../js/historyloader.js"></script>
<script type="text/javascript" src="../js/fiddle.js"></script>
<script type="text/javascript" src="../assets/scripts/tools/mock/modal.js"></script>
<script type="text/javascript" src="../assets/scripts/tools/mock//uianimation.js"></script>
<script type="text/javascript" src="../assets/scripts/tools/mock/datatransfer.js"></script>
<script type="text/javascript" src="../assets/scripts/tools/mock/historyloader.js"></script>
<script type="text/javascript" src="../assets/scripts/tools/mock/fiddle.js"></script>
</body>
</html>