From 80ade0b3f42d8f9477bf7b85070d0a21ad1f6988 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Fri, 14 Mar 2014 01:20:16 +0100 Subject: [PATCH] Split abstract connection and debug code and fixed a couple of code markers. --- .../x4o/xml/eld/xsd/EldXsdWriterElement.java | 2 +- .../org/x4o/xml/io/AbstractX4OConnection.java | 123 +------------ .../xml/io/AbstractX4OConnectionDebug.java | 171 ++++++++++++++++++ .../java/org/x4o/xml/io/DefaultX4OReader.java | 6 +- .../java/org/x4o/xml/io/DefaultX4OWriter.java | 12 +- .../org/x4o/xml/io/sax/X4ODebugWriter.java | 4 +- .../x4o/xml/io/sax/ext/PropertyConfig.java | 11 +- .../org/x4o/xml/lang/DefaultX4OLanguage.java | 25 ++- .../java/org/x4o/xml/lang/X4OLanguage.java | 5 +- .../java/org/x4o/xml/eld/EldParserTest.java | 1 - .../xml/eld/xsd/EldXsdLanguageTaskTest.java | 2 +- .../java/org/x4o/xml/test/TestDriver.java | 2 - .../org/x4o/xml/eld/doc/EldDocWriter.java | 10 +- 13 files changed, 209 insertions(+), 165 deletions(-) create mode 100644 x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnectionDebug.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 ac95d0a..ea7faad 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 @@ -157,7 +157,7 @@ public class EldXsdWriterElement { //xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); xsdWriter.comment(COMMENT_SEPERATOR); - String byValue = propertyConfig.getPropertyStringOrValue(EldXsdWriter.PROLOG_GENERATED_BY, EldXsdWriter.class.getSimpleName()); + String byValue = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_GENERATED_BY, EldXsdWriter.class.getSimpleName()); if (!byValue.endsWith(".")) { byValue += '.'; } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnection.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnection.java index 22e4f6e..b534601 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnection.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnection.java @@ -22,28 +22,12 @@ */ package org.x4o.xml.io; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.x4o.xml.io.sax.X4ODebugWriter; -import org.x4o.xml.io.sax.ext.ContentWriter; -import org.x4o.xml.io.sax.ext.ContentWriterXml; import org.x4o.xml.io.sax.ext.PropertyConfig; import org.x4o.xml.lang.X4OLanguage; -import org.x4o.xml.lang.X4OLanguageSession; -import org.x4o.xml.lang.X4OLanguageSessionLocal; -import org.x4o.xml.lang.phase.X4OPhase; -import org.x4o.xml.lang.phase.X4OPhaseException; -import org.x4o.xml.lang.phase.X4OPhaseLanguageRead; -import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; /** * AbstractX4OConnection is the read/write interface for the classes. @@ -51,15 +35,11 @@ import org.xml.sax.helpers.AttributesImpl; * @author Willem Cazander * @version 1.0 Apr 6, 2013 */ -public abstract class AbstractX4OConnection implements X4OConnection { +public abstract class AbstractX4OConnection extends AbstractX4OConnectionDebug { private final X4OLanguage language; - private boolean debugStarted = false; - private OutputStream debugCloseOutputStream = null; protected String phaseStop = null; protected List phaseSkip = null; - protected final static String ABSTRACT_DEBUG_OUTPUT_HANDLER = "debug/output-handler"; - protected final static String ABSTRACT_DEBUG_OUTPUT_STREAM = "debug/output-stream"; public AbstractX4OConnection(X4OLanguage language) { this.language=language; @@ -96,105 +76,4 @@ public abstract class AbstractX4OConnection implements X4OConnection { public void addPhaseSkip(String phaseId) { phaseSkip.add( phaseId ); } - - protected void debugStart(X4OLanguageSession languageSession,String debugHandlerKey,String debugStreamKey) throws UnsupportedEncodingException, SAXException { - Object debugOutputHandler = getProperty(debugHandlerKey); - Object debugOutputStream = getProperty(debugStreamKey); - if (languageSession.getX4ODebugWriter()==null) { - ContentWriter xmlDebugWriter = null; - if (debugOutputHandler instanceof ContentWriter) { - xmlDebugWriter = (ContentWriter)debugOutputHandler; - } else if (debugOutputStream instanceof OutputStream) { - debugCloseOutputStream = (OutputStream)debugOutputStream; - xmlDebugWriter = new ContentWriterXml(debugCloseOutputStream); - } - if (xmlDebugWriter!=null) { - xmlDebugWriter.startDocument(); - xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI); - X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter); - X4OLanguageSessionLocal local = (X4OLanguageSessionLocal)languageSession; - local.setX4ODebugWriter(debugWriter); - - // We only close if we started it, this is for recursief debugging. - debugStarted = true; - } - } - - // debug language - if (languageSession.hasX4ODebugWriter()) { - languageSession.getX4ODebugWriter().debugConnectionStart(languageSession, this); - - // Add debug phases for all phases - for (String key:languageSession.getLanguage().getPhaseManager().getPhaseKeys()) { - X4OPhase p = languageSession.getLanguage().getPhaseManager().getPhase(key); - - p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugX4OPhaseListener()); - - if (shouldPrintTree(p)) { - p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugPrintTreePhaseListener()); - } - } - } - } - - private boolean shouldPrintTree(X4OPhase p) { - String phase = p.getId(); - if (X4OPhaseLanguageWrite.WRITE_END.equals(phase)) { - return true; - } - if (X4OPhaseLanguageRead.READ_END.equals(phase)) { - return true; - } - if (X4OPhaseLanguageRead.READ_RUN_ATTRIBUTE.equals(phase)) { - return true; - } - if (X4OPhaseLanguageRead.READ_TRANSFORM.equals(phase)) { - return true; - } - if (X4OPhaseLanguageRead.READ_BIND_ELEMENT.equals(phase)) { - return true; - } - return false; - } - - protected void debugException(X4OLanguageSession languageSession,Exception e) { - if (languageSession.hasX4ODebugWriter()) { - try { - AttributesImpl atts = new AttributesImpl(); - atts.addAttribute ("", "message", "", "", e.getMessage()); - if (e instanceof X4OPhaseException) { - atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId()); - } - languageSession.getX4ODebugWriter().getContentWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts); - StringWriter writer = new StringWriter(); - PrintWriter printer = new PrintWriter(writer); - printer.append('\n'); - if (e.getCause()==null) { - e.printStackTrace(printer); - } else { - e.getCause().printStackTrace(printer); - } - char[] stack = writer.getBuffer().toString().toCharArray(); - languageSession.getX4ODebugWriter().getContentWriter().characters(stack, 0, stack.length); - languageSession.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); - } catch (Exception ee) { - // TODO print e; - //logger.warning(ee.getMessage()); - } - } - } - - protected void debugStop(X4OLanguageSession languageSession) throws SAXException, IOException { - if (languageSession.hasX4ODebugWriter()) { - languageSession.getX4ODebugWriter().debugConnectionEnd(); - } - if (debugStarted && languageSession.hasX4ODebugWriter()) { - languageSession.getX4ODebugWriter().getContentWriter().endPrefixMapping("debug"); - languageSession.getX4ODebugWriter().getContentWriter().endDocument(); - if (debugCloseOutputStream!=null) { - debugCloseOutputStream.flush(); - debugCloseOutputStream.close(); // need this here ? - } - } - } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnectionDebug.java b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnectionDebug.java new file mode 100644 index 0000000..9b4261a --- /dev/null +++ b/x4o-driver/src/main/java/org/x4o/xml/io/AbstractX4OConnectionDebug.java @@ -0,0 +1,171 @@ +/* + * 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; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +import org.x4o.xml.io.sax.X4ODebugWriter; +import org.x4o.xml.io.sax.ext.ContentWriter; +import org.x4o.xml.io.sax.ext.ContentWriterXml; +import org.x4o.xml.lang.X4OLanguageSession; +import org.x4o.xml.lang.X4OLanguageSessionLocal; +import org.x4o.xml.lang.phase.X4OPhase; +import org.x4o.xml.lang.phase.X4OPhaseException; +import org.x4o.xml.lang.phase.X4OPhaseLanguageRead; +import org.x4o.xml.lang.phase.X4OPhaseLanguageWrite; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * AbstractX4OConnectionDebug has the abstract debug code of all connections. + * + * @author Willem Cazander + * @version 1.0 Mar 14, 2014 + */ +public abstract class AbstractX4OConnectionDebug implements X4OConnection { + + private boolean debugStarted = false; + private boolean debugAutoCloseOutputStream = true; + private OutputStream debugCloseOutputStream = null; + protected final static String ABSTRACT_DEBUG_OUTPUT_HANDLER = "debug/output-handler"; + protected final static String ABSTRACT_DEBUG_OUTPUT_STREAM = "debug/output-stream"; + protected final static String ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE = "debug/output-stream-close"; + + protected void debugStart(X4OLanguageSession languageSession,String debugHandlerKey,String debugStreamKey,String debugStreamCloseKey) throws UnsupportedEncodingException, SAXException { + debugAutoCloseOutputStream = (Boolean)getProperty(debugStreamCloseKey); + Object debugOutputHandler = getProperty(debugHandlerKey); + Object debugOutputStream = getProperty(debugStreamKey); + if (languageSession.getX4ODebugWriter()==null) { + ContentWriter xmlDebugWriter = null; + if (debugOutputHandler instanceof ContentWriter) { + xmlDebugWriter = (ContentWriter)debugOutputHandler; + } else if (debugOutputStream instanceof OutputStream) { + debugCloseOutputStream = (OutputStream)debugOutputStream; + xmlDebugWriter = new ContentWriterXml(debugCloseOutputStream); + } + if (xmlDebugWriter!=null) { + xmlDebugWriter.startDocument(); + xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI); + X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter); + X4OLanguageSessionLocal local = (X4OLanguageSessionLocal)languageSession; + local.setX4ODebugWriter(debugWriter); + + // We only close if we started it, this is for recursief debugging. + debugStarted = true; + } + } + + // debug language + if (languageSession.hasX4ODebugWriter()) { + languageSession.getX4ODebugWriter().debugConnectionStart(languageSession, this); + + // Add debug phases for all phases + for (String key:languageSession.getLanguage().getPhaseManager().getPhaseKeys()) { + X4OPhase p = languageSession.getLanguage().getPhaseManager().getPhase(key); + + p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugX4OPhaseListener()); + + if (shouldPrintTree(p)) { + p.addPhaseListener(languageSession.getX4ODebugWriter().createDebugPrintTreePhaseListener()); + } + } + } + } + + private boolean shouldPrintTree(X4OPhase p) { + String phase = p.getId(); + if (X4OPhaseLanguageWrite.WRITE_END.equals(phase)) { + return true; + } + if (X4OPhaseLanguageRead.READ_END.equals(phase)) { + return true; + } + if (X4OPhaseLanguageRead.READ_RUN_ATTRIBUTE.equals(phase)) { + return true; + } + if (X4OPhaseLanguageRead.READ_TRANSFORM.equals(phase)) { + return true; + } + if (X4OPhaseLanguageRead.READ_BIND_ELEMENT.equals(phase)) { + return true; + } + return false; + } + + protected void debugException(X4OLanguageSession languageSession,Exception e) throws X4OConnectionException { + if (!languageSession.hasX4ODebugWriter()) { + return; + } + try { + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute ("", "message", "", "", e.getMessage()); + if (e instanceof X4OPhaseException) { + atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId()); + } + languageSession.getX4ODebugWriter().getContentWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts); + StringWriter writer = new StringWriter(); + PrintWriter printer = new PrintWriter(writer); + printer.append('\n'); + if (e.getCause()==null) { + e.printStackTrace(printer); + } else { + e.getCause().printStackTrace(printer); + } + char[] stack = writer.getBuffer().toString().toCharArray(); + languageSession.getX4ODebugWriter().getContentWriter().characters(stack, 0, stack.length); + languageSession.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); + } catch (SAXException ee) { + throw new X4OConnectionException("Error while writing debug; "+ee.getMessage(),ee); + } + } + + protected void debugStop(X4OLanguageSession languageSession) throws X4OConnectionException { + if (!languageSession.hasX4ODebugWriter()) { + return; + } + try { + languageSession.getX4ODebugWriter().debugConnectionEnd(); + if (!debugStarted) { + return; // not in this instance started so no stopping then. + } + languageSession.getX4ODebugWriter().getContentWriter().endPrefixMapping("debug"); + languageSession.getX4ODebugWriter().getContentWriter().endDocument(); + if (debugCloseOutputStream==null) { + return; // we have handler + } + debugCloseOutputStream.flush(); + if (!debugAutoCloseOutputStream) { + return; // no auto close + } + debugCloseOutputStream.close(); + } catch (SAXException ee) { + throw new X4OConnectionException("Error while closing debug; "+ee.getMessage(),ee); + } catch (IOException ee) { + throw new X4OConnectionException("Error while closing debug; "+ee.getMessage(),ee); + } + } +} diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OReader.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OReader.java index f9c94ab..0feaafe 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OReader.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OReader.java @@ -75,6 +75,7 @@ public class DefaultX4OReader extends AbstractX4OReader { public final static String VALIDATION_INPUT_SCHEMA = PROPERTY_CONTEXT_PREFIX + "validation/input-schema"; public final static String DEBUG_OUTPUT_HANDLER = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_HANDLER; public final static String DEBUG_OUTPUT_STREAM = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM; + public final static String DEBUG_OUTPUT_STREAM_CLOSE = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE; static { DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX, @@ -92,7 +93,8 @@ public class DefaultX4OReader extends AbstractX4OReader { new PropertyConfigItem(VALIDATION_INPUT_DOC,Boolean.class,false), new PropertyConfigItem(VALIDATION_INPUT_SCHEMA,Boolean.class,false), new PropertyConfigItem(DEBUG_OUTPUT_HANDLER,ContentWriter.class), - new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class) + new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class), + new PropertyConfigItem(DEBUG_OUTPUT_STREAM_CLOSE,Boolean.class,true) ); } @@ -150,7 +152,7 @@ public class DefaultX4OReader extends AbstractX4OReader { } // init debug - debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM); + debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM, DEBUG_OUTPUT_STREAM_CLOSE); try { // Run document parsing diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java index 6bdbb2d..67ff582 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4OWriter.java @@ -71,6 +71,7 @@ public class DefaultX4OWriter extends AbstractX4OWriter { public final static String SCHEMA_ROOT_URI = PROPERTY_CONTEXT_PREFIX+"schema/root-uri"; public final static String DEBUG_OUTPUT_HANDLER = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_HANDLER; public final static String DEBUG_OUTPUT_STREAM = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM; + public final static String DEBUG_OUTPUT_STREAM_CLOSE = PROPERTY_CONTEXT_PREFIX + ABSTRACT_DEBUG_OUTPUT_STREAM_CLOSE; static { DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX, @@ -78,7 +79,8 @@ public class DefaultX4OWriter extends AbstractX4OWriter { new PropertyConfigItem(SCHEMA_PRINT,Boolean.class,true), new PropertyConfigItem(SCHEMA_ROOT_URI,String.class), new PropertyConfigItem(DEBUG_OUTPUT_HANDLER,ContentWriter.class), - new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class) + new PropertyConfigItem(DEBUG_OUTPUT_STREAM,OutputStream.class), + new PropertyConfigItem(DEBUG_OUTPUT_STREAM_CLOSE,Boolean.class,true) ); } @@ -108,7 +110,7 @@ public class DefaultX4OWriter extends AbstractX4OWriter { public void writeSession(X4OLanguageSession languageSession,OutputStream output) throws X4OConnectionException,SAXException,IOException { setProperty(OUTPUT_STREAM, output); addPhaseSkip(X4OPhaseLanguageWrite.WRITE_RELEASE); - debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM); + debugStart(languageSession, DEBUG_OUTPUT_HANDLER, DEBUG_OUTPUT_STREAM, DEBUG_OUTPUT_STREAM_CLOSE); try { languageSession.getLanguage().getPhaseManager().runPhases(languageSession, X4OPhaseType.XML_WRITE); } catch (X4OPhaseException e) { @@ -161,11 +163,6 @@ public class DefaultX4OWriter extends AbstractX4OWriter { debugException(languageSession, e); throw new X4OConnectionException(e); } finally { - try { - debugStop(languageSession); - } catch (Exception e1) { - // FIXME - } if (out!=null) { try { out.close(); @@ -173,6 +170,7 @@ public class DefaultX4OWriter extends AbstractX4OWriter { //logger.warning(e.getMessage()); } } + debugStop(languageSession); } } 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 75cc8f4..008ffee 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 @@ -41,7 +41,7 @@ import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementNamespace; import org.x4o.xml.element.ElementNamespaceInstanceProvider; -import org.x4o.xml.io.AbstractX4OConnection; +import org.x4o.xml.io.X4OConnection; import org.x4o.xml.io.sax.ext.ContentWriter; import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModuleLoaderResult; @@ -130,7 +130,7 @@ public class X4ODebugWriter { return buf.toString(); } - public void debugConnectionStart(X4OLanguageSession languageSession,AbstractX4OConnection ec) throws SAXException { + public void debugConnectionStart(X4OLanguageSession languageSession,X4OConnection ec) throws SAXException { AttributesImpl atts = new AttributesImpl(); atts.addAttribute ("", "language", "", "", languageSession.getLanguage().getLanguageName()); atts.addAttribute ("", "languageVersion", "", "", languageSession.getLanguage().getLanguageVersion()); diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/PropertyConfig.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/PropertyConfig.java index e1c1635..df9adab 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/PropertyConfig.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/ext/PropertyConfig.java @@ -299,7 +299,7 @@ public final class PropertyConfig implements Cloneable { } throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); } - + @SuppressWarnings("unchecked") public final List getPropertyList(String key) { Object value = getProperty(key); @@ -335,11 +335,10 @@ public final class PropertyConfig implements Cloneable { throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key); } - // TODO: better name this - public final String getPropertyStringOrValue(String key,String value) { + public final String getPropertyString(String key,String defaultValue) { String propertyValue = getPropertyString(key); if (propertyValue==null) { - return value; + return defaultValue; } else { return propertyValue; } @@ -403,9 +402,7 @@ public final class PropertyConfig implements Cloneable { setProperty(key, result); } if (listValues.length!=2) { - System.err.println("Could not parse map value: "+value); - System.exit(1); - return; + throw new IllegalArgumentException("Coult not parse map value: '"+value+"' parsed length: "+listValues.length+" needs to be 2."); } String mKey = listValues[0]; String mValue = listValues[1]; diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguage.java b/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguage.java index 506f6c8..f874e40 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguage.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguage.java @@ -23,7 +23,10 @@ package org.x4o.xml.lang; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import org.x4o.xml.el.X4OExpressionFactory; @@ -52,6 +55,7 @@ public class DefaultX4OLanguage implements X4OLanguageLocal { private String languageName = null; private String languageVersion = null; private X4OPhaseManager phaseManager = null; + private Map keyedNamespaceLookup = null; public DefaultX4OLanguage(X4OLanguageConfiguration languageConfiguration,X4OPhaseManager phaseManager,String languageName,String languageVersion) { if (languageName==null) { @@ -62,6 +66,7 @@ public class DefaultX4OLanguage implements X4OLanguageLocal { } logger = Logger.getLogger(DefaultX4OLanguage.class.getName()); elementLanguageModules = new ArrayList(20); + keyedNamespaceLookup = new HashMap(20); this.languageConfiguration=languageConfiguration; this.languageName=languageName; this.languageVersion=languageVersion; @@ -109,12 +114,16 @@ public class DefaultX4OLanguage implements X4OLanguageLocal { } } elementLanguageModules.add(elementLanguageModule); + + for (ElementNamespace ns:elementLanguageModule.getElementNamespaces()) { + keyedNamespaceLookup.put(ns.getUri(), ns); + } } - + /** * @see org.x4o.xml.lang.X4OLanguage#getLanguageModules() */ - public List getLanguageModules() { + public Collection getLanguageModules() { return elementLanguageModules; } @@ -255,16 +264,6 @@ public class DefaultX4OLanguage implements X4OLanguageLocal { * @see org.x4o.xml.lang.X4OLanguage#findElementNamespace(java.lang.String) */ public ElementNamespace findElementNamespace(String namespaceUri) { - - // TODO: refactor so no search for every tag !! - ElementNamespace result = null; - for (int i=0;i getLanguageModules(); + Collection getLanguageModules(); } 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 5dfc98b..daf2638 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 @@ -29,7 +29,6 @@ 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; diff --git a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/EldXsdLanguageTaskTest.java b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/EldXsdLanguageTaskTest.java index 5267060..3a84b87 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/EldXsdLanguageTaskTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/EldXsdLanguageTaskTest.java @@ -63,7 +63,7 @@ public class EldXsdLanguageTaskTest extends TestCase { File outputPath = createOutputPath(outputPostfix); config.setProperty(EldXsdWriter.OUTPUT_PATH,outputPath); config.setProperty(EldXsdWriter.OUTPUT_DOCUMENTATION,false); - config.setProperty(ContentWriterXml.PROLOG_LICENCE_FILE,new File("../license.txt")); // TODO: s or c ? + config.setProperty(ContentWriterXml.PROLOG_LICENCE_FILE,new File("../license.txt")); config.setProperty(ContentWriterXml.PROLOG_USER_COMMENT,"Generated by junit-test-run in class: "+this.getClass().getSimpleName()); if (props!=null) { for (String key:props.keySet()) { diff --git a/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java b/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java index 4ec44ae..b4732e7 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java +++ b/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java @@ -24,8 +24,6 @@ package org.x4o.xml.test; import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriverManager; -import org.x4o.xml.io.X4OReaderSession; -import org.x4o.xml.io.X4OWriterSession; import org.x4o.xml.test.models.TestObjectRoot; public class TestDriver extends X4ODriver { 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 ac1c9d8..8950791 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 @@ -160,11 +160,11 @@ public class EldDocWriter { // Generic config ApiDoc doc = new ApiDoc(); - doc.setName( propertyConfig.getPropertyStringOrValue(DOC_NAME, DEFAULT_NAME)); - doc.setDescription( propertyConfig.getPropertyStringOrValue(DOC_DESCRIPTION, DEFAULT_DESCRIPTION)); - doc.setDocAbout( propertyConfig.getPropertyStringOrValue(DOC_ABOUT, createLanguageAbout())); - doc.setDocCopyright( propertyConfig.getPropertyStringOrValue(DOC_COPYRIGHT, createLanguageCopyright())); - doc.setDocPageSubTitle( propertyConfig.getPropertyStringOrValue(DOC_PAGE_SUB_TITLE, createPageSubTitle())); + doc.setName( propertyConfig.getPropertyString(DOC_NAME, DEFAULT_NAME)); + doc.setDescription( propertyConfig.getPropertyString(DOC_DESCRIPTION, DEFAULT_DESCRIPTION)); + doc.setDocAbout( propertyConfig.getPropertyString(DOC_ABOUT, createLanguageAbout())); + doc.setDocCopyright( propertyConfig.getPropertyString(DOC_COPYRIGHT, createLanguageCopyright())); + doc.setDocPageSubTitle( propertyConfig.getPropertyString(DOC_PAGE_SUB_TITLE, createPageSubTitle())); doc.setMetaStyleSheetThema( propertyConfig.getPropertyString(META_STYLESHEET_THEMA)); doc.setMetaStyleSheet( propertyConfig.getPropertyFile(META_STYLESHEET)); List keywords = propertyConfig.getPropertyList(META_KEYWORDS);