diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriver.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriver.java index b377482..6047c54 100644 --- a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriver.java +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriver.java @@ -37,19 +37,17 @@ import java.io.StringWriter; import java.io.Writer; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import java.util.Objects; +import org.x4o.o2o.io.sax3.xdbx.XDBXReaderXml; +import org.x4o.o2o.io.sax3.xdbx.XDBXWriterXml; import org.x4o.o2o.io.tlv.TLVChainOctalSex; import org.x4o.o2o.io.tlv.TLVChainSexTeenBit; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0HeaderField; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0Section; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0TheMimeType; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0TheVersion; -import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContent; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContentPulser; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContentStringHandler; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; import love.distributedrebirth.nx01.warp.manifestor.scopic.ioini.ScopicIniConstants; @@ -62,6 +60,8 @@ import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf3.ScopicManifest3 import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf4.ScopicManifest4ContentHandler; import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf4.ScopicManifest4ContentReader; import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf4.ScopicManifest4ContentWriter; +import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5.ScopicManifest5ContentParser; +import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5.ScopicManifest5ContentWriter; /// Warp Manifestor Driver. /// @@ -170,6 +170,27 @@ public enum WarpManifestorDriver { return result; } + public WarpManifestX8 readV5Buffer(ByteBuffer input) { + return readV5Array(input.array()); + } + + public WarpManifestX8 readV5Array(byte[] input) { + return readV5Stream(new ByteArrayInputStream(input)); + } + + public WarpManifestX8 readV5Stream(InputStream input) { + WarpManifestX8 result = new WarpManifestX8(); + ScopicManifestContentStringHandler handler = new ScopicManifestContentStringHandler(result, WarpManifestX0TheVersion.VERSION_5_0); + ScopicManifest5ContentParser contentParser = new ScopicManifest5ContentParser(handler); + XDBXReaderXml reader = new XDBXReaderXml(contentParser); + try { + reader.parse(input); + } catch (IOException e) { + throw new ScopicManifestException(e); + } + return result; + } + public WarpManifestX8 readViniString(String input) { return readViniArray(input.getBytes(StandardCharsets.UTF_8)); } @@ -194,33 +215,7 @@ public enum WarpManifestorDriver { return result; } - // An "geniface" for complex generics would be nice, note all this generics is only to add 2 default methods in a interface... - private , H extends WarpManifestX0HeaderField, S extends WarpManifestX0Section> void strobelight(WarpManifestX0 manifest, ScopicManifestContent writer, T version) { - writer.strobeManifestStart(); - writer.strobeManifestDeclaration(Objects.requireNonNull(version, "Can't print null version")); - for (WarpManifestX0HeaderField mainAttr : manifest.getAttributes()) { - Objects.requireNonNull(mainAttr.getName(), "Can't print null attribute name"); - for (T remarkValue : mainAttr.getRemarks()) { - writer.strobeRemarkContent(remarkValue); - } - writer.strobeMainAttribute(mainAttr.getName(), mainAttr.getBody()); - } - for (WarpManifestX0Section section : manifest.getSections()) { - Objects.requireNonNull(section.getName(), "Can't print null section name"); - for (T remarkValue : section.getRemarks()) { - writer.strobeRemarkContent(remarkValue); - } - writer.strobeSectionHeader(section.getName()); - for (WarpManifestX0HeaderField sectionAttr : section.getAttributes()) { - Objects.requireNonNull(sectionAttr.getName(), "Can't print null section attribute name"); - for (T remarkValue : sectionAttr.getRemarks()) { - writer.strobeRemarkContent(remarkValue); - } - writer.strobeSectionAttribute(sectionAttr.getName(), sectionAttr.getBody()); - } - } - writer.strobeManifestEnd(); - } + // ================================================================================================================= public String writeV1String(WarpManifestX8 manifest) { StringWriter writer = new StringWriter(); @@ -233,7 +228,7 @@ public enum WarpManifestorDriver { } public void writeV1StreamChar(WarpManifestX8 manifest, Writer output) { - strobelight(manifest, new ScopicManifestContentWriter(output), WarpManifestX0TheVersion.VERSION_1_0.getQName()); + ScopicManifestContentPulser.strobelight(manifest, new ScopicManifestContentWriter(output), WarpManifestX0TheVersion.VERSION_1_0.getQName()); } public String writeV2String(WarpManifestX8 manifest) { @@ -247,7 +242,7 @@ public enum WarpManifestorDriver { } public void writeV2StreamChar(WarpManifestX8 manifest, Writer output) { - strobelight(manifest, new ScopicManifestContentWriter(output), WarpManifestX0TheVersion.VERSION_2_0.getQName()); + ScopicManifestContentPulser.strobelight(manifest, new ScopicManifestContentWriter(output), WarpManifestX0TheVersion.VERSION_2_0.getQName()); } public ByteBuffer writeV3Buffer(WarpManifestX8 manifest) { @@ -262,7 +257,7 @@ public enum WarpManifestorDriver { public void writeV3Stream(WarpManifestX8 manifest, OutputStream output) { TLVChainSexTeenBit chain = new TLVChainSexTeenBit(); - strobelight(manifest, new ScopicManifest3ContentWriter(chain), WarpManifestX0TheVersion.VERSION_3_0.getQName()); + ScopicManifestContentPulser.strobelight(manifest, new ScopicManifest3ContentWriter(chain), WarpManifestX0TheVersion.VERSION_3_0.getQName()); try { WarpManifestX0TheMimeType.magicMarkerWrite(output, WarpManifestX0TheMimeType.MANIFEST_3); chain.dataWriteStream(output); @@ -283,7 +278,7 @@ public enum WarpManifestorDriver { public void writeV4Stream(WarpManifestX18 manifest, OutputStream output) { TLVChainOctalSex chain = new TLVChainOctalSex(); - strobelight(manifest, new ScopicManifest4ContentWriter(chain), WarpManifestX0TheVersion.VERSION_4_0); + ScopicManifestContentPulser.strobelight(manifest, new ScopicManifest4ContentWriter(chain), WarpManifestX0TheVersion.VERSION_4_0); try { WarpManifestX0TheMimeType.magicMarkerWrite(output, WarpManifestX0TheMimeType.MANIFEST_4); chain.dataWriteStream(output); @@ -292,6 +287,22 @@ public enum WarpManifestorDriver { } } + public ByteBuffer writeV5Buffer(WarpManifestX8 manifest) { + return ByteBuffer.wrap(writeV5Array(manifest)); + } + + public byte[] writeV5Array(WarpManifestX8 manifest) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writeV5Stream(manifest, baos); + return baos.toByteArray(); + } + + public void writeV5Stream(WarpManifestX8 manifest, OutputStream output) { + XDBXWriterXml writerXml = new XDBXWriterXml(output); + ScopicManifest5ContentWriter writer = new ScopicManifest5ContentWriter(writerXml); + ScopicManifestContentPulser.strobelight(manifest, writer, WarpManifestX0TheVersion.VERSION_5_0.getQName()); + } + public String writeViniString(WarpManifestX8 manifest) { StringWriter writer = new StringWriter(); writeViniStreamChar(manifest, writer); @@ -303,6 +314,6 @@ public enum WarpManifestorDriver { } public void writeViniStreamChar(WarpManifestX8 manifest, Writer output) { - strobelight(manifest, new ScopicIniContentWriter(output), ScopicIniConstants.VERSION_NEW_TESTAMENT); + ScopicManifestContentPulser.strobelight(manifest, new ScopicIniContentWriter(output), ScopicIniConstants.VERSION_NEW_TESTAMENT); } } diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0TheVersion.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0TheVersion.java index 060764d..dcea133 100644 --- a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0TheVersion.java +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0TheVersion.java @@ -47,18 +47,21 @@ public enum WarpManifestX0TheVersion { /// Format: Custom TLV 8 bit binary with unicode VERSION_3_0("3.0"), - ; + /// Format: Custom TLV 18 bit binary (18 bit or 6 octals as byte replacement) - public static final PrimordialOctalOrangeJuiceCord VERSION_4_0 = PrimordialOctalOrangeString.valueOfSmurfs(Arrays.asList(4, 0)); + // FIXME: move into enum // TODO: Format: SAX3 binary 8 bit XDBX XML with unicode manifest data - // VERSION_5_0 + VERSION_5_0("5.0"), // TODO: Format: SAX4 binary adult 18 bit XML with manifest in 4C, but tags/attr in FCDotCDC1604DashP6 // VERSION_6_0 // TODO: Format: SAX4 binary adult 18 bit XML with manifest data and XML structure in 4C // VERSION_7_0 + ; + + public static final PrimordialOctalOrangeJuiceCord VERSION_4_0 = PrimordialOctalOrangeString.valueOfSmurfs(Arrays.asList(4, 0)); private final String qName; diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/ScopicManifestContentPulser.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/ScopicManifestContentPulser.java new file mode 100644 index 0000000..7259b4b --- /dev/null +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/ScopicManifestContentPulser.java @@ -0,0 +1,69 @@ +/* + * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.warp.manifestor.scopic; + +import java.util.Objects; + +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0HeaderField; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0Section; + +/// Stroboscopic manifestor content pulser. +/// +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public final class ScopicManifestContentPulser { + + // An "geniface" for complex generics would be nice, note all this generics is only to add 2 default methods in a interface... + static public , H extends WarpManifestX0HeaderField, S extends WarpManifestX0Section> void strobelight(WarpManifestX0 manifest, ScopicManifestContent writer, T version) { + writer.strobeManifestStart(); + writer.strobeManifestDeclaration(Objects.requireNonNull(version, "Can't print null version")); + for (WarpManifestX0HeaderField mainAttr : manifest.getAttributes()) { + Objects.requireNonNull(mainAttr.getName(), "Can't print null attribute name"); + for (T remarkValue : mainAttr.getRemarks()) { + writer.strobeRemarkContent(remarkValue); + } + writer.strobeMainAttribute(mainAttr.getName(), mainAttr.getBody()); + } + for (WarpManifestX0Section section : manifest.getSections()) { + Objects.requireNonNull(section.getName(), "Can't print null section name"); + for (T remarkValue : section.getRemarks()) { + writer.strobeRemarkContent(remarkValue); + } + writer.strobeSectionHeader(section.getName()); + for (WarpManifestX0HeaderField sectionAttr : section.getAttributes()) { + Objects.requireNonNull(sectionAttr.getName(), "Can't print null section attribute name"); + for (T remarkValue : sectionAttr.getRemarks()) { + writer.strobeRemarkContent(remarkValue); + } + writer.strobeSectionAttribute(sectionAttr.getName(), sectionAttr.getBody()); + } + } + writer.strobeManifestEnd(); + } +} diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf3/ScopicManifest3ContentWriter.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf3/ScopicManifest3ContentWriter.java index 0692267..ea49f45 100644 --- a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf3/ScopicManifest3ContentWriter.java +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf3/ScopicManifest3ContentWriter.java @@ -36,7 +36,7 @@ import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestDuplica import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf.ScopicManifestConstants; -/// Stroboscopic manifest 3 binary content writer. +/// Stroboscopic manifest 5 binary 8 bit XDBX content writer. /// /// @author للَّٰهِilLצسُو /// @version ©Δ∞ 仙上主天 diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentParser.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentParser.java new file mode 100644 index 0000000..a83b8c6 --- /dev/null +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentParser.java @@ -0,0 +1,129 @@ +/* + * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5; + +import java.util.Objects; + +import org.x4o.o2o.io.sax3.ContentWriterAdapter; +import org.x4o.o2o.io.sax3.XMLConstants; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContent; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; + +/// Stroboscopic manifest 5 text XML content reader. +/// +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public class ScopicManifest5ContentParser extends ContentWriterAdapter { + + private final ScopicManifestContent handler; + private boolean attrMain = true; + private String attrName; + private StringBuilder attrValue = new StringBuilder(300); + + public ScopicManifest5ContentParser(ScopicManifestContent handler) { + this.handler = Objects.requireNonNull(handler); + } + + @Override + public void startDocument() throws SAXException { + handler.strobeManifestStart(); + } + + @Override + public void endDocument() throws SAXException { + handler.strobeManifestEnd(); + } + + @Override + public void comment(String text) throws SAXException { + if (text == null) { + return; + } + if (text.isEmpty()) { + return; + } + handler.strobeRemarkContent(text); + } + + @Override + public void characters(String text) throws SAXException { + if (text == null) { + return; + } + if (text.isEmpty()) { + return; + } + attrValue.append(text); + } + + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + String space = new String(ch, start, length); + System.out.println("white space: \"" + space + "\""); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (ScopicManifest5FrameElement.ATTRIBUTE.name().equals(localName)) { + attrName = attributes.getValue(XMLConstants.NULL_NS_URI, ScopicManifest5FrameElement.ATTRIBUTE_NAME); + return; + } + if (ScopicManifest5FrameElement.SECTION.name().equals(localName)) { + attrMain = false; + String sectionName = attributes.getValue(XMLConstants.NULL_NS_URI, ScopicManifest5FrameElement.SECTION_NAME); + handler.strobeSectionHeader(sectionName); + return; + } + if (ScopicManifest5FrameElement.MANIFEST.name().equals(localName)) { + String version = attributes.getValue(XMLConstants.NULL_NS_URI, ScopicManifest5FrameElement.MANIFEST_VERSION); + handler.strobeManifestDeclaration(version); + return; + } + throw new ScopicManifestException("Unknown XML tag: " + localName); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (ScopicManifest5FrameElement.ATTRIBUTE.name().equals(localName)) { + if (attrMain) { + handler.strobeMainAttribute(attrName, attrValue.toString()); + } else { + handler.strobeSectionAttribute(attrName, attrValue.toString()); + } + attrValue = new StringBuilder(); + return; + } + if (ScopicManifest5FrameElement.SECTION.name().equals(localName)) { + attrMain = true; // Support normal xml tree layout + return; + } + } +} diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentWriter.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentWriter.java new file mode 100644 index 0000000..08fcf5a --- /dev/null +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5ContentWriter.java @@ -0,0 +1,147 @@ +/* +w * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5; + +import org.x4o.o2o.io.sax3.ContentWriter; +import org.x4o.o2o.io.sax3.ContentWriterTagWrapper; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0TheVersion; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContent; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestDuplicateDetector; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestDuplicatePart; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; +import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf.ScopicManifestConstants; + +/// Stroboscopic manifest 5 binary XML content writer. +/// +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public class ScopicManifest5ContentWriter implements ScopicManifestContent { + + private final ContentWriterTagWrapper writer; + private final ScopicManifestDuplicateDetector duplicateDetector; + private boolean openSection = false; + + public ScopicManifest5ContentWriter(ContentWriter writerXml) { + this.writer = new ContentWriterTagWrapper<>(writerXml); + this.duplicateDetector = new ScopicManifestDuplicateDetector<>(v -> v.length()); + } + + @Override + public void strobeManifestStart() { + try { + writer.startDocument(); + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } + + @Override + public void strobeManifestDeclaration(String version) { + if (version.length() > ScopicManifestConstants.ATTR_MANIFEST_VERSION_MAX_LENGHT) { + throw new ScopicManifestException("Declaration version too large: " + version.length()); + } + try { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", ScopicManifest5FrameElement.MANIFEST_VERSION, "", "", WarpManifestX0TheVersion.VERSION_5_0.getQName()); + writer.printTagStart(ScopicManifest5FrameElement.MANIFEST, atts); + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } + + @Override + public void strobeMainAttribute(String name, String body) { + duplicateDetector.validateUniqueKey(ScopicManifestDuplicatePart.MAIN_ATTRIBUTE, name); + writeAttribute(name, body); + } + + @Override + public void strobeSectionHeader(String sectionName) { + duplicateDetector.validateUniqueKey(ScopicManifestDuplicatePart.SECTION_NAME, sectionName); + duplicateDetector.clearPart(ScopicManifestDuplicatePart.SECTION_ATTRIBUTE); + try { + if (openSection) { + writer.printTagEnd(ScopicManifest5FrameElement.SECTION); + } + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", ScopicManifest5FrameElement.SECTION_NAME, "", "", sectionName); + writer.printTagStart(ScopicManifest5FrameElement.SECTION, atts); + openSection = true; + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } + + @Override + public void strobeSectionAttribute(String name, String body) { + duplicateDetector.validateUniqueKey(ScopicManifestDuplicatePart.SECTION_ATTRIBUTE, name); + writeAttribute(name, body); + } + + @Override + public void strobeRemarkContent(String remark) { + try { + writer.printComment(remark); + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } + + @Override + public void strobeManifestEnd() { + duplicateDetector.clearAll(); + try { + if (openSection) { + writer.printTagEnd(ScopicManifest5FrameElement.SECTION); + openSection = false; + } + writer.printTagEnd(ScopicManifest5FrameElement.MANIFEST); + writer.endDocument(); + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } + + private void writeAttribute(String name, String value) { + if (!ScopicManifestConstants.isOtherChar(name)) { + throw new ScopicManifestException("Illegal control characters detected: " + name); + } + try { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", ScopicManifest5FrameElement.ATTRIBUTE_NAME, "", "", name); + writer.printTagStart(ScopicManifest5FrameElement.ATTRIBUTE, atts); + writer.printCharacters(value); + writer.printTagEnd(ScopicManifest5FrameElement.ATTRIBUTE); + } catch (SAXException e) { + throw new ScopicManifestException(e); + } + } +} diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5FrameElement.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5FrameElement.java new file mode 100644 index 0000000..7b310c5 --- /dev/null +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/scopic/iomf5/ScopicManifest5FrameElement.java @@ -0,0 +1,56 @@ +/* + * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5; + +import org.x4o.o2o.io.tlv.TLVChainSexTeenBitFrameType; + +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public enum ScopicManifest5FrameElement { + + MANIFEST, + ATTRIBUTE, + SECTION, + + /* + META_DECLARATION_VERSION (22), // SYN Synchronize + META_REMARK_CONTENT (7), // BEL Bell + + MAIN_ATTRIBUTE_NAME (2), // STX Start of Text + MAIN_ATTRIBUTE_BODY (3), // ETX End of Text + + SECTION_HEADER_NAME (1), // SOH Start of Heading + SECTION_ATTRIBUTE_NAME (5), // ENQ Enquiry + SECTION_ATTRIBUTE_BODY (6), // ACK Acknowledge + */ + ; + + static public final String MANIFEST_VERSION = "VERSION"; + static public final String SECTION_NAME = "NAME"; + static public final String ATTRIBUTE_NAME = "NAME"; +} diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestChinaTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestChinaTest.java index 9321c8e..6ae0dae 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestChinaTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestChinaTest.java @@ -27,12 +27,17 @@ package love.distributedrebirth.nx01.warp.manifestor; +import java.io.StringWriter; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.x4o.o2o.io.sax3.ContentWriterXml; -import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX0TheVersion; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8Section; +import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestContentPulser; +import love.distributedrebirth.nx01.warp.manifestor.scopic.iomf5.ScopicManifest5ContentWriter; /// @author للَّٰهِilLצسُو /// @version ©Δ∞ 仙上主天s @@ -196,10 +201,19 @@ public class WarpManifestChinaTest { section.withAttribute("七號線", "不得不服從"); section.withAttribute("八號線", "在正義中。"); - String output = WarpManifestorDriver.亞.writeV2String(manifest); - Assertions.assertNotNull(output); - System.out.println(output); - System.out.println("========="); - System.out.println(WarpManifestorDriver.亞.writeViniString(new WarpManifestX8().withSections(manifest.getSections()))); + String outputV2 = WarpManifestorDriver.亞.writeV2String(manifest); + Assertions.assertNotNull(outputV2); + String outputIni = WarpManifestorDriver.亞.writeViniString(new WarpManifestX8().withSections(manifest.getSections())); // removes main attributes + Assertions.assertNotNull(outputIni); + byte[] outputV5 = WarpManifestorDriver.亞.writeV5Array(manifest); + Assertions.assertNotNull(outputV5); + + WarpManifestX8 manifestV5 = WarpManifestorDriver.亞.readV5Array(outputV5); + StringWriter outputXml = new StringWriter(); + ContentWriterXml writerXml = new ContentWriterXml(outputXml); + ScopicManifest5ContentWriter writer = new ScopicManifest5ContentWriter(writerXml); + ScopicManifestContentPulser.strobelight(manifestV5, writer, WarpManifestX0TheVersion.VERSION_5_0.getQName()); + Assertions.assertTrue(outputXml.toString().contains("")); + Assertions.assertTrue(outputXml.toString().contains("威廉斯·範·納蘇韋")); } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java index d6f219e..6949b46 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java @@ -30,7 +30,6 @@ package love.distributedrebirth.nx01.warp.manifestor; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; /// @author للَّٰهِilLצسُو @@ -42,7 +41,7 @@ public class WarpManifestorDriverTest { WarpManifestX8 manifest = new WarpManifestX8(); manifest.makeAttribute("foo", "bar"); manifest.makeSection("my1").withAttribute("foo1", "bar1"); - String output = WarpManifestorDriver.亞.writeV2String(manifest); + String output = WarpManifestorDriver.亞.writeV1String(manifest); Assertions.assertNotNull(output); Assertions.assertTrue(output.contains("foo1")); } @@ -51,7 +50,7 @@ public class WarpManifestorDriverTest { public void testLineWrapAsLastLine() { String checkWrap = "https://github.com/shrinkwrap/resolver/shrinkwrap-resolver-spi-maven-archive"; String checkWrapLast = "http://www.jboss.org/shrinkwrap-resolver-parent/shrinkwrap-resolver-spi-maven-archive"; - WarpManifestX8 manitest = WarpManifestorDriver.亞.readV2Stream(getClass().getResourceAsStream("test-line-wrap.mf")); + WarpManifestX8 manitest = WarpManifestorDriver.亞.readV1Stream(getClass().getResourceAsStream("test-line-wrap.mf")); Assertions.assertNotNull(manitest); Assertions.assertEquals(21, manitest.getAttributes().size()); Assertions.assertEquals("Implementation-Title", manitest.getAttributes().get(0).getName()); diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java index 3b0bce0..922223e 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java @@ -30,7 +30,6 @@ package love.distributedrebirth.nx01.warp.manifestor; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; /// @author للَّٰهِilLצسُو diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBigBodyTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBigBodyTest.java index eb4614f..d94a526 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBigBodyTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBigBodyTest.java @@ -33,7 +33,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBodyIllegalTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBodyIllegalTest.java index f38ece9..137e674 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBodyIllegalTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestBodyIllegalTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameDupTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameDupTest.java index d1abf74..2bb149c 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameDupTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameDupTest.java @@ -34,8 +34,6 @@ import org.junit.jupiter.api.Test; import org.x4o.o2o.octal.PrimordialOctalOrangeString; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -159,4 +157,23 @@ public class WarpManifestNameDupTest { WarpManifestorDriver.亞.writeV4Array(manifest); }); } + + @Test + public void testWriteV5DuplicateSection() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.makeSection("junit"); + manifest.makeSection("junit"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } + + @Test + public void testWriteV5DuplicateSectionAttribute() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.makeSection("junit").withAttribute("foo", "bar1").withAttribute("foo", "bar1"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameEmptyTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameEmptyTest.java index a0d55f2..02d790e 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameEmptyTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameEmptyTest.java @@ -34,8 +34,6 @@ import org.junit.jupiter.api.Test; import org.x4o.o2o.octal.PrimordialOctalOrangeString; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -77,4 +75,13 @@ public class WarpManifestNameEmptyTest { WarpManifestorDriver.亞.writeV4Array(manifest); }); } + + @Test + public void testWriteV5NameEmpty() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("", "bar"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameForbidCharTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameForbidCharTest.java index 78ea8ff..9c43076 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameForbidCharTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameForbidCharTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -118,4 +117,31 @@ public class WarpManifestNameForbidCharTest { WarpManifestorDriver.亞.writeV3Array(manifest); }); } + + @Test + public void testWriteV5NameNewLine() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("foo\n", "bar"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } + + @Test + public void testWriteV5NameLineFeed() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("foo\r", "bar"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } + + @Test + public void testWriteV5NameNull() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("foo\u0000", "bar"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameLimitTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameLimitTest.java index d6ba21f..6340b04 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameLimitTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameLimitTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameSeperatorTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameSeperatorTest.java index 5d8b8b0..e9e8de0 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameSeperatorTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameSeperatorTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -69,4 +68,17 @@ public class WarpManifestNameSeperatorTest { Assertions.assertEquals("ju n it:", manitest.getAttributes().get(0).getName()); Assertions.assertEquals("junit:", manitest.getAttributes().get(0).getBody()); } + + @Test + public void testWriteV5OutputSeperator() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("ju n it:", "junit:"); + byte[] output = WarpManifestorDriver.亞.writeV5Array(manifest); + Assertions.assertNotNull(output); + WarpManifestX8 manitest = WarpManifestorDriver.亞.readV5Array(output); + Assertions.assertNotNull(manitest); + Assertions.assertEquals(1, manitest.getAttributes().size()); + Assertions.assertEquals("ju n it:", manitest.getAttributes().get(0).getName()); + Assertions.assertEquals("junit:", manitest.getAttributes().get(0).getBody()); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameUnicodeTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameUnicodeTest.java index 9e33bb8..639b45b 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameUnicodeTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestNameUnicodeTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -85,4 +84,18 @@ public class WarpManifestNameUnicodeTest { Assertions.assertEquals("foo", manitest.getAttributes().get(0).getName()); Assertions.assertEquals("仙上主天", manitest.getAttributes().get(1).getName()); } + + @Test + public void testWriteV5NameUnicode() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.withAttribute("foo", "仙上主天"); + manifest.withAttribute("仙上主天", "bar"); + byte[] output = WarpManifestorDriver.亞.writeV5Array(manifest); + Assertions.assertNotNull(output); + WarpManifestX8 manitest = WarpManifestorDriver.亞.readV5Array(output); + Assertions.assertNotNull(manitest); + Assertions.assertEquals(2, manitest.getAttributes().size()); + Assertions.assertEquals("foo", manitest.getAttributes().get(0).getName()); + Assertions.assertEquals("仙上主天", manitest.getAttributes().get(1).getName()); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestSectionNameEmptyTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestSectionNameEmptyTest.java index 9d1a287..6398d3c 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestSectionNameEmptyTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestSectionNameEmptyTest.java @@ -34,8 +34,6 @@ import org.junit.jupiter.api.Test; import org.x4o.o2o.octal.PrimordialOctalOrangeString; import love.distributedrebirth.nx01.warp.manifestor.WarpManifestorDriver; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; -import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18; import love.distributedrebirth.nx01.warp.manifestor.scopic.ScopicManifestException; /// @author للَّٰهِilLצسُو @@ -78,4 +76,13 @@ public class WarpManifestSectionNameEmptyTest { WarpManifestorDriver.亞.writeV4Array(manifest); }); } + + @Test + public void testWriteV5SectionNameEmpty() { + WarpManifestX8 manifest = new WarpManifestX8(); + manifest.makeSection("").withAttribute("foo", "bar"); + Assertions.assertThrows(ScopicManifestException.class, () -> { + WarpManifestorDriver.亞.writeV5Array(manifest); + }); + } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/AbstractContentWriterHandler.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/AbstractContentWriterHandler.java index 44fbb5f..55e374c 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/AbstractContentWriterHandler.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/AbstractContentWriterHandler.java @@ -284,6 +284,7 @@ public class AbstractContentWriterHandler implements ContentHandler { startElementTag(uri,localName); startElementNamespace(uri); + startElementNamespaceAll(); startElementAttributes(atts); startElement.append(XMLConstants.TAG_CLOSE); indent++; @@ -308,12 +309,55 @@ public class AbstractContentWriterHandler implements ContentHandler { } public void startElementNamespace(String uri) throws SAXException { - if ((uri!=null & XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) { - String prefix = prefixMapping.get(uri); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); + if (uri == null) { + return; + } + if (XMLConstants.NULL_NS_URI.equals(uri)) { + return; + } + if (printedMappings.contains(uri)) { + return; + } + String prefix = prefixMapping.get(uri); + if (prefix == null) { + throw new SAXException("preFixUri: "+uri+" is not started."); + } + printedMappings.add(uri); + + startElement.append(' '); + startElement.append(XMLConstants.XMLNS_ATTRIBUTE); + if ("".equals(prefix)==false) { + startElement.append(XMLConstants.XMLNS_ASSIGN); + startElement.append(prefix); + } + startElement.append("=\""); + startElement.append(uri); + startElement.append('"'); + } + + public void startElementNamespaceAll() throws SAXException { + if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) { + return; + } + String prefix = null; + boolean first = true; + for (String uri2:prefixMapping.keySet()) { + if (printedMappings.contains(uri2)) { + continue; + } + prefix = prefixMapping.get(uri2); + if (prefix==null) { + throw new SAXException("preFixUri: "+uri2+" is not started."); + } + printedMappings.add(uri2); + if (XMLConstants.NULL_NS_URI.equals(uri2)) { + continue; // don't print empty namespace uri location + } + + if (first) { + startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); + first = false; } - printedMappings.add(uri); startElement.append(' '); startElement.append(XMLConstants.XMLNS_ATTRIBUTE); @@ -322,42 +366,9 @@ public class AbstractContentWriterHandler implements ContentHandler { startElement.append(prefix); } startElement.append("=\""); - startElement.append(uri); + startElement.append(uri2); startElement.append('"'); - } - startElementNamespaceAll(uri); - } - - public void startElementNamespaceAll(String uri) throws SAXException { - if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) { - return; - } - String prefix = null; - boolean first = true; - for (String uri2:prefixMapping.keySet()) { - if (printedMappings.contains(uri2)==false) { - prefix = prefixMapping.get(uri2); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); - } - printedMappings.add(uri2); - - if (first) { - startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); - first = false; - } - - startElement.append(' '); - startElement.append(XMLConstants.XMLNS_ATTRIBUTE); - if ("".equals(prefix)==false) { - startElement.append(XMLConstants.XMLNS_ASSIGN); - startElement.append(prefix); - } - startElement.append("=\""); - startElement.append(uri2); - startElement.append('"'); - startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); - } + startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterAdapter.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterAdapter.java new file mode 100644 index 0000000..cadc976 --- /dev/null +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterAdapter.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2004-2014, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.x4o.o2o.io.sax3; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + + +/** + * ContentWriterAdapter is base ContentHandler for writing SAX3 events. + * + * @author Willem Cazander + * @version 1.0 Dec 27, 2024 + */ +abstract public class ContentWriterAdapter implements ContentWriter { + + public void comment(char[] ch, int start, int length) throws SAXException { + comment(new String(ch,start,length)); + } + + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + ignorableWhitespace(new String(ch,start,length)); + } + + public void ignorableWhitespace(char c) throws SAXException { + ignorableWhitespace(new char[]{c},0,1); + } + + public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException { + startElement(uri,localName,name, atts); + endElement(uri, localName, name); + } + + public void characters(char c) throws SAXException { + characters(new char[]{c},0,1); + } + + public void characters(char[] ch, int start, int length) throws SAXException { + characters(new String(ch,start,length)); + } + + @Override + public void endCDATA() throws SAXException { + } + + @Override + public void endDTD() throws SAXException { + } + + @Override + public void endEntity(String arg0) throws SAXException { + } + + @Override + public void startCDATA() throws SAXException { + } + + @Override + public void startDTD(String arg0, String arg1, String arg2) throws SAXException { + } + + @Override + public void startEntity(String arg0) throws SAXException { + } + + @Override + public void endPrefixMapping(String arg0) throws SAXException { + } + + @Override + public void processingInstruction(String arg0, String arg1) throws SAXException { + } + + @Override + public void setDocumentLocator(Locator arg0) { + } + + @Override + public void skippedEntity(String arg0) throws SAXException { + } + + @Override + public void startPrefixMapping(String arg0, String arg1) throws SAXException { + } + + @Override + public void comment(String text) throws SAXException { + } + + @Override + public void ignorableWhitespace(String text) throws SAXException { + } +} diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterTagWrapper.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterTagWrapper.java index 918d786..698e50c 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterTagWrapper.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/ContentWriterTagWrapper.java @@ -38,8 +38,12 @@ public class ContentWriterTagWrapper,TAG_WRITER extends Cont private final TAG_WRITER contentWriter; private final String tagNamespaceUri; private final String tagNamespacePrefix; - - public ContentWriterTagWrapper(TAG_WRITER contentWriter,String tagNamespaceUri,String tagNamespacePrefix) { + + public ContentWriterTagWrapper(TAG_WRITER contentWriter) { + this(contentWriter, XMLConstants.NULL_NS_URI, XMLConstants.NULL_NS_URI); + } + + public ContentWriterTagWrapper(TAG_WRITER contentWriter, String tagNamespaceUri, String tagNamespacePrefix) { if (contentWriter==null) { throw new NullPointerException("Can't create wrapper on null ContentWriter"); } @@ -71,7 +75,7 @@ public class ContentWriterTagWrapper,TAG_WRITER extends Cont contentWriter.endDocument(); } - public void printTagStartEnd(TAG tag,Attributes atts) throws SAXException { + public void printTagStartEnd(TAG tag, Attributes atts) throws SAXException { printTagStart(tag,atts); printTagEnd(tag); } @@ -85,7 +89,7 @@ public class ContentWriterTagWrapper,TAG_WRITER extends Cont printTagStart(tag,EMPTY_ATTRIBUTES); } - public void printTagStart(TAG tag,Attributes atts) throws SAXException { + public void printTagStart(TAG tag, Attributes atts) throws SAXException { contentWriter.startElement (getTagNamespaceUri(), toTagString(tag), "", atts); } @@ -102,7 +106,7 @@ public class ContentWriterTagWrapper,TAG_WRITER extends Cont return result; } - public void printTagCharacters(TAG tag,String text) throws SAXException { + public void printTagCharacters(TAG tag, String text) throws SAXException { printTagStart(tag); if (text==null) { text = " "; diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/xdbx/XDBXReaderXml.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/xdbx/XDBXReaderXml.java index 5b0d92f..bca9445 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/xdbx/XDBXReaderXml.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/sax3/xdbx/XDBXReaderXml.java @@ -61,32 +61,36 @@ public class XDBXReaderXml { return this; } - public void parse(InputStream in) throws IOException, SAXException { + public void parse(InputStream in) throws IOException { if (!Arrays.equals(XDBXConstants.HEADER_MARKER, in.readNBytes(2))) { - throw new SAXException("Wrong magic marker"); + throw new IOException("Wrong magic marker"); } int headerLength = in.read(); if (XDBXConstants.HEADER_LENGHT != headerLength) { - throw new SAXException("Wrong header length"); + throw new IOException("Wrong header length"); } int headerVersion = in.read(); if (XDBXConstants.HEADER_VERSION != headerVersion) { - throw new SAXException("Wrong magic version"); + throw new IOException("Wrong magic version"); } int flags = readHeaderFlags(in); if (0 != (flags & XDBXConstants.FLAG_XML_SEQUENCE)) { - throw new SAXException("XML Sequence mode is not supported"); + throw new IOException("XML Sequence mode is not supported"); } if (0 == (flags & XDBXConstants.FLAG_STRING_ID)) { - throw new SAXException("None StringID mode is not supported"); + throw new IOException("None StringID mode is not supported"); } - out.startDocument(); - int next = in.read(); - while (next != -1) { - parseToken(next, in); - next = in.read(); + try { + out.startDocument(); + int next = in.read(); + while (next != -1) { + parseToken(next, in); + next = in.read(); + } + out.endDocument(); + } catch (SAXException e) { + throw new IOException(e); } - out.endDocument(); } private void parseToken(int token, InputStream in) throws IOException, SAXException { 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 3ba446d..08bfd91 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 @@ -34,7 +34,6 @@ import java.util.List; import org.x4o.o2o.io.sax3.ContentWriter; import org.x4o.o2o.io.sax3.ContentWriterTagWrapper; import org.x4o.o2o.io.sax3.ContentWriterXml; -import org.x4o.o2o.io.sax3.XMLConstants; import org.x4o.o2o.io.sax3.xdbx.XDBXWriterXml; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -145,7 +144,7 @@ public class WarpCorePlasmaInspectorServlet extends HttpServlet { public class ContentWriterInspector extends ContentWriterTagWrapper { public ContentWriterInspector(ContentWriter writer) { - super(writer, XMLConstants.NULL_NS_URI, XMLConstants.NULL_NS_URI); + super(writer); } }