From 76ff798ea1a0cc5885edbd750d426a6d4eeafb61 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Tue, 3 Sep 2013 22:01:35 +0200 Subject: [PATCH] Added more properties to xml content writer and xsd writer. --- .gitignore | 1 - .../org/x4o/xml/eld/EldModuleLoaderCore.java | 12 +- .../org/x4o/xml/eld/xsd/EldXsdWriter.java | 44 +++--- .../x4o/xml/eld/xsd/EldXsdWriterElement.java | 85 +---------- .../sax/ext/AbstractContentWriterHandler.java | 139 +++++++++++++++++- .../xml/lang/task/run/X4OTaskCommandLine.java | 2 +- .../xml/eld/xsd/EldXsdLanguageTaskTest.java | 56 ++++++- .../x4o/xml/io/sax/ContentWriterXmlTest.java | 36 +++-- x4o-tool/x4o-tool-ant-plugin/pom.xml | 4 +- .../junit/test-write-language-doc.xml | 6 +- .../maven/plugin/X4OLanguageTaskMojoTest.java | 3 + 11 files changed, 250 insertions(+), 138 deletions(-) diff --git a/.gitignore b/.gitignore index 17d9faf..e7edcde 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,3 @@ Desktop.ini # Ignore kde dolphin files .directory - diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java b/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java index 1df1bbf..f9595d8 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java @@ -66,12 +66,16 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader { private static final String PP_CEL_XSD_FILE = "-1.0.xsd"; private static final String CEL_CORE = "cel-core"; private static final String CEL_ROOT = "cel-root"; - private static final String CEL_CORE_URI = PP_CEL_XMLNS+CEL_CORE; - private static final String CEL_ROOT_URI = PP_CEL_XMLNS+CEL_ROOT; - private static final String CEL_CORE_XSD_URI = CEL_CORE_URI+PP_CEL_XSD_FILE; - private static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+PP_CEL_XSD_FILE; private static final String CEL_CORE_XSD_FILE = CEL_CORE+PP_CEL_XSD_FILE; private static final String CEL_ROOT_XSD_FILE = CEL_ROOT+PP_CEL_XSD_FILE; + /** The cel core namespace uri. */ + public static final String CEL_CORE_URI = PP_CEL_XMLNS+CEL_CORE; + /** The cel root namespace uri. */ + public static final String CEL_ROOT_URI = PP_CEL_XMLNS+CEL_ROOT; + /** The cel core schema namespace uri. */ + public static final String CEL_CORE_XSD_URI = CEL_CORE_URI+PP_CEL_XSD_FILE; + /** The cel root schema namespace uri. */ + public static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+PP_CEL_XSD_FILE; /** * Creates the CEL module loader. diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java index b04f0b9..03f21a0 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/EldXsdWriter.java @@ -49,31 +49,23 @@ public class EldXsdWriter { private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_ELD_XSD; public final static PropertyConfig DEFAULT_PROPERTY_CONFIG; - public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path"; - public final static String OUTPUT_DOCUMENTATION = PROPERTY_CONTEXT_PREFIX+"output/documentation"; - public final static String FILTER_NAMESPACE = PROPERTY_CONTEXT_PREFIX+"filter/namespace"; - public final static String FILTER_ELEMENT = PROPERTY_CONTEXT_PREFIX+"filter/element"; - public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-file"; - public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-resource"; - public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX+"prolog/licence-encoding"; - public final static String PROLOG_PRINT_LICENCE = PROPERTY_CONTEXT_PREFIX+"prolog/print-licence"; - public final static String PROLOG_PRINT_GENERATOR = PROPERTY_CONTEXT_PREFIX+"prolog/print-generator"; - public final static String PROLOG_PRINT_PROVIDER = PROPERTY_CONTEXT_PREFIX+"prolog/print-provider"; - public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment"; + public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path"; + public final static String OUTPUT_DOCUMENTATION = PROPERTY_CONTEXT_PREFIX+"output/documentation"; + public final static String FILTER_NAMESPACE = PROPERTY_CONTEXT_PREFIX+"filter/namespace"; + public final static String FILTER_ELEMENT = PROPERTY_CONTEXT_PREFIX+"filter/element"; + public final static String PROLOG_GENERATED_BY = PROPERTY_CONTEXT_PREFIX+"prolog/generated-by"; + public final static String PROLOG_GENERATED_BY_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/generated-by-enable"; + public final static String PROLOG_PROVIDER_INFO_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/provider-info-enable"; static { DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX, - new PropertyConfigItem(true,OUTPUT_PATH,File.class), - new PropertyConfigItem(OUTPUT_DOCUMENTATION,Boolean.class,true), - new PropertyConfigItem(false,FILTER_NAMESPACE,String.class), - new PropertyConfigItem(false,FILTER_ELEMENT,String.class), - new PropertyConfigItem(false,PROLOG_LICENCE_ENCODING,String.class), - new PropertyConfigItem(false,PROLOG_LICENCE_FILE,File.class), - new PropertyConfigItem(false,PROLOG_LICENCE_RESOURCE,String.class), - new PropertyConfigItem(PROLOG_PRINT_LICENCE,Boolean.class,true), - new PropertyConfigItem(PROLOG_PRINT_GENERATOR,Boolean.class,true), - new PropertyConfigItem(PROLOG_PRINT_PROVIDER,Boolean.class,true), - new PropertyConfigItem(false,PROLOG_USER_COMMENT,String.class) + new PropertyConfigItem(true,OUTPUT_PATH, File.class ), + new PropertyConfigItem(OUTPUT_DOCUMENTATION, Boolean.class, true), + new PropertyConfigItem(FILTER_NAMESPACE, String.class ), + new PropertyConfigItem(FILTER_ELEMENT, String.class ), + new PropertyConfigItem(PROLOG_GENERATED_BY, String.class ), + new PropertyConfigItem(PROLOG_GENERATED_BY_ENABLE, Boolean.class, true), + new PropertyConfigItem(PROLOG_PROVIDER_INFO_ENABLE, Boolean.class, true) ); } @@ -143,14 +135,20 @@ public class EldXsdWriter { if (ns==null) { throw new NullPointerException("Could not find namespace: "+namespaceUri); } - + String filterElement = propertyConfig.getPropertyString(FILTER_ELEMENT); EldXsdWriterElement xsdWriterElement = new EldXsdWriterElement(xsdWriter,language,propertyConfig); xsdWriterElement.startNamespaces(namespaceUri); xsdWriterElement.startSchema(ns); for (ElementClass ec:ns.getElementClasses()) { + if (filterElement!=null && !ec.getId().equals(filterElement)) { + continue; + } xsdWriterElement.writeElementClass(ec,ns); } for (ElementClass ec:ns.getElementClasses()) { + if (filterElement!=null && !ec.getId().equals(filterElement)) { + continue; + } xsdWriterElement.writeElement(ec,ns); } xsdWriterElement.endSchema(); 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 cce5936..602285f 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 @@ -22,14 +22,7 @@ */ package org.x4o.xml.eld.xsd; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.reflect.Method; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -50,7 +43,6 @@ import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.sax.ext.ContentWriterXsd; import org.x4o.xml.io.sax.ext.ContentWriterXsd.Tag; import org.x4o.xml.io.sax.ext.PropertyConfig; -import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguage; import org.xml.sax.SAXException; @@ -155,68 +147,23 @@ public class EldXsdWriterElement { } } - private String readLicenceStream(InputStream inputStream,String encoding) throws IOException { - if (encoding==null) { - encoding = XMLConstants.XML_DEFAULT_ENCODING; - } - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding))); - try { - StringBuilder sb = new StringBuilder(); - sb.append('\n'); // like plugin - sb.append('\n'); // like plugin - String line = br.readLine(); - while (line != null) { - if (line.length()>0) { - sb.append(" "); // like plugin - } - sb.append(line); - sb.append('\n'); - line = br.readLine(); - } - sb.append('\n'); // like plugin - String out = sb.toString(); - return out; - } finally { - br.close(); - } - } - private static final String COMMENT_SEPERATOR = " ==================================================================== "; private static final String COMMENT_TEXT = "====="; - private void prologWriteLicence() throws SAXException, IOException { - if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_PRINT_LICENCE)) { - return; - } - InputStream licenceInput = null; - String licenceEncoding = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_LICENCE_ENCODING); - String licenceResource = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_LICENCE_RESOURCE); - if (licenceResource!=null) { - licenceInput = X4OLanguageClassLoader.getResourceAsStream(licenceResource); - if (licenceInput==null) { - throw new NullPointerException("Could not load licence resource from: "+licenceResource); - } - } - if (licenceInput==null) { - File licenceFile = propertyConfig.getPropertyFile(EldXsdWriter.PROLOG_LICENCE_FILE); - if (licenceFile==null) { - return; - } - licenceInput = new FileInputStream(licenceFile); - } - String licenceText = readLicenceStream(licenceInput,licenceEncoding); - xsdWriter.comment(licenceText); - } - private void prologWriteGenerator() throws SAXException { - if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_PRINT_GENERATOR)) { + if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_GENERATED_BY_ENABLE)) { return; } //xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); xsdWriter.comment(COMMENT_SEPERATOR); + String byValue = propertyConfig.getPropertyStringOrValue(EldXsdWriter.PROLOG_GENERATED_BY, EldXsdWriter.class.getSimpleName()); + if (!byValue.endsWith(".")) { + byValue += '.'; + } + // this is a mess; - String desc = "Automatic generated schema for language: "+language.getLanguageName(); + String desc = "Automatic generated schema for language: "+language.getLanguageName()+" by "+byValue; int space = COMMENT_SEPERATOR.length()-desc.length()-(2*COMMENT_TEXT.length())-4; StringBuffer b = new StringBuffer(COMMENT_SEPERATOR.length()); b.append(" "); @@ -233,7 +180,7 @@ public class EldXsdWriterElement { } private void prologWriteProvider(ElementNamespace ns) throws SAXException { - if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_PRINT_PROVIDER)) { + if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_PROVIDER_INFO_ENABLE)) { return; } X4OLanguageModule module = null; @@ -258,28 +205,12 @@ public class EldXsdWriterElement { xsdWriter.comment(b.toString()); } - private void prologWriteUserComment() throws SAXException { - String userComment = propertyConfig.getPropertyString(EldXsdWriter.PROLOG_USER_COMMENT); - if (userComment==null) { - return; - } - xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); - xsdWriter.comment(" "+userComment+" "); - xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE); - } - public void startSchema(ElementNamespace ns) throws SAXException { xsdWriter.startDocument(); - try { - prologWriteLicence(); - } catch (IOException e) { - throw new SAXException(e); - } prologWriteGenerator(); prologWriteProvider(ns); - prologWriteUserComment(); xsdWriter.startPrefixMapping("", SCHEMA_URI); for (String uri:namespaces.keySet()) { 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 3152aac..ed11c41 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 @@ -22,8 +22,15 @@ */ package org.x4o.xml.io.sax.ext; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Writer; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,6 +40,7 @@ import java.util.Stack; import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.sax.ext.PropertyConfig.PropertyConfigItem; +import org.x4o.xml.lang.X4OLanguageClassLoader; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; @@ -60,15 +68,39 @@ public class AbstractContentWriterHandler implements ContentHandler { private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_WRITER_XML; public final static PropertyConfig DEFAULT_PROPERTY_CONFIG; - public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+"output/encoding"; - public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX+"output/charTab"; - public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX+"output/newLine"; + public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+"output/encoding"; + public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX+"output/char-tab"; + public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX+"output/char-newline"; + public final static String OUTPUT_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"output/comment-enable"; + public final static String OUTPUT_COMMENT_AUTO_SPACE = PROPERTY_CONTEXT_PREFIX+"output/comment-auto-space"; + //public final static String OUTPUT_LINE_BREAK_WIDTH = PROPERTY_CONTEXT_PREFIX+"output/line-break-width"; + //public final static String OUTPUT_LINE_PER_ATTRIBUTE = PROPERTY_CONTEXT_PREFIX+"output/line-per-attribute"; + public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-file"; + public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-resource"; + public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX+"prolog/licence-encoding"; + public final static String PROLOG_LICENCE_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-enable"; + public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment"; + public final static String PROLOG_USER_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment-enable"; + public final static String ROOT_END_APPEND_NEWLINE = PROPERTY_CONTEXT_PREFIX+"root/end-append-newline"; + public final static String ROOT_START_NAMESPACE_ALL = PROPERTY_CONTEXT_PREFIX+"root/start-namespace-all"; static { DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX, - new PropertyConfigItem(OUTPUT_ENCODING,String.class,XMLConstants.XML_DEFAULT_ENCODING), - new PropertyConfigItem(OUTPUT_CHAR_TAB,String.class,XMLConstants.CHAR_TAB+""), - new PropertyConfigItem(OUTPUT_CHAR_NEWLINE,String.class,XMLConstants.CHAR_NEWLINE+"") + new PropertyConfigItem(OUTPUT_ENCODING, String.class, XMLConstants.XML_DEFAULT_ENCODING), + new PropertyConfigItem(OUTPUT_CHAR_TAB, String.class, XMLConstants.CHAR_TAB+""), + new PropertyConfigItem(OUTPUT_CHAR_NEWLINE, String.class, XMLConstants.CHAR_NEWLINE+""), + new PropertyConfigItem(OUTPUT_COMMENT_ENABLE, Boolean.class, true), + new PropertyConfigItem(OUTPUT_COMMENT_AUTO_SPACE, Boolean.class, true), +// TODO new PropertyConfigItem(OUTPUT_LINE_BREAK_WIDTH, Integer.class, -1), +// TODO new PropertyConfigItem(OUTPUT_LINE_PER_ATTRIBUTE, Boolean.class, false), + new PropertyConfigItem(PROLOG_LICENCE_ENCODING, String.class, XMLConstants.XML_DEFAULT_ENCODING), + new PropertyConfigItem(PROLOG_LICENCE_FILE, File.class ), + new PropertyConfigItem(PROLOG_LICENCE_RESOURCE, String.class ), + new PropertyConfigItem(PROLOG_LICENCE_ENABLE, Boolean.class, true), + new PropertyConfigItem(PROLOG_USER_COMMENT, String.class ), + new PropertyConfigItem(PROLOG_USER_COMMENT_ENABLE, Boolean.class, true), + new PropertyConfigItem(ROOT_END_APPEND_NEWLINE, Boolean.class, true), + new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true) ); } @@ -113,6 +145,80 @@ public class AbstractContentWriterHandler implements ContentHandler { public void startDocument() throws SAXException { indent = 0; write(XMLConstants.getDocumentDeclaration(getPropertyConfig().getPropertyString(OUTPUT_ENCODING))); + prologWriteLicence(); + prologWriteUserComment(); + } + + private void prologWriteLicence() throws SAXException { + if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) { + return; + } + InputStream licenceInput = null; + String licenceEncoding = propertyConfig.getPropertyString(PROLOG_LICENCE_ENCODING); + String licenceResource = propertyConfig.getPropertyString(PROLOG_LICENCE_RESOURCE); + if (licenceResource!=null) { + licenceInput = X4OLanguageClassLoader.getResourceAsStream(licenceResource); + if (licenceInput==null) { + throw new NullPointerException("Could not load licence resource from: "+licenceResource); + } + } + if (licenceInput==null) { + File licenceFile = propertyConfig.getPropertyFile(PROLOG_LICENCE_FILE); + if (licenceFile==null) { + return; + } + try { + licenceInput = new FileInputStream(licenceFile); + } catch (FileNotFoundException e) { + throw new SAXException(e); + } + } + String licenceText; + try { + licenceText = readLicenceStream(licenceInput,licenceEncoding); + } catch (IOException e) { + throw new SAXException(e); + } + comment(licenceText); + } + + private String readLicenceStream(InputStream inputStream,String encoding) throws IOException { + if (encoding==null) { + encoding = XMLConstants.XML_DEFAULT_ENCODING; + } + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding))); + try { + StringBuilder sb = new StringBuilder(); + sb.append('\n'); // like plugin + sb.append('\n'); // like plugin + String line = br.readLine(); + while (line != null) { + if (line.length()>0) { + sb.append(" "); // like plugin + } + sb.append(line); + sb.append('\n'); + line = br.readLine(); + } + sb.append('\n'); // like plugin + String out = sb.toString(); + return out; + } finally { + br.close(); + } + } + + private void prologWriteUserComment() throws SAXException { + if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) { + return; + } + String userComment = propertyConfig.getPropertyString(PROLOG_USER_COMMENT); + if (userComment==null) { + return; + } + ignorableWhitespace(XMLConstants.CHAR_NEWLINE); + comment(" "+userComment+" "); + ignorableWhitespace(XMLConstants.CHAR_NEWLINE); } /** @@ -195,6 +301,9 @@ public class AbstractContentWriterHandler implements ContentHandler { } public void startElementNamespaceAll(String uri) throws SAXException { + if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) { + return; + } String prefix = null; boolean first = true; for (String uri2:prefixMapping.keySet()) { @@ -303,8 +412,11 @@ public class AbstractContentWriterHandler implements ContentHandler { write(localName); } write(XMLConstants.TAG_CLOSE); + if (elements.isEmpty() && propertyConfig.getPropertyBoolean(ROOT_END_APPEND_NEWLINE)) { + ignorableWhitespace(XMLConstants.CHAR_NEWLINE); + } } - + /** * Starts the prefix mapping of an xml namespace uri. * @param prefix The xml prefix of this xml namespace uri. @@ -483,6 +595,19 @@ public class AbstractContentWriterHandler implements ContentHandler { if (text==null) { return; } + if (!propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_ENABLE)) { + return; + } + if (propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_AUTO_SPACE)) { + char textStart = text.charAt(0); + char textEnd = text.charAt(text.length()-1); + if (textStart!=' ' && textStart!='\t' && textStart!='\n') { + text = " "+text; + } + if (textEnd!=' ' && textEnd!='\t' && textEnd!='\n') { + text = text + " "; + } + } autoCloseStartElement(); checkPrintedReturn(text); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE)); diff --git a/x4o-driver/src/main/java/org/x4o/xml/lang/task/run/X4OTaskCommandLine.java b/x4o-driver/src/main/java/org/x4o/xml/lang/task/run/X4OTaskCommandLine.java index 4059d28..63bd69e 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/lang/task/run/X4OTaskCommandLine.java +++ b/x4o-driver/src/main/java/org/x4o/xml/lang/task/run/X4OTaskCommandLine.java @@ -186,7 +186,7 @@ public class X4OTaskCommandLine { if (config.isPropertyRequired(key)) { def = "(required=\"true\")"; } - System.out.println(String.format("%1$-60s - %2$-8s %3$s", key,keyType.getSimpleName(),def)); + System.out.println(String.format("%1$-65s - %2$-8s %3$s", key,keyType.getSimpleName(),def)); } System.out.println(); System.exit(0); 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 d496133..5267060 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 @@ -23,12 +23,17 @@ package org.x4o.xml.eld.xsd; import java.io.File; +import java.util.HashMap; +import java.util.Map; 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.EldModuleLoaderCore; import org.x4o.xml.eld.xsd.EldXsdLanguageTask; +import org.x4o.xml.io.X4OWriterTest; +import org.x4o.xml.io.sax.ext.ContentWriterXml; import org.x4o.xml.io.sax.ext.PropertyConfig; import org.x4o.xml.lang.task.X4OLanguageTask; import org.x4o.xml.test.swixml.SwiXmlDriver; @@ -51,30 +56,67 @@ public class EldXsdLanguageTaskTest extends TestCase { return result; } - private void testSchema(String language,String outputPostfix) throws Exception { + private File testSchema(String language,String outputPostfix,Map props) throws Exception { X4ODriver driver = X4ODriverManager.getX4ODriver(language); X4OLanguageTask task = driver.getLanguageTask(EldXsdLanguageTask.TASK_ID); PropertyConfig config = task.createTaskConfig(); File outputPath = createOutputPath(outputPostfix); config.setProperty(EldXsdWriter.OUTPUT_PATH,outputPath); config.setProperty(EldXsdWriter.OUTPUT_DOCUMENTATION,false); - config.setProperty(EldXsdWriter.PROLOG_LICENCE_FILE,new File("../license.txt")); // TODO: s or c ? - config.setProperty(EldXsdWriter.PROLOG_USER_COMMENT,"Generated by junit-test-run in class: "+this.getClass().getSimpleName()); + config.setProperty(ContentWriterXml.PROLOG_LICENCE_FILE,new File("../license.txt")); // TODO: s or c ? + config.setProperty(ContentWriterXml.PROLOG_USER_COMMENT,"Generated by junit-test-run in class: "+this.getClass().getSimpleName()); + if (props!=null) { + for (String key:props.keySet()) { + Object value = props.get(key); + config.setProperty(key, value); + } + } task.createTaskExecutor(config).execute(driver.createLanguage()); assertTrue(outputPath.exists()); assertTrue(outputPath.list()!=null); - assertTrue(outputPath.list().length>1); + return outputPath; } public void testEldSchema() throws Exception { - testSchema(EldDriver.LANGUAGE_NAME,"junit-xsd-eld"); + File outputPath = testSchema(EldDriver.LANGUAGE_NAME,"junit-xsd-eld",null); + assertTrue(outputPath.list().length>2); } public void testEldCoreSchema() throws Exception { - testSchema(CelDriver.LANGUAGE_NAME,"junit-xsd-cel"); + File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-xsd-cel",null); + assertTrue(outputPath.list().length>1); } public void testSwiXmlSchema() throws Exception { - testSchema(SwiXmlDriver.LANGUAGE_NAME,"junit-xsd-swixml"); + File outputPath = testSchema(SwiXmlDriver.LANGUAGE_NAME,"junit-xsd-swixml",null); + assertTrue(outputPath.list().length>1); + } + + public void testFilterNamespace() throws Exception { + Map props = new HashMap(); + props.put(EldXsdWriter.FILTER_NAMESPACE, EldModuleLoaderCore.CEL_ROOT_URI); + File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-one-ns",props); + assertTrue(outputPath.list().length==1); + } + + public void testFilterElement() throws Exception { + Map props = new HashMap(); + props.put(EldXsdWriter.FILTER_NAMESPACE, EldModuleLoaderCore.CEL_CORE_URI); + props.put(EldXsdWriter.FILTER_ELEMENT, "elementInterface"); + props.put(EldXsdWriter.PROLOG_GENERATED_BY_ENABLE, false); + props.put(EldXsdWriter.PROLOG_PROVIDER_INFO_ENABLE, false); + props.put(ContentWriterXml.PROLOG_LICENCE_ENABLE,false); + File outputPath = testSchema(CelDriver.LANGUAGE_NAME,"junit-one-element",props); + assertTrue(outputPath.list().length==1); + + String text = X4OWriterTest.readFile(new File("target/tests/junit-one-element/cel-core-1.0.xsd")); + assertNotNull(text); + assertTrue(text.contains("elementInterface")); + assertFalse(text.contains("module")); + assertFalse(text.contains("attributeAlias")); + assertFalse(text.contains("bindingHandler")); + assertFalse(text.contains("classConverter")); + + assertTrue(text.length()<10000); } } diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java index 5c0b50b..d0f4a7f 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/sax/ContentWriterXmlTest.java @@ -50,7 +50,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("foobar")); + assertTrue(output,output.equals("foobar")); } public void testCDATANoneTagEscape() throws Exception { @@ -64,7 +64,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("foobar<test/>")); + assertTrue(output,output.equals("foobar<test/>")); } public void testCDATANormal() throws Exception { @@ -80,7 +80,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("")); + assertTrue(output,output.equals("")); } public void testCDATAEscapeTag() throws Exception { @@ -96,7 +96,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("]]>")); + assertTrue(output,output.equals("]]>")); } public void testCDATAEscapeStart() throws Exception { @@ -112,7 +112,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("")); + assertTrue(output,output.equals("")); } public void testCDATAEscapeEnd() throws Exception { @@ -128,7 +128,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("")); + assertTrue(output,output.equals("")); } public void testCDATAEscapeInvalid() throws Exception { @@ -144,7 +144,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("]]>")); + assertTrue(output,output.equals("]]>")); } public void testCDATAEscapeValid() throws Exception { @@ -174,7 +174,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("test is foobar!")); + assertTrue(output,output.equals("test is foobar!")); } public void testCharactersEscape() throws Exception { @@ -188,7 +188,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("<test/> & 'foobar' is "e;quoted"e;!")); + assertTrue(output,output.equals("<test/> & 'foobar' is "e;quoted"e;!")); } public void testAttributeNormal() throws Exception { @@ -204,7 +204,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n")); + assertTrue(output,output.equals("\n")); } public void testAttributeEscape() throws Exception { @@ -220,7 +220,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n")); + assertTrue(output,output.equals("\n")); } @@ -235,7 +235,7 @@ public class ContentWriterXmlTest extends TestCase { String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n")); + assertTrue(output,output.equals("\n")); } public void testCommentEscape() throws Exception { @@ -246,10 +246,16 @@ public class ContentWriterXmlTest extends TestCase { writer.comment(""); writer.endDocument(); + // note two space because auto-space is before escaping and places spaces over comment tags. + // 1) "" - argu + // 2) " " - auto-space (default enabled) + // 3) " foobar " - escapes + // 4) "" - printed + String output = outputWriter.toString(); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n")); + assertTrue(output,output.equals("\n")); } public void testXmlInvalid() throws Exception { @@ -313,7 +319,7 @@ public class ContentWriterXmlTest extends TestCase { assertNull(e); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n\n")); + assertTrue(output,output.equals("\n\n")); } public void testProcessingInstructionInline() throws Exception { @@ -336,7 +342,7 @@ public class ContentWriterXmlTest extends TestCase { assertNull(e); assertNotNull(output); assertTrue(output.length()>0); - assertTrue(output.equals("\n\n\n\t\n")); + assertTrue(output,output.equals("\n\n\n\t\n\n")); } public void testProcessingInstructionTargetXmlPrefix() throws Exception { diff --git a/x4o-tool/x4o-tool-ant-plugin/pom.xml b/x4o-tool/x4o-tool-ant-plugin/pom.xml index 220c87a..80f4a51 100644 --- a/x4o-tool/x4o-tool-ant-plugin/pom.xml +++ b/x4o-tool/x4o-tool-ant-plugin/pom.xml @@ -89,7 +89,7 @@ - + @@ -128,7 +128,7 @@ - + diff --git a/x4o-tool/x4o-tool-ant-plugin/src/test/resources/junit/test-write-language-doc.xml b/x4o-tool/x4o-tool-ant-plugin/src/test/resources/junit/test-write-language-doc.xml index b153eb8..8baf365 100644 --- a/x4o-tool/x4o-tool-ant-plugin/src/test/resources/junit/test-write-language-doc.xml +++ b/x4o-tool/x4o-tool-ant-plugin/src/test/resources/junit/test-write-language-doc.xml @@ -71,9 +71,13 @@ value="${test.dir}/eld-custom" /> + 2);