diff --git a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java index 5fc42ab..d3ec2cf 100644 --- a/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java +++ b/nx01-zerofungus-server/src/main/java/love/distributedrebirth/nx01/zerofungus/server/web/WarpCorePlasmaInspectorServlet.java @@ -29,8 +29,15 @@ package love.distributedrebirth.nx01.zerofungus.server.web; import java.io.IOException; import java.io.PrintWriter; +import java.io.Writer; import java.util.List; +import org.x4o.xml.io.XMLConstants; +import org.x4o.xml.io.sax.ext.ContentWriterTagWrapper; +import org.x4o.xml.io.sax.ext.ContentWriterXml; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -53,57 +60,74 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet { WarpCoreReactor reactor = ZeroFungus.INSTANCE.getWarpCore(); List slots = reactor.listChilds(null); - out.println("\n"); - out.println("\n"); - for (WarpReactPlasma slot : slots) { - WarpCorePlasmaIntermixChamber contract = reactor.getSlotContract(slot); - out.println("\t\n"); - printClaims(out, "in", contract.getSlotTypesIn()); - printClaims(out, "out", contract.getSlotTypesOut()); - printRequireServices(out, contract.getRequireServices()); - printRequireSlots(out, contract.getRequireSlots()); - out.println("\n"); + ContentWriterInspector writer = new ContentWriterInspector(out, response.getCharacterEncoding()); + try { + writer.startDocument(); + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", "ไป™ไธŠไธปๅคฉ", "", "", "๐‘€ณ๐‘‚๐‘€ฎ๐‘€บ๐‘€‰๐‘„๐‘€ค๐‘„๐‘€ญ๐‘‚๐‘€ก๐‘€ช๐‘€ธ๐‘€•"); + writer.printTagStart(Tag.reactor, atts); + for (WarpReactPlasma slot : slots) { + WarpCorePlasmaIntermixChamber contract = reactor.getSlotContract(slot); + atts = new AttributesImpl(); + atts.addAttribute ("", "path", "", "", slot.getSlotPath()); + if ("true".equalsIgnoreCase(request.getParameter("___willem"))) { + atts.addAttribute ("", "แ’กแ’ขแ‘Šแ’ปแ’ปแ“ซแ”ฟ", "", "", "๐‘€ณ๐‘‚๐‘€ฎ๐‘€บ๐‘€‰๐‘„๐‘€ค๐‘„๐‘€ญ๐‘‚๐‘€ก๐‘€ช๐‘€ธ๐‘€•"); + } + writer.printTagStart(Tag.slot, atts); + printClaims(writer, Tag.claimIn, contract.getSlotTypesIn()); + printClaims(writer, Tag.claimOut, contract.getSlotTypesOut()); + printRequireServices(writer, contract.getRequireServices()); + printRequireSlots(writer, contract.getRequireSlots()); + writer.printTagEnd(Tag.slot); + } + writer.printTagEnd(Tag.reactor); + writer.endDocument(); + } catch (SAXException e) { + throw new IllegalStateException(e); } - out.println("\t\n"); - out.flush(); } - private void printClaims(PrintWriter out, String tag, List> clazzes) { + private void printClaims(ContentWriterInspector writer, Tag tag, List> clazzes) throws SAXException { if (clazzes.isEmpty()) { return; } - out.println("\t\t\n"); + writer.printTagStart(tag); for (Class cls : clazzes) { - out.print("\t\t\t"); - out.print(cls); - out.println("\n"); + writer.printTagCharacters(Tag.claimType, cls.toString()); } - out.println("\t\t\n"); + writer.printTagEnd(tag); } - private void printRequireServices(PrintWriter out, List> clazzes) { + private void printRequireServices(ContentWriterInspector writer, List> clazzes) throws SAXException { if (clazzes.isEmpty()) { return; } - out.println("\t\t\n"); + writer.printTagStart(Tag.requireServices); for (Class cls : clazzes) { - out.print("\t\t\t"); - out.print(cls); - out.println("\n"); + writer.printTagCharacters(Tag.requireService, cls.toString()); } - out.println("\t\t\n"); + writer.printTagEnd(Tag.requireServices); } - private void printRequireSlots(PrintWriter out, List slots) { + private void printRequireSlots(ContentWriterInspector writer, List slots) throws SAXException { if (slots.isEmpty()) { return; } - out.println("\t\t\n"); + writer.printTagStart(Tag.requireSlots); for (WarpReactPlasma slot : slots) { - out.print("\t\t\t"); - out.print(slot.getSlotPath()); - out.println("\n"); + writer.printTagCharacters(Tag.requireSlot, slot.getSlotPath()); } - out.println("\t\t\n"); + writer.printTagEnd(Tag.requireSlots); + } + + public class ContentWriterInspector extends ContentWriterTagWrapper { + + public ContentWriterInspector(Writer out,String encoding) { + super(new ContentWriterXml(out, encoding),XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI); + } + } + + public enum Tag { + reactor,slot,requireSlots,requireSlot,requireServices,requireService,claimIn,claimOut,claimType; } } \ No newline at end of file