From 5f08acb488bb9135a68f5e52ec109ad48350ab12 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Thu, 6 Mar 2014 23:15:53 +0100 Subject: [PATCH] added more xml writer options and improved api doc output. --- todo.txt | 14 +- versions.txt | 4 + .../org/x4o/xml/eld/xsd/EldXsdWriter.java | 2 +- .../sax/ext/AbstractContentWriterHandler.java | 50 +++-- .../io/sax/ContentWriterXmlAttributeTest.java | 133 +++++++++++++ .../xml/io/sax/ContentWriterXmlCDataTest.java | 162 ++++++++++++++++ .../x4o/xml/io/sax/ContentWriterXmlTest.java | 179 ------------------ .../org/x4o/xml/eld/doc/EldDocWriter.java | 4 +- .../org/x4o/xml/eld/doc/api/ApiDocWriter.java | 121 +++++++----- .../org/x4o/xml/eld/doc/api/dom/ApiDoc.java | 15 +- .../xml/eld/doc/api/dom/ApiDocIndexItem.java | 127 +++++++++++++ .../xml/eld/doc/api/dom/ApiDocNodeData.java | 10 + 12 files changed, 571 insertions(+), 250 deletions(-) create mode 100644 x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlAttributeTest.java create mode 100644 x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlCDataTest.java create mode 100644 x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocIndexItem.java diff --git a/todo.txt b/todo.txt index b153de9..89b4172 100644 --- a/todo.txt +++ b/todo.txt @@ -1,14 +1,12 @@ -- x4o TODO list -- +-- Fix debug output -- RM function methods from Element interface. --- Change global attr to namespace attributes. - finish eld doc-output content. - Make generic/safe? config bean. - Make language config done by driver xml parser. - - Add langauge task api + reg via driver conf or service - - Convert ant/mvn plugin to single task executor. -- change x4o language to "x4o-" prefix so; x4o-cel,x4o-eld,x4o-meta +- change (internal) x4o language to "x4o-" prefix so; x4o-cel,x4o-eld,x4o-meta - Add language locking, and lock eld/cel and add -eld wrap language for eld extentions per language. - Add doc version upgrade handler; @@ -44,6 +42,14 @@ - make element tree jdom api compatible - Test if possible to use threadpool for executing phases +?? v2; +x4o-driver +x4o-s4j-jaxp (dom,sax,stax,xslt) (jsr; 5,63,173) +x4o-s4j-sax +x4o-s4j-stax +x4o-s4j-jaxb (jsr; 222) + + -- TODO for version 1.0 -- ## NON-CODE diff --git a/versions.txt b/versions.txt index 834c46f..340e535 100644 --- a/versions.txt +++ b/versions.txt @@ -8,6 +8,10 @@ Version 0.8.7: - Renamed ElementNamespaceContext to ElementNamespace. - Removed binding handler from element interface. - Refactored all property keys with PropertyConfig bean. +- Change global attr to namespace attributes. +- Updated ant/maven plugins to new task and properties. +- Added options to xml writer like OUTPUT_LINE_BREAK_WIDTH. + Version 0.8.6: - Changed to X4ODriver interface. diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java index 03f21a0..3e454c4 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java @@ -39,7 +39,7 @@ import org.x4o.xml.lang.X4OLanguage; import org.xml.sax.SAXException; /** - * EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver. + * EldXsdWriter creates XML Schema files fom a x4o language. * * @author Willem Cazander * @version 1.0 Aug 8, 2012 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 ed11c41..cc79578 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 @@ -71,10 +71,11 @@ public class AbstractContentWriterHandler implements ContentHandler { 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 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"; @@ -89,10 +90,11 @@ 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_COMMENT_ENABLE, Boolean.class, true), new PropertyConfigItem(OUTPUT_COMMENT_AUTO_SPACE, Boolean.class, true), -// TODO new PropertyConfigItem(OUTPUT_LINE_BREAK_WIDTH, Integer.class, -1), -// TODO new PropertyConfigItem(OUTPUT_LINE_PER_ATTRIBUTE, Boolean.class, false), + new PropertyConfigItem(OUTPUT_LINE_BREAK_WIDTH, Integer.class, -1), + new PropertyConfigItem(OUTPUT_LINE_PER_ATTRIBUTE, Boolean.class, false), new PropertyConfigItem(PROLOG_LICENCE_ENCODING, String.class, XMLConstants.XML_DEFAULT_ENCODING), new PropertyConfigItem(PROLOG_LICENCE_FILE, File.class ), new PropertyConfigItem(PROLOG_LICENCE_RESOURCE, String.class ), @@ -289,7 +291,7 @@ public class AbstractContentWriterHandler implements ContentHandler { startElement.append(' '); startElement.append(XMLConstants.XMLNS_ATTRIBUTE); if ("".equals(prefix)==false) { - startElement.append(':'); + startElement.append(XMLConstants.XMLNS_ASSIGN); startElement.append(prefix); } startElement.append("=\""); @@ -333,17 +335,32 @@ public class AbstractContentWriterHandler implements ContentHandler { } } + private void printElementAttributeNewLineSpace() { + startElement.append(XMLConstants.CHAR_NEWLINE); + for (int ii = 0; ii < indent+1; ii++) { + startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB)); + } + } + private void startElementAttributes(Attributes atts) throws SAXException { + int prevChars = 0; for (int i=0;i80; // TODO add config - if (printNewLine) { - startElement.append(XMLConstants.CHAR_NEWLINE); - for (int ii = 0; ii < indent+1; ii++) { - startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB)); + + if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) { + printElementAttributeNewLineSpace(); + } + + int breakLines = propertyConfig.getPropertyInteger(OUTPUT_LINE_BREAK_WIDTH); + if (breakLines>0) { + if (prevChars==0 && startElement.length() > breakLines) { + printElementAttributeNewLineSpace(); + prevChars = startElement.length(); + } + if (prevChars>0 && (startElement.length()-prevChars) > breakLines) { + printElementAttributeNewLineSpace(); + prevChars = startElement.length(); } } } diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlAttributeTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlAttributeTest.java new file mode 100644 index 0000000..72eed3c --- /dev/null +++ b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlAttributeTest.java @@ -0,0 +1,133 @@ +/* + * 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; + +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; + +import org.x4o.xml.io.sax.ext.ContentWriterXml; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import junit.framework.TestCase; + +/** + * ContentWriterXmlAttributeTest test xml attribute printing. * + * @author Willem Cazander + * @version 1.0 S 17, 2012 + */ +public class ContentWriterXmlAttributeTest extends TestCase { + + public void testAttributeNormal() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", "attr", "", "", "foobar"); + writer.startElementEnd("", "test", "", atts); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("\n")); + } + + public void testAttributeEscape() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", "attr", "", "", " & 'foobar' is \"quoted\"!"); + writer.startElementEnd("", "test", "", atts); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("\n")); + } + + private String createLongAttribute(Map para) throws SAXException { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + for (String key:para.keySet()) { + Object value = para.get(key); + writer.getPropertyConfig().setProperty(key, value); + } + + AttributesImpl atts = new AttributesImpl(); + String data = "_FOR_FOO_BAR"; + String dataValue = "LOOP"; + for (int i=0;i<15;i++) { + atts.addAttribute("", "attr"+i, "", "", dataValue+=data); + } + writer.startDocument(); + writer.startElement("", "test", "", atts); + writer.startElement("", "testNode", "", new AttributesImpl()); + writer.endElement("", "testNode", ""); + writer.endElement("", "test", ""); + writer.endDocument(); + + String output = outputWriter.toString(); + return output; + } + + public void testAttributeLongNormal() throws Exception { + Map para = new HashMap(); + String output = createLongAttribute(para); + int newlines = output.split("\n").length; + assertNotNull(output); + assertTrue("outputs: "+newlines,newlines==4); + } + + public void testAttributeLongPerLine() throws Exception { + Map para = new HashMap(); + para.put(ContentWriterXml.OUTPUT_LINE_PER_ATTRIBUTE, true); + String output = createLongAttribute(para); + int newlines = output.split("\n").length; + assertNotNull(output); + assertTrue("outputs: "+newlines,newlines==20); + } + + public void testAttributeLongSplit80() throws Exception { + Map para = new HashMap(); + para.put(ContentWriterXml.OUTPUT_LINE_BREAK_WIDTH, 80); + String output = createLongAttribute(para); + int newlines = output.split("\n").length; + assertNotNull(output); + assertTrue("outputs: "+newlines,newlines==16); + } + + public void testAttributeLongSplit180() throws Exception { + Map para = new HashMap(); + para.put(ContentWriterXml.OUTPUT_LINE_BREAK_WIDTH, 180); + String output = createLongAttribute(para); + int newlines = output.split("\n").length; + assertNotNull(output); + assertTrue("outputs: "+newlines,newlines==11); + } +} diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlCDataTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlCDataTest.java new file mode 100644 index 0000000..f9e46f5 --- /dev/null +++ b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlCDataTest.java @@ -0,0 +1,162 @@ +/* + * 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; + +import java.io.StringWriter; + +import org.x4o.xml.io.sax.ext.ContentWriterXml; + +import junit.framework.TestCase; + +/** + * ContentWriterXmlCDataTest tests cdata xml escaping. + * + * @author Willem Cazander + * @version 1.0 Sep 17, 2013 + */ +public class ContentWriterXmlCDataTest extends TestCase { + + public void testCDATANone() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.characters("foobar"); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("foobar")); + } + + public void testCDATANoneTagEscape() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.characters("foobar"); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("foobar<test/>")); + } + + public void testCDATANormal() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("foobar"); + writer.endCDATA(); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("")); + } + + public void testCDATAEscapeTag() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("foobar"); + writer.endCDATA(); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("]]>")); + } + + public void testCDATAEscapeStart() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("0); + assertTrue(output,output.equals("")); + } + + public void testCDATAEscapeEnd() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("foobar]]>"); + writer.endCDATA(); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("")); + } + + public void testCDATAEscapeInvalid() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("' are ]]>"); + writer.endCDATA(); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output,output.equals("]]>")); + } + + public void testCDATAEscapeValid() throws Exception { + StringWriter outputWriter = new StringWriter(); + ContentWriterXml writer = new ContentWriterXml(outputWriter); + + writer.startDocument(); + writer.startCDATA(); + writer.characters("' are ]]>"); + writer.endCDATA(); + writer.endDocument(); + + String output = outputWriter.toString(); + assertNotNull(output); + assertTrue(output.length()>0); + assertTrue(output.equals("\' are ]]>")); + } +} diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java index d0f4a7f..dec2815 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java @@ -39,130 +39,6 @@ import junit.framework.TestCase; */ public class ContentWriterXmlTest extends TestCase { - public void testCDATANone() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.characters("foobar"); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("foobar")); - } - - public void testCDATANoneTagEscape() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.characters("foobar"); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("foobar<test/>")); - } - - public void testCDATANormal() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("foobar"); - writer.endCDATA(); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("")); - } - - public void testCDATAEscapeTag() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("foobar"); - writer.endCDATA(); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("]]>")); - } - - public void testCDATAEscapeStart() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("0); - assertTrue(output,output.equals("")); - } - - public void testCDATAEscapeEnd() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("foobar]]>"); - writer.endCDATA(); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("")); - } - - public void testCDATAEscapeInvalid() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("' are ]]>"); - writer.endCDATA(); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("]]>")); - } - - public void testCDATAEscapeValid() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - writer.startCDATA(); - writer.characters("' are ]]>"); - writer.endCDATA(); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output.equals("\' are ]]>")); - } - public void testCharactersNormal() throws Exception { StringWriter outputWriter = new StringWriter(); ContentWriterXml writer = new ContentWriterXml(outputWriter); @@ -190,39 +66,6 @@ public class ContentWriterXmlTest extends TestCase { assertTrue(output.length()>0); assertTrue(output,output.equals("<test/> & 'foobar' is "e;quoted"e;!")); } - - public void testAttributeNormal() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "attr", "", "", "foobar"); - writer.startElementEnd("", "test", "", atts); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("\n")); - } - - public void testAttributeEscape() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - writer.startDocument(); - AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "attr", "", "", " & 'foobar' is \"quoted\"!"); - writer.startElementEnd("", "test", "", atts); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.length()>0); - assertTrue(output,output.equals("\n")); - } - public void testCommentNormal() throws Exception { StringWriter outputWriter = new StringWriter(); @@ -394,26 +237,4 @@ public class ContentWriterXmlTest extends TestCase { assertTrue(e.getMessage().contains("invalid char")); assertTrue(e.getMessage().contains("isInvalidChar=55296")); } - - public void testAttributeValueLongData() throws Exception { - StringWriter outputWriter = new StringWriter(); - ContentWriterXml writer = new ContentWriterXml(outputWriter); - - AttributesImpl atts = new AttributesImpl(); - String data = "_FOR_FOO_BAR"; - String dataValue = "LOOP"; - for (int i=0;i<15;i++) { - atts.addAttribute("", "attr"+i, "", "", dataValue+=data); - } - writer.startDocument(); - writer.startElement("", "test", "", atts); - writer.startElement("", "testNode", "", new AttributesImpl()); - writer.endElement("", "testNode", ""); - writer.endElement("", "test", ""); - writer.endDocument(); - - String output = outputWriter.toString(); - assertNotNull(output); - assertTrue(output.split("\n").length==13); - } } diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriter.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriter.java index e237551..2779656 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriter.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/EldDocWriter.java @@ -175,8 +175,8 @@ public class EldDocWriter { doc.setNoFrameAllName("All Elements"); doc.setFrameNavPrintParent(true); doc.setFrameNavPrintParentId(true); - doc.setGroupTypeName("summary", "Summary"); - doc.setGroupTypeName("overview", "Overview"); + doc.setGroupTypeName("summary", "Summary",1); + doc.setGroupTypeName("overview", "Overview",2); // Javadoc linking config List javadocLinkList = propertyConfig.getPropertyList(JAVADOC_LINK); diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocWriter.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocWriter.java index 5667b40..acda83e 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocWriter.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocWriter.java @@ -94,13 +94,13 @@ public class ApiDocWriter extends AbstractApiDocWriter { writeAllFrameNav(true); writeAllFrameNav(false); - // Write pages + // Write api doc tree + writeNode(doc.getRootNode()); + + // Write pages last for (ApiDocPage page:doc.getDocPages()) { writePage(page); } - - // Write api doc tree - writeNode(doc.getRootNode()); } private void writeNode(ApiDocNode node) throws SAXException { @@ -371,7 +371,11 @@ public class ApiDocWriter extends AbstractApiDocWriter { private void configSubNavLinks(ApiDocNode node) { ApiDocNodeData conf = doc.getNodeData(); - for (ApiDocNodeWriter writer:findNodeBodyWriters(node, null)) { + List orderedWriters = new ArrayList(10); + for (ApiDocNodeBody bodyType:ApiDocNodeBody.values()) { + orderedWriters.addAll(findNodeBodyWriters(node,bodyType)); // enum order is oke + } + for (ApiDocNodeWriter writer:orderedWriters) { String group = writer.getContentGroup(); String groupTypeKey = writer.getContentGroupType(); if (group==null | groupTypeKey==null) { @@ -464,10 +468,16 @@ public class ApiDocWriter extends AbstractApiDocWriter { } private List findNodeBodyWriters(ApiDocNode node,ApiDocNodeBody nodeBody) { + if (node==null) { + throw new NullPointerException("Can't search writers on null node."); + } + if (nodeBody==null) { + throw new NullPointerException("Can't search writers with null nodeBody."); // for sorting rules + } List result = new ArrayList(); final Class objClass = node.getUserData().getClass(); for (ApiDocNodeWriter writer:doc.getNodeBodyWriters()) { - if (nodeBody!=null && !nodeBody.equals(writer.getNodeBody())) { + if (!nodeBody.equals(writer.getNodeBody())) { continue; } for (Class c:writer.getTargetClasses()) { @@ -476,46 +486,45 @@ public class ApiDocWriter extends AbstractApiDocWriter { } } } - Collections.sort(result, new Comparator() { - public int compare(ApiDocNodeWriter o1, ApiDocNodeWriter o2) { - int index1 = -1; - int index2 = -1; - for (int i=0;i c = o1.getTargetClasses().get(i); - if (c.isAssignableFrom(objClass)) { - index1 = i; - break; - } + Collections.sort(result, new ApiDocNodeWriterComparator(objClass)); + return result; + } + + private class ApiDocNodeWriterComparator implements Comparator { + final Class objClass; + public ApiDocNodeWriterComparator(Class objClass) { + this.objClass=objClass; + } + public int compare(ApiDocNodeWriter o1, ApiDocNodeWriter o2) { + int index1 = -1; + int index2 = -1; + for (int i=0;i c = o1.getTargetClasses().get(i); + if (c.isAssignableFrom(objClass)) { + index1 = i; + break; } - for (int i=0;i c = o2.getTargetClasses().get(i); - if (c.isAssignableFrom(objClass)) { - index1 = i; - break; - } - } - // TODO: note check return value if are oke in order.. - if (index1==-1 && index2==-1) { - return 0; - } - if (index1==-1) { - return 1; - } - if (index2==-1) { - return -1; - } - int orderValue1 = o1.getNodeBodyOrders().get(index1); - int orderValue2 = o2.getNodeBodyOrders().get(index2); - if (orderValue1==orderValue2) { - return 0; - } - if (orderValue1 > orderValue2) { - return -1; + } + for (int i=0;i c = o2.getTargetClasses().get(i); + if (c.isAssignableFrom(objClass)) { + index2 = i; + break; } + } + if (index1==-1 && index2==-1) { + return 0; + } + if (index1==-1) { return 1; } - }); - return result; + if (index2==-1) { + return -1; + } + Integer orderValue1 = o1.getNodeBodyOrders().get(index1); + Integer orderValue2 = o2.getNodeBodyOrders().get(index2); + return orderValue1.compareTo(orderValue2); + } } private List findDataConfigurators(ApiDocNode node) { @@ -980,6 +989,7 @@ public class ApiDocWriter extends AbstractApiDocWriter { atts.addAttribute ("", "href", "", "", "#skip-"+barId); atts.addAttribute ("", "title", "", "", "Skip navigation links"); writer.startElement("", "a", "", atts); + writer.comment(" "); writer.endElement("", "a", ""); writer.printHrefNamed(barId+"_firstrow"); @@ -1055,18 +1065,27 @@ public class ApiDocWriter extends AbstractApiDocWriter { } writer.printTagEnd(Tag.div); } - String tabSpace = " | "; - List groupKeys = conf.getGroupTypeKeys(); - boolean printLink = groupKeys.isEmpty()==false; + boolean printLink = conf.getGroupTypeKeys().isEmpty()==false; if (printLink) { - writer.printTagStart(Tag.div); - writer.printTagStart(Tag.ul,ApiDocContentCss.subNavList); + List groupKeys = new ArrayList(5); + for (String groupKey:doc.getGroupTypesOrdered()) { + if (!conf.getGroupTypeKeys().contains(groupKey)) { + continue; + } + groupKeys.add(groupKey); + } + boolean printDiv = false; for (int i=0;i links = conf.getGroupTypeLinks(groupKey); if (links.isEmpty()==false) { + if (!printDiv) { + printDiv = true; + 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); for (int l=0;l groupTypeNames = null; + private Map groupTypeOrder = null; private String docPageSubTitle = null; public ApiDoc() { @@ -88,6 +90,7 @@ public class ApiDoc { annotatedClasses = new ArrayList>(5); remoteClasses = new ArrayList(5); groupTypeNames = new HashMap(3); + groupTypeOrder = new HashMap(3); } public void checkModel() throws NullPointerException,IllegalArgumentException { @@ -671,6 +674,15 @@ public class ApiDoc { this.printConceptPrevNext = printConceptPrevNext; } + public List getGroupTypesOrdered() { + Map orderedMap = new TreeMap(); + for (String key:groupTypeOrder.keySet()) { + Integer order = groupTypeOrder.get(key); + orderedMap.put(order, key); + } + return new ArrayList(orderedMap.values()); + } + public String getGroupTypeName(String groupTypeKey) { String result = groupTypeNames.get(groupTypeKey); if (result==null) { @@ -679,8 +691,9 @@ public class ApiDoc { return result; } - public void setGroupTypeName(String groupTypeKey,String name) { + public void setGroupTypeName(String groupTypeKey,String name,int order) { groupTypeNames.put(groupTypeKey,name); + groupTypeOrder.put(groupTypeKey, order); } /** diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocIndexItem.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocIndexItem.java new file mode 100644 index 0000000..e9ad42f --- /dev/null +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocIndexItem.java @@ -0,0 +1,127 @@ +/* + * 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.eld.doc.api.dom; + +/** + * ApiDocIndexItem holds data to print the index all page. + * + * @author Willem Cazander + * @version 1.0 Nov 09, 2013 + */ +public class ApiDocIndexItem { + + private String linkHref = null; + private String linkText = null; + private String titlePostHref = null; + private String titlePostText = null; + + private String title = null; + private String description = null; + + public ApiDocIndexItem() { + } + + /** + * @return the linkHref + */ + public String getLinkHref() { + return linkHref; + } + + /** + * @param linkHref the linkHref to set + */ + public void setLinkHref(String linkHref) { + this.linkHref = linkHref; + } + + /** + * @return the linkText + */ + public String getLinkText() { + return linkText; + } + + /** + * @param linkText the linkText to set + */ + public void setLinkText(String linkText) { + this.linkText = linkText; + } + + /** + * @return the titlePostHref + */ + public String getTitlePostHref() { + return titlePostHref; + } + + /** + * @param titlePostHref the titlePostHref to set + */ + public void setTitlePostHref(String titlePostHref) { + this.titlePostHref = titlePostHref; + } + + /** + * @return the titlePostText + */ + public String getTitlePostText() { + return titlePostText; + } + + /** + * @param titlePostText the titlePostText to set + */ + public void setTitlePostText(String titlePostText) { + this.titlePostText = titlePostText; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } +} diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocNodeData.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocNodeData.java index c88d071..b188aec 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocNodeData.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDocNodeData.java @@ -43,11 +43,21 @@ public class ApiDocNodeData { private String nextLink = null; private String framePath = null;; private List navLinks = null; + private List indexItems = null; public ApiDocNodeData() { navLinks = new ArrayList(12); groupTypeKeys = new ArrayList(navLinks.size()/3); groupTypeLinks = new HashMap>(groupTypeKeys.size()); + indexItems = new ArrayList(500); + } + + public List getIndexItems() { + return indexItems; + } + + public void addIndexItem(ApiDocIndexItem indexItem) { + indexItems.add(indexItem); } public void addGroupTypeKey(String groupTypeKey) {