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

Resolve merge conflict
This commit is contained in:
2023-04-14 11:09:24 +02:00
4 changed files with 4665 additions and 391 deletions

View File

@@ -32,12 +32,16 @@ public class SparkApplication {
.setPrettyPrinting() .setPrettyPrinting()
.create(); .create();
Gson jsongson = new GsonBuilder()
.disableHtmlEscaping()
.create();
RestControllerRegistry registry = new RestControllerRegistry(); RestControllerRegistry registry = new RestControllerRegistry();
registry.registerController(new ProcessorInfoController(logger)); registry.registerController(new ProcessorInfoController(logger));
registry.registerController(new XsdController(gson, logger)); registry.registerController(new XsdController(gson, logger));
registry.registerController(new XPathController(gson, logger)); registry.registerController(new XPathController(gson, logger));
registry.registerController(new XsltController(gson, logger)); registry.registerController(new XsltController(gson, logger));
registry.registerController(new JsonController()); registry.registerController(new JsonController(gson, jsongson, logger));
registry.register(); registry.register();

View File

@@ -1,7 +1,7 @@
package com.r11.tools.controller; package com.r11.tools.controller;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; //import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.r11.tools.controller.internal.GlobalControllerManifest; import com.r11.tools.controller.internal.GlobalControllerManifest;
import com.r11.tools.controller.internal.HandlerType; import com.r11.tools.controller.internal.HandlerType;
@@ -9,18 +9,22 @@ import com.r11.tools.controller.internal.RestController;
import com.r11.tools.controller.internal.ScopedControllerManifest; import com.r11.tools.controller.internal.ScopedControllerManifest;
import spark.Request; import spark.Request;
import spark.Response; import spark.Response;
import org.apache.logging.log4j.Logger;
@GlobalControllerManifest(path = "/json") @GlobalControllerManifest(path = "/json")
public class JsonController implements RestController { public class JsonController implements RestController {
private final Gson prettyGson = new GsonBuilder() private final Logger logger;
.disableHtmlEscaping()
.setPrettyPrinting()
.create();
private final Gson gson = new GsonBuilder() private final Gson prettyGson;
.disableHtmlEscaping()
.create(); private final Gson gson;
public JsonController(Gson prettyGson, Gson jsongson,Logger logger) {
this.logger = logger;
this.prettyGson = prettyGson;
this.gson = jsongson;
}
@ScopedControllerManifest(method = HandlerType.POST, path = "/formatting") @ScopedControllerManifest(method = HandlerType.POST, path = "/formatting")
public void formatting(Request request, Response response) { public void formatting(Request request, Response response) {
@@ -35,17 +39,20 @@ public class JsonController implements RestController {
responseJson.addProperty("data", this.prettyGson.toJson(requestJson)); responseJson.addProperty("data", this.prettyGson.toJson(requestJson));
responseJson.addProperty("time", System.currentTimeMillis() - startProcess); responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson));
} catch (Exception e) { } catch (Exception e) {
this.logger.error("Error on formatting Json " + e);
Throwable cause = e.getCause(); Throwable cause = e.getCause();
response.status(500); response.status(400);
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage()); responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
responseJson.addProperty("time", System.currentTimeMillis() - startProcess); responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson));
} }
this.logger.info("Json processed in " + responseJson.get("time").toString() + " ms.");
response.body(this.prettyGson.toJson(responseJson));
} }
@ScopedControllerManifest(method = HandlerType.POST, path = "/minimize") @ScopedControllerManifest(method = HandlerType.POST, path = "/minimize")
@@ -63,14 +70,16 @@ public class JsonController implements RestController {
response.body(this.gson.toJson(responseJson)); response.body(this.gson.toJson(responseJson));
} catch (Exception e) { } catch (Exception e) {
this.logger.error("Error on minimizeing Json " + e);
Throwable cause = e.getCause(); Throwable cause = e.getCause();
response.status(500); response.status(400);
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage()); responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
responseJson.addProperty("time", System.currentTimeMillis() - startProcess); responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson)); response.body(this.prettyGson.toJson(responseJson));
} }
this.logger.info("Json processed in " + responseJson.get("time").toString() + " ms.");
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,12 @@
<option value="xalan">Xalan</option> <option value="xalan">Xalan</option>
<option value="libxml">libXML</option> <option value="libxml">libXML</option>
</select> </select>
<select name="versions" id="versions" style="display: none;">
<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="3.0">3.0</option>
<option class="hideable saxon" value="3.1">3.1</option>
</select>
</div> </div>
<div> <div>
<button class="action-button active" id="clearXMLButton" style="padding: 3px 10px;" <button class="action-button active" id="clearXMLButton" style="padding: 3px 10px;"