diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnum.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnum.java index 458b312..202c496 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnum.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnum.java @@ -20,7 +20,7 @@ * 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.sax3; +package org.x4o.sax3; import java.io.Closeable; import java.io.IOException; @@ -38,16 +38,16 @@ import org.xml.sax.helpers.AttributesImpl; * * @author Willem Cazander * @version 1.0 May 3, 2013 - * @param The enum for the XML tag values. + * @param The enum for the XML tag values. * @param The tag writer to output to. */ -public class SAX3WriterEnum,TAG_WRITER extends ContentWriter> implements SAX3WriterEnumHammer, Closeable { - +public class SAX3WriterEnum, TAG_WRITER extends ContentWriter> implements SAX3WriterEnumHammer, Closeable { + private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); private final TAG_WRITER contentWriter; private final String tagNamespaceUri; private final String tagNamespacePrefix; - + public SAX3WriterEnum(TAG_WRITER contentWriter) { this(contentWriter, SAX3XMLConstants.NULL_NS_URI, SAX3XMLConstants.NULL_NS_URI); } @@ -57,20 +57,20 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter this.tagNamespaceUri = Objects.requireNonNull(tagNamespaceUri, "Can't create wrapper with null tagNamespaceUri"); this.tagNamespacePrefix = Objects.requireNonNull(tagNamespacePrefix, "Can't create wrapper with null tagNamespacePrefix"); } - + @Override public void close() throws IOException { contentWriter.close(); } - + public TAG_WRITER getContentWriterWrapped() { return contentWriter; } - + public String getTagNamespaceUri() { return tagNamespaceUri; } - + public void startDocument() throws IOException { try { contentWriter.startDocument(); @@ -79,7 +79,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter throw new IOException(e); } } - + public void endDocument() throws IOException { try { contentWriter.endDocument(); @@ -87,30 +87,30 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter throw new IOException(e); } } - + public ContentCloseable printTag(TAG tag) throws IOException { return printTag(tag, EMPTY_ATTRIBUTES); } - + public ContentCloseable printTag(TAG tag, Attributes atts) throws IOException { printTagStart(tag, atts); return () -> printTagEnd(tag); } - + public void printTagStartEnd(TAG tag, Attributes atts) throws IOException { printTagStart(tag, atts); printTagEnd(tag); } - + public void printTagStartEnd(TAG tag) throws IOException { printTagStart(tag); printTagEnd(tag); } - + public void printTagStart(TAG tag) throws IOException { printTagStart(tag, EMPTY_ATTRIBUTES); } - + public void printTagStart(TAG tag, Attributes atts) throws IOException { try { contentWriter.startElement(getTagNamespaceUri(), toTagString(tag), "", atts); @@ -118,15 +118,15 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter throw new IOException(e); } } - + public void printTagEnd(TAG tag) throws IOException { try { - contentWriter.endElement(getTagNamespaceUri(),toTagString(tag) , ""); + contentWriter.endElement(getTagNamespaceUri(), toTagString(tag), ""); } catch (SAXException e) { throw new IOException(e); } } - + private String toTagString(TAG tag) { String result = tag.name(); if (result.startsWith("_")) { @@ -134,7 +134,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter } return result; } - + public void printTagCharacters(TAG tag, String text) throws IOException { printTagStart(tag); if (text == null) { @@ -143,7 +143,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter printCharacters(text); printTagEnd(tag); } - + public void printCharacters(String text) throws IOException { try { contentWriter.characters(text); @@ -151,7 +151,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter throw new IOException(e); } } - + public void printComment(String text) throws IOException { try { contentWriter.comment(text); diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnumHammer.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnumHammer.java index 602ae6c..31e7b1d 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnumHammer.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterEnumHammer.java @@ -20,7 +20,7 @@ * 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.sax3; +package org.x4o.sax3; import java.io.IOException; @@ -34,26 +34,26 @@ import org.xml.sax.Attributes; * @param The enum for the XML tag values. */ public interface SAX3WriterEnumHammer> { - + String getTagNamespaceUri(); - + void startDocument() throws IOException; - + void endDocument() throws IOException; - + void printTagStartEnd(TAG tag) throws IOException; - + void printTagStartEnd(TAG tag, Attributes atts) throws IOException; - + void printTagStart(TAG tag) throws IOException; - + void printTagStart(TAG tag, Attributes atts) throws IOException; - + void printTagEnd(TAG tag) throws IOException; - + void printTagCharacters(TAG tag, String text) throws IOException; - + void printCharacters(String text) throws IOException; - + void printComment(String text) throws IOException; } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterHtml.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterHtml.java index d507f8a..cbd3893 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterHtml.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/SAX3WriterHtml.java @@ -20,7 +20,7 @@ * 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.sax3; +package org.x4o.sax3; import java.io.IOException; import java.io.Writer; @@ -38,16 +38,16 @@ import org.xml.sax.helpers.AttributesImpl; * @author Willem Cazander * @version 1.0 Apr 30, 2013 */ -public class SAX3WriterHtml extends SAX3WriterEnum { - +public class SAX3WriterHtml extends SAX3WriterEnum { + public SAX3WriterHtml(Writer out, String encoding) { super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI); } - + public SAX3PropertyConfig getPropertyConfig() { return getContentWriterWrapped().getPropertyConfig(); } - + public void printDocType(DocType doc) throws IOException { try { getContentWriterWrapped().startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId()); @@ -55,7 +55,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum 0) { atts.addAttribute("", "class", "", "", spanClass); } - printTagStart(Tag.span,atts); + printTagStart(Tag.span, atts); } printCharacters(text); if (spanClass != null) { @@ -176,11 +178,11 @@ public class SAX3WriterHtml extends SAX3WriterEnum tagClassEnum) throws IOException { return printTag(tag, tagClassEnum, null); } - + public ContentCloseable printTag(Tag tag, Enum tagClassEnum, String tagId) throws IOException { return printTag(tag, tagClassEnum, tagId, null); } - + public ContentCloseable printTag(Tag tag, Enum tagClassEnum, String tagId, String typeId) throws IOException { return printTag(tag, tagClassEnum.name(), tagId, typeId); } - + public ContentCloseable printTag(Tag tag, String tagClass, String tagId, String typeId) throws IOException { printTagStart(tag, tagClass, tagId, typeId); return () -> printTagEnd(tag); } - + public void printTagStart(Tag tag, String tagClass) throws IOException { printTagStart(tag, tagClass, null, null); } - + public void printTagStart(Tag tag, Enum tagClassEnum) throws IOException { printTagStart(tag, tagClassEnum, null); } - + public void printTagStart(Tag tag, Enum tagClassEnum, String tagId) throws IOException { printTagStart(tag, tagClassEnum, tagId, null); } - + public void printTagStart(Tag tag, Enum tagClassEnum, String tagId, String typeId) throws IOException { printTagStart(tag, tagClassEnum.name(), tagId, typeId); } - + public void printTagStart(Tag tag, String tagClass, String tagId, String typeId) throws IOException { AttributesImpl atts = new AttributesImpl(); if (tagId != null && tagId.length() > 0) { @@ -240,80 +242,180 @@ public class SAX3WriterHtml extends SAX3WriterEnum { - +public class SAX3WriterXsd extends SAX3WriterEnum { + public SAX3WriterXsd(Writer out, String encoding) { super(new SAX3WriterXml(out, encoding), SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI); } - + public SAX3PropertyConfig getPropertyConfig() { return getContentWriterWrapped().getPropertyConfig(); } - + public void printXsdImport(String namespace, String schemaLocation) throws IOException { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "namespace", "", "", namespace); atts.addAttribute("", "schemaLocation", "", "", schemaLocation); printTagStartEnd(Tag._import, atts); } - + public void printXsdDocumentation(String description) throws IOException { if (description == null) { return; @@ -64,7 +64,7 @@ public class SAX3WriterXsd extends SAX3WriterEnum prefixMapping = null; + private Map prefixMapping = null; private List printedMappings = null; private StringBuilder startElement = null; private boolean printReturn = false; private String lastElement = null; private Stack elements = null; - + + //@formatter:off private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "content/"; // TODO: change to "writer/xml" public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG; public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding"; @@ -105,19 +106,21 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true) ); } - + //@formatter:on + /** * Creates XmlWriter which prints to the Writer interface. - * @param out The writer to print the xml to. + * + * @param out The writer to print the xml to. */ public AbstractContentWriterHandler(Writer out) { this.out = Objects.requireNonNull(out, "Can't write on null writer."); - this.prefixMapping = new HashMap(15); + this.prefixMapping = new HashMap(15); this.printedMappings = new ArrayList(15); this.elements = new Stack(); this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX); } - + public SAX3PropertyConfig getPropertyConfig() { return propertyConfig; } @@ -126,7 +129,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { public void close() throws IOException { out.close(); } - + /** * @see org.xml.sax.ContentHandler#startDocument() */ @@ -140,7 +143,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { prologWriteLicence(); prologWriteUserComment(); } - + private void prologWriteLicence() throws SAXException { if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) { return; @@ -177,7 +180,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } comment(licenceText); } - + private String readLicenceStream(InputStream inputStream, String encoding) throws IOException { if (encoding == null) { encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING; @@ -203,7 +206,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { br.close(); } } - + private void prologWriteUserComment() throws SAXException { if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) { return; @@ -220,7 +223,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { userComment = userComment.replaceAll("\n", chEnter + chTab); comment(chEnter + chTab + userComment + chEnter); } - + /** * @see org.xml.sax.ContentHandler#endDocument() */ @@ -230,19 +233,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { throw new SAXException("Invalid xml still have " + elements.size() + " elements open."); } } - + /** - * @param uri The xml namespace uri. - * @param localName The local name of the xml tag. - * @param name The (full) name of the xml tag. - * @param atts The attributes of the xml tag. + * @param uri The xml namespace uri. + * @param localName The local name of the xml tag. + * @param name The (full) name of the xml tag. + * @param atts The attributes of the xml tag. * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { if (localName == null) { throw new SAXException("LocalName may not be null."); } - if (SAX3XMLConstants.isNameString(localName)==false) { + if (SAX3XMLConstants.isNameString(localName) == false) { throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'"); } for (int i = 0; i < atts.getLength(); i++) { @@ -272,8 +275,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB)); } startElement.append(SAX3XMLConstants.TAG_OPEN); - - startElementTag(uri,localName); + + startElementTag(uri, localName); startElementNamespace(uri); startElementNamespaceAll(); startElementAttributes(atts); @@ -282,7 +285,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { lastElement = localName; elements.push(localName); } - + public void startElementTag(String uri, String localName) throws SAXException { if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { startElement.append(localName); @@ -298,7 +301,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { startElement.append(localName); } } - + public void startElementNamespace(String uri) throws SAXException { if (uri == null) { return; @@ -314,7 +317,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { throw new SAXException("preFixUri: " + uri + " is not started."); } printedMappings.add(uri); - + startElement.append(' '); startElement.append(SAX3XMLConstants.XMLNS_ATTRIBUTE); if ("".equals(prefix) == false) { @@ -325,7 +328,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { startElement.append(uri); startElement.append('"'); } - + public void startElementNamespaceAll() throws SAXException { if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) { return; @@ -360,14 +363,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); } } - + private void printElementAttributeNewLineSpace() { startElement.append(SAX3XMLConstants.CHAR_NEWLINE); - for (int ii = 0; ii < indent+1; ii++) { + for (int ii = 0; ii < indent + 1; ii++) { startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB)); } } - + private void startElementAttributes(Attributes atts) throws SAXException { int prevChars = 0; for (int i = 0; i < atts.getLength(); i++) { @@ -378,7 +381,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { attributeValue = propertyConfig.getPropertyString(OUTPUT_CHAR_NULL); } String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue); - + if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) { if (i == 0) { printElementAttributeNewLineSpace(); @@ -396,11 +399,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { startElement.append("=\""); startElement.append(attributeValueSafe); startElement.append('"'); - + if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) { printElementAttributeNewLineSpace(); } - + int breakLines = propertyConfig.getPropertyInteger(OUTPUT_LINE_BREAK_WIDTH); if (breakLines > 0) { if (prevChars == 0 && startElement.length() > breakLines) { @@ -414,11 +417,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } } } - + /** - * @param uri The xml namespace uri. - * @param localName The local name of the xml tag. - * @param name The (full) name of the xml tag. + * @param uri The xml namespace uri. + * @param localName The local name of the xml tag. + * @param name The (full) name of the xml tag. * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) */ public void endElement(String uri, String localName, String name) throws SAXException { @@ -426,16 +429,16 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek()); } elements.pop(); - + if (startElement != null) { String tag = startElement.toString(); - write(tag.substring(0,tag.length() - 1));// rm normal close + write(tag.substring(0, tag.length() - 1));// rm normal close write(SAX3XMLConstants.TAG_CLOSE_EMPTY); startElement = null; indent--; return; } - + indent--; if (printReturn || !localName.equals(lastElement)) { write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); @@ -446,7 +449,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { if (localName == null) { localName = "null"; } - + write(SAX3XMLConstants.TAG_OPEN_END); if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { write(localName); @@ -466,25 +469,26 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { ignorableWhitespace(SAX3XMLConstants.CHAR_NEWLINE); } } - + /** * Starts the prefix mapping of an xml namespace uri. - * @param prefix The xml prefix of this xml namespace uri. - * @param uri The xml namespace uri to add the prefix for. + * + * @param prefix The xml prefix of this xml namespace uri. + * @param uri The xml namespace uri to add the prefix for. * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) */ public void startPrefixMapping(String prefix, String uri) throws SAXException { prefixMapping.put(uri, prefix); } - + /** - * @param prefix The xml prefix of this xml namespace uri to be ended. + * @param prefix The xml prefix of this xml namespace uri to be ended. * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) */ public void endPrefixMapping(String prefix) throws SAXException { - Set> s = prefixMapping.entrySet(); + Set> s = prefixMapping.entrySet(); String uri = null; - for (Map.Entry e : s) { + for (Map.Entry e : s) { if (e.getValue() == null) { continue; // way ? } @@ -501,8 +505,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { /** * Prints xml characters and uses characters(java.lang.String) method. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ContentHandler#characters(char[], int, int) @@ -510,9 +514,10 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { public void characters(char[] ch, int start, int length) throws SAXException { characters(new String(ch, start, length)); } - + /** * Escape and prints xml characters. + * * @param text The text to write. * @throws SAXException When IOException has happend while printing. * @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String) @@ -523,11 +528,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } charactersRaw(SAX3XMLConstants.escapeCharacters(text)); } - + public void characters(char c) throws SAXException { - characters(new char[]{c}, 0, 1); + characters(new char[] { c }, 0, 1); } - + // move or remove ? protected void charactersRaw(String text) throws SAXException { if (text == null) { @@ -537,12 +542,12 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { checkPrintedReturn(text); write(text); } - + /** * Prints xml ignorable whitespace. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) @@ -550,11 +555,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { ignorableWhitespace(new String(ch, start, length)); } - + /** * Prints xml ignorable whitespace. * - * @param text The text to print. + * @param text The text to print. * @throws SAXException When IOException has happend while printing. * @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String) */ @@ -565,23 +570,23 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { autoCloseStartElement(); write(text); // TODO: check chars } - + /** * Prints xml ignorable whitespace character. * - * @param c The character to print. + * @param c The character to print. * @throws SAXException When IOException has happend while printing. */ public void ignorableWhitespace(char c) throws SAXException { - ignorableWhitespace(new char[]{c}, 0, 1); + ignorableWhitespace(new char[] { c }, 0, 1); } - + /** * Prints xml instructions. * * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) * @param target The target. - * @param data The data. + * @param data The data. */ public void processingInstruction(String target, String data) throws SAXException { String targetLow = target.toLowerCase(); @@ -605,7 +610,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { writeFlush(); printReturn = true; } - + /** * Not implemented. * @@ -614,7 +619,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { */ public void setDocumentLocator(Locator locator) { } - + /** * Not implemented. * @@ -624,12 +629,12 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { public void skippedEntity(String name) throws SAXException { // is for validating parser support, so not needed in xml writing. } - + /** * Prints xml comment. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int) @@ -637,7 +642,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { public void comment(char[] ch, int start, int length) throws SAXException { comment(new String(ch, start, length)); } - + /** * Prints xml comment. * @@ -667,15 +672,15 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); writeIndent(); write(SAX3XMLConstants.COMMENT_START); - write(SAX3XMLConstants.escapeCharactersComment(text,getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB), indent)); + write(SAX3XMLConstants.escapeCharactersComment(text, getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB), indent)); write(SAX3XMLConstants.COMMENT_END); printReturn = true; } - + /** * Checks if the value contains any new lines and sets the printReturn field. * - * @param value The value to check. + * @param value The value to check. */ private void checkPrintedReturn(String value) { if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) { @@ -684,10 +689,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { printReturn = false; } } - + /** * Auto close the start element if working in printing event. - * @throws SAXException When prints gives exception. + * + * @throws SAXException When prints gives exception. */ protected void autoCloseStartElement() throws SAXException { if (startElement == null) { @@ -696,17 +702,18 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { write(startElement.toString()); startElement = null; } - + /** * Indent the output writer with tabs by indent count. - * @throws SAXException When prints gives exception. + * + * @throws SAXException When prints gives exception. */ private void writeIndent() throws SAXException { for (int i = 0; i < indent; i++) { write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB)); } } - + protected void writeFlush() throws SAXException { try { out.flush(); @@ -714,7 +721,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { throw new SAXException(e); } } - + private void write(String text) throws SAXException { try { out.write(text); @@ -722,7 +729,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { throw new SAXException(e); } } - + private void write(char c) throws SAXException { try { out.write(c); diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterLexical.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterLexical.java index 39bce0b..41dea4f 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterLexical.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterLexical.java @@ -20,7 +20,7 @@ * 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.sax3.io; +package org.x4o.sax3.io; import java.io.Writer; @@ -33,18 +33,19 @@ import org.xml.sax.ext.LexicalHandler; * @author Willem Cazander * @version 1.0 May 3, 2013 */ -public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler { - +public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler { + protected boolean printCDATA = false; - + /** * Creates XmlWriter which prints to the Writer interface. - * @param out The writer to print the xml to. + * + * @param out The writer to print the xml to. */ public AbstractContentWriterLexical(Writer out) { super(out); } - + /** * @see org.xml.sax.ext.LexicalHandler#startCDATA() */ @@ -53,7 +54,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter charactersRaw(SAX3XMLConstants.CDATA_START); printCDATA = true; } - + /** * @see org.xml.sax.ext.LexicalHandler#endCDATA() */ @@ -61,7 +62,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter charactersRaw(SAX3XMLConstants.CDATA_END); printCDATA = false; } - + /** * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String) */ @@ -80,26 +81,26 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter } charactersRaw(SAX3XMLConstants.TAG_CLOSE); } - + /** * @see org.xml.sax.ext.LexicalHandler#endDTD() */ public void endDTD() throws SAXException { writeFlush(); } - + /** * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) */ public void startEntity(String arg0) throws SAXException { } - + /** * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String) */ public void endEntity(String arg0) throws SAXException { } - + /** * @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int) */ @@ -107,7 +108,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter public void characters(char[] ch, int start, int length) throws SAXException { characters(new String(ch, start, length)); } - + /** * @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String) */ diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AttributeMap.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AttributeMap.java index fc04591..a3eafa8 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AttributeMap.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AttributeMap.java @@ -37,14 +37,14 @@ import java.util.Set; * @param The key class. * @param The value class. */ -public class AttributeMap implements Map { - +public class AttributeMap implements Map { + /** stores the SAX attributes set */ private Attributes attributes = null; /** stores the namespace uri for this attributes */ private String uri = null; - + /** * Constuctes an new AttributeMap. * @@ -53,27 +53,27 @@ public class AttributeMap implements Map { public AttributeMap(Attributes attributes) { setAttributes(attributes); } - + /** * Constructes an new AttributesMap. * - * @param attributes The data backed of this map. - * @param uri The namespace of these attributes. + * @param attributes The data backed of this map. + * @param uri The namespace of these attributes. */ public AttributeMap(Attributes attributes, String uri) { setAttributes(attributes); setNameSpace(uri); } - + /** * Sets the data backend of this map. * - * @param attributes The Attributes to be used as data backend. + * @param attributes The Attributes to be used as data backend. */ public void setAttributes(Attributes attributes) { this.attributes = attributes; } - + /** * Return the data backend of this map. * @@ -82,16 +82,16 @@ public class AttributeMap implements Map { public Attributes getAttributes() { return attributes; } - + /** * Sets the namespace uri, when set to null it is disabled(default). * - * @param uri The namespace uri for when parsing when an certain namespace is required. + * @param uri The namespace uri for when parsing when an certain namespace is required. */ public void setNameSpace(String uri) { this.uri = uri; } - + /** * Returns the namespace used for these attributes. * @@ -100,13 +100,13 @@ public class AttributeMap implements Map { public String getNameSpace() { return uri; } - + // --------------- inner util functions. - + /** * Gets the local of full name by index. * - * @param index The index of the attribute. + * @param index The index of the attribute. * @return The name of the attribute. */ private String getName(int index) { @@ -115,7 +115,7 @@ public class AttributeMap implements Map { } return attributes.getQName(index); } - + /** * Gets the value of the attributes. uses the uri if not null. * @@ -131,9 +131,10 @@ public class AttributeMap implements Map { } return attributes.getValue(name); } - + /** * Gets the attribute value. + * * @param key The name of the attribute. * @return The value of the attribute. */ @@ -143,9 +144,9 @@ public class AttributeMap implements Map { } return getValue(key.toString()); } - + // ------------------------------ MAP intreface - + /** * Returns the size of the map. * @@ -154,7 +155,7 @@ public class AttributeMap implements Map { public int size() { return attributes.getLength(); } - + /** * Checks if there are attributes in this map. * @@ -166,11 +167,11 @@ public class AttributeMap implements Map { } return false; } - + /** * Checks if there is an attributes with an certain key. * - * @param key The name of an attribute. + * @param key The name of an attribute. * @return True if the attributes excist. */ public boolean containsKey(Object key) { @@ -179,11 +180,11 @@ public class AttributeMap implements Map { } return false; } - + /** * Checks if there is an attributes with an value. * - * @param value The value to check. + * @param value The value to check. * @return True if an attributes has this value. */ public boolean containsValue(Object value) { @@ -194,56 +195,56 @@ public class AttributeMap implements Map { } return false; } - + /** * Returns The value of an attribute. * - * @param key The name of the attribute. + * @param key The name of the attribute. * @return The value of the attribute. */ @SuppressWarnings("unchecked") public V get(Object key) { - return (V)getValue(key); + return (V) getValue(key); } - + /** * Function not implements. because we can't add to the attributes. * - * @param key ignored. - * @param value ignored. + * @param key ignored. + * @param value ignored. * @return always null */ public V put(K key, V value) { return null; // we can't add. } - + /** * Function not implements. because we can't remove to the attributes. * - * @param key ignored. + * @param key ignored. * @return always null */ public V remove(Object key) { - return null ;// we can't remove + return null;// we can't remove } - + /** * Function not implements. because we can't add to the attributes. * - * @param t ignored. + * @param t ignored. */ @SuppressWarnings("rawtypes") public void putAll(Map t) { // we can't add. } - + /** * Function not implements. because we can't clear the attributes. */ public void clear() { // we can't clear } - + /** * Returns a new Set whith the names of the attributes. * @@ -253,11 +254,11 @@ public class AttributeMap implements Map { public Set keySet() { HashSet result = new HashSet(); for (int i = 0; i < size(); i++) { - result.add((K)getName(i)); + result.add((K) getName(i)); } return result; } - + /** * Returns an Collection of the values in the attributes list. * @@ -267,14 +268,13 @@ public class AttributeMap implements Map { public Collection values() { ArrayList result = new ArrayList(); for (int i = 0; i < size(); i++) { - result.add((V)attributes.getValue(i)); + result.add((V) attributes.getValue(i)); } return result; } - + /** - * Returns an Set made of Map.Entry. note: This Map.Entry is not refenced by - * the attribute list. so changes to not reflect to this map object. + * Returns an Set made of Map.Entry. note: This Map.Entry is not refenced by the attribute list. so changes to not reflect to this map object. * * @see java.util.Map#entrySet() * @return An entry set. @@ -289,17 +289,17 @@ public class AttributeMap implements Map { } return result; } - + /** * Compares the SAX attribute list. * - * @param o The Object to compare with. + * @param o The Object to compare with. * @return True if the object are equal. */ public boolean equals(Object o) { return attributes.equals(o); // compare to attributes } - + /** * returns the hashCode of the attribute list. * @@ -308,33 +308,35 @@ public class AttributeMap implements Map { public int hashCode() { return attributes.hashCode(); } - + /** * An innerclass used by entrySet(). */ @SuppressWarnings("rawtypes") class AttributeMapEntry implements Map.Entry { - + private Object key = null; private Object value = null; - + /** * Creates AttributeMapEntry with key object. - * @param key The key. + * + * @param key The key. */ protected AttributeMapEntry(Object key) { this.key = key; } - + /** * @return Returns the key. */ public Object getKey() { return key; } - + /** * Sets the value of this Map.Entry. + * * @param value The value to set. * @return The old value. */ @@ -343,14 +345,14 @@ public class AttributeMap implements Map { this.value = value; return result; } - + /** * @return The value of this Map.Entry. */ public Object getValue() { return value; } - + /** * @param o Check if o is equal. * @return True if key and value of Map.Entry are equal. diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentCloseable.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentCloseable.java index 5d1b78b..58def53 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentCloseable.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentCloseable.java @@ -20,12 +20,11 @@ * 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.sax3.io; +package org.x4o.sax3.io; import java.io.Closeable; import java.io.IOException; - /** * Functional closable callback for indenting api flow. * @@ -34,9 +33,9 @@ import java.io.IOException; */ @FunctionalInterface public interface ContentCloseable extends Closeable { - + void closeContent() throws IOException; - + @Override default void close() throws IOException { closeContent(); // wrap for stack trace users diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriter.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriter.java index e7ab7e3..0d78670 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriter.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriter.java @@ -20,7 +20,7 @@ * 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.sax3.io; +package org.x4o.sax3.io; import java.io.Closeable; import java.io.IOException; @@ -30,7 +30,6 @@ import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; - /** * ContentWriter is ContentHandler for writing sax events. * @@ -38,12 +37,12 @@ import org.xml.sax.ext.LexicalHandler; * @version 1.0 Apr 30, 2013 */ public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable { - + /** * Wrap startDocument and endDocument in a body closable code block. * * @return An closable resource block reference. - * @throws SAXException When IOException is thrown. + * @throws SAXException When IOException is thrown. */ default ContentCloseable startDocumentClosure() throws SAXException { startDocument(); @@ -55,49 +54,55 @@ public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable } }; } - + /** * Starts and ends an element in one call. - * @param uri The uri of the element. - * @param localName The localName of the element. - * @param name The name of the element. - * @param atts The attributes of the element. - * @throws SAXException When IOException is thrown. + * + * @param uri The uri of the element. + * @param localName The localName of the element. + * @param name The name of the element. + * @param atts The attributes of the element. + * @throws SAXException When IOException is thrown. */ void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException; - + /** * Writes a String as xml comment. - * @param text The text to have embedded as comment in xml. - * @throws SAXException On error. + * + * @param text The text to have embedded as comment in xml. + * @throws SAXException On error. */ void comment(String text) throws SAXException; - + /** * Writes a whitespace String to the body. - * @param text The String of whitespace to write. - * @throws SAXException On error. + * + * @param text The String of whitespace to write. + * @throws SAXException On error. */ void ignorableWhitespace(String text) throws SAXException; - + /** * Writes a whitespace character to the body. - * @param c The character to write. + * + * @param c The character to write. * @throws SAXException On error; */ void ignorableWhitespace(char c) throws SAXException; - + /** * Writes a String in the body. - * @param text The text to write. - * @throws SAXException On error. + * + * @param text The text to write. + * @throws SAXException On error. */ void characters(String text) throws SAXException; - + /** * Writes a single character in the body body. - * @param c The character to write. - * @throws SAXException On error. + * + * @param c The character to write. + * @throws SAXException On error. */ void characters(char c) throws SAXException; } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriterAdapter.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriterAdapter.java index 690dbde..b2d72ec 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriterAdapter.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/ContentWriterAdapter.java @@ -20,13 +20,12 @@ * 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.sax3.io; +package org.x4o.sax3.io; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.SAXException; - /** * ContentWriterAdapter is base ContentHandler for writing SAX3 events. * @@ -34,80 +33,80 @@ import org.xml.sax.SAXException; * @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); + 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); + 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-sax3/src/main/java/org/x4o/sax3/io/SAX3PropertyConfig.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3PropertyConfig.java index 927b93b..4b1badd 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3PropertyConfig.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3PropertyConfig.java @@ -20,7 +20,7 @@ * 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.sax3.io; +package org.x4o.sax3.io; import java.io.File; import java.util.ArrayList; @@ -37,12 +37,12 @@ import java.util.function.Supplier; * @version 1.0 May 1, 2013 */ public final class SAX3PropertyConfig implements Cloneable { - + public final static String X4O_PROPERTIES_PREFIX = "http://x4o.org/properties/"; - private final Map items; + private final Map items; private final boolean readOnly; private final String keyPrefix; - + public SAX3PropertyConfig(String keyPrefix, PropertyConfigItem... items) { this(false, null, keyPrefix, items); } @@ -50,14 +50,14 @@ public final class SAX3PropertyConfig implements Cloneable { public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... items) { this(false, parentPropertyConfig, keyPrefix, items); } - + public SAX3PropertyConfig(boolean readOnly, SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... itemConfig) { if (keyPrefix == null) { throw new NullPointerException("Can't create PropertyConfig with null keyPrefix."); } this.readOnly = readOnly; this.keyPrefix = appendSlashIfMissing(keyPrefix); - Map fillItems = new HashMap(itemConfig.length); + Map fillItems = new HashMap(itemConfig.length); fillPropertyConfigItems(fillItems, itemConfig); copyParentPropertyConfig(fillItems, parentPropertyConfig); if (fillItems.isEmpty()) { @@ -71,22 +71,22 @@ public final class SAX3PropertyConfig implements Cloneable { } items = Collections.unmodifiableMap(fillItems); } - + private final String appendSlashIfMissing(String keyPrefix) { if (keyPrefix.endsWith("/") == false) { keyPrefix += "/"; } return keyPrefix; } - - private final void fillPropertyConfigItems(Map fillItems, PropertyConfigItem... itemConfig) { + + private final void fillPropertyConfigItems(Map fillItems, PropertyConfigItem... itemConfig) { for (int i = 0; i < itemConfig.length; i++) { PropertyConfigItem item = itemConfig[i]; - fillItems.put(item.getValueKey(),item); + fillItems.put(item.getValueKey(), item); } } - - private final void copyParentPropertyConfig(Map fillItems, SAX3PropertyConfig parentPropertyConfig) { + + private final void copyParentPropertyConfig(Map fillItems, SAX3PropertyConfig parentPropertyConfig) { if (parentPropertyConfig == null) { return; } @@ -94,26 +94,26 @@ public final class SAX3PropertyConfig implements Cloneable { fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key)); } } - + public static final class PropertyConfigItem implements Cloneable { private final boolean valueRequired; private final String valueKey; private final Class valueType; private final Object valueDefault; private Object value = null; - + public PropertyConfigItem(boolean valueRequired, String valueKey, Class valueType) { this(valueRequired, valueKey, valueType, null); } - + public PropertyConfigItem(String valueKey, Class valueType) { this(false, valueKey, valueType, null); } - + public PropertyConfigItem(String valueKey, Class valueType, Object valueDefault) { this(false, valueKey, valueType, valueDefault); // with default then value can not be required. } - + private PropertyConfigItem(boolean valueRequired, String valueKey, Class valueType, Object valueDefault) { if (valueKey == null) { throw new NullPointerException("Can't create PropertyConfigItem with null valueKey."); @@ -126,51 +126,52 @@ public final class SAX3PropertyConfig implements Cloneable { this.valueType = valueType; this.valueDefault = valueDefault; } - + /** * @return the value key. */ public String getValueKey() { return valueKey; } - + /** * @return the valueType. */ public Class getValueType() { return valueType; } - + /** * @return the value default. */ public Object getValueDefault() { return valueDefault; } - + /** * @return the valueRequired. */ public boolean isValueRequired() { return valueRequired; } - + /** * @return the value. */ public Object getValue() { return value; } - + /** * @param value the value to set. */ public void setValue(Object value) { this.value = value; } - + /** * Clones all the fields into the new PropertyConfigItem. + * * @see java.lang.Object#clone() */ @Override @@ -180,7 +181,7 @@ public final class SAX3PropertyConfig implements Cloneable { return clone; } } - + private final PropertyConfigItem getPropertyConfigItem(String key) { if (key == null) { throw new NullPointerException("Can't search with null key."); @@ -191,23 +192,23 @@ public final class SAX3PropertyConfig implements Cloneable { } return item; } - + public final String getKeyPrefix() { return keyPrefix; } - + public final boolean isPropertyRequired(String key) { return getPropertyKeysRequired().contains(key); } - + public final List getPropertyKeysRequired() { return findPropertyKeysRequired(false); } - + public final List getPropertyKeysRequiredValues() { return findPropertyKeysRequired(true); } - + private final List findPropertyKeysRequired(boolean checkValue) { List result = new ArrayList(10); for (String key : getPropertyKeys()) { @@ -223,26 +224,26 @@ public final class SAX3PropertyConfig implements Cloneable { } return result; } - + public final List getPropertyKeys() { List result = new ArrayList(items.keySet()); Collections.sort(result); return Collections.unmodifiableList(result); } - - public final void setProperty(String key,Object value) { + + public final void setProperty(String key, Object value) { if (readOnly) { throw new IllegalStateException("This property is readonly for key:" + key); } PropertyConfigItem item = getPropertyConfigItem(key); item.setValue(value); } - + public final Object getPropertyDefault(String key) { PropertyConfigItem item = getPropertyConfigItem(key); return item.getValueDefault(); } - + public final Object getProperty(String key) { PropertyConfigItem item = getPropertyConfigItem(key); Object value = item.getValue(); @@ -251,12 +252,12 @@ public final class SAX3PropertyConfig implements Cloneable { } return value; } - + public final Class getPropertyType(String key) { PropertyConfigItem item = getPropertyConfigItem(key); return item.getValueType(); } - + public final Class getPropertyType(String key, Supplier> defaultValue) { Class result = getPropertyType(key); if (result != null) { @@ -264,18 +265,18 @@ public final class SAX3PropertyConfig implements Cloneable { } return defaultValue.get(); } - + public final File getPropertyFile(String key) { Object value = getProperty(key); if (value instanceof File) { - return (File)value; + return (File) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - + public final File getPropertyFile(String key, Supplier defaultValue) { File result = getPropertyFile(key); if (result != null) { @@ -283,18 +284,18 @@ public final class SAX3PropertyConfig implements Cloneable { } return defaultValue.get(); } - + public final Boolean getPropertyBoolean(String key) { Object value = getProperty(key); if (value instanceof Boolean) { - return (Boolean)value; + return (Boolean) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - + public final Boolean getPropertyBoolean(String key, Supplier defaultValue) { Boolean result = getPropertyBoolean(key); if (result != null) { @@ -302,18 +303,18 @@ public final class SAX3PropertyConfig implements Cloneable { } return defaultValue.get(); } - + public final Integer getPropertyInteger(String key) { Object value = getProperty(key); if (value instanceof Integer) { - return (Integer)value; + return (Integer) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - + public final Integer getPropertyInteger(String key, Supplier defaultValue) { Integer result = getPropertyInteger(key); if (result != null) { @@ -321,19 +322,19 @@ public final class SAX3PropertyConfig implements Cloneable { } return defaultValue.get(); } - + @SuppressWarnings("unchecked") public final List getPropertyList(String key) { Object value = getProperty(key); if (value instanceof List) { - return (List)value; + return (List) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - + public final List getPropertyList(String key, Supplier> defaultValue) { List result = getPropertyList(key); if (result != null) { @@ -341,39 +342,39 @@ public final class SAX3PropertyConfig implements Cloneable { } return defaultValue.get(); } - + @SuppressWarnings("unchecked") - public final Map getPropertyMap(String key) { + public final Map getPropertyMap(String key) { Object value = getProperty(key); if (value instanceof Map) { - return (Map)value; + return (Map) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - - public final Map getPropertyMap(String key, Supplier> defaultValue) { - Map result = getPropertyMap(key); + + public final Map getPropertyMap(String key, Supplier> defaultValue) { + Map result = getPropertyMap(key); if (result != null) { return result; } return defaultValue.get(); } - + public final String getPropertyString(String key) { Object value = getProperty(key); if (value instanceof String) { - return (String)value; + return (String) value; } if (value == null) { return null; } throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - - public final String getPropertyString(String key,String defaultValue) { + + public final String getPropertyString(String key, String defaultValue) { String propertyValue = getPropertyString(key); if (propertyValue == null) { return defaultValue; @@ -381,15 +382,15 @@ public final class SAX3PropertyConfig implements Cloneable { return propertyValue; } } - - public final String getPropertyString(String key,Supplier defaultValue) { + + public final String getPropertyString(String key, Supplier defaultValue) { String result = getPropertyString(key); if (result != null) { return result; } return defaultValue.get(); } - + public final void copyParentProperties(SAX3PropertyConfig config) { for (String key : getPropertyKeys()) { Object value = config.getProperty(key); @@ -399,9 +400,9 @@ public final class SAX3PropertyConfig implements Cloneable { setProperty(key, value); } } - + @SuppressWarnings("unchecked") - public final void setPropertyParsedValue(String key,String value) { + public final void setPropertyParsedValue(String key, String value) { Class valueType = getPropertyType(key); if (String.class.equals(valueType)) { setProperty(key, value); @@ -429,7 +430,7 @@ public final class SAX3PropertyConfig implements Cloneable { } if (List.class.equals(valueType)) { String[] listValues = value.split(","); - List result = (List)getProperty(key); + List result = (List) getProperty(key); if (result == null) { result = new ArrayList(10); setProperty(key, result); @@ -441,9 +442,9 @@ public final class SAX3PropertyConfig implements Cloneable { } if (Map.class.equals(valueType)) { String[] listValues = value.split(","); - Map result = (Map)getProperty(key); + Map result = (Map) getProperty(key); if (result == null) { - result = new HashMap(10); + result = new HashMap(10); setProperty(key, result); } if (listValues.length != 2) { @@ -455,9 +456,10 @@ public final class SAX3PropertyConfig implements Cloneable { return; } } - + /** * Clones all the properties into the new PropertyConfig. + * * @see java.lang.Object#clone() */ @Override diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3XMLConstants.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3XMLConstants.java index 48951c3..ed1a2bb 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3XMLConstants.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/SAX3XMLConstants.java @@ -31,139 +31,140 @@ import java.util.PrimitiveIterator; * @version 1.0 Mrt 31, 2012 */ public final class SAX3XMLConstants { - + /** * Lowcase xml. */ public static final String XML = javax.xml.XMLConstants.XML_NS_PREFIX; // "xml" - + /** * XML Default encoding is utf-8. */ public static final String XML_DEFAULT_ENCODING = "UTF-8"; - + /** * XML Default version is 1.0. */ public static final String XML_DEFAULT_VERSION = "1.0"; - + /** * XML Namespace prefix attribute. */ public static final String XMLNS_ATTRIBUTE = javax.xml.XMLConstants.XMLNS_ATTRIBUTE; // "xmlns" - + /** * XML Namespace prefix seperator */ public static final String XMLNS_ASSIGN = ":"; - + /** * XML Schema namespace URI. */ - public static final String XML_SCHEMA_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; // "http://www.w3.org/2001/XMLSchema" - + public static final String XML_SCHEMA_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; // "http://www.w3.org/2001/XMLSchema" + /** * XML Schema instance namespace URI. */ public static final String XML_SCHEMA_INSTANCE_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; // "http://www.w3.org/2001/XMLSchema-instance" - + /** * Null or empty namespace uri. + * * @see Namespaces in XML, 5.2 Namespace Defaulting */ public static final String NULL_NS_URI = javax.xml.XMLConstants.NULL_NS_URI; // "" - + /** * Definition of DTD doctype opening tag. */ public static final String XML_DOCTYPE_TAG_OPEN = ""; - + /** * Close empty xml element tag. */ public static final String TAG_CLOSE_EMPTY = "/>"; - + /** * Starts a comment. */ public static final String COMMENT_START = ""; - + /** * Starts a processing instruction. */ public static final String PROCESS_START = ""; - + /** * Starts a cdata section. */ public static final String CDATA_START = ""; - + /** * The regex expression of a cdata start section. */ - public static final String CDATA_START_REGEX = ""; - + public static final String CDATA_END_REGEX = "\\x" + Integer.toHexString(']') + "\\x" + Integer.toHexString(']') + ">"; + /** * Tab char */ public static final char CHAR_TAB = '\t'; - + /** * Newline char */ public static final char CHAR_NEWLINE = '\n'; - + /// Unicode entity reference escape sequence starter public static final int CODE_POINT_ENTIY_REF_ESCAPE = '&'; - + /// Unicode entity reference by number public static final int CODE_POINT_ENTIY_REF_NUMBER = '#'; - + /// Unicode entity reference by hex number public static final int CODE_POINT_ENTIY_REF_NUMBER_HEX = 'x'; - + /// Unicode entity reference escape sequence terminator public static final int CODE_POINT_ENTIY_REF_TERMINATOR = ';'; - + static public String getDocumentDeclaration(String encoding) { - return getDocumentDeclaration(encoding,null); + return getDocumentDeclaration(encoding, null); } - + static public String getDocumentDeclaration(String encoding, String version) { if (encoding == null) { encoding = XML_DEFAULT_ENCODING; @@ -173,65 +174,136 @@ public final class SAX3XMLConstants { } return String.format("", version, encoding); } - + static public boolean isChar(int c) { // Exclude "compatibility characters", as defined in section 2.3 of [Unicode] - if (c>=0x7F & c<=0x84) { return false; } - if (c>=0x86 & c<=0x9F) { return false; } - if (c>=0xFDD0 & c<=0xFDEF) { return false; } - if ((c>=0x1FFFE & c<=0x1FFFF)||(c>=0x2FFFE & c<=0x2FFFF)|(c>=0x3FFFE & c<=0x3FFFF)) { return false; } - if ((c>=0x4FFFE & c<=0x4FFFF)||(c>=0x5FFFE & c<=0x5FFFF)|(c>=0x6FFFE & c<=0x6FFFF)) { return false; } - if ((c>=0x7FFFE & c<=0x7FFFF)||(c>=0x8FFFE & c<=0x8FFFF)|(c>=0x9FFFE & c<=0x9FFFF)) { return false; } - if ((c>=0xAFFFE & c<=0xAFFFF)||(c>=0xBFFFE & c<=0xBFFFF)|(c>=0xCFFFE & c<=0xCFFFF)) { return false; } - if ((c>=0xDFFFE & c<=0xDFFFF)||(c>=0xEFFFE & c<=0xEFFFF)|(c>=0xFFFFE & c<=0xFFFFF)) { return false; } - if (c>=0x10FFFE & c<=0x10FFFF) { return false; } - + if (c >= 0x7F & c <= 0x84) { + return false; + } + if (c >= 0x86 & c <= 0x9F) { + return false; + } + if (c >= 0xFDD0 & c <= 0xFDEF) { + return false; + } + if ((c >= 0x1FFFE & c <= 0x1FFFF) || (c >= 0x2FFFE & c <= 0x2FFFF) | (c >= 0x3FFFE & c <= 0x3FFFF)) { + return false; + } + if ((c >= 0x4FFFE & c <= 0x4FFFF) || (c >= 0x5FFFE & c <= 0x5FFFF) | (c >= 0x6FFFE & c <= 0x6FFFF)) { + return false; + } + if ((c >= 0x7FFFE & c <= 0x7FFFF) || (c >= 0x8FFFE & c <= 0x8FFFF) | (c >= 0x9FFFE & c <= 0x9FFFF)) { + return false; + } + if ((c >= 0xAFFFE & c <= 0xAFFFF) || (c >= 0xBFFFE & c <= 0xBFFFF) | (c >= 0xCFFFE & c <= 0xCFFFF)) { + return false; + } + if ((c >= 0xDFFFE & c <= 0xDFFFF) || (c >= 0xEFFFE & c <= 0xEFFFF) | (c >= 0xFFFFE & c <= 0xFFFFF)) { + return false; + } + if (c >= 0x10FFFE & c <= 0x10FFFF) { + return false; + } + // Source; // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - if (c==0x9) { return true; } - if (c==0xA) { return true; } - if (c==0xD) { return true; } - if (c>=0x20 & c<=0xD7FF) { return true; } - if (c>=0xE000 & c<=0xFFFD) { return true; } - if (c>=0x10000 & c<=0x10FFFF) { return true; } + if (c == 0x9) { + return true; + } + if (c == 0xA) { + return true; + } + if (c == 0xD) { + return true; + } + if (c >= 0x20 & c <= 0xD7FF) { + return true; + } + if (c >= 0xE000 & c <= 0xFFFD) { + return true; + } + if (c >= 0x10000 & c <= 0x10FFFF) { + return true; + } return false; } - + static public boolean isNameStartChar(int c) { // Source; - // ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] - if (c>='a' & c<='z') { return true; } - if (c>='A' & c<='Z') { return true; } - if (c==':' || c=='_') { return true; } - if (c>=0xC0 & c<=0xD6) { return true; } - if (c>=0xD8 & c<=0xF6) { return true; } - if (c>=0xF8 & c<=0x2FF) { return true; } - if (c>=0x370 & c<=0x37D) { return true; } - if (c>=0x37F & c<=0x1FFF) { return true; } - if (c>=0x200C & c<=0x200D) { return true; } - if (c>=0x2070 & c<=0x218F) { return true; } - if (c>=0x2C00 & c<=0x2FEF) { return true; } - if (c>=0x3001 & c<=0xD7FF) { return true; } - if (c>=0xF900 & c<=0xFDCF) { return true; } - if (c>=0xFDF0 & c<=0xFFFD) { return true; } - if (c>=0x10000 & c<=0xEFFFF) { return true; } + // ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | + // [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] + if (c >= 'a' & c <= 'z') { + return true; + } + if (c >= 'A' & c <= 'Z') { + return true; + } + if (c == ':' || c == '_') { + return true; + } + if (c >= 0xC0 & c <= 0xD6) { + return true; + } + if (c >= 0xD8 & c <= 0xF6) { + return true; + } + if (c >= 0xF8 & c <= 0x2FF) { + return true; + } + if (c >= 0x370 & c <= 0x37D) { + return true; + } + if (c >= 0x37F & c <= 0x1FFF) { + return true; + } + if (c >= 0x200C & c <= 0x200D) { + return true; + } + if (c >= 0x2070 & c <= 0x218F) { + return true; + } + if (c >= 0x2C00 & c <= 0x2FEF) { + return true; + } + if (c >= 0x3001 & c <= 0xD7FF) { + return true; + } + if (c >= 0xF900 & c <= 0xFDCF) { + return true; + } + if (c >= 0xFDF0 & c <= 0xFFFD) { + return true; + } + if (c >= 0x10000 & c <= 0xEFFFF) { + return true; + } return false; } - + static public boolean isNameChar(int c) { // Source; // NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] if (isNameStartChar(c)) { return true; } - if (c=='-' || c=='.') { return true; } - if (c>='0' & c<='9') { return true; } - if (c==0xB7) { return true; } - if (c>=0x0300 & c<=0x036F) { return true; } - if (c>=0x203F & c<=0x2040) { return true; } + if (c == '-' || c == '.') { + return true; + } + if (c >= '0' & c <= '9') { + return true; + } + if (c == 0xB7) { + return true; + } + if (c >= 0x0300 & c <= 0x036F) { + return true; + } + if (c >= 0x203F & c <= 0x2040) { + return true; + } return false; } - + static public boolean isCharString(String value) { PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); while (iterator.hasNext()) { @@ -242,7 +314,7 @@ public final class SAX3XMLConstants { } return true; } - + static public boolean isNameString(String value) { boolean first = true; PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); @@ -260,7 +332,7 @@ public final class SAX3XMLConstants { } return true; } - + static private boolean escapeXMLValueAppend(int codePoint, StringBuilder result) { if (codePoint == '<') { result.append("<"); @@ -284,23 +356,23 @@ public final class SAX3XMLConstants { } return false; } - + static public String escapeAttributeValue(String value) { - // Reference ::= EntityRef | CharRef - // AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" + // Reference ::= EntityRef | CharRef + // AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" StringBuilder result = new StringBuilder(value.length()); PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.nextInt(); // 3.3.3 Attribute-Value Normalization. - if (escapeXMLValueAppend(c,result)) { + if (escapeXMLValueAppend(c, result)) { continue; } result.appendCodePoint(c); } return result.toString(); } - + static public String escapeCharacters(String value) { StringBuilder result = new StringBuilder(value.length()); PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); @@ -323,18 +395,18 @@ public final class SAX3XMLConstants { result.append(entity); continue; // contine to next i char. } else { - //i = iOrg; // continue normal escape. + // i = iOrg; // continue normal escape. PrimitiveIterator.OfInt entityIterator = entity.codePoints().iterator(); while (entityIterator.hasNext()) { int entityCodePoint = entityIterator.nextInt(); - if (escapeXMLValueAppend(entityCodePoint,result)) { + if (escapeXMLValueAppend(entityCodePoint, result)) { continue; } result.appendCodePoint(entityCodePoint); } } } else { - if (escapeXMLValueAppend(c,result)) { + if (escapeXMLValueAppend(c, result)) { continue; } result.appendCodePoint(c); @@ -342,60 +414,110 @@ public final class SAX3XMLConstants { } return result.toString(); } - + // TODO: make it loaded and xml and html version aware for correctness. static private boolean charEntityAllowed(String entity) { - + // Hex code points if (entity.startsWith("&#")) { - String hex = entity.substring(2,entity.length() - 1); + String hex = entity.substring(2, entity.length() - 1); if (hex.startsWith("x")) { hex = hex.substring(1); } int codePoint = Integer.parseInt(hex, 16); return codePoint > 0; // TODO: check if code point is valid. } - + // XML - if ("<".equals(entity)) { return true; } - if (">".equals(entity)) { return true; } - if ("&".equals(entity)) { return true; } - if (""".equals(entity)) { return true; } - if ("'".equals(entity)) { return true; } - + if ("<".equals(entity)) { + return true; + } + if (">".equals(entity)) { + return true; + } + if ("&".equals(entity)) { + return true; + } + if (""".equals(entity)) { + return true; + } + if ("'".equals(entity)) { + return true; + } + // HTML - if ("´".equals(entity)) { return true; } - if ("ℵ".equals(entity)) { return true; } - if ("≈".equals(entity)) { return true; } - if ("∠".equals(entity)) { return true; } - if ("∗".equals(entity)) { return true; } - if ("♣".equals(entity)) { return true; } - if ("♦".equals(entity)) { return true; } - if ("♥".equals(entity)) { return true; } - if ("♠".equals(entity)) { return true; } + if ("´".equals(entity)) { + return true; + } + if ("ℵ".equals(entity)) { + return true; + } + if ("≈".equals(entity)) { + return true; + } + if ("∠".equals(entity)) { + return true; + } + if ("∗".equals(entity)) { + return true; + } + if ("♣".equals(entity)) { + return true; + } + if ("♦".equals(entity)) { + return true; + } + if ("♥".equals(entity)) { + return true; + } + if ("♠".equals(entity)) { + return true; + } // TODO: etc/etc - if ("ÿ".equals(entity)) { return true; } - if ("ý".equals(entity)) { return true; } - if ("ù".equals(entity)) { return true; } - if ("ü".equals(entity)) { return true; } - if ("û".equals(entity)) { return true; } - if ("ú".equals(entity)) { return true; } - - if ("÷".equals(entity)) { return true; } - if (" ".equals(entity)) { return true; } - if ("®".equals(entity)) { return true; } - if ("™".equals(entity)) { return true; } - if ("©".equals(entity)) { return true; } + if ("ÿ".equals(entity)) { + return true; + } + if ("ý".equals(entity)) { + return true; + } + if ("ù".equals(entity)) { + return true; + } + if ("ü".equals(entity)) { + return true; + } + if ("û".equals(entity)) { + return true; + } + if ("ú".equals(entity)) { + return true; + } + + if ("÷".equals(entity)) { + return true; + } + if (" ".equals(entity)) { + return true; + } + if ("®".equals(entity)) { + return true; + } + if ("™".equals(entity)) { + return true; + } + if ("©".equals(entity)) { + return true; + } return false; } - - static public String escapeCharactersCdata(String value,String replaceCdataStart,String replaceCdataEnd) { + + static public String escapeCharactersCdata(String value, String replaceCdataStart, String replaceCdataEnd) { value = value.replaceAll(CDATA_START_REGEX, replaceCdataStart); - value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd); + value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd); return value; } - - static public String escapeCharactersComment(String value,String charTab,int indent) { + + static public String escapeCharactersComment(String value, String charTab, int indent) { value = value.replaceAll(COMMENT_START, ""); value = value.replaceAll(COMMENT_END, ""); StringBuilder result = new StringBuilder(value.length()); diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriter.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriter.java index cc2accf..7d9a6d3 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriter.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriter.java @@ -20,7 +20,7 @@ * 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.sax3.io.xdbx; +package org.x4o.sax3.io.xdbx; import java.io.OutputStream; @@ -38,7 +38,8 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple /** * Creates writer which prints to the stream interface. - * @param out The stream to print the xml to. + * + * @param out The stream to print the xml to. */ public AbstractXDBXWriter(OutputStream out) { super(out); @@ -46,10 +47,11 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple /** * Starts and end then element. + * * @see org.x4o.sax3.io.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException { - startElement(uri,localName,name, atts); + startElement(uri, localName, name, atts); endElement(uri, localName, name); } } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterHandler.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterHandler.java index 0bff7b1..8b8439a 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterHandler.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterHandler.java @@ -20,7 +20,7 @@ * 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.sax3.io.xdbx; +package org.x4o.sax3.io.xdbx; import java.io.BufferedReader; import java.io.Closeable; @@ -56,15 +56,16 @@ import org.xml.sax.SAXException; * @author Willem Cazander * @version 1.0 Dec 19, 2024 */ -public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { - +public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { + private final SAX3PropertyConfig propertyConfig; private final OutputStream out; - private Map prefixMapping = null; + private Map prefixMapping = null; private List printedMappings = null; private Stack elements = null; - private Map stringIdx = null; - + private Map stringIdx = null; + + //@formatter:off private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"writer/xdbx/"; public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG; public final static String OUTPUT_DECLARATION = PROPERTY_CONTEXT_PREFIX+"output/declaration"; @@ -94,34 +95,36 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true) ); } - + //@formatter:on + /** * Creates writer which prints to the stream interface. - * @param out The stream to print the xml to. + * + * @param out The stream to print the xml to. */ public AbstractXDBXWriterHandler(OutputStream out) { this.out = Objects.requireNonNull(out, "Can't write on null OutputStream."); - this.prefixMapping = new HashMap(15); + this.prefixMapping = new HashMap(15); this.printedMappings = new ArrayList(15); this.elements = new Stack(); this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX); this.stringIdx = new HashMap<>(); } - + public SAX3PropertyConfig getPropertyConfig() { return propertyConfig; } - + @Override public void close() throws IOException { out.close(); } - + protected boolean xdbxStringId(String data) { Integer result = stringIdx.get(data); return result != null; } - + protected int xdbxStringStore(String data) { Integer result = stringIdx.get(data); if (result != null) { @@ -131,7 +134,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { stringIdx.put(data, result); return result; } - + /** * @see org.xml.sax.ContentHandler#startDocument() */ @@ -146,14 +149,14 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeLengthValue("1.0"); writeTag(XDBXContentTag.ENCODING); writeLengthValue("utf-8"); - //Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1. - //write(XDBXContentTag.STANDALONE); - //write(1); + // Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1. + // write(XDBXContentTag.STANDALONE); + // write(1); } prologWriteLicence(); prologWriteUserComment(); } - + private void prologWriteLicence() throws SAXException { if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) { return; @@ -168,7 +171,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } licenceInput = cl.getResourceAsStream(licenceResource); if (licenceInput == null) { - throw new NullPointerException("Could not load licence resource from: "+licenceResource); + throw new NullPointerException("Could not load licence resource from: " + licenceResource); } } if (licenceInput == null) { @@ -190,7 +193,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } comment(licenceText); } - + private String readLicenceStream(InputStream inputStream, String encoding) throws IOException { if (encoding == null) { encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING; @@ -202,7 +205,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { sb.append('\n'); String line = br.readLine(); while (line != null) { - if (line.length()>0) { + if (line.length() > 0) { sb.append(" "); } sb.append(line); @@ -216,7 +219,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { br.close(); } } - + private void prologWriteUserComment() throws SAXException { if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) { return; @@ -228,12 +231,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { if (userComment.isEmpty()) { return; } - String chEnter = "\n"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE); - String chTab = "\t"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB); + String chEnter = "\n"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE); + String chTab = "\t"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB); userComment = userComment.replaceAll("\n", chEnter + chTab); comment(chEnter + chTab + userComment + chEnter); } - + /** * @see org.xml.sax.ContentHandler#endDocument() */ @@ -244,12 +247,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { throw new SAXException("Invalid xml still have " + elements.size() + " elements open."); } } - + /** - * @param uri The xml namespace uri. - * @param localName The local name of the xml tag. - * @param name The (full) name of the xml tag. - * @param atts The attributes of the xml tag. + * @param uri The xml namespace uri. + * @param localName The local name of the xml tag. + * @param name The (full) name of the xml tag. + * @param atts The attributes of the xml tag. * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { @@ -279,7 +282,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } } } - startElementTag(uri,localName,name); + startElementTag(uri, localName, name); startElementNamespace(uri); startElementAttributes(atts); if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { @@ -288,10 +291,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { elements.push(uri + ":" + name); } } - + public void startElementTag(String uri, String localName, String name) throws SAXException { boolean localNameIdx = xdbxStringId(localName); - if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri==null) { + if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { if (localNameIdx) { writeTag(XDBXContentTag.ELEMENT_I); writeVariableInteger(xdbxStringStore(localName)); @@ -305,7 +308,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } else { String prefix = prefixMapping.get(uri); if (prefix == null) { - throw new SAXException("preFixUri: "+uri+" is not started."); + throw new SAXException("preFixUri: " + uri + " is not started."); } if (localNameIdx) { writeTag(XDBXContentTag.ELEMENT_III); @@ -318,22 +321,22 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeVariableInteger(xdbxStringStore(uri)); } } - + public void startElementNamespace(String uri) throws SAXException { if ((uri != null && SAX3XMLConstants.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."); + throw new SAXException("preFixUri: " + uri + " is not started."); } printedMappings.add(uri); - + writeTag(XDBXContentTag.NS_DECL_II); writeVariableInteger(xdbxStringStore(prefix)); writeVariableInteger(xdbxStringStore(uri)); } startElementNamespaceAll(uri); } - + public void startElementNamespaceAll(String uri) throws SAXException { if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) { return; @@ -343,17 +346,17 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { if (printedMappings.contains(uri2) == false) { prefix = prefixMapping.get(uri2); if (prefix == null) { - throw new SAXException("preFixUri: "+uri+" is not started."); + throw new SAXException("preFixUri: " + uri + " is not started."); } printedMappings.add(uri2); - + writeTag(XDBXContentTag.NS_DECL_II); writeVariableInteger(xdbxStringStore(prefix)); writeVariableInteger(xdbxStringStore(uri2)); } } } - + private void startElementAttributes(Attributes atts) throws SAXException { for (int i = 0; i < atts.getLength(); i++) { String attributeUri = atts.getURI(i); @@ -365,8 +368,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue); boolean attributeValueSimple = attributeValue.equals(attributeValueSafe); boolean attributeNameIdx = xdbxStringId(attributeName); - - if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri ==null) { + + if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri == null) { if (attributeNameIdx) { writeTag(XDBXContentTag.ATTRIBUTE_I); writeVariableInteger(xdbxStringStore(attributeName)); @@ -399,15 +402,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeLengthValue(attributeValueSafe); } } - + /** - * @param uri The xml namespace uri. - * @param localName The local name of the xml tag. - * @param name The (full) name of the xml tag. + * @param uri The xml namespace uri. + * @param localName The local name of the xml tag. + * @param name The (full) name of the xml tag. * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) */ public void endElement(String uri, String localName, String name) throws SAXException { - if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri==null) { + if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { if (elements.size() > 0 && elements.peek().equals(localName) == false) { throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek()); } @@ -420,16 +423,17 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { elements.pop(); writeTag(XDBXContentTag.END_ELEMENT); } - + /** * Starts the prefix mapping of an xml namespace uri. - * @param prefix The xml prefix of this xml namespace uri. - * @param uri The xml namespace uri to add the prefix for. + * + * @param prefix The xml prefix of this xml namespace uri. + * @param uri The xml namespace uri to add the prefix for. * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) */ public void startPrefixMapping(String prefix, String uri) throws SAXException { prefixMapping.put(uri, prefix); - + boolean prefixIdx = xdbxStringId(prefix); if (!prefixIdx) { int prefixIdxNum = xdbxStringStore(prefix); @@ -443,15 +447,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeVariableInteger(uriIdxNum); } } - + /** - * @param prefix The xml prefix of this xml namespace uri to be ended. + * @param prefix The xml prefix of this xml namespace uri to be ended. * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) */ public void endPrefixMapping(String prefix) throws SAXException { - Set> s = prefixMapping.entrySet(); + Set> s = prefixMapping.entrySet(); String uri = null; - for (Map.Entry e : s) { + for (Map.Entry e : s) { if (e.getValue() == null) { continue; // way ? } @@ -463,12 +467,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { prefixMapping.remove(uri); } } - + /** * Prints xml characters and uses characters(java.lang.String) method. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ContentHandler#characters(char[], int, int) @@ -476,9 +480,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void characters(char[] ch, int start, int length) throws SAXException { characters(new String(ch, start, length)); } - + /** * Escape and prints xml characters. + * * @param text The text to write. * @throws SAXException When IOException has happend while printing. * @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String) @@ -489,11 +494,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } charactersRaw(SAX3XMLConstants.escapeCharacters(text)); } - + public void characters(char c) throws SAXException { - characters(new char[]{c}, 0, 1); + characters(new char[] { c }, 0, 1); } - + // move or remove ? protected void charactersRaw(String text) throws SAXException { if (text == null) { @@ -501,12 +506,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } writeTagLengthValue(XDBXContentTag.TEXT_T, text); } - + /** * Prints xml ignorable whitespace. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) @@ -514,11 +519,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { ignorableWhitespace(new String(ch, start, length)); } - + /** * Prints xml ignorable whitespace. * - * @param text The text to print. + * @param text The text to print. * @throws SAXException When IOException has happend while printing. * @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String) */ @@ -528,23 +533,23 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } writeTagLengthValue(XDBXContentTag.TEXT_WHITE_SPACE, text); } - + /** * Prints xml ignorable whitespace character. * - * @param c The character to print. + * @param c The character to print. * @throws SAXException When IOException has happend while printing. */ public void ignorableWhitespace(char c) throws SAXException { - ignorableWhitespace(new char[]{c}, 0, 1); + ignorableWhitespace(new char[] { c }, 0, 1); } - + /** * Prints xml instructions. * * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) * @param target The target. - * @param data The data. + * @param data The data. */ public void processingInstruction(String target, String data) throws SAXException { String targetLow = target.toLowerCase(); @@ -557,20 +562,20 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { if (SAX3XMLConstants.isCharString(data) == false) { throw new SAXException("Processing instruction data is invalid char; '" + data + "'"); } - - //'I' LengthValue StringID + + // 'I' LengthValue StringID int targetIdx = xdbxStringStore(target); writeTagLengthValue(XDBXContentTag.STRING_ID, target); writeVariableInteger(targetIdx); - - //'P' StringID LengthValue + + // 'P' StringID LengthValue writeTag(XDBXContentTag.PROCESSING_INSTRUCTION); writeVariableInteger(targetIdx); writeLengthValue(data); - + writeFlush(); } - + /** * Not implemented. * @@ -579,7 +584,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { */ public void setDocumentLocator(Locator locator) { } - + /** * Not implemented. * @@ -589,12 +594,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void skippedEntity(String name) throws SAXException { // is for validating parser support, so not needed in xml writing. } - + /** * Prints xml comment. * - * @param ch Character buffer. - * @param start The start index of the chars in the ch buffer. + * @param ch Character buffer. + * @param start The start index of the chars in the ch buffer. * @param length The length index of the chars in the ch buffer. * @throws SAXException When IOException has happend while printing. * @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int) @@ -602,7 +607,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void comment(char[] ch, int start, int length) throws SAXException { comment(new String(ch, start, length)); } - + /** * Prints xml comment. * @@ -621,7 +626,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { char textStart = text.charAt(0); char textEnd = text.charAt(text.length() - 1); if (textStart != ' ' && textStart != '\t' && textStart != '\n') { - text = " "+text; + text = " " + text; } if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') { text = text + " "; @@ -629,7 +634,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text, "", 0)); } - + protected void writeFlush() throws SAXException { try { out.flush(); @@ -637,7 +642,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { throw new SAXException(e); } } - + private void write(byte[] data) throws SAXException { try { out.write(data); @@ -645,7 +650,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { throw new SAXException(e); } } - + private void write(int c) throws SAXException { try { out.write(c); @@ -653,23 +658,23 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { throw new SAXException(e); } } - + public void writeHeaderFlags(OutputStream out, int flags) throws SAXException { write(flags >> 24); write(flags >> 16); write(flags >> 8); write(flags >> 0); } - + protected void writeTag(XDBXContentTag tag) throws SAXException { write(tag.getTagNumber()); } - + protected void writeTagLengthValue(XDBXContentTag tag, String data) throws SAXException { writeTag(tag); writeLengthValue(data); } - + protected void writeVariableInteger(int i) throws SAXException { if (i < 128) { write(i); @@ -684,12 +689,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { write((i >> 7) & 0b1111111 + 128); write(i & 0b1111111); } - + protected void writeLengthValue(byte[] data) throws SAXException { writeVariableInteger(data.length); write(data); } - + protected void writeLengthValue(String data) throws SAXException { writeLengthValue(data.getBytes(StandardCharsets.UTF_8)); } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterLexical.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterLexical.java index d15e8ee..6800a07 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterLexical.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/AbstractXDBXWriterLexical.java @@ -20,7 +20,7 @@ * 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.sax3.io.xdbx; +package org.x4o.sax3.io.xdbx; import java.io.OutputStream; @@ -35,56 +35,57 @@ import org.xml.sax.ext.LexicalHandler; * @version 1.0 Dec 20, 2024 */ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandler implements LexicalHandler { - + protected boolean printCDATA = false; - + /** * Creates writer which prints to the stream interface. - * @param out The stream to print the xml to. + * + * @param out The stream to print the xml to. */ public AbstractXDBXWriterLexical(OutputStream out) { super(out); } - + /** * @see org.xml.sax.ext.LexicalHandler#startCDATA() */ public void startCDATA() throws SAXException { printCDATA = true; } - + /** * @see org.xml.sax.ext.LexicalHandler#endCDATA() */ public void endCDATA() throws SAXException { printCDATA = false; } - + /** * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String) */ public void startDTD(String name, String publicId, String systemId) throws SAXException { // not supported } - + /** * @see org.xml.sax.ext.LexicalHandler#endDTD() */ public void endDTD() throws SAXException { } - + /** * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) */ public void startEntity(String arg0) throws SAXException { } - + /** * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String) */ - public void endEntity(String arg0) throws SAXException { + public void endEntity(String arg0) throws SAXException { } - + /** * @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int) */ @@ -92,7 +93,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle public void characters(char[] ch, int start, int length) throws SAXException { characters(new String(ch, start, length)); } - + /** * @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String) */ diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXConstants.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXConstants.java index 6b5430d..0ff58a6 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXConstants.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXConstants.java @@ -29,11 +29,11 @@ package org.x4o.sax3.io.xdbx; * @version 1.0 Dec 20, 2024 */ public final class XDBXConstants { - - static public final byte[] HEADER_MARKER = new byte[] {(byte) 0xCA, 0x3B}; + + static public final byte[] HEADER_MARKER = new byte[] { (byte) 0xCA, 0x3B }; static public final byte HEADER_LENGHT = 0x05; static public final byte HEADER_VERSION = 0x01; - + static public final int FLAG_XML_SEQUENCE = 0x1; static public final int FLAG_STRING_ID = 0x2; static public final int FLAG_STRING_ID_IDX = 0x20; diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXContentTag.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXContentTag.java index b1a7ea2..333b740 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXContentTag.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXContentTag.java @@ -29,7 +29,7 @@ package org.x4o.sax3.io.xdbx; * @version 1.0 Dec 20, 2024 */ public enum XDBXContentTag { - + DOCUMENT_END('Z'), COMPLETED_DOC('d'), ATOMIC_VALUE('V'), @@ -54,15 +54,14 @@ public enum XDBXContentTag { PROCESSING_INSTRUCTION('P'), STRING_ID('I'), HINT('H'), - SEQUENCE_SEPERATOR('@'), - ; - + SEQUENCE_SEPERATOR('@'),; + private final int tagNumber; - + private XDBXContentTag(char tag) { tagNumber = tag; } - + public int getTagNumber() { return tagNumber; } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXReaderXml.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXReaderXml.java index fb0d63a..31d3c46 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXReaderXml.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXReaderXml.java @@ -20,7 +20,7 @@ * 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.sax3.io.xdbx; +package org.x4o.sax3.io.xdbx; import java.io.IOException; import java.io.InputStream; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; * @author Willem Cazander * @version 1.0 Dec 20, 2024 */ -public class XDBXReaderXml { +public class XDBXReaderXml { private final ContentWriter out; private final Map stringIdx; @@ -48,19 +48,19 @@ public class XDBXReaderXml { private String docEncoding; private Stack elementStack; private boolean failOnUnsupportedTag = true; - + public XDBXReaderXml(ContentWriter out) { this.out = out; this.stringIdx = new HashMap<>(); this.elementStack = new Stack<>(); } - + // TODO: replace with proper PropertyConfig support public XDBXReaderXml withNoFailOnUnsupportedTag() { failOnUnsupportedTag = false; - return this; + return this; } - + public void parse(InputStream in) throws IOException { if (!Arrays.equals(XDBXConstants.HEADER_MARKER, in.readNBytes(2))) { throw new IOException("Wrong magic marker"); @@ -92,7 +92,7 @@ public class XDBXReaderXml { throw new IOException(e); } } - + private void parseToken(int token, InputStream in) throws IOException, SAXException { if (XDBXContentTag.STRING_ID.getTagNumber() == token) { String value = readLengthValue(in); @@ -233,10 +233,10 @@ public class XDBXReaderXml { return; // NOP is done by caller } if (failOnUnsupportedTag) { - throw new SAXException("Unsupported tag: " + (char)token + " 0x" + Integer.toHexString(token).toUpperCase()); + throw new SAXException("Unsupported tag: " + (char) token + " 0x" + Integer.toHexString(token).toUpperCase()); } } - + protected void flushDocDeclaration() throws SAXException { if (docMetaFlushed) { return; @@ -244,7 +244,7 @@ public class XDBXReaderXml { docMetaFlushed = true; out.declaration(docXmlVersion, docEncoding, ""); } - + protected void flushElement() throws SAXException { flushDocDeclaration(); if (elementStack.isEmpty()) { @@ -257,13 +257,13 @@ public class XDBXReaderXml { element.started = true; out.startElement(element.uri, element.localName, element.name, element.atts); } - + protected String readLengthValue(InputStream in) throws IOException { int len = readVariableInteger(in); String value = new String(in.readNBytes(len)); return value; } - + protected int readVariableInteger(InputStream in) throws IOException { int result = in.read(); if (result < 128) { @@ -275,7 +275,7 @@ public class XDBXReaderXml { } return result + (in.read() << 14); } - + public int readHeaderFlags(InputStream in) throws IOException { int result = 0; result += in.read() << 24; @@ -284,7 +284,7 @@ public class XDBXReaderXml { result += in.read() << 0; return result; } - + public String getDocXmlVersion() { return docXmlVersion; } @@ -292,17 +292,18 @@ public class XDBXReaderXml { public String getDocEncoding() { return docEncoding; } - + class XDBXElement { String uri; String localName; String name; final AttributesImpl atts; boolean started = false; - + XDBXElement() { atts = new AttributesImpl(); } + XDBXElement(String localName) { this(); this.localName = localName; diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXWriterXml.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXWriterXml.java index 4967809..17a8f30 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXWriterXml.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/xdbx/XDBXWriterXml.java @@ -20,7 +20,7 @@ * 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.sax3.io.xdbx; +package org.x4o.sax3.io.xdbx; import java.io.OutputStream; @@ -30,11 +30,12 @@ import java.io.OutputStream; * @author Willem Cazander * @version 1.0 Dev 20, 2024 */ -public class XDBXWriterXml extends AbstractXDBXWriter { +public class XDBXWriterXml extends AbstractXDBXWriter { /** * Creates XmlWriter which prints to the OutputStream interface. - * @param out The OutputStream to write to. + * + * @param out The OutputStream to write to. */ public XDBXWriterXml(OutputStream out) { super(out); diff --git a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlAttributeTest.java b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlAttributeTest.java index 54a5976..ac38a66 100644 --- a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlAttributeTest.java +++ b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlAttributeTest.java @@ -47,39 +47,41 @@ import org.xml.sax.helpers.AttributesImpl; * @version 1.0 S 17, 2012 */ public class SAX3WriterXmlAttributeTest { - + @Test public void testAttributeNormal() throws Exception { StringWriter outputWriter = new StringWriter(); try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) { writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "attr", "", "", "foobar"); + atts.addAttribute("", "attr", "", "", "foobar"); writer.startElementEnd("", "test", "", atts); writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n"), output); } - + @Test public void testAttributeEscape() throws Exception { StringWriter outputWriter = new StringWriter(); try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) { writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "attr", "", "", " & 'foobar' is \"quoted\"!"); + atts.addAttribute("", "attr", "", "", " & 'foobar' is \"quoted\"!"); writer.startElementEnd("", "test", "", atts); writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); - Assertions.assertTrue(output.equals("\n"), output); + Assertions.assertTrue(output.length() > 0); + Assertions.assertTrue( + output.equals("\n"), + output); } - + @Test public void testAttributeWhiteSpace() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -87,57 +89,57 @@ public class SAX3WriterXmlAttributeTest { writer.startDocument(); Assertions.assertThrows(SAXException.class, () -> { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "", "", "", "junit"); + atts.addAttribute("", "", "", "", "junit"); writer.startElementEnd("", "test", "", atts); }); Assertions.assertThrows(SAXException.class, () -> { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", " ", "", "", "junit"); + atts.addAttribute("", " ", "", "", "junit"); writer.startElementEnd("", "test", "", atts); }); Assertions.assertThrows(SAXException.class, () -> { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "foo bar", "", "", "junit"); + atts.addAttribute("", "foo bar", "", "", "junit"); writer.startElementEnd("", "test", "", atts); }); Assertions.assertThrows(SAXException.class, () -> { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "foobar", "", "", "junit"); + atts.addAttribute("", "foobar", "", "", "junit"); writer.startElementEnd("", "test junit", "", atts); }); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "abc", "", "", " junit "); + atts.addAttribute("", "abc", "", "", " junit "); writer.startElementEnd("", "root", "", atts); writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n"), output); } - + @Test public void testAttributeChinees() throws Exception { StringWriter outputWriter = new StringWriter(); try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) { writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "仙上主天", "", "", "仙上主天"); + atts.addAttribute("", "仙上主天", "", "", "仙上主天"); writer.startElementEnd("", "chinees", "", atts); writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n"), output); - + SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); - XMLReader saxReader = saxParser.getXMLReader(); + XMLReader saxReader = saxParser.getXMLReader(); saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8)))); Assertions.assertNotNull(saxReader); } - + @Test public void testAttributeBrahmi() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -145,38 +147,40 @@ public class SAX3WriterXmlAttributeTest { // Legal by spec, but not in JVM SAX Reader writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); - atts.addAttribute ("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ"); + atts.addAttribute("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕"); + atts.addAttribute("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ"); writer.startElementEnd("", "test", "", atts); writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); - Assertions.assertTrue(output.equals("\n"), output); - + Assertions.assertTrue(output.length() > 0); + Assertions.assertTrue(output.equals( + "\n"), + output); + // TODO: fix SAX impl Assertions.assertThrows(SAXException.class, () -> { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); - XMLReader saxReader = saxParser.getXMLReader(); + XMLReader saxReader = saxParser.getXMLReader(); saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8)))); }); } - - private String createLongAttribute(Map para) throws SAXException, IOException { + + private String createLongAttribute(Map para) throws SAXException, IOException { StringWriter outputWriter = new StringWriter(); try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) { - for (String key:para.keySet()) { + for (String key : para.keySet()) { Object value = para.get(key); writer.getPropertyConfig().setProperty(key, value); } - + AttributesImpl atts = new AttributesImpl(); String data = "_FOR_FOO_BAR"; String dataValue = "LOOP"; - for (int i=0;i<15;i++) { - atts.addAttribute("", "attr"+i, "", "", dataValue+=data); + for (int i = 0; i < 15; i++) { + atts.addAttribute("", "attr" + i, "", "", dataValue += data); } writer.startDocument(); writer.startElement("", "test", "", atts); @@ -187,43 +191,43 @@ public class SAX3WriterXmlAttributeTest { } return outputWriter.toString(); } - + @Test public void testAttributeLongNormal() throws Exception { - Map para = new HashMap(); + Map para = new HashMap(); String output = createLongAttribute(para); int newlines = output.split("\n").length; Assertions.assertNotNull(output); - Assertions.assertTrue(newlines==4, "outputs: "+newlines); + Assertions.assertTrue(newlines == 4, "outputs: " + newlines); } - + @Test public void testAttributeLongPerLine() throws Exception { - Map para = new HashMap(); + Map para = new HashMap(); para.put(SAX3WriterXml.OUTPUT_LINE_PER_ATTRIBUTE, true); String output = createLongAttribute(para); int newlines = output.split("\n").length; Assertions.assertNotNull(output); - Assertions.assertTrue(newlines==20, "outputs: "+newlines); + Assertions.assertTrue(newlines == 20, "outputs: " + newlines); } - + @Test public void testAttributeLongSplit80() throws Exception { - Map para = new HashMap(); + Map para = new HashMap(); para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 80); String output = createLongAttribute(para); int newlines = output.split("\n").length; Assertions.assertNotNull(output); - Assertions.assertTrue(newlines==16, "outputs: "+newlines); + Assertions.assertTrue(newlines == 16, "outputs: " + newlines); } - + @Test public void testAttributeLongSplit180() throws Exception { - Map para = new HashMap(); + Map para = new HashMap(); para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 180); String output = createLongAttribute(para); int newlines = output.split("\n").length; Assertions.assertNotNull(output); - Assertions.assertTrue(newlines==11, "outputs: "+newlines); + Assertions.assertTrue(newlines == 11, "outputs: " + newlines); } } diff --git a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlCDataTest.java b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlCDataTest.java index 8bcae75..e836e28 100644 --- a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlCDataTest.java +++ b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlCDataTest.java @@ -35,7 +35,7 @@ import org.x4o.sax3.SAX3WriterXml; * @version 1.0 Sep 17, 2013 */ public class SAX3WriterXmlCDataTest { - + @Test public void testCDATANone() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -46,10 +46,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("foobar"), output); } - + @Test public void testCDATANoneTagEscape() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -60,10 +60,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("foobar<test/>"), output); } - + @Test public void testCDATANormal() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -76,10 +76,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals(""), output); } - + @Test public void testCDATAEscapeTag() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -92,10 +92,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("]]>"), output); } - + @Test public void testCDATAEscapeStart() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -108,10 +108,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals(""), output); } - + @Test public void testCDATAEscapeEnd() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -124,10 +124,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals(""), output); } - + @Test public void testCDATAEscapeEndEskimo() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -140,10 +140,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals(""), output); } - + @Test public void testCDATAEscapeInvalid() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -156,10 +156,10 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("]]>"), output); } - + @Test public void testCDATAEscapeValid() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -172,7 +172,7 @@ public class SAX3WriterXmlCDataTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\' are ]]>")); } } diff --git a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlTest.java b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlTest.java index 9c57f71..2a0537b 100644 --- a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlTest.java +++ b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/SAX3WriterXmlTest.java @@ -37,7 +37,7 @@ import org.xml.sax.helpers.AttributesImpl; * @version 1.0 Aug 26, 2012 */ public class SAX3WriterXmlTest { - + @Test public void testCharactersNormal() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -48,10 +48,10 @@ public class SAX3WriterXmlTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("test is foobar!"), output); } - + @Test public void testCharactersEscape() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -62,10 +62,10 @@ public class SAX3WriterXmlTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("<test/> & 'foobar' is "quoted"!"), output); } - + @Test public void testCommentNormal() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -76,10 +76,10 @@ public class SAX3WriterXmlTest { } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n"), output); } - + @Test public void testCommentEscape() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -89,17 +89,17 @@ public class SAX3WriterXmlTest { writer.endDocument(); } // note two space because auto-space is before escaping and places spaces over comment tags. - // 1) "" - argu + // 1) "" - argu // 2) " " - auto-space (default enabled) - // 3) " foobar " - escapes - // 4) "" - printed - + // 3) " foobar " - escapes + // 4) "" - printed + String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); - Assertions.assertTrue(output.equals("\n"), output); + Assertions.assertTrue(output.length() > 0); + Assertions.assertTrue(output.equals("\n"), output); } - + @Test public void testXmlInvalid() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -110,13 +110,13 @@ public class SAX3WriterXmlTest { writer.startElement("", "test", "", atts); writer.startElement("", "foobar", "", atts); writer.endElement("", "test", ""); - writer.endDocument(); + writer.endDocument(); }); Assertions.assertTrue(e.getMessage().contains("tag")); Assertions.assertTrue(e.getMessage().contains("foobar")); } } - + @Test public void testXmlInvalidEnd() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -133,7 +133,7 @@ public class SAX3WriterXmlTest { Assertions.assertTrue(e.getMessage().contains("open")); } } - + @Test public void testProcessingInstruction() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -143,14 +143,14 @@ public class SAX3WriterXmlTest { writer.processingInstruction("target", "data"); writer.startElement("", "test", "", atts); writer.endElement("", "test", ""); - writer.endDocument(); + writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); + Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n\n"), output); } - + @Test public void testProcessingInstructionInline() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -161,14 +161,15 @@ public class SAX3WriterXmlTest { writer.startElement("", "test", "", atts); writer.processingInstruction("target-doc", "data-doc"); writer.endElement("", "test", ""); - writer.endDocument(); + writer.endDocument(); } String output = outputWriter.toString(); Assertions.assertNotNull(output); - Assertions.assertTrue(output.length()>0); - Assertions.assertTrue(output.equals("\n\n\n\t\n\n"), output); + Assertions.assertTrue(output.length() > 0); + Assertions.assertTrue(output.equals("\n\n\n\t\n\n"), + output); } - + @Test public void testProcessingInstructionTargetXmlPrefix() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -181,7 +182,7 @@ public class SAX3WriterXmlTest { Assertions.assertTrue(e.getMessage().contains("start with xml")); } } - + @Test public void testProcessingInstructionTargetNoneNameChar() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -195,14 +196,14 @@ public class SAX3WriterXmlTest { Assertions.assertTrue(e.getMessage().contains("4Prefix")); } } - + @Test public void testProcessingInstructionDataNoneChar() throws Exception { StringWriter outputWriter = new StringWriter(); try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) { SAXException e = Assertions.assertThrows(SAXException.class, () -> { writer.startDocument(); - writer.processingInstruction("target", "isInvalidChar="+0xD800); + writer.processingInstruction("target", "isInvalidChar=" + 0xD800); }); Assertions.assertTrue(e.getMessage().contains("instruction")); Assertions.assertTrue(e.getMessage().contains("invalid char")); diff --git a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXReaderXmlTest.java b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXReaderXmlTest.java index 6541d0b..3b65033 100644 --- a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXReaderXmlTest.java +++ b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXReaderXmlTest.java @@ -45,61 +45,61 @@ import org.xml.sax.helpers.AttributesImpl; * @version 1.0 Dec 21, 2024 */ public class XDBXReaderXmlTest { - + @Test public void testReadWrite() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (XDBXWriterXml writer = new XDBXWriterXml(baos)) { writer.startDocument(); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "attr", "", "", "foobar"); + atts.addAttribute("", "attr", "", "", "foobar"); writer.startElementEnd("", "test", "", atts); writer.endDocument(); } - + StringWriter outputXmlStr = new StringWriter(); SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr); XDBXReaderXml reader = new XDBXReaderXml(outputXml); byte[] writeData = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(writeData); reader.parse(bais); - + String output = outputXmlStr.toString(); Assertions.assertNotNull(output); Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.equals("\n"), output); } - + @Test public void testReadWritePom() throws Exception { SAXParserFactory saxFactory = SAXParserFactory.newInstance(); saxFactory.setNamespaceAware(true); SAXParser saxParser = saxFactory.newSAXParser(); - XMLReader saxReader = saxParser.getXMLReader(); - + XMLReader saxReader = saxParser.getXMLReader(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); XDBXWriterXml writer = new XDBXWriterXml(baos); - + saxReader.setContentHandler(writer); saxReader.parse(new InputSource(new FileInputStream(new File("../pom.xml")))); - + StringWriter outputXmlStr = new StringWriter(); SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr); XDBXReaderXml reader = new XDBXReaderXml(outputXml); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); reader.parse(bais); - + String output = outputXmlStr.toString(); Assertions.assertNotNull(output); Assertions.assertTrue(output.length() > 0); Assertions.assertTrue(output.contains("nx01-x4o-driver"), output); - + long sizePom = new File("../pom.xml").length(); long sizeXDBX = baos.toByteArray().length; - + System.out.println("size-pom.xml:: " + sizePom); System.out.println("size-pom.xdbx: " + sizeXDBX); - + Assertions.assertTrue(sizePom > sizeXDBX, "XDBX is not smaller"); } } diff --git a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXWriterXmlTest.java b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXWriterXmlTest.java index 5b64b08..2bcd316 100644 --- a/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXWriterXmlTest.java +++ b/nx01-x4o-sax3/src/test/java/org/x4o/sax3/io/xdbx/XDBXWriterXmlTest.java @@ -38,104 +38,103 @@ import org.xml.sax.helpers.AttributesImpl; * @version 1.0 Dec 21, 2024 */ public class XDBXWriterXmlTest { - + @Test public void testExample1DefaultEncoding() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (XDBXWriterXml writer = new XDBXWriterXml(baos)) { writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false); - + writer.startDocument(); writer.startElement("", "root", "", new AttributesImpl()); - - AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "mgr", "", "", "NO"); + + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute("", "mgr", "", "", "NO"); writer.startElement("", "name", "", atts); writer.characters("Joe"); writer.endElement("", "name", ""); - + writer.startElement("", "name", "", new AttributesImpl()); writer.characters("Susan"); writer.endElement("", "name", ""); writer.startElement("", "name", "", new AttributesImpl()); writer.characters("Bill"); writer.endElement("", "name", ""); - + writer.endElement("", "root", ""); writer.endDocument(); } - + byte[] output = baos.toByteArray(); int outIdx = 8; Assertions.assertNotNull(output); Assertions.assertTrue(output.length > 0); - Assertions.assertEquals((byte)'X', output[outIdx++]); + Assertions.assertEquals((byte) 'X', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'t', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 't', output[outIdx++]); Assertions.assertEquals((byte) 1, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); - - Assertions.assertEquals((byte)'X', output[outIdx++]); + + Assertions.assertEquals((byte) 'X', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'n', output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); - Assertions.assertEquals((byte)'m', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); + Assertions.assertEquals((byte) 'n', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); + Assertions.assertEquals((byte) 'm', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); - - Assertions.assertEquals((byte)'Y', output[outIdx++]); + + Assertions.assertEquals((byte) 'Y', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'m', output[outIdx++]); - Assertions.assertEquals((byte)'g', output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); + Assertions.assertEquals((byte) 'm', output[outIdx++]); + Assertions.assertEquals((byte) 'g', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - Assertions.assertEquals((byte)'N', output[outIdx++]); - Assertions.assertEquals((byte)'O', output[outIdx++]); - Assertions.assertEquals((byte)'T', output[outIdx++]); + Assertions.assertEquals((byte) 'N', output[outIdx++]); + Assertions.assertEquals((byte) 'O', output[outIdx++]); + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'J', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); - - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + Assertions.assertEquals((byte) 'J', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); + + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace Assertions.assertEquals((byte) 2, output[outIdx++]); - //Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace - //Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace - Assertions.assertEquals((byte)'T', output[outIdx++]); + // Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + // Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 5, output[outIdx++]); - Assertions.assertEquals((byte)'S', output[outIdx++]); - Assertions.assertEquals((byte)'u', output[outIdx++]); - Assertions.assertEquals((byte)'s', output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); - Assertions.assertEquals((byte)'n', output[outIdx++]); - - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + Assertions.assertEquals((byte) 'S', output[outIdx++]); + Assertions.assertEquals((byte) 'u', output[outIdx++]); + Assertions.assertEquals((byte) 's', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); + Assertions.assertEquals((byte) 'n', output[outIdx++]); + + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace Assertions.assertEquals((byte) 2, output[outIdx++]); - //Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace - //Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace - Assertions.assertEquals((byte)'T', output[outIdx++]); + // Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + // Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'B', output[outIdx++]); - Assertions.assertEquals((byte)'i', output[outIdx++]); - Assertions.assertEquals((byte)'l', output[outIdx++]); - Assertions.assertEquals((byte)'l', output[outIdx++]); - - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'Z', output[outIdx++]); + Assertions.assertEquals((byte) 'B', output[outIdx++]); + Assertions.assertEquals((byte) 'i', output[outIdx++]); + Assertions.assertEquals((byte) 'l', output[outIdx++]); + Assertions.assertEquals((byte) 'l', output[outIdx++]); + + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'Z', output[outIdx++]); } - @Test public void testExample3StringIds() throws Exception { @@ -143,14 +142,14 @@ public class XDBXWriterXmlTest { try (XDBXWriterXml writer = new XDBXWriterXml(baos)) { writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false); AttributesImpl atts; - + writer.startDocument(); writer.startPrefixMapping("foo", "bar"); writer.startElement("", "root", "", new AttributesImpl()); - + writer.startElement("", "Person", "", new AttributesImpl()); - atts = new AttributesImpl(); - atts.addAttribute ("", "mgr", "", "", "NO"); + atts = new AttributesImpl(); + atts.addAttribute("", "mgr", "", "", "NO"); writer.startElement("", "name", "", atts); writer.characters("Bill"); writer.endElement("", "name", ""); @@ -158,10 +157,10 @@ public class XDBXWriterXmlTest { writer.characters("35"); writer.endElement("bar", "age", "age"); writer.endElement("", "Person", ""); - + writer.startElement("", "Person", "", new AttributesImpl()); - atts = new AttributesImpl(); - atts.addAttribute ("", "mgr", "", "", "NO"); + atts = new AttributesImpl(); + atts.addAttribute("", "mgr", "", "", "NO"); writer.startElement("", "name", "", atts); writer.characters("Joe"); writer.endElement("", "name", ""); @@ -169,134 +168,134 @@ public class XDBXWriterXmlTest { writer.characters("45"); writer.endElement("bar", "age", "age"); writer.endElement("", "Person", ""); - + writer.endElement("", "root", ""); writer.endDocument(); } - + byte[] output = baos.toByteArray(); int outIdx = 8; Assertions.assertNotNull(output); Assertions.assertTrue(output.length > 0); - Assertions.assertEquals((byte)'I', output[outIdx++]); + Assertions.assertEquals((byte) 'I', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'f', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); + Assertions.assertEquals((byte) 'f', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); Assertions.assertEquals((byte) 1, output[outIdx++]); - Assertions.assertEquals((byte)'I', output[outIdx++]); + Assertions.assertEquals((byte) 'I', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'b', output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); + Assertions.assertEquals((byte) 'b', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - - Assertions.assertEquals((char)'X', (char)output[outIdx++]); + + Assertions.assertEquals((char) 'X', (char) output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'t', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 't', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); - Assertions.assertEquals((char)'m', (char)output[outIdx++]); + Assertions.assertEquals((char) 'm', (char) output[outIdx++]); Assertions.assertEquals((byte) 1, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - - Assertions.assertEquals((char)'X', (char)output[outIdx++]); + + Assertions.assertEquals((char) 'X', (char) output[outIdx++]); Assertions.assertEquals((byte) 6, output[outIdx++]); - Assertions.assertEquals((byte)'P', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); - Assertions.assertEquals((byte)'s', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'n', output[outIdx++]); + Assertions.assertEquals((byte) 'P', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); + Assertions.assertEquals((byte) 's', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'n', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); - - Assertions.assertEquals((char)'X', (char)output[outIdx++]); + + Assertions.assertEquals((char) 'X', (char) output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'n', output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); - Assertions.assertEquals((byte)'m', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); + Assertions.assertEquals((byte) 'n', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); + Assertions.assertEquals((byte) 'm', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); Assertions.assertEquals((byte) 5, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); - - Assertions.assertEquals((char)'Y', (char)output[outIdx++]); + + Assertions.assertEquals((char) 'Y', (char) output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'m', output[outIdx++]); - Assertions.assertEquals((byte)'g', output[outIdx++]); - Assertions.assertEquals((byte)'r', output[outIdx++]); + Assertions.assertEquals((byte) 'm', output[outIdx++]); + Assertions.assertEquals((byte) 'g', output[outIdx++]); + Assertions.assertEquals((byte) 'r', output[outIdx++]); Assertions.assertEquals((byte) 6, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 0, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - Assertions.assertEquals((byte)'N', output[outIdx++]); - Assertions.assertEquals((byte)'O', output[outIdx++]); - - Assertions.assertEquals((byte)'T', output[outIdx++]); + Assertions.assertEquals((byte) 'N', output[outIdx++]); + Assertions.assertEquals((byte) 'O', output[outIdx++]); + + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'B', output[outIdx++]); - Assertions.assertEquals((byte)'i', output[outIdx++]); - Assertions.assertEquals((byte)'l', output[outIdx++]); - Assertions.assertEquals((byte)'l', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - - Assertions.assertEquals((char)'X', (char)output[outIdx++]); + Assertions.assertEquals((byte) 'B', output[outIdx++]); + Assertions.assertEquals((byte) 'i', output[outIdx++]); + Assertions.assertEquals((byte) 'l', output[outIdx++]); + Assertions.assertEquals((byte) 'l', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + + Assertions.assertEquals((char) 'X', (char) output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); - Assertions.assertEquals((byte)'g', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); + Assertions.assertEquals((byte) 'g', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); Assertions.assertEquals((byte) 7, output[outIdx++]); Assertions.assertEquals((byte) 1, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - Assertions.assertEquals((byte)'3', output[outIdx++]); - Assertions.assertEquals((byte)'5', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); + Assertions.assertEquals((byte) '3', output[outIdx++]); + Assertions.assertEquals((byte) '5', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); Assertions.assertEquals((byte) 4, output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); Assertions.assertEquals((byte) 5, output[outIdx++]); - Assertions.assertEquals((byte)'a', output[outIdx++]); + Assertions.assertEquals((byte) 'a', output[outIdx++]); Assertions.assertEquals((byte) 6, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - Assertions.assertEquals((byte)'N', output[outIdx++]); - Assertions.assertEquals((byte)'O', output[outIdx++]); - - Assertions.assertEquals((byte)'T', output[outIdx++]); + Assertions.assertEquals((byte) 'N', output[outIdx++]); + Assertions.assertEquals((byte) 'O', output[outIdx++]); + + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 3, output[outIdx++]); - Assertions.assertEquals((byte)'J', output[outIdx++]); - Assertions.assertEquals((byte)'o', output[outIdx++]); - Assertions.assertEquals((byte)'e', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'x', output[outIdx++]); + Assertions.assertEquals((byte) 'J', output[outIdx++]); + Assertions.assertEquals((byte) 'o', output[outIdx++]); + Assertions.assertEquals((byte) 'e', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'x', output[outIdx++]); Assertions.assertEquals((byte) 7, output[outIdx++]); Assertions.assertEquals((byte) 1, output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - - Assertions.assertEquals((byte)'T', output[outIdx++]); + + Assertions.assertEquals((byte) 'T', output[outIdx++]); Assertions.assertEquals((byte) 2, output[outIdx++]); - Assertions.assertEquals((byte)'4', output[outIdx++]); - Assertions.assertEquals((byte)'5', output[outIdx++]); - - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'z', output[outIdx++]); - Assertions.assertEquals((byte)'Z', output[outIdx++]); - + Assertions.assertEquals((byte) '4', output[outIdx++]); + Assertions.assertEquals((byte) '5', output[outIdx++]); + + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'z', output[outIdx++]); + Assertions.assertEquals((byte) 'Z', output[outIdx++]); + StringWriter outputXmlStr = new StringWriter(); SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr); XDBXReaderXml reader = new XDBXReaderXml(outputXml); ByteArrayInputStream bais = new ByteArrayInputStream(output); reader.parse(bais); - + String outputStr = outputXmlStr.toString(); Assertions.assertTrue(outputStr.contains("