From edbe6bb73793e4f892bc4d2021e7cc897f71b8c1 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Mon, 29 Apr 2013 01:04:24 +0200 Subject: [PATCH] Fixed some checkstyle and javadoc warnings and added a few new IO unit tests. --- src/site/apt/usage.apt | 23 +-- .../java/org/x4o/xml/X4ODriverManager.java | 2 +- .../java/org/x4o/xml/el/X4OELContext.java | 11 +- .../org/x4o/xml/el/X4OELFunctionMapper.java | 13 +- .../main/java/org/x4o/xml/eld/CelDriver.java | 2 + .../lang/AttributeFromBodyConfigurator.java | 5 +- .../x4o/xml/eld/lang/DescriptionElement.java | 11 +- .../xsd/X4OWriteLanguageSchemaExecutor.java | 11 +- .../AbstractElementClassAttribute.java | 56 +++---- .../xml/element/AbstractElementClassBase.java | 5 + ...faultElementNamespaceInstanceProvider.java | 5 +- .../ElementNamespaceInstanceProvider.java | 7 +- .../org/x4o/xml/io/AbstractX4OConnection.java | 9 +- .../x4o/xml/io/AbstractX4OReaderContext.java | 8 +- .../x4o/xml/io/AbstractX4OWriterContext.java | 4 +- .../java/org/x4o/xml/io/DefaultX4OReader.java | 1 + .../java/org/x4o/xml/io/DefaultX4OWriter.java | 2 +- .../main/java/org/x4o/xml/io/X4OReader.java | 7 +- .../org/x4o/xml/io/sax/X4OEntityResolver.java | 2 + .../xml/lang/AbstractX4OLanguageContext.java | 2 +- .../xml/lang/DefaultX4OLanguageContext.java | 3 + .../java/org/x4o/xml/lang/X4OLanguage.java | 1 + .../x4o/xml/lang/X4OLanguageClassLoader.java | 2 +- .../org/x4o/xml/lang/X4OLanguageModule.java | 4 +- .../xml/lang/phase/X4OPhaseLanguageWrite.java | 1 + .../org/x4o/xml/lang/phase/X4OPhaseType.java | 11 +- .../org/x4o/xml/lang/phase/package-info.java | 2 +- .../org/x4o/xml/core/AttributeBeanTest.java | 17 ++ .../X4OWriteLanguageSchemaExecutorTest.java | 9 + .../org/x4o/xml/io/X4OConnectionTest.java | 86 ++++++++++ ...extTest.java => X4OReaderContextTest.java} | 22 ++- ...ractReaderTest.java => X4OReaderTest.java} | 23 ++- .../org/x4o/xml/io/X4OWriterContextTest.java | 155 ++++++++++++++++++ .../java/org/x4o/xml/io/X4OWriterTest.java | 90 ++++++---- .../resources/META-INF/test/test-lang.eld | 14 +- .../resources/tests/attributes/test-body.xml | 32 ++++ .../org/x4o/xml/eld/doc/EldDocGenerator.java | 14 +- .../eld/doc/X4OWriteLanguageDocExecutor.java | 9 +- .../maven/X4OWriteLanguageDocMojoTest.java | 11 ++ 39 files changed, 581 insertions(+), 111 deletions(-) create mode 100644 x4o-driver/src/test/java/org/x4o/xml/io/X4OConnectionTest.java rename x4o-driver/src/test/java/org/x4o/xml/io/{X4OAbstractReaderContextTest.java => X4OReaderContextTest.java} (92%) rename x4o-driver/src/test/java/org/x4o/xml/io/{X4OAbstractReaderTest.java => X4OReaderTest.java} (90%) create mode 100644 x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java create mode 100644 x4o-driver/src/test/resources/tests/attributes/test-body.xml diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt index f5c4b27..62bc097 100644 --- a/src/site/apt/usage.apt +++ b/src/site/apt/usage.apt @@ -39,7 +39,7 @@ Usage * x4o-plugin-ant = X4O Ant plugins for schema and documentation task. - * x4o-plugin-ant-schema = Ant x4o schema task. + * x4o-plugin-maven = X4O Maven plugin task. * Setup as library @@ -58,17 +58,12 @@ Usage * Setup build task - Append one or both of the x4o eld ant tasks; + Append the x4o ant tasks; +-- org.x4o.plugin - x4o-plugin-ant-elddoc - ${project.version} - - - org.x4o.plugin - x4o-plugin-ant-schema + x4o-plugin-ant ${project.version} +-- @@ -76,21 +71,21 @@ Usage Use in ant and set the supportclass from the language you want to run the task for. +-- - - + + - - +-- diff --git a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java index 9f27ca4..e5ff3f0 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java +++ b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java @@ -272,7 +272,7 @@ public final class X4ODriverManager { if (classdrivers.containsKey(className)==false) { classdrivers.put(language,className); } - } else if ("defaultDriver".equals("tab")) { + } else if ("defaultDriver".equals(tag)) { String language = attr.getValue("language"); logger.finest("DefaultDriver language: "+language); if (defaultDrivers.containsKey(language)==false) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java b/x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java index b7a1e86..943ff54 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/el/X4OELContext.java @@ -47,6 +47,9 @@ public class X4OELContext extends ELContext { private FunctionMapper functionMapper = null; private VariableMapper variableMapper = null; + /** + * Creates a X4OELContext. + */ public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) { CompositeELResolver compositeELResolver = new CompositeELResolver(); @@ -62,6 +65,8 @@ public class X4OELContext extends ELContext { } /** + * Returns the ELResolver. + * @return The ELResolver. * @see javax.el.ELContext#getELResolver() */ @Override @@ -70,6 +75,8 @@ public class X4OELContext extends ELContext { } /** + * Returns the FunctionMapper. + * @return The FunctionMapper. * @see javax.el.ELContext#getFunctionMapper() */ @Override @@ -78,10 +85,12 @@ public class X4OELContext extends ELContext { } /** + * Returns the VariableMapper. + * @return The VariableMapper. * @see javax.el.ELContext#getVariableMapper() */ @Override public VariableMapper getVariableMapper() { return variableMapper; } -} \ No newline at end of file +} diff --git a/x4o-driver/src/main/java/org/x4o/xml/el/X4OELFunctionMapper.java b/x4o-driver/src/main/java/org/x4o/xml/el/X4OELFunctionMapper.java index c6ce113..7b5eaf3 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/el/X4OELFunctionMapper.java +++ b/x4o-driver/src/main/java/org/x4o/xml/el/X4OELFunctionMapper.java @@ -39,6 +39,9 @@ import javax.el.FunctionMapper; public class X4OELFunctionMapper extends FunctionMapper { private Map functionMap = null; + /** + * Creates a X4OELFunctionMapper. + */ public X4OELFunctionMapper() { functionMap = new HashMap(50); } @@ -48,7 +51,13 @@ public class X4OELFunctionMapper extends FunctionMapper { String key = prefix + ":" + localName; return functionMap.get(key); } - + + /** + * Add an static method to the function mapper. + * @param prefix The function prefix. + * @param localName The local name of function. + * @param method The method to execute on. + */ public void addFunction(String prefix, String localName, Method method) { if(prefix==null || localName==null || method==null) { throw new NullPointerException(); @@ -68,4 +77,4 @@ public class X4OELFunctionMapper extends FunctionMapper { String key = prefix + ":" + localName; functionMap.put(key, method); } -} \ No newline at end of file +} diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java b/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java index 54dc2ae..ea60a23 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java @@ -36,6 +36,8 @@ public class CelDriver extends X4ODriver { /** Defines the identifier of the 'Core Element Language' language. */ public static final String LANGUAGE_NAME = "cel"; + + /** Defines the versions this langauge knowns. */ public static final String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION}; @Override diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java index 106e26e..a3833c5 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/AttributeFromBodyConfigurator.java @@ -42,6 +42,9 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator { private String bodyType = null; /** + * Config an element body as attribute of parent elememt. + * @param element The element to config. + * @throws ElementConfiguratorException Is thrown when object tree is non valid. * @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element) */ public void doConfigElement(Element element) throws ElementConfiguratorException { @@ -64,7 +67,7 @@ public class AttributeFromBodyConfigurator extends AbstractElementConfigurator { } else { throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType); } - if (value.length()==0) { + if (value.trim().length()==0) { return; } element.getAttributes().put(name, value); diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/DescriptionElement.java b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/DescriptionElement.java index d23bed9..c9027e8 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/lang/DescriptionElement.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/lang/DescriptionElement.java @@ -28,9 +28,7 @@ import org.x4o.xml.element.ElementMetaBase; import org.x4o.xml.element.ElementException; /** - * Fills all the ElementDescription which the description - * - * + * Fills all the ElementDescription which the description. * * @author Willem Cazander * @version 1.0 Jan 13, 2009 @@ -38,6 +36,8 @@ import org.x4o.xml.element.ElementException; public class DescriptionElement extends AbstractElement { /** + * Starts the description element and validates that it is not root and parent is meta base. + * @throws ElementException When parent element object is not meta base object. * @see org.x4o.xml.element.AbstractElement#doElementStart() */ @Override @@ -51,6 +51,9 @@ public class DescriptionElement extends AbstractElement { } /** + * The description elememt body characters are stored as element object. + * @param characters The text of the description. + * @throws ElementException When super has error. * @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String) */ @Override @@ -60,6 +63,8 @@ public class DescriptionElement extends AbstractElement { } /** + * Ends the description element and sets the description on the parent. + * @throws ElementException When parent element object is not meta base object. * @see org.x4o.xml.element.AbstractElement#doElementEnd() */ @Override diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java index 5c89308..8f7a8a6 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java @@ -46,7 +46,11 @@ public class X4OWriteLanguageSchemaExecutor { private String languageNamespaceUri = null; private File basePath; - static public void main(String argu[]) { + /** + * Config and executes this language task. + * @param argu The command line arguments. + */ + public static void main(String[] argu) { X4OWriteLanguageSchemaExecutor languageSchema = new X4OWriteLanguageSchemaExecutor(); List arguList = Arrays.asList(argu); Iterator arguIterator = arguList.iterator(); @@ -107,7 +111,10 @@ public class X4OWriteLanguageSchemaExecutor { return; } } - + + /** + * Executes this language task. + */ public void execute() throws ElementException { // Start xsd generator X4ODriver driver = X4ODriverManager.getX4ODriver(getLanguageName()); diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassAttribute.java b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassAttribute.java index 091febc..d97c918 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassAttribute.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassAttribute.java @@ -36,7 +36,6 @@ import org.x4o.xml.conv.ObjectConverter; */ public abstract class AbstractElementClassAttribute extends AbstractElementMetaBase implements ElementClassAttribute { - private String name = null; private ObjectConverter objectConverter = null; private Object defaultValue = null; private List attributeAliases = null; @@ -46,40 +45,33 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB private Boolean runConverters = null; private Boolean runBeanValue = null; private Integer writeOrder = null; - + + /** + * Creates a AbstractElementClassAttribute. + */ public AbstractElementClassAttribute() { attributeAliases = new ArrayList(3); } - - /** - * @see org.x4o.xml.element.ElementClassAttribute#getName() - */ - public String getName() { - return name; - } /** - * @see org.x4o.xml.element.ElementClassAttribute#setName(java.lang.String) - */ - public void setName(String name) { - this.name=name; - } - - /** - * @return the objectConverter + * Returns the objectConverter. + * @return The objectConverter. */ public ObjectConverter getObjectConverter() { return objectConverter; } /** - * @param objectConverter the objectConverter to set + * Sets the objectConverter. + * @param objectConverter The objectConverter to set. */ public void setObjectConverter(ObjectConverter objectConverter) { this.objectConverter = objectConverter; } /** + * Sets the default value. + * @param defaultValue The defaultValue to set. * @see org.x4o.xml.element.ElementClassAttribute#setDefaultValue(java.lang.Object) */ public void setDefaultValue(Object defaultValue) { @@ -87,6 +79,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB } /** + * Returns the default value. + * @return The default value. * @see org.x4o.xml.element.ElementClassAttribute#getDefaultValue() */ public Object getDefaultValue() { @@ -94,6 +88,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB } /** + * Adds an alias of this attribute. + * @param alias The alias to add. * @see org.x4o.xml.element.ElementClassAttribute#addAttributeAlias(java.lang.String) */ public void addAttributeAlias(String alias) { @@ -101,6 +97,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB } /** + * Removes an alias of this attribute. + * @param alias The alias to remove. * @see org.x4o.xml.element.ElementClassAttribute#removeAttributeAlias(java.lang.String) */ public void removeAttributeAlias(String alias) { @@ -108,6 +106,8 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB } /** + * Returns all aliases of this attribute. + * @return An list of aliases. * @see org.x4o.xml.element.ElementClassAttribute#getAttributeAliases() */ public List getAttributeAliases() { @@ -115,70 +115,70 @@ public abstract class AbstractElementClassAttribute extends AbstractElementMetaB } /** - * @return the required + * @return the required. */ public Boolean getRequired() { return required; } /** - * @param required the required to set + * @param required the required to set. */ public void setRequired(Boolean required) { this.required = required; } /** - * @return the runResolveEL + * @return the runResolveEL. */ public Boolean getRunResolveEL() { return runResolveEL; } /** - * @param runResolveEL the runResolveEL to set + * @param runResolveEL the runResolveEL to set. */ public void setRunResolveEL(Boolean runResolveEL) { this.runResolveEL = runResolveEL; } /** - * @return the runConverters + * @return the runConverters. */ public Boolean getRunConverters() { return runConverters; } /** - * @param runConverters the runConverters to set + * @param runConverters the runConverters to set. */ public void setRunConverters(Boolean runConverters) { this.runConverters = runConverters; } /** - * @return the runBeanValue + * @return the runBeanValue. */ public Boolean getRunBeanValue() { return runBeanValue; } /** - * @param runBeanValue the runBeanValue to set + * @param runBeanValue the runBeanValue to set. */ public void setRunBeanValue(Boolean runBeanValue) { this.runBeanValue = runBeanValue; } /** - * @return the writeOrder + * @return the writeOrder. */ public Integer getWriteOrder() { return writeOrder; } /** - * @param writeOrder the writeOrder to set + * @param writeOrder the writeOrder to set. */ public void setWriteOrder(Integer writeOrder) { this.writeOrder = writeOrder; diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java index d5790b0..2750073 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java @@ -41,6 +41,9 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i private List elementConfigurators = null; private Map> elementParents = null; + /** + * Creates a AbstractElementClassBase. + */ public AbstractElementClassBase() { elementConfigurators = new ArrayList(5); elementClassAttributes = new HashMap(15); @@ -48,6 +51,8 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i } /** + * Returns a list of ElementConfigurators. + * @return List of ElementConfigurators. * @see ElementClass#getElementConfigurators() */ public List getElementConfigurators() { diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementNamespaceInstanceProvider.java b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementNamespaceInstanceProvider.java index 59e5d96..a5a56e4 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementNamespaceInstanceProvider.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementNamespaceInstanceProvider.java @@ -75,10 +75,11 @@ public class DefaultElementNamespaceInstanceProvider implements ElementNamespace try { if (elementClass.getElementClass()!=null) { Object obj = X4OLanguageClassLoader.newInstance(elementClass.getElementClass()); - if ((obj instanceof Element) == false) { + if (obj instanceof Element) { + element = (Element) obj; + } else { throw new ElementNamespaceInstanceProviderException(this,"Provided elementClassName is not an Element: "+obj.getClass()); } - element = (Element) obj; } else { element = (Element)X4OLanguageClassLoader.newInstance((languageContext.getLanguage().getLanguageConfiguration().getDefaultElement())); } diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/ElementNamespaceInstanceProvider.java b/x4o-driver/src/main/java/org/x4o/xml/element/ElementNamespaceInstanceProvider.java index b9f389b..4031d17 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/ElementNamespaceInstanceProvider.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/ElementNamespaceInstanceProvider.java @@ -36,17 +36,18 @@ public interface ElementNamespaceInstanceProvider { /** * Starts the ElementProvider. - * @param elementLanguage The ElementLanguage to start in. + * @param language The X4OLanguage to start in. * @param elementNamespaceContext The ElementNamespaceContext to start for. * @throws ElementNamespaceInstanceProviderException Thrown when error happened in language. */ - void start(X4OLanguage elementLanguage,ElementNamespaceContext elementNamespaceContext) throws ElementNamespaceInstanceProviderException; + void start(X4OLanguage language,ElementNamespaceContext elementNamespaceContext) throws ElementNamespaceInstanceProviderException; /** * Provide an Element for an xml tag. + * @param languageContext The languageContext to create element for. * @param tag The xml tag to create instance for. * @return An new Element instance. * @throws ElementNamespaceInstanceProviderException Thrown when error happened in language. */ - Element createElementInstance(X4OLanguageContext elementLanguage,String tag) throws ElementNamespaceInstanceProviderException; + Element createElementInstance(X4OLanguageContext languageContext,String tag) throws ElementNamespaceInstanceProviderException; } 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 f1d2c8a..87656e0 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 @@ -36,10 +36,17 @@ public abstract class AbstractX4OConnection implements X4OConnection { private X4OLanguageContext languageContext = null; + /** + * Creates a AbstractX4OConnection. + * @param languageContext The language context of this connection. + */ public AbstractX4OConnection(X4OLanguageContext languageContext) { this.languageContext=languageContext; } + /** + * @return Returns the language context. + */ protected X4OLanguageContext getLanguageContext() { return languageContext; } @@ -50,7 +57,7 @@ public abstract class AbstractX4OConnection implements X4OConnection { * @param value The vlue of the property to set. */ public void setProperty(String key,Object value) { - String keyLimits[] = getPropertyKeySet(); + String[] keyLimits = getPropertyKeySet(); for (int i=0;i extends AbstractX4OConnection try { return readContext(inputStream,file.getAbsolutePath(),basePath); } finally { - if(inputStream!=null) { - inputStream.close(); - } + inputStream.close(); } } @@ -121,9 +119,7 @@ abstract public class AbstractX4OReaderContext extends AbstractX4OConnection try { return readContext(inputStream,url.toExternalForm(),basePath); } finally { - if(inputStream!=null) { - inputStream.close(); - } + inputStream.close(); } } 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 c21803e..a0fc93b 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 @@ -58,9 +58,7 @@ public abstract class AbstractX4OWriterContext extends AbstractX4OConnection try { writeContext(context,outputStream); } finally { - if(outputStream!=null) { - outputStream.close(); - } + outputStream.close(); } } } 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 82a067e..3a056e2 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 @@ -156,6 +156,7 @@ public class DefaultX4OReader extends AbstractX4OReader { languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length); languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); } catch (Exception ee) { + logger.warning(ee.getMessage()); } } 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 b5763af..757105a 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 @@ -52,7 +52,7 @@ public class DefaultX4OWriter extends AbstractX4OWriter { * @see org.x4o.xml.io.X4OWriterContext#writeContext(org.x4o.xml.lang.X4OLanguageContext, java.io.OutputStream) */ public void writeContext(X4OLanguageContext languageContext,OutputStream output) throws X4OConnectionException,SAXException,IOException { - setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output); + languageContext.setLanguageProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output); try { languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE); } catch (X4OPhaseException e) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java index f85ad58..cd007dc 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/X4OReader.java @@ -39,7 +39,12 @@ import org.xml.sax.SAXException; */ public interface X4OReader extends X4OConnection { - public void addELBeanInstance(String name,Object bean); + /** + * Adds an bean instance to the el context. + * @param name The el name for the bean. + * @param bean The bean to add to the el context. + */ + void addELBeanInstance(String name,Object bean); /** * Method to parse the xml data. diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OEntityResolver.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OEntityResolver.java index 255974f..96d82c9 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OEntityResolver.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/X4OEntityResolver.java @@ -103,6 +103,8 @@ public class X4OEntityResolver implements EntityResolver { * * @param publicId The public id to search for. * @param systemId The system id to search for. + * @throws IOException When resource could not be read. + * @throws SAXException When exception is thrown. * @return Returns null or the InputSource of the requested ids. */ public InputSource resolveEntity(String publicId, String systemId) throws IOException,SAXException { diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/AbstractX4OLanguageContext.java b/x4o-driver/src/main/java/org/x4o/xml/lang/AbstractX4OLanguageContext.java index 05df29a..f477447 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/AbstractX4OLanguageContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/AbstractX4OLanguageContext.java @@ -57,7 +57,7 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo private Map languageProperties; /** - * Creates a new empty ElementLanguage. + * Creates a new empty language context. */ public AbstractX4OLanguageContext(X4OLanguage language) { if (language==null) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguageContext.java b/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguageContext.java index b6aad4f..bba5883 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguageContext.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/DefaultX4OLanguageContext.java @@ -32,6 +32,9 @@ package org.x4o.xml.lang; */ public class DefaultX4OLanguageContext extends AbstractX4OLanguageContext { + /** + * Creates a new empty language context. + */ public DefaultX4OLanguageContext(X4OLanguage language) { super(language); } diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguage.java b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguage.java index b58e11c..28e07f2 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguage.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguage.java @@ -63,6 +63,7 @@ public interface X4OLanguage { /** * Creates and fills the initial element language used to store the language. + * @param driver The driver to create language context for. * @return The newly created ElementLanguage. */ X4OLanguageContext createLanguageContext(X4ODriver driver); 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 f2ceaba..dff54a3 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 @@ -29,7 +29,7 @@ package org.x4o.xml.lang; * @author Willem Cazander * @version 1.0 6 Aug 2012 */ -public class X4OLanguageClassLoader { +public final class X4OLanguageClassLoader { /** * Made X4OLanguageClassLoader have private constructor. diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageModule.java b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageModule.java index 01c9b36..cea3079 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageModule.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/X4OLanguageModule.java @@ -54,12 +54,12 @@ public interface X4OLanguageModule extends ElementMetaBase { /** * @return the providerHost */ - public String getProviderHost(); + String getProviderHost(); /** * @param providerHost the providerHost to set */ - public void setProviderHost(String providerHost); + void setProviderHost(String providerHost); /** * Adds an ElementAttributeHandler. diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageWrite.java b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageWrite.java index dde40ec..d6c8cd4 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageWrite.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseLanguageWrite.java @@ -237,6 +237,7 @@ public class X4OPhaseLanguageWrite { try { out.close(); } catch (IOException e) { + logger.warning(e.getMessage()); } } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseType.java b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseType.java index e3295c7..fd36c4b 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseType.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/X4OPhaseType.java @@ -24,16 +24,25 @@ package org.x4o.xml.lang.phase; /** - * X4OPhaseType + * X4OPhaseType defines which phase type there are to put phases in to execute. * * @author Willem Cazander * @version 1.0 Apr 30, 2013 */ public enum X4OPhaseType { + /** Language init. */ INIT, + + /** Read/Write xml.(not used) */ XML_RW, + + /** XML Reading. */ XML_READ, + + /** XML Writing. */ XML_WRITE, + + /** XML Schema writing. */ XML_WRITE_SCHEMA } diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/package-info.java b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/package-info.java index ea57344..bc2c519 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/phase/package-info.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/phase/package-info.java @@ -27,4 +27,4 @@ * @since 1.0 */ -package org.x4o.xml.lang.phase; \ No newline at end of file +package org.x4o.xml.lang.phase; diff --git a/x4o-driver/src/test/java/org/x4o/xml/core/AttributeBeanTest.java b/x4o-driver/src/test/java/org/x4o/xml/core/AttributeBeanTest.java index 8fb4fee..aeb3921 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/core/AttributeBeanTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/core/AttributeBeanTest.java @@ -23,10 +23,13 @@ package org.x4o.xml.core; +import java.util.List; + import org.x4o.xml.X4ODriver; import org.x4o.xml.io.X4OReader; import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.models.TestBean; +import org.x4o.xml.test.models.TestObjectChild; import org.x4o.xml.test.models.TestObjectRoot; import junit.framework.TestCase; @@ -39,6 +42,20 @@ import junit.framework.TestCase; */ public class AttributeBeanTest extends TestCase { + public void testBeanBody() throws Exception { + X4ODriver driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + + TestObjectRoot root = reader.readResource("tests/attributes/test-body.xml"); + assertNotNull(root); + List childs = root.getTestObjectChilds(); + assertEquals(2,childs.size()); + TestObjectChild child0 = childs.get(0); + TestObjectChild child1 = childs.get(1); + assertEquals("attr-name",child0.getName()); + assertEquals("body-name",child1.getName()); + } + public void testBeanProperties() throws Exception { X4ODriver driver = TestDriver.getInstance(); X4OReader reader = driver.createReader(); diff --git a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java index 834d103..caab24b 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java @@ -25,9 +25,12 @@ package org.x4o.xml.eld.xsd; import java.io.File; +import org.x4o.xml.X4ODriver; +import org.x4o.xml.X4ODriverManager; import org.x4o.xml.eld.CelDriver; import org.x4o.xml.eld.EldDriver; import org.x4o.xml.eld.xsd.X4OWriteLanguageSchemaExecutor; +import org.x4o.xml.io.X4OSchemaWriter; import org.x4o.xml.test.swixml.SwiXmlDriver; import junit.framework.TestCase; @@ -52,6 +55,12 @@ public class X4OWriteLanguageSchemaExecutorTest extends TestCase { return result; } + public void testSchemaWriterDirect() throws Exception { + X4ODriver driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME); + X4OSchemaWriter xsd = driver.createSchemaWriter(); + xsd.writeSchema(getTempPath("junit-xsd-cel-direct")); + } + public void testEldSchema() throws Exception { X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor(); writer.setBasePath(getTempPath("junit-xsd-eld")); diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OConnectionTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OConnectionTest.java new file mode 100644 index 0000000..3d7b58b --- /dev/null +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OConnectionTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2004-2012, 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 org.x4o.xml.X4ODriver; +import org.x4o.xml.io.X4OReader; +import org.x4o.xml.lang.X4OLanguagePropertyKeys; +import org.x4o.xml.test.TestDriver; +import org.x4o.xml.test.models.TestObjectRoot; + +import junit.framework.TestCase; + +/** + * X4OConnectionTest. + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2013 + */ +public class X4OConnectionTest extends TestCase { + + public void testReaderPropertyFail() throws Exception { + Exception e = null; + try { + X4ODriver driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + reader.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test"); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("key")); + assertTrue("Wrong exception message",e.getMessage().contains("protected")); + } + + public void testWriterPropertyFail() throws Exception { + Exception e = null; + try { + X4ODriver driver = TestDriver.getInstance(); + X4OWriter writer = driver.createWriter(); + writer.setProperty(X4OLanguagePropertyKeys.READER_INPUT_ENCODING, "test"); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("key")); + assertTrue("Wrong exception message",e.getMessage().contains("protected")); + } + + public void testSchemaWriterPropertyFail() throws Exception { + Exception e = null; + try { + X4ODriver driver = TestDriver.getInstance(); + X4OSchemaWriter schemaWriter = driver.createSchemaWriter(); + schemaWriter.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test"); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("key")); + assertTrue("Wrong exception message",e.getMessage().contains("protected")); + } +} diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderContextTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderContextTest.java similarity index 92% rename from x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderContextTest.java rename to x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderContextTest.java index ceadb8e..ea20aa3 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderContextTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderContextTest.java @@ -38,12 +38,12 @@ import org.x4o.xml.test.models.TestObjectRoot; import junit.framework.TestCase; /** - * X4OAbstractReaderContextTest. + * X4OReaderContextTest. * * @author Willem Cazander * @version 1.0 Apr 15, 2013 */ -public class X4OAbstractReaderContextTest extends TestCase { +public class X4OReaderContextTest extends TestCase { private File copyResourceToTempFile() throws IOException { File tempFile = File.createTempFile("test-resource", ".xml"); @@ -132,6 +132,24 @@ public class X4OAbstractReaderContextTest extends TestCase { assertTrue("Wrong exception message",e.getMessage().contains("File")); } + public void testReadFileNotReadable() throws Exception { + if (File.separatorChar != '/') { + return; // only test on real os. + } + TestDriver driver = TestDriver.getInstance(); + X4OReaderContext reader = driver.createReaderContext(); + Exception e = null; + try { + reader.readFileContext(new File("/etc/shadow")); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",IOException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("exists")); + assertTrue("Wrong exception message",e.getMessage().contains("read")); + } + public void testReadResource() throws Exception { TestDriver driver = TestDriver.getInstance(); diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderTest.java similarity index 90% rename from x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderTest.java rename to x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderTest.java index efa0731..5e135c0 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/X4OAbstractReaderTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OReaderTest.java @@ -24,7 +24,9 @@ package org.x4o.xml.io; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import org.x4o.xml.X4ODriver; @@ -36,12 +38,12 @@ import org.x4o.xml.test.models.TestObjectRoot; import junit.framework.TestCase; /** - * X4OAbstractReaderTest. + * X4OReaderTest. * * @author Willem Cazander * @version 1.0 Apr 15, 2013 */ -public class X4OAbstractReaderTest extends TestCase { +public class X4OReaderTest extends TestCase { private File copyResourceToTempFile() throws IOException { File tempFile = File.createTempFile("test-resource", ".xml"); @@ -57,6 +59,23 @@ public class X4OAbstractReaderTest extends TestCase { return tempFile; } + public void testReadInputStream() throws Exception { + TestDriver driver = TestDriver.getInstance(); + X4OReaderContext reader = driver.createReaderContext(); + File xmlFile = copyResourceToTempFile(); + URL basePath = new File(xmlFile.getAbsolutePath()).toURI().toURL(); + InputStream inputStream = new FileInputStream(xmlFile); + TestObjectRoot root = null; + try { + root = reader.read(inputStream, xmlFile.getAbsolutePath(), basePath); + } finally { + inputStream.close(); + } + assertNotNull(root); + assertTrue(root.getTestBeans().size()>0); + TestBean bean = root.getTestBeans().get(0); + assertNotNull(bean); + } public void testReadResource() throws Exception { X4ODriver driver = TestDriver.getInstance(); diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java new file mode 100644 index 0000000..146ec1a --- /dev/null +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2004-2012, 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.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Scanner; + +import org.x4o.xml.X4ODriver; +import org.x4o.xml.element.Element; +import org.x4o.xml.io.X4OReader; +import org.x4o.xml.lang.X4OLanguageContext; +import org.x4o.xml.test.TestDriver; +import org.x4o.xml.test.models.TestObjectRoot; +import org.xml.sax.SAXException; + +import junit.framework.TestCase; + +/** + * X4OWriterContextTest. + * + * @author Willem Cazander + * @version 1.0 Apr 28, 2013 + */ +public class X4OWriterContextTest extends TestCase { + + private File createOutputFile() throws IOException { + File outputFile = File.createTempFile("test-writer-context", ".xml"); + outputFile.deleteOnExit(); + return outputFile; + } + + private X4OLanguageContext createContext() throws SAXException, X4OConnectionException, IOException { + X4ODriver driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); + X4OLanguageContext context = driver.createLanguageContext(); + Element rootElement = null; + try { + rootElement = (Element)context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance(); + } catch (InstantiationException e) { + throw new SAXException(e); + } catch (IllegalAccessException e) { + throw new SAXException(e); + } + rootElement.setElementObject(root); + context.setRootElement(rootElement); + return context; + } + + public void testWriteFile() throws Exception { + File outputFile = createOutputFile(); + X4ODriver driver = TestDriver.getInstance(); + X4OWriterContext writer = driver.createWriterContext(); + + writer.writeFileContext(createContext(), outputFile); + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" writer = driver.createWriterContext(); + Exception e = null; + File nullFile = null; + try { + writer.writeFileContext(createContext(), nullFile); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",NullPointerException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("null")); + assertTrue("Wrong exception message",e.getMessage().contains("file")); + } + + public void testWriteFileName() throws Exception { + File outputFile = createOutputFile(); + X4ODriver driver = TestDriver.getInstance(); + X4OWriterContext writer = driver.createWriterContext(); + + writer.writeFileContext(createContext(), outputFile.getAbsolutePath()); + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" writer = driver.createWriterContext(); + Exception e = null; + String nullFileName = null; + try { + writer.writeFileContext(createContext(), nullFileName); + } catch (Exception catchE) { + e = catchE; + } + assertNotNull("No exception",e); + assertEquals("Wrong exception class",NullPointerException.class, e.getClass()); + assertTrue("Wrong exception message",e.getMessage().contains("null")); + assertTrue("Wrong exception message",e.getMessage().contains("fileName")); + } + + public void testWriteStream() throws Exception { + File outputFile = createOutputFile(); + X4ODriver driver = TestDriver.getInstance(); + X4OWriterContext writer = driver.createWriterContext(); + + OutputStream outputStream = new FileOutputStream(outputFile); + try { + writer.writeContext(createContext(),outputStream); + } finally { + outputStream.close(); + } + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" driver = TestDriver.getInstance(); - X4OReader reader = driver.createReader(); - X4OWriter writer = driver.createWriter(); - - writer.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_CHAR_TAB, " "); - writer.setProperty(X4OLanguagePropertyKeys.WRITER_SCHEMA_URI_PRINT, false); - - TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); - writer.writeFile(root, outputFile); - - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); - outputFile.delete(); - System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath()); - - assertTrue(text.startsWith("")); - assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); - assertTrue(text.contains("")); - assertTrue(text.contains(" driver = SwiXmlDriver.getInstance(); X4OReader reader = driver.createReader(); - X4OWriter writer = driver.createWriter(); + X4OWriter writer = driver.createWriter(SwiXmlDriver.LANGUAGE_VERSION_3); //reader.setProperty(key, value); //writer.setProperty(key, value); @@ -102,4 +78,62 @@ public class X4OWriterTest extends TestCase { outputFile.delete(); } + + public void testWriteFile() throws Exception { + File outputFile = createOutputFile(); + X4ODriver driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + X4OWriter writer = driver.createWriter(); + + TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); + writer.writeFile(root, outputFile); + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + X4OWriter writer = driver.createWriter(); + + TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); + writer.writeFile(root, outputFile.getAbsolutePath()); + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" driver = TestDriver.getInstance(); + X4OReader reader = driver.createReader(); + X4OWriter writer = driver.createWriter(); + + TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); + OutputStream outputStream = new FileOutputStream(outputFile); + try { + writer.write(root,outputStream); + } finally { + outputStream.close(); + } + + writer.writeFile(root, outputFile.getAbsolutePath()); + String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + outputFile.delete(); + + assertTrue(text.startsWith("")); + assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); + assertTrue(text.contains("")); + assertTrue(text.contains(" - + + + + diff --git a/x4o-driver/src/test/resources/tests/attributes/test-body.xml b/x4o-driver/src/test/resources/tests/attributes/test-body.xml new file mode 100644 index 0000000..d29f92f --- /dev/null +++ b/x4o-driver/src/test/resources/tests/attributes/test-body.xml @@ -0,0 +1,32 @@ + + + + + body-name + diff --git a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java index 90762db..6009db1 100644 --- a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java +++ b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/EldDocGenerator.java @@ -24,6 +24,7 @@ package org.x4o.xml.eld.doc; import java.io.File; +import java.io.IOException; import org.x4o.xml.element.ElementAttributeHandler; import org.x4o.xml.element.ElementBindingHandler; @@ -45,10 +46,19 @@ public class EldDocGenerator { private X4OLanguageContext context = null; + /** + * Creates an EldDocGenerator for this langauge context. + * @param context The language context to generate doc for. + */ public EldDocGenerator(X4OLanguageContext context) { this.context=context; } + /** + * Writes the language documentation to the base path. + * @param basePath The path to write to documentation to. + * @throws ElementException Is thrown when error is done. + */ public void writeDoc(File basePath) throws ElementException { EldDocHtmlWriter writer = new EldDocHtmlWriter(); try { @@ -97,8 +107,8 @@ public class EldDocGenerator { } } - } catch (Exception e) { - throw new ElementException(e); // todo rm + } catch (IOException e) { + throw new ElementException(e); } } } diff --git a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java index 0a77a6c..8e84cf0 100644 --- a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java +++ b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java @@ -45,7 +45,11 @@ public class X4OWriteLanguageDocExecutor { private String languageVersion = null; private File basePath; - static public void main(String argu[]) { + /** + * Config and executes this language task. + * @param argu The command line arguments. + */ + public static void main(String[] argu) { X4OWriteLanguageDocExecutor languageSchema = new X4OWriteLanguageDocExecutor(); List arguList = Arrays.asList(argu); Iterator arguIterator = arguList.iterator(); @@ -87,6 +91,9 @@ public class X4OWriteLanguageDocExecutor { } } + /** + * Executes this language task. + */ public void execute() throws ElementException { X4ODriver driver = X4ODriverManager.getX4ODriver(getLanguageName()); X4OLanguageContext context = driver.createLanguageContext(getLanguageVersion()); diff --git a/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java b/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java index 702351c..b299d25 100644 --- a/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java +++ b/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java @@ -25,6 +25,7 @@ package org.x4o.plugin.maven; import java.io.File; +import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.testing.AbstractMojoTestCase; /** @@ -54,6 +55,16 @@ public class X4OWriteLanguageDocMojoTest extends AbstractMojoTestCase { mojo.execute(); } + public void testHelp() throws Exception { + File pom = getTestFile("src/test/resources/junit/test-plugin-defaults.pom"); + assertNotNull(pom); + assertTrue(pom.exists()); + Mojo mojo = lookupMojo("help",pom); + assertNotNull(mojo); + mojo.execute(); + + } + public void testConfAllWriteDoc() throws Exception { executeGoal(X4OWriteLanguageDocMojo.GOAL,"src/test/resources/junit/test-plugin-conf-all.pom"); File outputDir = new File("target/jtest/test-plugin-conf-all/doc-eld-1.0");