From 5ba12c3a3ea7c5c1818cd7a8b878a0ff4499b39e Mon Sep 17 00:00:00 2001 From: Willem Date: Wed, 29 Jan 2025 18:43:31 +0100 Subject: [PATCH] Added more white space and tab space in the code --- .../java/org/x4o/sax3/SAX3WriterEnum.java | 15 +- .../org/x4o/sax3/SAX3WriterEnumHammer.java | 6 +- .../java/org/x4o/sax3/SAX3WriterHtml.java | 28 +-- .../main/java/org/x4o/sax3/SAX3WriterXml.java | 6 +- .../main/java/org/x4o/sax3/SAX3WriterXsd.java | 24 +-- .../x4o/sax3/io/AbstractContentWriter.java | 6 +- .../sax3/io/AbstractContentWriterHandler.java | 188 +++++++++--------- .../sax3/io/AbstractContentWriterLexical.java | 20 +- .../java/org/x4o/sax3/io/AttributeMap.java | 54 ++--- .../org/x4o/sax3/io/ContentWriterAdapter.java | 40 ++-- .../org/x4o/sax3/io/SAX3PropertyConfig.java | 131 ++++++------ .../org/x4o/sax3/io/SAX3XMLConstants.java | 29 ++- .../io/xdbx/AbstractXDBXWriterHandler.java | 131 ++++++------ .../io/xdbx/AbstractXDBXWriterLexical.java | 16 +- .../org/x4o/sax3/io/xdbx/XDBXReaderXml.java | 12 +- 15 files changed, 349 insertions(+), 357 deletions(-) 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 999b632..68fa56a 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 @@ -40,12 +40,12 @@ import org.xml.sax.helpers.AttributesImpl; * @version 1.0 May 3, 2013 */ 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); } @@ -91,12 +91,12 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter } public ContentCloseable printTag(TAG tag, Attributes atts) throws IOException { - printTagStart(tag,atts); + printTagStart(tag, atts); return () -> printTagEnd(tag); } public void printTagStartEnd(TAG tag, Attributes atts) throws IOException { - printTagStart(tag,atts); + printTagStart(tag, atts); printTagEnd(tag); } @@ -106,7 +106,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter } public void printTagStart(TAG tag) throws IOException { - printTagStart(tag,EMPTY_ATTRIBUTES); + printTagStart(tag, EMPTY_ATTRIBUTES); } public void printTagStart(TAG tag, Attributes atts) throws IOException { @@ -127,8 +127,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter private String toTagString(TAG tag) { String result = tag.name(); - if (result.startsWith("_")) - { + if (result.startsWith("_")) { result = result.substring(1); // remove _ } return result; @@ -136,7 +135,7 @@ public class SAX3WriterEnum,TAG_WRITER extends ContentWriter public void printTagCharacters(TAG tag, String text) throws IOException { printTagStart(tag); - if (text==null) { + if (text == null) { text = " "; } printCharacters(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 bf3d567..aaa1864 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 @@ -42,15 +42,15 @@ public interface SAX3WriterEnumHammer> { void printTagStartEnd(TAG tag) throws IOException; - void printTagStartEnd(TAG tag,Attributes atts) 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 printTagStart(TAG tag, Attributes atts) throws IOException; void printTagEnd(TAG tag) throws IOException; - void printTagCharacters(TAG tag,String text) throws IOException; + void printTagCharacters(TAG tag, String text) throws IOException; void printCharacters(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 9b86246..3628a8f 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 @@ -40,7 +40,7 @@ import org.xml.sax.helpers.AttributesImpl; */ public class SAX3WriterHtml extends SAX3WriterEnum { - public SAX3WriterHtml(Writer out,String encoding) { + public SAX3WriterHtml(Writer out, String encoding) { super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI); } @@ -58,10 +58,10 @@ public class SAX3WriterHtml extends SAX3WriterEnum0) { + if (spanClass.length() > 0) { atts.addAttribute("", "class", "", "", spanClass); } printTagStart(Tag.span,atts); @@ -180,7 +180,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum { - public SAX3WriterXsd(Writer out,String encoding) { - super(new SAX3WriterXml(out, encoding),SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI); + 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 { + public void printXsdImport(String namespace, String schemaLocation) throws IOException { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "namespace", "", "", namespace); - atts.addAttribute ("", "schemaLocation", "", "", schemaLocation); + atts.addAttribute("", "namespace", "", "", namespace); + atts.addAttribute("", "schemaLocation", "", "", schemaLocation); printTagStartEnd(Tag._import, atts); } public void printXsdDocumentation(String description) throws IOException { - if (description==null) { + if (description == null) { return; } printTagStart(Tag.annotation); AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "xml:lang", "", "", "en"); - printTagStart(Tag.documentation,atts); + atts.addAttribute("", "xml:lang", "", "", "en"); + printTagStart(Tag.documentation, atts); printCharacters(description); printTagEnd(Tag.documentation); printTagEnd(Tag.annotation); } - public void printXsdElementAttribute(String name,String type,String description) throws IOException { + public void printXsdElementAttribute(String name, String type, String description) throws IOException { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "name", "", "", name); - atts.addAttribute ("", "type", "", "", type); - printTagStart(Tag.attribute,atts); + atts.addAttribute("", "name", "", "", name); + atts.addAttribute("", "type", "", "", type); + printTagStart(Tag.attribute, atts); printXsdDocumentation(description); printTagEnd(Tag.attribute); } diff --git a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriter.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriter.java index f96cded..9a739c1 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriter.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriter.java @@ -34,7 +34,7 @@ import org.xml.sax.SAXException; * @version 1.0 May 3, 2013 */ public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter { - + /** * Creates an Lecical content writer for XML. * @param out The writer to write to. @@ -42,13 +42,13 @@ public abstract class AbstractContentWriter extends AbstractContentWriterLexical public AbstractContentWriter(Writer out) { super(out); } - + /** * 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/AbstractContentWriterHandler.java b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterHandler.java index 86e6687..eff177a 100644 --- a/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterHandler.java +++ b/nx01-x4o-sax3/src/main/java/org/x4o/sax3/io/AbstractContentWriterHandler.java @@ -65,24 +65,24 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { private String lastElement = null; private Stack elements = null; - private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"content/"; // TODO: change to "writer/xml" + 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"; - public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX+"output/char-tab"; - public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX+"output/char-newline"; - public final static String OUTPUT_CHAR_NULL = PROPERTY_CONTEXT_PREFIX+"output/char-null"; - public final static String OUTPUT_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"output/comment-enable"; - public final static String OUTPUT_COMMENT_AUTO_SPACE = PROPERTY_CONTEXT_PREFIX+"output/comment-auto-space"; - public final static String OUTPUT_LINE_BREAK_WIDTH = PROPERTY_CONTEXT_PREFIX+"output/line-break-width"; - public final static String OUTPUT_LINE_PER_ATTRIBUTE = PROPERTY_CONTEXT_PREFIX+"output/line-per-attribute"; - public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-file"; - public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-resource"; - public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX+"prolog/licence-encoding"; - public final static String PROLOG_LICENCE_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-enable"; - public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment"; - public final static String PROLOG_USER_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment-enable"; - public final static String ROOT_END_APPEND_NEWLINE = PROPERTY_CONTEXT_PREFIX+"root/end-append-newline"; - public final static String ROOT_START_NAMESPACE_ALL = PROPERTY_CONTEXT_PREFIX+"root/start-namespace-all"; + public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding"; + public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX + "output/char-tab"; + public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX + "output/char-newline"; + public final static String OUTPUT_CHAR_NULL = PROPERTY_CONTEXT_PREFIX + "output/char-null"; + public final static String OUTPUT_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX + "output/comment-enable"; + public final static String OUTPUT_COMMENT_AUTO_SPACE = PROPERTY_CONTEXT_PREFIX + "output/comment-auto-space"; + public final static String OUTPUT_LINE_BREAK_WIDTH = PROPERTY_CONTEXT_PREFIX + "output/line-break-width"; + public final static String OUTPUT_LINE_PER_ATTRIBUTE = PROPERTY_CONTEXT_PREFIX + "output/line-per-attribute"; + public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-file"; + public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-resource"; + public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX + "prolog/licence-encoding"; + public final static String PROLOG_LICENCE_ENABLE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-enable"; + public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX + "prolog/user-comment"; + public final static String PROLOG_USER_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX + "prolog/user-comment-enable"; + public final static String ROOT_END_APPEND_NEWLINE = PROPERTY_CONTEXT_PREFIX + "root/end-append-newline"; + public final static String ROOT_START_NAMESPACE_ALL = PROPERTY_CONTEXT_PREFIX + "root/start-namespace-all"; static { DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX, @@ -114,7 +114,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { 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.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX); } public SAX3PropertyConfig getPropertyConfig() { @@ -143,19 +143,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { InputStream licenceInput = null; String licenceEncoding = propertyConfig.getPropertyString(PROLOG_LICENCE_ENCODING); String licenceResource = propertyConfig.getPropertyString(PROLOG_LICENCE_RESOURCE); - if (licenceResource!=null) { + if (licenceResource != null) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = this.getClass().getClassLoader(); } licenceInput = cl.getResourceAsStream(licenceResource); - if (licenceInput==null) { - throw new NullPointerException("Could not load licence resource from: "+licenceResource); + if (licenceInput == null) { + throw new NullPointerException("Could not load licence resource from: " + licenceResource); } } - if (licenceInput==null) { + if (licenceInput == null) { File licenceFile = propertyConfig.getPropertyFile(PROLOG_LICENCE_FILE); - if (licenceFile==null) { + if (licenceFile == null) { return; } try { @@ -166,7 +166,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } String licenceText; try { - licenceText = readLicenceStream(licenceInput,licenceEncoding); + licenceText = readLicenceStream(licenceInput, licenceEncoding); } catch (IOException e) { throw new SAXException(e); } @@ -174,24 +174,24 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } private String readLicenceStream(InputStream inputStream, String encoding) throws IOException { - if (encoding==null) { + if (encoding == null) { encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING; } - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding))); + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(encoding))); try { StringBuilder sb = new StringBuilder(); - sb.append('\n'); // like plugin - sb.append('\n'); // like plugin + sb.append('\n'); + sb.append('\n'); String line = br.readLine(); while (line != null) { - if (line.length()>0) { - sb.append(" "); // like plugin + if (line.length() > 0) { + sb.append(" "); } sb.append(line); sb.append('\n'); line = br.readLine(); } - sb.append('\n'); // like plugin + sb.append('\n'); String out = sb.toString(); return out; } finally { @@ -221,8 +221,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { */ public void endDocument() throws SAXException { writeFlush(); - if (elements.size()>0) { - throw new SAXException("Invalid xml still have "+elements.size()+" elements open."); + if (elements.size() > 0) { + throw new SAXException("Invalid xml still have " + elements.size() + " elements open."); } } @@ -234,13 +234,13 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @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) { + if (localName == null) { throw new SAXException("LocalName may not be null."); } if (SAX3XMLConstants.isNameString(localName)==false) { - throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'"); + throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'"); } - for (int i=0;i0) { - if (prevChars==0 && startElement.length() > breakLines) { + if (breakLines > 0) { + if (prevChars == 0 && startElement.length() > breakLines) { printElementAttributeNewLineSpace(); prevChars = startElement.length(); } - if (prevChars>0 && (startElement.length()-prevChars) > breakLines) { + if (prevChars > 0 && (startElement.length() - prevChars) > breakLines) { printElementAttributeNewLineSpace(); prevChars = startElement.length(); } @@ -420,17 +417,16 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @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 (elements.size()>0 && elements.peek().equals((localName))==false) { - throw new SAXException("Unexpected end tag: "+localName+" should be: "+elements.peek()); + if (elements.size() > 0 && elements.peek().equals((localName)) == false) { + throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek()); } elements.pop(); - if (startElement!=null) { + 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; + startElement = null; indent--; return; } @@ -442,19 +438,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } else { printReturn = true; } - if (localName==null) { + if (localName == null) { localName = "null"; } write(SAX3XMLConstants.TAG_OPEN_END); - if (SAX3XMLConstants.NULL_NS_URI.equals(uri) | uri==null) { + if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) { write(localName); } else { String prefix = prefixMapping.get(uri); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); + if (prefix == null) { + throw new SAXException("preFixUri: " + uri + " is not started."); } - if (SAX3XMLConstants.NULL_NS_URI.equals(prefix)==false) { + if (SAX3XMLConstants.NULL_NS_URI.equals(prefix) == false) { write(prefix); write(SAX3XMLConstants.XMLNS_ASSIGN); } @@ -484,14 +480,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { Set> s = prefixMapping.entrySet(); String uri = null; for (Map.Entry e:s) { - if (e.getValue()==null) { + if (e.getValue() == null) { continue; // way ? } if (e.getValue().equals(prefix)) { uri = e.getKey(); } } - if (uri!=null) { + if (uri != null) { printedMappings.remove(uri); prefixMapping.remove(uri); } @@ -507,7 +503,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ContentHandler#characters(char[], int, int) */ public void characters(char[] ch, int start, int length) throws SAXException { - characters(new String(ch,start,length)); + characters(new String(ch, start, length)); } /** @@ -517,19 +513,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String) */ public void characters(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } 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) { + if (text == null) { return; } autoCloseStartElement(); @@ -547,7 +543,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) */ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - ignorableWhitespace(new String(ch,start,length)); + ignorableWhitespace(new String(ch, start, length)); } /** @@ -558,7 +554,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String) */ public void ignorableWhitespace(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } autoCloseStartElement(); @@ -572,9 +568,9 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @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. * @@ -587,11 +583,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { if (targetLow.startsWith(SAX3XMLConstants.XML)) { throw new SAXException("Processing instruction may not start with xml."); } - if (SAX3XMLConstants.isNameString(target)==false) { - throw new SAXException("Processing instruction target is invalid name; '"+target+"'"); + if (SAX3XMLConstants.isNameString(target) == false) { + throw new SAXException("Processing instruction target is invalid name; '" + target + "'"); } - if (SAX3XMLConstants.isCharString(data)==false) { - throw new SAXException("Processing instruction data is invalid char; '"+data+"'"); + if (SAX3XMLConstants.isCharString(data) == false) { + throw new SAXException("Processing instruction data is invalid char; '" + data + "'"); } autoCloseStartElement(); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); @@ -604,7 +600,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { writeFlush(); printReturn = true; } - + /** * Not implemented. * @@ -613,7 +609,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { */ public void setDocumentLocator(Locator locator) { } - + /** * Not implemented. * @@ -623,7 +619,7 @@ 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. * @@ -634,7 +630,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int) */ public void comment(char[] ch, int start, int length) throws SAXException { - comment(new String(ch,start,length)); + comment(new String(ch, start, length)); } /** @@ -645,7 +641,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#comment(java.lang.String) */ public void comment(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } if (!propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_ENABLE)) { @@ -653,11 +649,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { } if (propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_AUTO_SPACE)) { char textStart = text.charAt(0); - char textEnd = text.charAt(text.length()-1); - if (textStart!=' ' && textStart!='\t' && textStart!='\n') { - text = " "+text; + char textEnd = text.charAt(text.length() - 1); + if (textStart != ' ' && textStart != '\t' && textStart != '\n') { + text = " " + text; } - if (textEnd!=' ' && textEnd!='\t' && textEnd!='\n') { + if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') { text = text + " "; } } @@ -666,7 +662,7 @@ 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; } @@ -677,7 +673,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @param value The value to check. */ private void checkPrintedReturn(String value) { - if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE)>0) { + if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) { printReturn = true; } else { printReturn = false; @@ -689,11 +685,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable { * @throws SAXException When prints gives exception. */ protected void autoCloseStartElement() throws SAXException { - if (startElement==null) { + if (startElement == null) { return; } write(startElement.toString()); - startElement=null; + startElement = null; } /** 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 c7b4b89..65524c1 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 @@ -34,7 +34,7 @@ import org.xml.sax.ext.LexicalHandler; * @version 1.0 May 3, 2013 */ public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler { - + protected boolean printCDATA = false; /** @@ -44,7 +44,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter public AbstractContentWriterLexical(Writer out) { super(out); } - + /** * @see org.xml.sax.ext.LexicalHandler#startCDATA() */ @@ -61,7 +61,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) */ @@ -69,11 +69,11 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter charactersRaw(SAX3XMLConstants.XML_DOCTYPE_TAG_OPEN); charactersRaw(" "); charactersRaw(name); - if (publicId!=null) { + if (publicId != null) { charactersRaw(" "); charactersRaw(publicId); } - if (systemId!=null) { + if (systemId != null) { charactersRaw(" \""); charactersRaw(systemId); charactersRaw("\""); @@ -87,7 +87,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter public void endDTD() throws SAXException { writeFlush(); } - + /** * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) */ @@ -97,9 +97,9 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter /** * @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) */ @@ -107,14 +107,14 @@ 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) */ @Override public void characters(String text) throws SAXException { if (printCDATA) { - charactersRaw(SAX3XMLConstants.escapeCharactersCdata(text,"","")); + charactersRaw(SAX3XMLConstants.escapeCharactersCdata(text, "", "")); } else { super.characters(text); } 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 b037bd9..fc04591 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 @@ -44,7 +44,7 @@ public class AttributeMap implements Map { /** stores the namespace uri for this attributes */ private String uri = null; - + /** * Constuctes an new AttributeMap. * @@ -53,7 +53,7 @@ public class AttributeMap implements Map { public AttributeMap(Attributes attributes) { setAttributes(attributes); } - + /** * Constructes an new AttributesMap. * @@ -64,7 +64,7 @@ public class AttributeMap implements Map { setAttributes(attributes); setNameSpace(uri); } - + /** * Sets the data backend of this map. * @@ -73,7 +73,7 @@ public class AttributeMap implements Map { public void setAttributes(Attributes attributes) { this.attributes = attributes; } - + /** * Return the data backend of this map. * @@ -82,7 +82,7 @@ public class AttributeMap implements Map { public Attributes getAttributes() { return attributes; } - + /** * Sets the namespace uri, when set to null it is disabled(default). * @@ -91,7 +91,7 @@ public class AttributeMap implements Map { public void setNameSpace(String uri) { this.uri = uri; } - + /** * Returns the namespace used for these attributes. * @@ -100,9 +100,9 @@ public class AttributeMap implements Map { public String getNameSpace() { return uri; } - + // --------------- inner util functions. - + /** * Gets the local of full name by 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,7 +131,7 @@ public class AttributeMap implements Map { } return attributes.getValue(name); } - + /** * Gets the attribute value. * @param key The name of the attribute. @@ -143,9 +143,9 @@ public class AttributeMap implements Map { } return getValue(key.toString()); } - + // ------------------------------ MAP intreface - + /** * Returns the size of the map. * @@ -154,7 +154,7 @@ public class AttributeMap implements Map { public int size() { return attributes.getLength(); } - + /** * Checks if there are attributes in this map. * @@ -166,7 +166,7 @@ public class AttributeMap implements Map { } return false; } - + /** * Checks if there is an attributes with an certain key. * @@ -179,7 +179,7 @@ public class AttributeMap implements Map { } return false; } - + /** * Checks if there is an attributes with an value. * @@ -194,7 +194,7 @@ public class AttributeMap implements Map { } return false; } - + /** * Returns The value of an attribute. * @@ -205,7 +205,7 @@ public class AttributeMap implements Map { public V get(Object key) { return (V)getValue(key); } - + /** * Function not implements. because we can't add to the attributes. * @@ -216,7 +216,7 @@ public class AttributeMap implements Map { public V put(K key, V value) { return null; // we can't add. } - + /** * Function not implements. because we can't remove to the attributes. * @@ -226,7 +226,7 @@ public class AttributeMap implements Map { public V remove(Object key) { return null ;// we can't remove } - + /** * Function not implements. because we can't add to the attributes. * @@ -236,14 +236,14 @@ public class AttributeMap implements Map { 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. * @@ -257,7 +257,7 @@ public class AttributeMap implements Map { } return result; } - + /** * Returns an Collection of the values in the attributes list. * @@ -271,7 +271,7 @@ public class AttributeMap implements Map { } 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. @@ -289,7 +289,7 @@ public class AttributeMap implements Map { } return result; } - + /** * Compares the SAX attribute list. * @@ -299,7 +299,7 @@ public class AttributeMap implements Map { public boolean equals(Object o) { return attributes.equals(o); // compare to attributes } - + /** * returns the hashCode of the attribute list. * @@ -308,7 +308,7 @@ public class AttributeMap implements Map { public int hashCode() { return attributes.hashCode(); } - + /** * An innerclass used by entrySet(). */ @@ -358,7 +358,7 @@ public class AttributeMap implements Map { public boolean equals(Object o) { if (o instanceof Map.Entry) { Map.Entry mapEntry = (Map.Entry) o; - if (mapEntry.getKey().equals(key) & mapEntry.getValue().equals(value)) { + if (mapEntry.getKey().equals(key) && mapEntry.getValue().equals(value)) { return true; } } 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 214e9e4..690dbde 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 @@ -34,80 +34,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)); + comment(new String(ch, start, length)); } public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - ignorableWhitespace(new String(ch,start,length)); + 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); + 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)); + 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 21e2877..927b93b 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 @@ -43,54 +43,54 @@ public final class SAX3PropertyConfig implements Cloneable { private final boolean readOnly; private final String keyPrefix; - public SAX3PropertyConfig(String keyPrefix,PropertyConfigItem...items) { - this(false,null,keyPrefix,items); + public SAX3PropertyConfig(String keyPrefix, PropertyConfigItem... items) { + this(false, null, keyPrefix, items); } - public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig,String keyPrefix,PropertyConfigItem...items) { - this(false,parentPropertyConfig,keyPrefix,items); + 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) { + 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); + this.readOnly = readOnly; + this.keyPrefix = appendSlashIfMissing(keyPrefix); Map fillItems = new HashMap(itemConfig.length); - fillPropertyConfigItems(fillItems,itemConfig); - copyParentPropertyConfig(fillItems,parentPropertyConfig); + fillPropertyConfigItems(fillItems, itemConfig); + copyParentPropertyConfig(fillItems, parentPropertyConfig); if (fillItems.isEmpty()) { throw new IllegalArgumentException("Can't create PropertyConfig with zero PropertyConfigItems."); } - for (String key:fillItems.keySet()) { + for (String key : fillItems.keySet()) { if (!key.startsWith(X4O_PROPERTIES_PREFIX)) { - throw new IllegalArgumentException("Illegal key missing prefix; "+key); + throw new IllegalArgumentException("Illegal key missing prefix; " + key); } - fillItems.put(key,fillItems.get(key).clone()); + fillItems.put(key, fillItems.get(key).clone()); } items = Collections.unmodifiableMap(fillItems); } private final String appendSlashIfMissing(String keyPrefix) { - if (keyPrefix.endsWith("/")==false) { + if (keyPrefix.endsWith("/") == false) { keyPrefix += "/"; } return keyPrefix; } - private final void fillPropertyConfigItems(Map fillItems,PropertyConfigItem...itemConfig) { - for (int i=0;i fillItems, PropertyConfigItem... itemConfig) { + for (int i = 0; i < itemConfig.length; i++) { PropertyConfigItem item = itemConfig[i]; fillItems.put(item.getValueKey(),item); } } - private final void copyParentPropertyConfig(Map fillItems,SAX3PropertyConfig parentPropertyConfig) { - if (parentPropertyConfig==null) { + private final void copyParentPropertyConfig(Map fillItems, SAX3PropertyConfig parentPropertyConfig) { + if (parentPropertyConfig == null) { return; } - for (String key:parentPropertyConfig.getPropertyKeys()) { + for (String key : parentPropertyConfig.getPropertyKeys()) { fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key)); } } @@ -102,29 +102,29 @@ public final class SAX3PropertyConfig implements Cloneable { private final Object valueDefault; private Object value = null; - public PropertyConfigItem(boolean valueRequired,String valueKey,Class valueType) { - this(valueRequired,valueKey,valueType,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) { + 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. + 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) { + private PropertyConfigItem(boolean valueRequired, String valueKey, Class valueType, Object valueDefault) { + if (valueKey == null) { throw new NullPointerException("Can't create PropertyConfigItem with null valueKey."); } - if (valueType==null) { + if (valueType == null) { throw new NullPointerException("Can't create PropertyConfigItem with null valueType."); } - this.valueRequired=valueRequired; - this.valueKey=valueKey; - this.valueType=valueType; - this.valueDefault=valueDefault; + this.valueRequired = valueRequired; + this.valueKey = valueKey; + this.valueType = valueType; + this.valueDefault = valueDefault; } /** @@ -175,19 +175,19 @@ public final class SAX3PropertyConfig implements Cloneable { */ @Override protected PropertyConfigItem clone() { - PropertyConfigItem clone = new PropertyConfigItem(valueRequired,valueKey,valueType,valueDefault); + PropertyConfigItem clone = new PropertyConfigItem(valueRequired, valueKey, valueType, valueDefault); clone.setValue(getValue()); return clone; } } private final PropertyConfigItem getPropertyConfigItem(String key) { - if (key==null) { + if (key == null) { throw new NullPointerException("Can't search with null key."); } PropertyConfigItem item = items.get(key); - if (item==null) { - throw new IllegalArgumentException("No config item found for key: "+key); + if (item == null) { + throw new IllegalArgumentException("No config item found for key: " + key); } return item; } @@ -210,14 +210,14 @@ public final class SAX3PropertyConfig implements Cloneable { private final List findPropertyKeysRequired(boolean checkValue) { List result = new ArrayList(10); - for (String key:getPropertyKeys()) { + for (String key : getPropertyKeys()) { PropertyConfigItem item = getPropertyConfigItem(key); if (!item.isValueRequired()) { continue; } if (!checkValue) { result.add(item.getValueKey()); - } else if (item.getValue()==null && item.getValueDefault()==null) { + } else if (item.getValue() == null && item.getValueDefault() == null) { result.add(item.getValueKey()); } } @@ -232,7 +232,7 @@ public final class SAX3PropertyConfig implements Cloneable { public final void setProperty(String key,Object value) { if (readOnly) { - throw new IllegalStateException("This property is readonly for key:"+key); + throw new IllegalStateException("This property is readonly for key:" + key); } PropertyConfigItem item = getPropertyConfigItem(key); item.setValue(value); @@ -246,7 +246,7 @@ public final class SAX3PropertyConfig implements Cloneable { public final Object getProperty(String key) { PropertyConfigItem item = getPropertyConfigItem(key); Object value = item.getValue(); - if (value==null) { + if (value == null) { value = item.getValueDefault(); } return value; @@ -257,7 +257,7 @@ public final class SAX3PropertyConfig implements Cloneable { return item.getValueType(); } - public final Class getPropertyType(String key,Supplier> defaultValue) { + public final Class getPropertyType(String key, Supplier> defaultValue) { Class result = getPropertyType(key); if (result != null) { return result; @@ -270,13 +270,13 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof File) { return (File)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - public final File getPropertyFile(String key,Supplier defaultValue) { + public final File getPropertyFile(String key, Supplier defaultValue) { File result = getPropertyFile(key); if (result != null) { return result; @@ -289,13 +289,13 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof Boolean) { return (Boolean)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - public final Boolean getPropertyBoolean(String key,Supplier defaultValue) { + public final Boolean getPropertyBoolean(String key, Supplier defaultValue) { Boolean result = getPropertyBoolean(key); if (result != null) { return result; @@ -308,13 +308,13 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof Integer) { return (Integer)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } - public final Integer getPropertyInteger(String key,Supplier defaultValue) { + public final Integer getPropertyInteger(String key, Supplier defaultValue) { Integer result = getPropertyInteger(key); if (result != null) { return result; @@ -328,10 +328,10 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof List) { return (List)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } public final List getPropertyList(String key, Supplier> defaultValue) { @@ -348,10 +348,10 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof Map) { return (Map)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } public final Map getPropertyMap(String key, Supplier> defaultValue) { @@ -367,15 +367,15 @@ public final class SAX3PropertyConfig implements Cloneable { if (value instanceof String) { return (String)value; } - if (value==null) { + if (value == null) { return null; } - throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); + throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key); } public final String getPropertyString(String key,String defaultValue) { String propertyValue = getPropertyString(key); - if (propertyValue==null) { + if (propertyValue == null) { return defaultValue; } else { return propertyValue; @@ -391,9 +391,9 @@ public final class SAX3PropertyConfig implements Cloneable { } public final void copyParentProperties(SAX3PropertyConfig config) { - for (String key:getPropertyKeys()) { + for (String key : getPropertyKeys()) { Object value = config.getProperty(key); - if (value==null) { + if (value == null) { continue; } setProperty(key, value); @@ -403,7 +403,6 @@ public final class SAX3PropertyConfig implements Cloneable { @SuppressWarnings("unchecked") public final void setPropertyParsedValue(String key,String value) { Class valueType = getPropertyType(key); - //System.out.println("key: "+key+" value: "+value+" type: "+valueType); if (String.class.equals(valueType)) { setProperty(key, value); return; @@ -431,11 +430,11 @@ public final class SAX3PropertyConfig implements Cloneable { if (List.class.equals(valueType)) { String[] listValues = value.split(","); List result = (List)getProperty(key); - if (result==null) { + if (result == null) { result = new ArrayList(10); setProperty(key, result); } - for (String listValue:listValues) { + for (String listValue : listValues) { result.add(listValue); } return; @@ -443,12 +442,12 @@ public final class SAX3PropertyConfig implements Cloneable { if (Map.class.equals(valueType)) { String[] listValues = value.split(","); Map result = (Map)getProperty(key); - if (result==null) { + if (result == null) { result = new HashMap(10); setProperty(key, result); } - if (listValues.length!=2) { - throw new IllegalArgumentException("Coult not parse map value: '"+value+"' parsed length: "+listValues.length+" needs to be 2."); + if (listValues.length != 2) { + throw new IllegalArgumentException("Coult not parse map value: '" + value + "' parsed length: " + listValues.length + " needs to be 2."); } String mKey = listValues[0]; String mValue = listValues[1]; @@ -463,7 +462,7 @@ public final class SAX3PropertyConfig implements Cloneable { */ @Override public SAX3PropertyConfig clone() { - SAX3PropertyConfig clone = new SAX3PropertyConfig(this,this.keyPrefix); + SAX3PropertyConfig clone = new SAX3PropertyConfig(this, this.keyPrefix); clone.copyParentProperties(this); return clone; } 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 2f400a8..48951c3 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 @@ -51,7 +51,7 @@ public final class SAX3XMLConstants { * XML Namespace prefix attribute. */ public static final String XMLNS_ATTRIBUTE = javax.xml.XMLConstants.XMLNS_ATTRIBUTE; // "xmlns" - + /** * XML Namespace prefix seperator */ @@ -61,7 +61,7 @@ public final class SAX3XMLConstants { * 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" - + /** * XML Schema instance namespace URI. */ @@ -164,14 +164,14 @@ public final class SAX3XMLConstants { return getDocumentDeclaration(encoding,null); } - static public String getDocumentDeclaration(String encoding,String version) { - if (encoding==null) { - encoding=XML_DEFAULT_ENCODING; + static public String getDocumentDeclaration(String encoding, String version) { + if (encoding == null) { + encoding = XML_DEFAULT_ENCODING; } - if (version==null) { - version=XML_DEFAULT_VERSION; + if (version == null) { + version = XML_DEFAULT_VERSION; } - return String.format("", version,encoding); + return String.format("", version, encoding); } static public boolean isChar(int c) { @@ -236,7 +236,7 @@ public final class SAX3XMLConstants { PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.nextInt(); - if (isNameChar(c)==false) { + if (isNameChar(c) == false) { return false; } } @@ -250,11 +250,11 @@ public final class SAX3XMLConstants { int c = iterator.nextInt(); if (first) { first = false; - if (isNameStartChar(c)==false) { + if (isNameStartChar(c) == false) { return false; } } - if (isNameChar(c)==false) { + if (isNameChar(c) == false) { return false; } } @@ -348,7 +348,7 @@ public final class SAX3XMLConstants { // 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); } @@ -362,7 +362,7 @@ public final class SAX3XMLConstants { 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; } @@ -397,7 +397,7 @@ public final class SAX3XMLConstants { static public String escapeCharactersComment(String value,String charTab,int indent) { value = value.replaceAll(COMMENT_START, ""); - value = value.replaceAll(COMMENT_END, ""); + value = value.replaceAll(COMMENT_END, ""); StringBuilder result = new StringBuilder(value.length()); PrimitiveIterator.OfInt iterator = value.codePoints().iterator(); while (iterator.hasNext()) { @@ -407,7 +407,6 @@ public final class SAX3XMLConstants { for (int ii = 0; ii < indent; ii++) { result.append(charTab); } - continue; } result.appendCodePoint(c); 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 5baa272..0bff7b1 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 @@ -104,7 +104,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { 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.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX); this.stringIdx = new HashMap<>(); } @@ -161,19 +161,19 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { InputStream licenceInput = null; String licenceEncoding = propertyConfig.getPropertyString(PROLOG_LICENCE_ENCODING); String licenceResource = propertyConfig.getPropertyString(PROLOG_LICENCE_RESOURCE); - if (licenceResource!=null) { + if (licenceResource != null) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = this.getClass().getClassLoader(); } licenceInput = cl.getResourceAsStream(licenceResource); - if (licenceInput==null) { + if (licenceInput == null) { throw new NullPointerException("Could not load licence resource from: "+licenceResource); } } - if (licenceInput==null) { + if (licenceInput == null) { File licenceFile = propertyConfig.getPropertyFile(PROLOG_LICENCE_FILE); - if (licenceFile==null) { + if (licenceFile == null) { return; } try { @@ -184,32 +184,32 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } String licenceText; try { - licenceText = readLicenceStream(licenceInput,licenceEncoding); + licenceText = readLicenceStream(licenceInput, licenceEncoding); } catch (IOException e) { throw new SAXException(e); } comment(licenceText); } - private String readLicenceStream(InputStream inputStream,String encoding) throws IOException { - if (encoding==null) { + private String readLicenceStream(InputStream inputStream, String encoding) throws IOException { + if (encoding == null) { encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING; } - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding))); + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(encoding))); try { StringBuilder sb = new StringBuilder(); - sb.append('\n'); // like plugin - sb.append('\n'); // like plugin + sb.append('\n'); + sb.append('\n'); String line = br.readLine(); while (line != null) { if (line.length()>0) { - sb.append(" "); // like plugin + sb.append(" "); } sb.append(line); sb.append('\n'); line = br.readLine(); } - sb.append('\n'); // like plugin + sb.append('\n'); String out = sb.toString(); return out; } finally { @@ -240,8 +240,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void endDocument() throws SAXException { writeTag(XDBXContentTag.DOCUMENT_END); writeFlush(); - if (elements.size()>0) { - throw new SAXException("Invalid xml still have "+elements.size()+" elements open."); + if (elements.size() > 0) { + throw new SAXException("Invalid xml still have " + elements.size() + " elements open."); } } @@ -253,13 +253,13 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @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) { + if (localName == null) { throw new SAXException("LocalName may not be null."); } - if (SAX3XMLConstants.isNameString(localName)==false) { - throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'"); + if (SAX3XMLConstants.isNameString(localName) == false) { + throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'"); } - for (int i=0;i0 && elements.peek().equals(localName)==false) { - throw new SAXException("Unexpected end tag: "+localName+" should be: "+elements.peek()); + 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()); } } else { String qName = uri + ":" + name; - if (elements.size()>0 && elements.peek().equals(qName)==false) { - throw new SAXException("Unexpected end tag: "+qName+" should be: "+elements.peek()); + if (elements.size() > 0 && elements.peek().equals(qName) == false) { + throw new SAXException("Unexpected end tag: " + qName + " should be: " + elements.peek()); } } elements.pop(); @@ -436,7 +436,6 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeTagLengthValue(XDBXContentTag.STRING_ID, prefix); writeVariableInteger(prefixIdxNum); } - boolean uriIdx = xdbxStringId(uri); if (!uriIdx) { int uriIdxNum = xdbxStringStore(uri); @@ -452,19 +451,19 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { public void endPrefixMapping(String prefix) throws SAXException { Set> s = prefixMapping.entrySet(); String uri = null; - for (Map.Entry e:s) { - if (e.getValue()==null) { + for (Map.Entry e : s) { + if (e.getValue() == null) { continue; // way ? } if (e.getValue().equals(prefix)) { uri = e.getKey(); } } - if (uri!=null) { + if (uri != null) { prefixMapping.remove(uri); } } - + /** * Prints xml characters and uses characters(java.lang.String) method. * @@ -475,7 +474,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ContentHandler#characters(char[], int, int) */ public void characters(char[] ch, int start, int length) throws SAXException { - characters(new String(ch,start,length)); + characters(new String(ch, start, length)); } /** @@ -485,19 +484,19 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String) */ public void characters(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } 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) { + if (text == null) { return; } writeTagLengthValue(XDBXContentTag.TEXT_T, text); @@ -513,7 +512,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) */ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - ignorableWhitespace(new String(ch,start,length)); + ignorableWhitespace(new String(ch, start, length)); } /** @@ -524,7 +523,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String) */ public void ignorableWhitespace(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } writeTagLengthValue(XDBXContentTag.TEXT_WHITE_SPACE, text); @@ -537,9 +536,9 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @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. * @@ -552,11 +551,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { if (targetLow.startsWith(SAX3XMLConstants.XML)) { throw new SAXException("Processing instruction may not start with xml."); } - if (SAX3XMLConstants.isNameString(target)==false) { - throw new SAXException("Processing instruction target is invalid name; '"+target+"'"); + if (SAX3XMLConstants.isNameString(target) == false) { + throw new SAXException("Processing instruction target is invalid name; '" + target + "'"); } - if (SAX3XMLConstants.isCharString(data)==false) { - throw new SAXException("Processing instruction data is invalid char; '"+data+"'"); + if (SAX3XMLConstants.isCharString(data) == false) { + throw new SAXException("Processing instruction data is invalid char; '" + data + "'"); } //'I' LengthValue StringID @@ -571,7 +570,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { writeFlush(); } - + /** * Not implemented. * @@ -580,7 +579,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { */ public void setDocumentLocator(Locator locator) { } - + /** * Not implemented. * @@ -590,7 +589,7 @@ 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. * @@ -601,7 +600,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int) */ public void comment(char[] ch, int start, int length) throws SAXException { - comment(new String(ch,start,length)); + comment(new String(ch, start, length)); } /** @@ -612,7 +611,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { * @see org.x4o.sax3.io.ContentWriter#comment(java.lang.String) */ public void comment(String text) throws SAXException { - if (text==null) { + if (text == null) { return; } if (!propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_ENABLE)) { @@ -620,15 +619,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable { } if (propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_AUTO_SPACE)) { char textStart = text.charAt(0); - char textEnd = text.charAt(text.length()-1); - if (textStart!=' ' && textStart!='\t' && textStart!='\n') { + char textEnd = text.charAt(text.length() - 1); + if (textStart != ' ' && textStart != '\t' && textStart != '\n') { text = " "+text; } - if (textEnd!=' ' && textEnd!='\t' && textEnd!='\n') { + if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') { text = text + " "; } } - writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text,"", 0)); + writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text, "", 0)); } protected void writeFlush() throws SAXException { 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 aae6c2a..d15e8ee 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 @@ -34,8 +34,8 @@ import org.xml.sax.ext.LexicalHandler; * @author Willem Cazander * @version 1.0 Dec 20, 2024 */ -public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandler implements LexicalHandler { - +public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandler implements LexicalHandler { + protected boolean printCDATA = false; /** @@ -45,7 +45,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle public AbstractXDBXWriterLexical(OutputStream out) { super(out); } - + /** * @see org.xml.sax.ext.LexicalHandler#startCDATA() */ @@ -59,7 +59,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle public void endCDATA() throws SAXException { printCDATA = false; } - + /** * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String) */ @@ -72,7 +72,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle */ public void endDTD() throws SAXException { } - + /** * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) */ @@ -84,7 +84,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle */ public void endEntity(String arg0) throws SAXException { } - + /** * @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int) */ @@ -92,14 +92,14 @@ 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) */ @Override public void characters(String text) throws SAXException { if (printCDATA) { - String textSafe = SAX3XMLConstants.escapeCharactersCdata(text,"",""); + String textSafe = SAX3XMLConstants.escapeCharactersCdata(text, "", ""); writeTagLengthValue(XDBXContentTag.TEXT_CDATA, textSafe); } else { super.characters(text); 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 d401619..fb0d63a 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 @@ -54,7 +54,7 @@ public class XDBXReaderXml { this.stringIdx = new HashMap<>(); this.elementStack = new Stack<>(); } - + // TODO: replace with proper PropertyConfig support public XDBXReaderXml withNoFailOnUnsupportedTag() { failOnUnsupportedTag = false; @@ -236,7 +236,7 @@ public class XDBXReaderXml { 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;