Split XSLT process method
This commit is contained in:
@@ -57,69 +57,78 @@ public class XsltController implements RestController {
|
|||||||
response.body("saxon, xalan");
|
response.body("saxon, xalan");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tmp;
|
|
||||||
long timeStart;
|
|
||||||
long duration;
|
|
||||||
|
|
||||||
JsonObject responseJson = new JsonObject();
|
JsonObject responseJson = new JsonObject();
|
||||||
switch (processor) {
|
switch (processor) {
|
||||||
case "saxon":
|
case "saxon":
|
||||||
timeStart = System.currentTimeMillis();
|
processWithSaxon(response, data, query, version, responseJson);
|
||||||
try {
|
|
||||||
tmp = saxon.processXSLT(data, query);
|
|
||||||
|
|
||||||
response.status(200);
|
|
||||||
|
|
||||||
responseJson.addProperty("result", tmp);
|
|
||||||
responseJson.addProperty("status", "OK");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.logger.error("Error on processing XSLT using Saxon. " + ex);
|
|
||||||
|
|
||||||
response.status(400);
|
|
||||||
|
|
||||||
responseJson.addProperty("result", ex.getMessage());
|
|
||||||
responseJson.addProperty("status", "ERR");
|
|
||||||
}
|
|
||||||
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
|
||||||
this.logger.info("Request (XSLT, Saxon) processed in " + duration + " ms.");
|
|
||||||
|
|
||||||
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version);
|
|
||||||
responseJson.addProperty("time", duration);
|
|
||||||
|
|
||||||
response.body(this.gson.toJson(responseJson));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case "xalan":
|
case "xalan":
|
||||||
timeStart = System.currentTimeMillis();
|
processWithXalan(response, data, query, responseJson);
|
||||||
try {
|
|
||||||
tmp = xalan.processXSLT(data, query);
|
|
||||||
|
|
||||||
response.status(200);
|
|
||||||
|
|
||||||
responseJson.addProperty("result", tmp);
|
|
||||||
responseJson.addProperty("status", "OK");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.logger.error("Error on processing XSLT using Xalan. " + ex);
|
|
||||||
|
|
||||||
response.status(400);
|
|
||||||
|
|
||||||
responseJson.addProperty("result", ex.getMessage());
|
|
||||||
responseJson.addProperty("status", "ERR");
|
|
||||||
}
|
|
||||||
|
|
||||||
duration = System.currentTimeMillis() - timeStart;
|
|
||||||
this.logger.info("Request (XSLT, Xalan) processed in " + duration + " ms.");
|
|
||||||
|
|
||||||
responseJson.addProperty("processor", xalan.getVersion());
|
|
||||||
responseJson.addProperty("time", duration);
|
|
||||||
|
|
||||||
response.body(this.gson.toJson(responseJson));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
response.body("saxon, xalan");
|
response.body("saxon, xalan");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processWithXalan(Response response, String data, String query, JsonObject responseJson) {
|
||||||
|
long duration;
|
||||||
|
long timeStart;
|
||||||
|
String tmp;
|
||||||
|
timeStart = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
tmp = xalan.processXSLT(data, query);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
|
||||||
|
responseJson.addProperty("result", tmp);
|
||||||
|
responseJson.addProperty("status", "OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
this.logger.error("Error on processing XSLT using Xalan. " + ex);
|
||||||
|
|
||||||
|
response.status(400);
|
||||||
|
|
||||||
|
responseJson.addProperty("result", ex.getMessage());
|
||||||
|
responseJson.addProperty("status", "ERR");
|
||||||
|
}
|
||||||
|
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
this.logger.info("Request (XSLT, Xalan) processed in " + duration + " ms.");
|
||||||
|
|
||||||
|
responseJson.addProperty("processor", xalan.getVersion());
|
||||||
|
responseJson.addProperty("time", duration);
|
||||||
|
|
||||||
|
response.body(this.gson.toJson(responseJson));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processWithSaxon(Response response, String data, String query, String version, JsonObject responseJson) {
|
||||||
|
long duration;
|
||||||
|
String tmp;
|
||||||
|
long timeStart;
|
||||||
|
timeStart = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
tmp = saxon.processXSLT(data, query);
|
||||||
|
|
||||||
|
response.status(200);
|
||||||
|
|
||||||
|
responseJson.addProperty("result", tmp);
|
||||||
|
responseJson.addProperty("status", "OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
this.logger.error("Error on processing XSLT using Saxon. " + ex);
|
||||||
|
|
||||||
|
response.status(400);
|
||||||
|
|
||||||
|
responseJson.addProperty("result", ex.getMessage());
|
||||||
|
responseJson.addProperty("status", "ERR");
|
||||||
|
}
|
||||||
|
|
||||||
|
duration = System.currentTimeMillis() - timeStart;
|
||||||
|
this.logger.info("Request (XSLT, Saxon) processed in " + duration + " ms.");
|
||||||
|
|
||||||
|
responseJson.addProperty("processor", "Saxon " + saxon.getVersion() + " " + version);
|
||||||
|
responseJson.addProperty("time", duration);
|
||||||
|
|
||||||
|
response.body(this.gson.toJson(responseJson));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user