From 6f2815491b684fb3b6010b25dae777522be7afd0 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sun, 23 Jun 2013 15:31:19 +0200 Subject: [PATCH] Fixed encoding bug,Added writeString support,Started on config bean. --- .gitignore | 4 + todo.txt | 2 +- .../x4o/xml/io/AbstractX4OReaderContext.java | 15 +- .../org/x4o/xml/io/AbstractX4OWriter.java | 4 + .../x4o/xml/io/AbstractX4OWriterContext.java | 9 + .../main/java/org/x4o/xml/io/X4OWriter.java | 2 + .../java/org/x4o/xml/io/X4OWriterContext.java | 2 + .../org/x4o/xml/io/sax/X4OContentHandler.java | 4 +- .../sax/ext/AbstractContentWriterHandler.java | 34 +++- .../org/x4o/xml/io/sax/ext/ContentConfig.java | 158 ++++++++++++++++++ .../xml/io/sax/ext/ContentWriterConfig.java | 38 ----- .../x4o/xml/lang/X4OLanguageClassLoader.java | 23 +++ .../org/x4o/xml/lang/X4OLanguageProperty.java | 7 +- .../xml/lang/phase/X4OPhaseLanguageRead.java | 6 +- .../java/org/x4o/xml/eld/EldParserTest.java | 36 +++- .../resources/META-INF/test/test-lang.eld | 4 + .../xml/eld/doc/api/ApiDocContentWriter.java | 35 ++-- .../xml/eld/doc/api/ApiDocNodeWriterBean.java | 17 +- .../org/x4o/xml/eld/doc/api/ApiDocWriter.java | 1 + .../org/x4o/xml/eld/doc/api/dom/ApiDoc.java | 13 +- 20 files changed, 319 insertions(+), 95 deletions(-) create mode 100644 x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentConfig.java delete mode 100644 x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterConfig.java diff --git a/.gitignore b/.gitignore index 24d2124..17d9faf 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,7 @@ nbproject Thumbs.db Desktop.ini +# Ignore kde dolphin files +.directory + + diff --git a/todo.txt b/todo.txt index fad194b..b153de9 100644 --- a/todo.txt +++ b/todo.txt @@ -13,7 +13,7 @@ - Add doc version upgrade handler; - per version step xslt doc upgrade (check dyna sax piplining hooking) - - per version eld + support code + backing objects + - per version eld + support code + backing objects (DONE) - per version eld for dyna tree convert to new backing objects. - Add *Local layer for X4OLanguage* classes. - Add default define (EL) layer diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReaderContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReaderContext.java index b7c4dee..9a9923f 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReaderContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OReaderContext.java @@ -30,7 +30,9 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageContext; +import org.x4o.xml.lang.X4OLanguageProperty; import org.xml.sax.SAXException; /** @@ -102,9 +104,7 @@ abstract public class AbstractX4OReaderContext extends AbstractX4OConnection if (resourceName==null) { throw new NullPointerException("Can't read null resourceName from classpath."); } - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) cl = getClass().getClassLoader(); // fallback - URL url = cl.getResource(resourceName); + URL url = X4OLanguageClassLoader.getResource(resourceName); if (url==null) { throw new NullPointerException("Could not find resource on classpath: "+resourceName); } @@ -114,7 +114,7 @@ abstract public class AbstractX4OReaderContext extends AbstractX4OConnection baseUrl = baseUrl.substring(0,lastSlash+1); } URL basePath = new URL(baseUrl); - InputStream inputStream = cl.getResourceAsStream(resourceName); + InputStream inputStream = X4OLanguageClassLoader.getResourceAsStream(resourceName); try { return readContext(inputStream,url.toExternalForm(),basePath); } finally { @@ -123,8 +123,8 @@ abstract public class AbstractX4OReaderContext extends AbstractX4OConnection } /** - * Converts a String to a InputStream to is can me readd by SAX. - * @param xmlString The xml as String to read. + * Converts a String to a InputStream to is can me read by SAX. + * @param xmlString The xml as (UTF-8) String to read. * @throws X4OConnectionException Is thrown after x4o exception. * @throws SAXException Is thrown after sax xml exception. * @throws IOException Is thrown after io exception. @@ -135,7 +135,8 @@ abstract public class AbstractX4OReaderContext extends AbstractX4OConnection throw new NullPointerException("Can't read null xml string."); } URL basePath = new File(System.getProperty("user.dir")).toURI().toURL(); - return readContext(new ByteArrayInputStream(xmlString.getBytes()),"inline-xml",basePath); + String encoding = getLanguageContext().getLanguagePropertyString(X4OLanguageProperty.READER_INPUT_ENCODING); + return readContext(new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath); } /** diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriter.java index 83c28b5..0e0fff4 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriter.java @@ -77,4 +77,8 @@ public abstract class AbstractX4OWriter extends AbstractX4OWriterContext i public void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException { writeFileContext(toObjectContext(object), file); } + + public String writeString(T object) throws X4OConnectionException,SAXException,IOException,FileNotFoundException { + return writeStringContext(toObjectContext(object)); + } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java index f6c59a8..844c397 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OWriterContext.java @@ -22,12 +22,14 @@ */ package org.x4o.xml.io; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.x4o.xml.lang.X4OLanguageContext; +import org.x4o.xml.lang.X4OLanguageProperty; import org.xml.sax.SAXException; /** @@ -60,4 +62,11 @@ public abstract class AbstractX4OWriterContext extends AbstractX4OConnection outputStream.close(); } } + + public String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(4096); + writeContext(context, out); + String encoding = context.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_ENCODING); + return out.toString(encoding); + } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java index 20bd7f0..1d5c7c9 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriter.java @@ -41,4 +41,6 @@ public interface X4OWriter extends X4OConnection { void writeFile(T object,String fileName) throws X4OConnectionException,SAXException,IOException; void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException; + + String writeString(T object) throws X4OConnectionException,SAXException,IOException; } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java index 7eab7aa..3d8f0b5 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OWriterContext.java @@ -42,4 +42,6 @@ public interface X4OWriterContext extends X4OWriter { void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException; void writeFileContext(X4OLanguageContext context,File file) throws X4OConnectionException,SAXException,IOException; + + String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException; } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OContentHandler.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OContentHandler.java index f8fc8ab..8b384a6 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OContentHandler.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OContentHandler.java @@ -172,7 +172,7 @@ public class X4OContentHandler extends DefaultHandler2 { overrideSaxHandler = (DefaultHandler2)element.getElementObject(); } } - + /** * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) */ @@ -201,7 +201,7 @@ public class X4OContentHandler extends DefaultHandler2 { throw new SAXParseException("Error while configing element: '"+tag+"' "+ee.getMessage(),locator,ee); } } - + /** * Gets called to pass the text between XML-tags and converts it to a String. * When this string is 0 length then nothing is done. 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 838b0e1..9c13c5a 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 @@ -83,6 +83,14 @@ public class AbstractContentWriterHandler implements ContentHandler { prefixMapping = new HashMap(15); printedMappings = new ArrayList(15); elements = new Stack(); + /* + ContentConfig conf = new ContentConfig( + new ContentConfigItem("writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING), + new ContentConfigItem("content/writer/output/charTab",String.class) + ); + conf.getPropertyString(""); + */ + } // TODO: check location of this. (add to api?) @@ -227,12 +235,8 @@ public class AbstractContentWriterHandler implements ContentHandler { attributeValue = "null"; // TODO: Add null value key to config. } String attributeValueSafe = XMLConstants.escapeAttributeValue(attributeValue); - boolean printNewLine = attributeValueSafe.length()>80; // TODO add config - if (i==0) { - startElement.append(' '); - } else if (!printNewLine) { - startElement.append(' '); - } + + startElement.append(' '); if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) { startElement.append(attributeName); } else { @@ -243,6 +247,7 @@ public class AbstractContentWriterHandler implements ContentHandler { startElement.append("=\""); startElement.append(attributeValueSafe); startElement.append('"'); + boolean printNewLine = attributeValueSafe.length()>80; // TODO add config if (printNewLine) { startElement.append(XMLConstants.CHAR_NEWLINE); for (int ii = 0; ii < indent+1; ii++) { @@ -385,6 +390,10 @@ public class AbstractContentWriterHandler implements ContentHandler { } /** + * Prints xml ignorable whitespace. + * + * @param text The text to print. + * @throws SAXException When IOException has happend while printing. * @see org.x4o.xml.io.sax.ext.ContentWriter#ignorableWhitespace(java.lang.String) */ public void ignorableWhitespace(String text) throws SAXException { @@ -395,6 +404,12 @@ public class AbstractContentWriterHandler implements ContentHandler { write(text); // TODO: check chars } + /** + * Prints xml ignorable whitespace character. + * + * @param c The character to print. + * @throws SAXException When IOException has happend while printing. + */ public void ignorableWhitespace(char c) throws SAXException { ignorableWhitespace(new char[]{c},0,1); } @@ -462,6 +477,8 @@ public class AbstractContentWriterHandler implements ContentHandler { } /** + * Prints xml comment. + * * @see org.x4o.xml.io.sax.ext.ContentWriter#comment(java.lang.String) */ public void comment(String text) throws SAXException { @@ -480,6 +497,11 @@ public class AbstractContentWriterHandler implements ContentHandler { printReturn = true; } + /** + * Checks if the value contains any new lines and sets the printReturn field. + * + * @param value The value to check. + */ private void checkPrintedReturn(String value) { if (value.indexOf(XMLConstants.CHAR_NEWLINE)>0) { printReturn = true; diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentConfig.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentConfig.java new file mode 100644 index 0000000..bea1743 --- /dev/null +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentConfig.java @@ -0,0 +1,158 @@ +/* + * 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.util.HashMap; +import java.util.Map; + +/** + * ContentConfig Defines checked config options. + * + * @author Willem Cazander + * @version 1.0 May 1, 2013 + */ +public final class ContentConfig { + + private final ContentConfigItem[] items; + private final Map itemKeys; + + public ContentConfig(ContentConfigItem...items) { + this.items=items; + itemKeys = new HashMap(items.length); + for (int i=0;i valueType = null; + private Object defaultValue = null; + private Object value = null; + + public ContentConfigItem(String key,Class valueType) { + this(key,valueType,null); + } + public ContentConfigItem(String key,Class valueType,Object defaultValue) { + setKey(key); + setValueType(valueType); + setDefaultValue(defaultValue); + } + /** + * @return the key + */ + public String getKey() { + return key; + } + /** + * @param key the key to set + */ + public void setKey(String key) { + this.key = key; + } + /** + * @return the valueType + */ + public Class getValueType() { + return valueType; + } + /** + * @param valueType the valueType to set + */ + public void setValueType(Class valueType) { + this.valueType = valueType; + } + /** + * @return the defaultValue + */ + public Object getDefaultValue() { + return defaultValue; + } + /** + * @param defaultValue the defaultValue to set + */ + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } + /** + * @return the value + */ + public Object getValue() { + return value; + } + /** + * @param value the value to set + */ + public void setValue(Object value) { + this.value = value; + } + } + + private final ContentConfigItem getContentConfigItem(String key) { + Integer keyIdx = itemKeys.get(key); + if (keyIdx==null) { + throw new IllegalArgumentException("Could not find config item for: "+key); + } + ContentConfigItem item = items[keyIdx]; + return item; + } + + public final void setProperty(String key,Object value) { + ContentConfigItem item = getContentConfigItem(key); + item.setValue(value); + } + + public final Object getProperty(String key) { + ContentConfigItem item = getContentConfigItem(key); + return item.getValue(); + } + + public final boolean getPropertyBoolean(String key) { + ContentConfigItem item = getContentConfigItem(key); + Object value = item.getValue(); + if (value instanceof Boolean) { + return (Boolean)value; + } + + return (Boolean)item.getDefaultValue(); + } + + public final int getPropertyInteger(String key) { + ContentConfigItem item = getContentConfigItem(key); + Object value = item.getValue(); + if (value instanceof Integer) { + return (Integer)value; + } + return (Integer)item.getDefaultValue(); + } + + public final String getPropertyString(String key) { + ContentConfigItem item = getContentConfigItem(key); + Object value = item.getValue(); + if (value instanceof String) { + return (String)value; + } + return (String)item.getDefaultValue(); + } +} diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterConfig.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterConfig.java deleted file mode 100644 index 963ffcb..0000000 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/ContentWriterConfig.java +++ /dev/null @@ -1,38 +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; - -/** - * ContentWriterConfig Defines config options for ContentWriter. - * - * @author Willem Cazander - * @version 1.0 May 1, 2013 - */ -public interface ContentWriterConfig { - - String getCharNewLine(); - String getCharTab(); - - String getReplaceCdataStart(); - String getReplaceCdataEnd(); -} diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageClassLoader.java b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageClassLoader.java index 91c9465..6e49204 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageClassLoader.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageClassLoader.java @@ -22,6 +22,9 @@ */ package org.x4o.xml.lang; +import java.io.InputStream; +import java.net.URL; + /** * X4OLanguageClassLoader is short hand for safe class loading. * @@ -82,4 +85,24 @@ public final class X4OLanguageClassLoader { public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { return newInstance(loadClass(className)); } + + /** + * Gets a resource from the classloader to an url. + * @param resourceName The resource to get from the classloader. + * @return The url to the resource or null if not found. + * @see java.lang.ClassLoader#getResource(String) + */ + public static URL getResource(String resourceName) { + return getClassLoader().getResource(resourceName); + } + + /** + * Gets a resource from the classloader to an inputstream. + * @param resourceName The resource to get from the classloader. + * @return The inputstream to the resource or null if not found. + * @see java.lang.ClassLoader#getResourceAsStream(String) + */ + public static InputStream getResourceAsStream(String resourceName) { + return getClassLoader().getResourceAsStream(resourceName); + } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageProperty.java b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageProperty.java index 81411e3..427b1dc 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageProperty.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageProperty.java @@ -33,6 +33,7 @@ import java.util.Map; import javax.el.ELContext; import javax.el.ExpressionFactory; +import org.x4o.xml.io.XMLConstants; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; @@ -60,7 +61,7 @@ public enum X4OLanguageProperty { READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class), /** When set it overrides automatic encoding detection of sax parser. */ - READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class), + READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING), /** When set use this InputSource instance for parsing. */ READER_INPUT_SOURCE(IO.READER,"reader/input/source",InputSource.class), @@ -107,7 +108,7 @@ public enum X4OLanguageProperty { WRITER_OUTPUT_STREAM(IO.WRITER,"writer/output/stream",OutputStream.class), /** The writer output encoding. */ - WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class), + WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING), /** The writer output newline. */ WRITER_OUTPUT_CHAR_NEWLINE(IO.WRITER,"writer/output/char/newline",String.class), @@ -129,7 +130,7 @@ public enum X4OLanguageProperty { SCHEMA_WRITER_OUTPUT_PATH(IO.SCHEMA_WRITER,"schema-writer/output/path",File.class), /** The schema writer output encoding. */ - SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class), + SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING), /** The schema writer output newline. */ SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE(IO.SCHEMA_WRITER,"schema-writer/output/char/newline",String.class), diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageRead.java b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageRead.java index 5db6201..4092cdf 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageRead.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageRead.java @@ -630,10 +630,10 @@ public class X4OPhaseLanguageRead { return; // has already runned. } try { - //if (parser.hasX4ODebugWriter()) { - // parser.getX4ODebugWriter().debugElement(element); + //if (element.getLanguageContext().hasX4ODebugWriter()) { + // element.getLanguageContext().getX4ODebugWriter().debugElement(element); //} - element.doElementRun(); + element.doElementRun(); } catch (ElementException e) { throw new X4OPhaseException(this,e); } diff --git a/x4o-driver/src/test/java/org/x4o/xml/eld/EldParserTest.java b/x4o-driver/src/test/java/org/x4o/xml/eld/EldParserTest.java index d6845be..08643dd 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/eld/EldParserTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/eld/EldParserTest.java @@ -22,6 +22,15 @@ */ package org.x4o.xml.eld; +import org.x4o.xml.X4ODriver; +import org.x4o.xml.X4ODriverManager; +import org.x4o.xml.io.X4OReader; +import org.x4o.xml.io.X4OWriter; +import org.x4o.xml.lang.DefaultX4OLanguageModule; +import org.x4o.xml.lang.X4OLanguage; +import org.x4o.xml.lang.X4OLanguageLocal; +import org.x4o.xml.lang.X4OLanguageModule; + import junit.framework.TestCase; /** @@ -95,10 +104,27 @@ public class EldParserTest extends TestCase { } public void testRunEldParser() throws Exception { - //EldDriver parser = new EldDriver(false); - //parser.parseResource("META-INF/test/test-lang.eld"); - //X4ODriver driver = (X4ODriver)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME); - //X4OReader reader = driver.createReader(); - //reader.readResource("META-INF/test/test-lang.eld"); + X4ODriver driver = (X4ODriver)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME); + X4OReader reader = driver.createReader(); + X4OWriter writer = driver.createWriter(); + + X4OLanguage language = driver.createLanguage(driver.getLanguageVersionDefault()); + X4OLanguageModule mod = new DefaultX4OLanguageModule(); + + reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration()); + reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE, language); + reader.addELBeanInstance(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE, mod); + + X4OLanguageModule modNew = reader.readResource("META-INF/test/test-lang.eld"); + + //int binds = mod.getElementBindingHandlers().size(); + //System.out.println(binds); + + String output = writer.writeString(mod); + assertNotNull(output); + + // TODO; fix element config+event to new interface + reserse for writing. + + //System.out.println(output); } } diff --git a/x4o-driver/src/test/resources/META-INF/test/test-lang.eld b/x4o-driver/src/test/resources/META-INF/test/test-lang.eld index d07b023..6690321 100644 --- a/x4o-driver/src/test/resources/META-INF/test/test-lang.eld +++ b/x4o-driver/src/test/resources/META-INF/test/test-lang.eld @@ -72,6 +72,7 @@ + + diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocContentWriter.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocContentWriter.java index 6efd4f5..2f926c5 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocContentWriter.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocContentWriter.java @@ -101,6 +101,7 @@ public class ApiDocContentWriter extends ContentWriterHtml { List navList = new ArrayList(10); Map navLinks = new HashMap(10); Map navNames = new HashMap(10); + Map navTitles = new HashMap(10); String pathPrefix; String prev; String next; @@ -169,15 +170,19 @@ public class ApiDocContentWriter extends ContentWriterHtml { for (String navKey:conf.navList) { String navName = conf.navNames.get(navKey); String navLink = conf.navLinks.get(navKey); + String navTitle = conf.navTitles.get(navKey); String selectedCss = null; if (navKey.equals(conf.navSelected)) { selectedCss = "navBarCell1Rev"; navLink = null; // disables link } + if (navTitle==null) { + navTitle = navName; + } if (navLink==null) { printTagCharacters(Tag.li, navName, selectedCss); } else { - docNavBarListItemHref(pathPrefix+navLink,navName,selectedCss); + docNavBarListItemHref(pathPrefix+navLink,navName,navTitle,selectedCss,null,null); } } endElement("", "ul", ""); @@ -203,12 +208,12 @@ public class ApiDocContentWriter extends ContentWriterHtml { if (conf.prev==null) { printTagCharacters(Tag.li, "Prev"); } else { - docNavBarListItemHref(pathPrefix+conf.prev,"Prev",null,"strong",null); + docNavBarListItemHref(pathPrefix+conf.prev,"Prev","Previous Item",null,"strong",null); } if (conf.next==null) { printTagCharacters(Tag.li, "Next"); } else { - docNavBarListItemHref(pathPrefix+conf.next,"Next",null,"strong",null); + docNavBarListItemHref(pathPrefix+conf.next,"Next","Next Item",null,"strong",null); } printTagEnd(Tag.ul); if (conf.frame!=null) { @@ -223,7 +228,7 @@ public class ApiDocContentWriter extends ContentWriterHtml { } if (conf.noFrameAllName!=null && conf.noFrameAllLink!=null) { printTagStart(Tag.ul,ApiDocContentCss.navList,"allclasses_"+barId); - docNavBarListItemHref(pathPrefix+conf.noFrameAllLink,conf.noFrameAllName,null,null,null); + docNavBarListItemHref(pathPrefix+conf.noFrameAllLink,conf.noFrameAllName,null,null,null,null); printTagEnd(Tag.ul); printTagStart(Tag.div); if (isTop) { @@ -233,6 +238,7 @@ public class ApiDocContentWriter extends ContentWriterHtml { } printTagEnd(Tag.div); } + String tabSpace = " | "; boolean printLink = conf.linkConstructors || conf.linkFields || conf.linkMethods; if (printLink) { @@ -241,13 +247,13 @@ public class ApiDocContentWriter extends ContentWriterHtml { printTagStart(Tag.li);charactersRaw("Summary: ");printTagEnd(Tag.li); //printTagText(Tag.li,"Nested | "); // TODO: Nested if (conf.linkFields) { - docNavBarListItemHref("#field_summary",conf.linkFieldName,null,null,tabSpace); + docNavBarListItemHrefLinkSpace("#field_summary",conf.linkFieldName); } else { printTagCharacters(Tag.li,conf.linkFieldName);charactersRaw(tabSpace); } if (conf.linkConstructors) { - docNavBarListItemHref("#constructor_summary",conf.linkConstructorName,null,null,tabSpace); + docNavBarListItemHrefLinkSpace("#constructor_summary",conf.linkConstructorName); } else { printTagCharacters(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace); } @@ -262,12 +268,12 @@ public class ApiDocContentWriter extends ContentWriterHtml { printTagStart(Tag.li);charactersRaw("Detail: ");printTagEnd(Tag.li); //printTagText(Tag.li,"Nested | "); if (conf.linkFields) { - docNavBarListItemHref("#field_detail",conf.linkFieldName,null,null,tabSpace); + docNavBarListItemHrefLinkSpace("#field_detail",conf.linkFieldName); } else { printTagCharacters(Tag.li,conf.linkFieldName);charactersRaw(tabSpace); } if (conf.linkConstructors) { - docNavBarListItemHref("#constructor_detail",conf.linkConstructorName,null,null,tabSpace); + docNavBarListItemHrefLinkSpace("#constructor_detail",conf.linkConstructorName); } else { printTagCharacters(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace); } @@ -286,12 +292,17 @@ public class ApiDocContentWriter extends ContentWriterHtml { comment("========= END OF "+barComment+" NAVBAR ======="); } - private void docNavBarListItemHref(String href,String title,String cssClass) throws SAXException { - docNavBarListItemHref(href, title, cssClass, null, null); + private void docNavBarListItemHrefLinkSpace(String href,String title) throws SAXException { + String tabSpace = " | "; + docNavBarListItemHref(href, title, title, null, null, tabSpace); } - private void docNavBarListItemHref(String href,String title,String cssClass,String spanCss,String linkSpace) throws SAXException { + + private void docNavBarListItemHref(String href,String title, String cssClass) throws SAXException { + docNavBarListItemHref(href, title, title, cssClass, null, null); + } + private void docNavBarListItemHref(String href,String title,String text,String cssClass,String spanCss,String linkSpace) throws SAXException { printTagStart(Tag.li,cssClass); - printHref(href,title,title,spanCss); + printHref(href,title,text,spanCss); charactersRaw(linkSpace); printTagEnd(Tag.li); } diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java index 8d95f41..2c45144 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java @@ -24,7 +24,6 @@ package org.x4o.xml.eld.doc.api; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.x4o.xml.eld.doc.api.dom.ApiDoc; @@ -56,11 +55,11 @@ public class ApiDocNodeWriterBean implements ApiDocNodeWriter { public ApiDocNodeWriterBean(ApiDocNodeBody nodeBody,Object bean,String method,Class...classes) { this(); - this.nodeBody=nodeBody; - this.bean=bean; - this.method=method; - if (classes!=null && classes.length>0) { - targetClasses.addAll(Arrays.asList(classes)); + setNodeBody(nodeBody); + setBean(bean); + setMethod(method); + for (Class cl:classes) { + addtargetClass(cl); } } @@ -91,10 +90,10 @@ public class ApiDocNodeWriterBean implements ApiDocNodeWriter { } public void writeNodeContent(ApiDocWriteEvent event) throws SAXException { - Class beanClass = bean.getClass(); + Class beanClass = getBean().getClass(); try { - Method methodBean = beanClass.getMethod(method, new Class[]{ApiDocWriteEvent.class}); - methodBean.invoke(bean, new Object[]{event}); + Method methodBean = beanClass.getMethod(getMethod(), new Class[]{ApiDocWriteEvent.class}); + methodBean.invoke(getBean(), new Object[]{event}); } catch (Exception e) { throw new SAXException(e); } 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 c21bd11..f422cf4 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 @@ -244,6 +244,7 @@ public class ApiDocWriter { if (concept.getParent()!=null && !concept.getParent().getId().equals(doc.getRootNode().getId())) { ApiDocConcept conceptParent = concept.getParent(); conf.navLinks.put(conceptParent.getId(), ApiDocContentWriter.toSafeUri(pathClean)+prefix+"/index.html"); + conf.navTitles.put(conceptParent.getId(), conceptParent.getDescriptionName()); configActiveNavConceptLinks(conf,node,concept.getParent(),prefix+"/.."); } } diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDoc.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDoc.java index e6708bc..2d03755 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDoc.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/dom/ApiDoc.java @@ -60,11 +60,6 @@ public class ApiDoc { treeNodeClassExcludes = new ArrayList>(5); } - public ApiDoc(ApiDocNode rootNode) { - this(); - setRootNode(rootNode); - } - public void checkModel() throws NullPointerException,IllegalArgumentException { checkNull(name,"name"); checkNull(description,"description"); @@ -79,16 +74,16 @@ public class ApiDoc { throw new IllegalStateException("Can't work with empty nodeBodyWriters"); } if (frameNavOverviewPrintParent==null) { - frameNavOverviewPrintParent=false; + setFrameNavOverviewPrintParent(false); } if (frameNavPrintParent==null) { - frameNavPrintParent=false; + setFrameNavPrintParent(false); } if (frameNavPrintParentParent==null) { - frameNavPrintParentParent=false; + setFrameNavPrintParentParent(false); } if (frameNavPrintParentId==null) { - frameNavPrintParentId=false; + setFrameNavPrintParentId(false); } }