From 82d966b8494e726bcfe0788eae1f53af75167fd7 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Fri, 14 Mar 2014 19:03:56 +0100 Subject: [PATCH] Split xml tag writer from content writer interface object hierachy. --- .../x4o/xml/eld/xsd/EldXsdWriterElement.java | 61 ++++----- .../org/x4o/xml/io/sax/X4ODebugWriter.java | 11 +- .../sax/ext/AbstractContentWriterHandler.java | 5 +- .../org/x4o/xml/io/sax/ext/ContentWriter.java | 27 +++- .../x4o/xml/io/sax/ext/ContentWriterTag.java | 22 +++- .../io/sax/ext/ContentWriterTagWrapper.java | 121 ++++++++++++++++++ .../xml/io/sax/ext/ContentWriterXmlTag.java | 76 ----------- .../x4o/xml/io/sax/ext/ContentWriterXsd.java | 20 ++- .../xml/eld/doc/EldDocWriterElementClass.java | 8 +- .../xml/eld/doc/EldDocXTreePageWriter.java | 4 +- .../xml/eld/doc/api/AbstractApiDocWriter.java | 2 +- .../xml/eld/doc/api/ApiDocContentWriter.java | 44 +++---- .../org/x4o/xml/eld/doc/api/ApiDocWriter.java | 56 ++++---- .../eld/doc/api/DefaultPageWriterHelp.java | 6 +- .../doc/api/DefaultPageWriterIndexAll.java | 4 +- .../eld/doc/api/DefaultPageWriterTree.java | 4 +- .../java/org/x4o/html/ContentWriterHtml.java | 35 +++-- 17 files changed, 294 insertions(+), 212 deletions(-) create mode 100644 x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTagWrapper.java delete mode 100644 x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXmlTag.java diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriterElement.java b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriterElement.java index ea7faad..6abf59e 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriterElement.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriterElement.java @@ -58,9 +58,6 @@ import org.xml.sax.helpers.AttributesImpl; */ public class EldXsdWriterElement { - - static public final String SCHEMA_URI = XMLConstants.XML_SCHEMA_NS_URI; - private PropertyConfig propertyConfig; protected X4OLanguage language = null; protected ContentWriterXsd xsdWriter = null; @@ -155,7 +152,7 @@ public class EldXsdWriterElement { return; } //xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); - xsdWriter.comment(COMMENT_SEPERATOR); + xsdWriter.printComment(COMMENT_SEPERATOR); String byValue = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_GENERATED_BY, EldXsdWriter.class.getSimpleName()); if (!byValue.endsWith(".")) { @@ -175,8 +172,8 @@ public class EldXsdWriterElement { } b.append(COMMENT_TEXT); b.append(" "); - xsdWriter.comment(b.toString()); - xsdWriter.comment(COMMENT_SEPERATOR); + xsdWriter.printComment(b.toString()); + xsdWriter.printComment(COMMENT_SEPERATOR); } private void prologWriteProvider(ElementNamespace ns) throws SAXException { @@ -202,7 +199,7 @@ public class EldXsdWriterElement { b.append(String.format(formatLine,"Created on:",new Date())); b.append("\n"); - xsdWriter.comment(b.toString()); + xsdWriter.printComment(b.toString()); } public void startSchema(ElementNamespace ns) throws SAXException { @@ -212,10 +209,9 @@ public class EldXsdWriterElement { prologWriteGenerator(); prologWriteProvider(ns); - xsdWriter.startPrefixMapping("", SCHEMA_URI); for (String uri:namespaces.keySet()) { String prefix = namespaces.get(uri); - xsdWriter.startPrefixMapping(prefix, uri); + xsdWriter.getContentWriterWrapped().startPrefixMapping(prefix, uri); } AttributesImpl atts = new AttributesImpl(); @@ -223,7 +219,7 @@ public class EldXsdWriterElement { atts.addAttribute ("", "elementFormDefault", "", "", "qualified"); atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified"); atts.addAttribute ("", "targetNamespace", "", "", ns.getUri()); - xsdWriter.startElement (SCHEMA_URI, "schema", "", atts); + xsdWriter.printTagStart(Tag.schema, atts); for (String uri:namespaces.keySet()) { if (ns.getUri().equals(uri)) { @@ -237,8 +233,8 @@ public class EldXsdWriterElement { } public void endSchema() throws SAXException { - xsdWriter.endElement (SCHEMA_URI, "schema" , ""); - xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); + xsdWriter.printTagEnd(Tag.schema); + xsdWriter.getContentWriterWrapped().ignorableWhitespace(XMLConstants.CHAR_NEWLINE); xsdWriter.endDocument(); } @@ -256,13 +252,13 @@ public class EldXsdWriterElement { AttributesImpl atts = new AttributesImpl(); if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) { atts.addAttribute ("", "name", "", "", ec.getId()); - xsdWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element. + xsdWriter.printTagStart(Tag.element, atts);// Only in the language root xsd there is an element. atts = new AttributesImpl(); - xsdWriter.startElement (SCHEMA_URI, "complexType", "", atts); + xsdWriter.printTagStart(Tag.complexType, atts); } else { atts.addAttribute ("", "name", "", "", ec.getId()+"Type"); - xsdWriter.startElement (SCHEMA_URI, "complexType", "", atts); + xsdWriter.printTagStart(Tag.complexType, atts); } if (ec.getSchemaContentBase()!=null) { @@ -271,27 +267,27 @@ public class EldXsdWriterElement { if (ec.getSchemaContentMixed()!=null && ec.getSchemaContentMixed()) { atts.addAttribute ("", "mixed", "", "", "true"); } - xsdWriter.startElement (SCHEMA_URI, "complexContent", "", atts); + xsdWriter.printTagStart(Tag.complexContent, atts); } else { - xsdWriter.startElement (SCHEMA_URI, "simpleContent", "", atts); + xsdWriter.printTagStart(Tag.simpleContent, atts); } atts = new AttributesImpl(); atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase()); - xsdWriter.startElement (SCHEMA_URI, "extension", "", atts); + xsdWriter.printTagStart(Tag.extension, atts); } if (ec.getSchemaContentBase()==null) { atts = new AttributesImpl(); atts.addAttribute ("", "minOccurs", "", "", "0"); // TODO: make unordered elements atts.addAttribute ("", "maxOccurs", "", "", "unbounded"); - xsdWriter.startElement (SCHEMA_URI, "choice", "", atts); + xsdWriter.printTagStart(Tag.choise, atts); for (X4OLanguageModule mod:language.getLanguageModules()) { for (ElementNamespace ns:mod.getElementNamespaces()) { writeElementClassNamespaces(ec,nsWrite,ns); } } - xsdWriter.endElement(SCHEMA_URI, "choice", ""); + xsdWriter.printTagEnd(Tag.choise); } List attrNames = new ArrayList(30); @@ -316,7 +312,7 @@ public class EldXsdWriterElement { if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) { // oke, reverse this if and rm whitespace. - xsdWriter.ignorableWhitespace(' '); + xsdWriter.getContentWriterWrapped().ignorableWhitespace(' '); } else { @@ -354,27 +350,25 @@ public class EldXsdWriterElement { } else { atts.addAttribute ("", "type", "", "", "string"); } - xsdWriter.startElement (SCHEMA_URI, "attribute", "", atts); - xsdWriter.endElement(SCHEMA_URI, "attribute", ""); + xsdWriter.printTagStartEnd(Tag.attribute, atts); } } } else { atts = new AttributesImpl(); - xsdWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts); - xsdWriter.endElement(SCHEMA_URI, "anyAttribute", ""); + xsdWriter.printTagStartEnd(Tag.anyAttribute, atts); } } if (ec.getSchemaContentBase()!=null) { - xsdWriter.endElement(SCHEMA_URI, "extension", ""); + xsdWriter.printTagEnd(Tag.extension); if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) { - xsdWriter.endElement(SCHEMA_URI, "complexContent", ""); + xsdWriter.printTagEnd(Tag.complexContent); } else { - xsdWriter.endElement(SCHEMA_URI, "simpleContent", ""); + xsdWriter.printTagEnd(Tag.simpleContent); } } - xsdWriter.endElement(SCHEMA_URI, "complexType", ""); + xsdWriter.printTagEnd(Tag.complexType); if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) { - xsdWriter.endElement(SCHEMA_URI, "element", ""); + xsdWriter.printTagEnd(Tag.element); } } @@ -426,8 +420,7 @@ public class EldXsdWriterElement { atts.addAttribute ("", "name", "", "", refElement); atts.addAttribute ("", "type", "", "", prefix+":"+refElement+"Type"); } - xsdWriter.startElement (SCHEMA_URI, "element", "", atts); - xsdWriter.endElement (SCHEMA_URI, "element", ""); + xsdWriter.printTagStartEnd(Tag.element,atts); } } } @@ -440,9 +433,9 @@ public class EldXsdWriterElement { AttributesImpl atts = new AttributesImpl(); atts.addAttribute ("", "name", "", "", ec.getId()); atts.addAttribute ("", "type", "", "", "this:"+ec.getId()+"Type"); - xsdWriter.startElement(SCHEMA_URI, "element", "", atts); + xsdWriter.printTagStart(Tag.element,atts); writeElementMetaBase(ec); - xsdWriter.endElement(SCHEMA_URI, "element", ""); + xsdWriter.printTagEnd(Tag.element); } private void writeElementAttribute(ElementMetaBase base,AttributesImpl atts) throws SAXException { diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4ODebugWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4ODebugWriter.java index 008ffee..b721125 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4ODebugWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4ODebugWriter.java @@ -61,7 +61,6 @@ import org.xml.sax.helpers.AttributesImpl; */ public class X4ODebugWriter { - static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output"; protected ContentWriter contentWriter = null; @@ -74,6 +73,12 @@ public class X4ODebugWriter { return contentWriter; } + enum X4ODebugTag { + execute222Phase, + testTasg, + stekel + } + public X4OPhaseListener createDebugX4OPhaseListener() { return new DebugX4OPhaseListener(); } @@ -94,7 +99,7 @@ public class X4ODebugWriter { if (elementLanguage!=null) { atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName()); } - contentWriter.startElement (DEBUG_URI, "executePhase", "", atts); + contentWriter.startElement (DEBUG_URI, X4ODebugTag.execute222Phase.name(), "", atts); } catch (SAXException e) { throw new X4OPhaseException(phase,e); } @@ -110,7 +115,7 @@ public class X4ODebugWriter { contentWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts); contentWriter.endElement (DEBUG_URI, "executePhaseDone" , ""); - contentWriter.endElement (DEBUG_URI, "executePhase" , ""); + contentWriter.endElement (DEBUG_URI, X4ODebugTag.execute222Phase.name() , ""); } catch (SAXException e) { throw new X4OPhaseException(phase,e); } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/AbstractContentWriterHandler.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/AbstractContentWriterHandler.java index 5ab876e..13a090e 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/AbstractContentWriterHandler.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/AbstractContentWriterHandler.java @@ -55,7 +55,6 @@ import org.xml.sax.helpers.AttributesImpl; */ public class AbstractContentWriterHandler implements ContentHandler { - protected final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); private final PropertyConfig propertyConfig; private Writer out = null; private int indent = 0; @@ -65,7 +64,7 @@ public class AbstractContentWriterHandler implements ContentHandler { private boolean printReturn = false; private String lastElement = null; private Stack elements = null; - + private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_WRITER_XML; public final static PropertyConfig DEFAULT_PROPERTY_CONFIG; public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+"output/encoding"; @@ -90,7 +89,7 @@ public class AbstractContentWriterHandler implements ContentHandler { new PropertyConfigItem(OUTPUT_ENCODING, String.class, XMLConstants.XML_DEFAULT_ENCODING), new PropertyConfigItem(OUTPUT_CHAR_TAB, String.class, XMLConstants.CHAR_TAB+""), new PropertyConfigItem(OUTPUT_CHAR_NEWLINE, String.class, XMLConstants.CHAR_NEWLINE+""), - new PropertyConfigItem(OUTPUT_CHAR_NULL, String.class, "null"), // TODO: or "" ?? (or skip) + new PropertyConfigItem(OUTPUT_CHAR_NULL, String.class, "NULL"), new PropertyConfigItem(OUTPUT_COMMENT_ENABLE, Boolean.class, true), new PropertyConfigItem(OUTPUT_COMMENT_AUTO_SPACE, Boolean.class, true), new PropertyConfigItem(OUTPUT_LINE_BREAK_WIDTH, Integer.class, -1), diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriter.java index 2fbb830..0397944 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriter.java @@ -46,13 +46,38 @@ public interface ContentWriter extends ContentHandler,LexicalHandler { */ 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. + */ 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. + */ void ignorableWhitespace(String text) throws SAXException; + /** + * Writes a whitespace character to the body. + * @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. + */ void characters(String text) throws SAXException; + /** + * Writes a single character in the body body. + * @param c The character to write. + * @throws SAXException On error. + */ void characters(char c) throws SAXException; } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTag.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTag.java index ef1ed3d..44a70a5 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTag.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTag.java @@ -31,19 +31,27 @@ import org.xml.sax.SAXException; * @author Willem Cazander * @version 1.0 May 3, 2013 */ -public interface ContentWriterTag> extends ContentWriter { +public interface ContentWriterTag> { String getTagNamespaceUri(); - void printTagStartEnd(T tag) throws SAXException; + void startDocument() throws SAXException; - void printTagStartEnd(T tag,Attributes atts) throws SAXException; + void endDocument() throws SAXException; - void printTagStart(T tag) throws SAXException; + void printTagStartEnd(TAG tag) throws SAXException; - void printTagStart(T tag,Attributes atts) throws SAXException; + void printTagStartEnd(TAG tag,Attributes atts) throws SAXException; - void printTagEnd(T tag) throws SAXException; + void printTagStart(TAG tag) throws SAXException; - void printTagCharacters(T tag,String text) throws SAXException; + void printTagStart(TAG tag,Attributes atts) throws SAXException; + + void printTagEnd(TAG tag) throws SAXException; + + void printTagCharacters(TAG tag,String text) throws SAXException; + + void printCharacters(String text) throws SAXException; + + void printComment(String text) throws SAXException; } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTagWrapper.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTagWrapper.java new file mode 100644 index 0000000..7416354 --- /dev/null +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterTagWrapper.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2004-2013, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.x4o.xml.io.sax.ext; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * ContentWriterXmlTag can write enum based xml events. + * + * @author Willem Cazander + * @version 1.0 May 3, 2013 + */ +public class ContentWriterTagWrapper,TAG_WRITER extends ContentWriter> implements ContentWriterTag { + + private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); + private final TAG_WRITER contentWriter; + private final String tagNamespaceUri; + private final String tagNamespacePrefix; + + public ContentWriterTagWrapper(TAG_WRITER contentWriter,String tagNamespaceUri,String tagNamespacePrefix) { + if (contentWriter==null) { + throw new NullPointerException("Can't create wrapper on null ContentWriter"); + } + if (tagNamespaceUri==null) { + throw new NullPointerException("Can't create wrapper with null tagNamespaceUri"); + } + if (tagNamespacePrefix==null) { + throw new NullPointerException("Can't create wrapper with null tagNamespacePrefix"); + } + this.contentWriter=contentWriter; + this.tagNamespaceUri=tagNamespaceUri; + this.tagNamespacePrefix=tagNamespacePrefix; + } + + public TAG_WRITER getContentWriterWrapped() { + return contentWriter; + } + + public String getTagNamespaceUri() { + return tagNamespaceUri; + } + + public void startDocument() throws SAXException { + contentWriter.startDocument(); + contentWriter.startPrefixMapping(tagNamespacePrefix, getTagNamespaceUri()); + } + + public void endDocument() throws SAXException { + contentWriter.endDocument(); + } + + public void printTagStartEnd(TAG tag,Attributes atts) throws SAXException { + printTagStart(tag,atts); + printTagEnd(tag); + } + + public void printTagStartEnd(TAG tag) throws SAXException { + printTagStart(tag); + printTagEnd(tag); + } + + public void printTagStart(TAG tag) throws SAXException { + printTagStart(tag,EMPTY_ATTRIBUTES); + } + + public void printTagStart(TAG tag,Attributes atts) throws SAXException { + contentWriter.startElement (getTagNamespaceUri(), toTagString(tag), "", atts); + } + + public void printTagEnd(TAG tag) throws SAXException { + contentWriter.endElement (getTagNamespaceUri(),toTagString(tag) , ""); + } + + private String toTagString(TAG tag) { + String result = tag.name(); + if (result.startsWith("_")) + { + result = result.substring(1); // remove _ + } + return result; + } + + public void printTagCharacters(TAG tag,String text) throws SAXException { + printTagStart(tag); + if (text==null) { + text = " "; + } + printCharacters(text); + printTagEnd(tag); + } + + public void printCharacters(String text) throws SAXException { + contentWriter.characters(text); + } + + public void printComment(String text) throws SAXException { + contentWriter.comment(text); + } +} diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXmlTag.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXmlTag.java deleted file mode 100644 index 54d4730..0000000 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXmlTag.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2004-2013, Willem Cazander - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.x4o.xml.io.sax.ext; - -import java.io.Writer; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * ContentWriterXml writes SAX content handler events to XML. - * - * @author Willem Cazander - * @version 1.0 May 3, 2013 - */ -public class ContentWriterXmlTag> extends ContentWriterXml implements ContentWriterTag { - - public ContentWriterXmlTag(Writer out,String encoding) { - super(out, encoding); - } - - public String getTagNamespaceUri() { - return ""; - } - - public void printTagStartEnd(T tag,Attributes atts) throws SAXException { - printTagStart(tag,atts); - printTagEnd(tag); - } - - public void printTagStartEnd(T tag) throws SAXException { - printTagStart(tag); - printTagEnd(tag); - } - - public void printTagStart(T tag) throws SAXException { - printTagStart(tag,EMPTY_ATTRIBUTES); - } - - public void printTagStart(T tag,Attributes atts) throws SAXException { - startElement (getTagNamespaceUri(), tag.name(), "", atts); - } - - public void printTagEnd(T tag) throws SAXException { - endElement (getTagNamespaceUri(),tag.name() , ""); - } - - public void printTagCharacters(T tag,String text) throws SAXException { - printTagStart(tag); - if (text==null) { - text = " "; - } - characters(text); - printTagEnd(tag); - } -} diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXsd.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXsd.java index c1cc671..accafb4 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXsd.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterXsd.java @@ -34,22 +34,21 @@ import org.xml.sax.helpers.AttributesImpl; * @author Willem Cazander * @version 1.0 May 3, 2013 */ -public class ContentWriterXsd extends ContentWriterXmlTag { +public class ContentWriterXsd extends ContentWriterTagWrapper { public ContentWriterXsd(Writer out,String encoding) { - super(out,encoding); + super(new ContentWriterXml(out, encoding),XMLConstants.XML_SCHEMA_NS_URI, XMLConstants.NULL_NS_URI); } - public String getTagNamespaceUri() { - return XMLConstants.XML_SCHEMA_NS_URI; + public PropertyConfig getPropertyConfig() { + return getContentWriterWrapped().getPropertyConfig(); } public void printXsdImport(String namespace,String schemaLocation) throws SAXException { AttributesImpl atts = new AttributesImpl(); atts.addAttribute ("", "namespace", "", "", namespace); atts.addAttribute ("", "schemaLocation", "", "", schemaLocation); - startElement (getTagNamespaceUri(), "import", "", atts); - endElement (getTagNamespaceUri(), "import", ""); // import is keyword + printTagStartEnd(Tag._import, atts); } public void printXsdDocumentation(String description) throws SAXException { @@ -60,8 +59,8 @@ public class ContentWriterXsd extends ContentWriterXmlTag AttributesImpl atts = new AttributesImpl(); atts.addAttribute ("", "xml:lang", "", "", "en"); printTagStart(Tag.documentation,atts); - characters(description); - printTagEnd(Tag.documentation); + printCharacters(description); + printTagEnd(Tag.documentation); printTagEnd(Tag.annotation); } @@ -70,16 +69,15 @@ public class ContentWriterXsd extends ContentWriterXmlTag atts.addAttribute ("", "name", "", "", name); atts.addAttribute ("", "type", "", "", type); printTagStart(Tag.attribute,atts); - printXsdDocumentation(description); + printXsdDocumentation(description); printTagEnd(Tag.attribute); } public enum Tag { all,annotation,any,anyAttribute,appinfo,attribute,attributeGroup, choise,complexContent,complexType,documentation,element,extension, - field,group,/*_import,*/include,key,keyref,list,notation, + field,group,_import,include,key,keyref,list,notation, redefine,restriction,schema,selector,sequence, simpleContent,simpleType,unoin,unique } - } diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriterElementClass.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriterElementClass.java index b954f99..55331cd 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriterElementClass.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriterElementClass.java @@ -131,14 +131,14 @@ public class EldDocWriterElementClass extends AbstractApiDocWriter { writer.printTagCharacters(Tag.dt,"All Element Parents:"); writer.printTagStart(Tag.dd); if (parents.isEmpty()) { - writer.characters("No parent."); + writer.printCharacters("No parent."); } for (int i=0;i keywords,String pathPrefix) throws SAXException { printDocType(DocType.HTML_4_TRANSITIONAL); - comment("NewPage"); + printComment("NewPage"); printHtmlStart("en"); // ====== Write head @@ -80,7 +80,7 @@ public class ApiDocContentWriter extends ContentWriterHtml { public void docHtmlEnd(String copyright,String statsJS) throws SAXException { printTagStart(Tag.p,ApiDocContentCss.legalCopy); printTagStart(Tag.small); - characters(copyright); + printCharacters(copyright); printTagEnd(Tag.small); printTagEnd(Tag.p); if (statsJS!=null) { @@ -97,7 +97,7 @@ public class ApiDocContentWriter extends ContentWriterHtml { String[] lines = about.split("\n"); for (int i=0;i event) throws SAXException { - event.getWriter().characters(event.getEventObject().getDescription()); + event.getWriter().printCharacters(event.getEventObject().getDescription()); } private void writeNodeDescription(ApiDocWriteEvent event,boolean isPageMode) throws SAXException { @@ -418,7 +419,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { String nodeTitle = node.getId(); if (nodes.hasNext()==false) { writer.printTagStart(Tag.li); - writer.characters(nodeTitle); + writer.printCharacters(nodeTitle); writer.printTagEnd(Tag.li); } else { writer.printTagStart(Tag.li); @@ -455,8 +456,8 @@ public class ApiDocWriter extends AbstractApiDocWriter { try { Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), encoding); ApiDocContentWriter result = new ApiDocContentWriter(out,encoding); - result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_NEWLINE, XMLConstants.CHAR_NEWLINE+""); - result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_TAB, " "); + result.getPropertyConfig().setProperty(ContentWriterXml.OUTPUT_CHAR_NEWLINE, XMLConstants.CHAR_NEWLINE+""); + result.getPropertyConfig().setProperty(ContentWriterXml.OUTPUT_CHAR_TAB, " "); return result; } catch (UnsupportedEncodingException e) { throw new SAXException(e); @@ -631,13 +632,14 @@ public class ApiDocWriter extends AbstractApiDocWriter { "\tif (targetPage != \"\" && targetPage != \"undefined\")\n"+ "\t\t { top."+ApiDocContentCss.frameContent.name()+".location = top.targetPage; }\n"+ "}\n"; - + + public void writeIndex() throws SAXException { File outputFile = createOutputPathFile(basePath,"index.html"); ApiDocContentWriter writer = createContentWriter(outputFile); try { writer.printDocType(DocType.HTML_4_FRAMESET); - writer.comment("NewPage"); + writer.printComment("NewPage"); writer.printHtmlStart("en"); writeHeader(writer,"",doc.getName()); writer.printScriptInline(FRAME_JS); @@ -682,16 +684,16 @@ public class ApiDocWriter extends AbstractApiDocWriter { writer.printScriptNoDiv(); writer.printTagCharacters(Tag.h2, "Frame Alert"); writer.printTagStart(Tag.p); - writer.characters("This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to "); + writer.printCharacters("This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to "); writer.printHref(rootLink, "Non-frame version"); - writer.characters("."); + writer.printCharacters("."); writer.printTagEnd(Tag.p); writer.printTagEnd(Tag.noframes); writer.printTagEnd(Tag.frameset); writer.printHtmlEnd(); } finally { - writer.closeWriterSafe(); + writer.getContentWriterWrapped().closeWriterSafe(); } } @@ -717,7 +719,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { String conceptParentPlural = conceptParent.getName()+"s"; writer.printDocType(DocType.HTML_4_TRANSITIONAL); - writer.comment("NewPage"); + writer.printComment("NewPage"); writer.printHtmlStart("en"); writeHeader(writer,"","All "+conceptPlural+" of "+doc.getName()); writer.printTagStart(Tag.body); @@ -748,7 +750,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { writer.printTagEnd(Tag.body); writer.printHtmlEnd(); } finally { - writer.closeWriterSafe(); + writer.getContentWriterWrapped().closeWriterSafe(); } } @@ -790,7 +792,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { //String conceptParentPlural = conceptParent.getName()+"s"; writer.printDocType(DocType.HTML_4_TRANSITIONAL); - writer.comment("NewPage"); + writer.printComment("NewPage"); writer.printHtmlStart("en"); writeHeader(writer,pathPrefix,"All "+conceptPlural+" of "+doc.getName()); writer.printTagStart(Tag.body); @@ -859,7 +861,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { writer.printTagEnd(Tag.body); writer.printHtmlEnd(); } finally { - writer.closeWriterSafe(); + writer.getContentWriterWrapped().closeWriterSafe(); } } @@ -887,7 +889,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { docNavBar(writer,false,null,null); writer.docHtmlEnd(doc.getDocCopyright(),doc.getDocStatsJS()); } finally { - writer.closeWriterSafe(); + writer.getContentWriterWrapped().closeWriterSafe(); } } @@ -957,7 +959,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { } File outputPath = new File(buf.toString()); if (outputPath.exists()==false) { - //System.out.println("Creating path: "+outputPath); + //System.out.println("Creating path: "+outputPath); // TODO add logger outputPath.mkdirs(); } buf.append(File.separatorChar); @@ -981,22 +983,22 @@ public class ApiDocWriter extends AbstractApiDocWriter { barCssDiv = "bottomNav"; barId = "navbar_bottom"; } - writer.comment("========= START OF "+barComment+" NAVBAR ======="); + writer.printComment("========= START OF "+barComment+" NAVBAR ======="); writer.printTagStart(Tag.div,barCssDiv); writer.printHrefNamed(barId); // Print named link navigation AttributesImpl atts = new AttributesImpl(); atts.addAttribute ("", "href", "", "", "#skip-"+barId); atts.addAttribute ("", "title", "", "", "Skip navigation links"); - writer.startElement("", "a", "", atts); - writer.comment(" "); - writer.endElement("", "a", ""); + writer.printTagStart(Tag.a, atts); + writer.printComment(" "); + writer.printTagEnd(Tag.a); writer.printHrefNamed(barId+"_firstrow"); atts = new AttributesImpl();// Print nav bar atts.addAttribute ("", "class", "", "", "navList"); atts.addAttribute ("", "title", "", "", "Navigation"); - writer.startElement("", "ul", "", atts); + writer.printTagStart(Tag.ul, atts); for (ApiDocNavLink navLink:conf.getNavLinks()) { String selectedCss = null; @@ -1015,7 +1017,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { docNavBarListItemHref(writer,pathPrefix+href,navTitle,navLink.getText(),selectedCss,null,null); } } - writer.endElement("", "ul", ""); + writer.printTagEnd(Tag.ul); writer.docNavBarAbout(doc.getDocAbout()); @@ -1086,7 +1088,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { writer.printTagStart(Tag.div); // don't print empty div } writer.printTagStart(Tag.ul,ApiDocContentCss.subNavList); - writer.printTagStart(Tag.li);writer.characters(groupName+": ");writer.printTagEnd(Tag.li); + writer.printTagStart(Tag.li);writer.printCharacters(groupName+": ");writer.printTagEnd(Tag.li); for (int l=0;l { +public class ContentWriterHtml extends ContentWriterTagWrapper { public ContentWriterHtml(Writer out,String encoding) { - super(out,encoding); + super(new ContentWriterXml(out, encoding),"", XMLConstants.NULL_NS_URI); + } + + public PropertyConfig getPropertyConfig() { + return getContentWriterWrapped().getPropertyConfig(); } public void printDocType(DocType doc) throws SAXException { - startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId()); + getContentWriterWrapped().startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId()); } public void printHtmlStart(String language) throws SAXException { @@ -70,15 +77,15 @@ public class ContentWriterHtml extends ContentWriterXmlTag