Added more config keys and refined xsd writer output.

This commit is contained in:
Willem Cazander 2013-08-31 11:35:25 +02:00
parent 6cd968eb17
commit e434c1dfe7
8 changed files with 249 additions and 105 deletions

View file

@ -50,12 +50,30 @@ public class EldXsdWriter {
public final static PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+"output/path";
public final static String NAMESPACE = PROPERTY_CONTEXT_PREFIX+"filter/namespace";
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";
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(true,OUTPUT_PATH,File.class),
new PropertyConfigItem(false,NAMESPACE,String.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)
);
}
@ -80,7 +98,7 @@ public class EldXsdWriter {
public void writeSchema() throws SAXException, IOException {
File basePath = propertyConfig.getPropertyFile(OUTPUT_PATH);
String encoding = propertyConfig.getPropertyString(ContentWriterXml.OUTPUT_ENCODING);
String namespace = propertyConfig.getPropertyString(NAMESPACE);
String namespace = propertyConfig.getPropertyString(FILTER_NAMESPACE);
if (basePath==null) {
throw new NullPointerException("Can't write schema to null output path.");
}
@ -96,9 +114,9 @@ public class EldXsdWriter {
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try {
ContentWriterXsd out = new ContentWriterXsd(wr,encoding);
out.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), out);
ContentWriterXsd xsdWriter = new ContentWriterXsd(wr,encoding);
xsdWriter.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), xsdWriter);
} finally {
wr.close();
}
@ -110,9 +128,9 @@ public class EldXsdWriter {
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try {
ContentWriterXsd out = new ContentWriterXsd(wr,encoding);
out.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), out);
ContentWriterXsd xsdWriter = new ContentWriterXsd(wr,encoding);
xsdWriter.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), xsdWriter);
} finally {
wr.close();
}
@ -120,21 +138,21 @@ public class EldXsdWriter {
}
}
private void generateSchema(String namespaceUri,ContentWriterXsd xmlWriter) throws SAXException {
private void generateSchema(String namespaceUri,ContentWriterXsd xsdWriter) throws SAXException {
ElementNamespace ns = language.findElementNamespace(namespaceUri);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespaceUri);
}
EldXsdWriterElement xsdWriter = new EldXsdWriterElement(xmlWriter,language);
xsdWriter.startNamespaces(namespaceUri);
xsdWriter.startSchema(ns);
EldXsdWriterElement xsdWriterElement = new EldXsdWriterElement(xsdWriter,language,propertyConfig);
xsdWriterElement.startNamespaces(namespaceUri);
xsdWriterElement.startSchema(ns);
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElementClass(ec,ns);
xsdWriterElement.writeElementClass(ec,ns);
}
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElement(ec,ns);
xsdWriterElement.writeElement(ec,ns);
}
xsdWriter.endSchema();
xsdWriterElement.endSchema();
}
}

View file

@ -22,7 +22,14 @@
*/
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;
@ -38,8 +45,12 @@ import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementNamespace;
import org.x4o.xml.element.ElementNamespaceAttribute;
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;
@ -58,14 +69,16 @@ public class EldXsdWriterElement {
static public final String SCHEMA_URI = XMLConstants.XML_SCHEMA_NS_URI;
private PropertyConfig propertyConfig;
protected X4OLanguage language = null;
protected ContentWriterXsd xmlWriter = null;
protected ContentWriterXsd xsdWriter = null;
protected String writeNamespace = null;
protected Map<String, String> namespaces = null;
public EldXsdWriterElement(ContentWriterXsd xmlWriter,X4OLanguage language) {
this.xmlWriter=xmlWriter;
public EldXsdWriterElement(ContentWriterXsd xsdWriter,X4OLanguage language,PropertyConfig propertyConfig) {
this.xsdWriter=xsdWriter;
this.language=language;
this.propertyConfig=propertyConfig;
this.namespaces=new HashMap<String,String>(10);
}
@ -141,18 +154,67 @@ 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 = "=====";
public void startSchema(ElementNamespace ns) throws SAXException {
xmlWriter.startDocument();
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xmlWriter.comment(COMMENT_SEPERATOR);
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
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)) {
return;
}
//xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xsdWriter.comment(COMMENT_SEPERATOR);
// this is a mess;
String desc = "Automatic generated schema for language: "+language.getLanguageName();
int space = COMMENT_SEPERATOR.length()-desc.length()-(2*COMMENT_TEXT.length())-4;
@ -166,11 +228,14 @@ public class EldXsdWriterElement {
}
b.append(COMMENT_TEXT);
b.append(" ");
xmlWriter.comment(b.toString());
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xmlWriter.comment(COMMENT_SEPERATOR);
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xsdWriter.comment(b.toString());
xsdWriter.comment(COMMENT_SEPERATOR);
}
private void prologWriteProvider(ElementNamespace ns) throws SAXException {
if (!propertyConfig.getPropertyBoolean(EldXsdWriter.PROLOG_PRINT_PROVIDER)) {
return;
}
X4OLanguageModule module = null;
for (X4OLanguageModule elm:language.getLanguageModules()) {
ElementNamespace s = elm.getElementNamespace(ns.getUri());
@ -179,24 +244,47 @@ public class EldXsdWriterElement {
break;
}
}
b = new StringBuffer(COMMENT_SEPERATOR.length());
b.append("\n\tID:\t\t"); b.append(module.getId());
b.append("\n\tProviderName:\t"); b.append(module.getProviderName());
b.append("\n\tProviderHost:\t"); b.append(module.getProviderHost());
b.append("\n\tNamespaces:\t\t"); b.append(module.getElementNamespaces().size());
b.append("\n\tUri:\t\t\t"); b.append(ns.getUri());
b.append("\n\tUri schema:\t"); b.append(ns.getSchemaUri());
b.append("\n\tCreated on:\t\t"); b.append(new Date());
StringBuffer b = new StringBuffer(COMMENT_SEPERATOR.length());
String formatLine = "\n\t%1$-20s %2$s";
b.append(String.format(formatLine,"Id:",module.getId()));
b.append(String.format(formatLine,"ProviderName:",module.getProviderName()));
b.append(String.format(formatLine,"ProviderHost:",module.getProviderHost()));
b.append(String.format(formatLine,"Namespaces:",module.getElementNamespaces().size()));
b.append(String.format(formatLine,"Uri:",ns.getUri()));
b.append(String.format(formatLine,"Uri schema",ns.getSchemaUri()));
b.append(String.format(formatLine,"Created on:",new Date()));
b.append("\n");
xmlWriter.comment(b.toString());
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 {
xmlWriter.startPrefixMapping("", SCHEMA_URI);
xsdWriter.startDocument();
try {
prologWriteLicence();
} catch (IOException e) {
throw new SAXException(e);
}
prologWriteGenerator();
prologWriteProvider(ns);
prologWriteUserComment();
xsdWriter.startPrefixMapping("", SCHEMA_URI);
for (String uri:namespaces.keySet()) {
String prefix = namespaces.get(uri);
xmlWriter.startPrefixMapping(prefix, uri);
xsdWriter.startPrefixMapping(prefix, uri);
}
AttributesImpl atts = new AttributesImpl();
@ -204,25 +292,32 @@ public class EldXsdWriterElement {
atts.addAttribute ("", "elementFormDefault", "", "", "qualified");
atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified");
atts.addAttribute ("", "targetNamespace", "", "", ns.getUri());
xmlWriter.startElement (SCHEMA_URI, "schema", "", atts);
xsdWriter.startElement (SCHEMA_URI, "schema", "", atts);
for (String uri:namespaces.keySet()) {
if (ns.getUri().equals(uri)) {
continue;
}
ElementNamespace nsContext = language.findElementNamespace(uri);
atts = new AttributesImpl();
atts.addAttribute ("", "namespace", "", "", nsContext.getUri());
atts.addAttribute ("", "schemaLocation", "", "", nsContext.getSchemaResource());
xmlWriter.startElement (SCHEMA_URI, "import", "", atts);
xmlWriter.endElement (SCHEMA_URI, "import", "");
xsdWriter.printXsdImport(nsContext.getUri(), nsContext.getSchemaResource());
}
writeNamespaceAttributes(ns);
}
public void endSchema() throws SAXException {
xmlWriter.endElement (SCHEMA_URI, "schema" , "");
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xmlWriter.endDocument();
xsdWriter.endElement (SCHEMA_URI, "schema" , "");
xsdWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
xsdWriter.endDocument();
}
private void writeNamespaceAttributes(ElementNamespace ns) throws SAXException {
for (ElementNamespaceAttribute eah:ns.getElementNamespaceAttributes()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
atts.addAttribute ("", "type", "", "", "string");
writeElementAttribute(eah,atts);
}
}
public void writeElementClass(ElementClass ec,ElementNamespace nsWrite) throws SAXException {
@ -230,13 +325,13 @@ public class EldXsdWriterElement {
AttributesImpl atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "name", "", "", ec.getId());
xmlWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
xsdWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
xsdWriter.startElement (SCHEMA_URI, "complexType", "", atts);
} else {
atts.addAttribute ("", "name", "", "", ec.getId()+"Type");
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
xsdWriter.startElement (SCHEMA_URI, "complexType", "", atts);
}
if (ec.getSchemaContentBase()!=null) {
@ -245,27 +340,27 @@ public class EldXsdWriterElement {
if (ec.getSchemaContentMixed()!=null && ec.getSchemaContentMixed()) {
atts.addAttribute ("", "mixed", "", "", "true");
}
xmlWriter.startElement (SCHEMA_URI, "complexContent", "", atts);
xsdWriter.startElement (SCHEMA_URI, "complexContent", "", atts);
} else {
xmlWriter.startElement (SCHEMA_URI, "simpleContent", "", atts);
xsdWriter.startElement (SCHEMA_URI, "simpleContent", "", atts);
}
atts = new AttributesImpl();
atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase());
xmlWriter.startElement (SCHEMA_URI, "extension", "", atts);
xsdWriter.startElement (SCHEMA_URI, "extension", "", atts);
}
if (ec.getSchemaContentBase()==null) {
atts = new AttributesImpl();
atts.addAttribute ("", "minOccurs", "", "", "0"); // TODO: make unordered elements
atts.addAttribute ("", "maxOccurs", "", "", "unbounded");
xmlWriter.startElement (SCHEMA_URI, "choice", "", atts);
xsdWriter.startElement (SCHEMA_URI, "choice", "", atts);
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespace ns:mod.getElementNamespaces()) {
writeElementClassNamespaces(ec,nsWrite,ns);
}
}
xmlWriter.endElement(SCHEMA_URI, "choice", "");
xsdWriter.endElement(SCHEMA_URI, "choice", "");
}
List<String> attrNames = new ArrayList<String>(30);
@ -287,21 +382,10 @@ public class EldXsdWriterElement {
writeElementAttribute(null,atts);
}
}
/* TODO: fix xsd namespace attribute printing !!!
for (X4OLanguageModule mod:language.getLanguageModules()) {
for (ElementNamespaceAttribute eah:ns.getElementNamespaceAttributes()) {
attrNames.add(eah.getAttributeName());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
atts.addAttribute ("", "type", "", "", "string");
writeElementAttribute(eah,atts);
}
}
*/
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
// oke, reverse this if and rm whitespace.
xmlWriter.ignorableWhitespace(' ');
xsdWriter.ignorableWhitespace(' ');
} else {
@ -319,6 +403,7 @@ public class EldXsdWriterElement {
if (attrNames.contains(n)) {
continue;
}
attrNames.add(n);
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", n);
@ -338,27 +423,27 @@ public class EldXsdWriterElement {
} else {
atts.addAttribute ("", "type", "", "", "string");
}
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
xsdWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xsdWriter.endElement(SCHEMA_URI, "attribute", "");
}
}
} else {
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "anyAttribute", "");
xsdWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts);
xsdWriter.endElement(SCHEMA_URI, "anyAttribute", "");
}
}
if (ec.getSchemaContentBase()!=null) {
xmlWriter.endElement(SCHEMA_URI, "extension", "");
xsdWriter.endElement(SCHEMA_URI, "extension", "");
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
xmlWriter.endElement(SCHEMA_URI, "complexContent", "");
xsdWriter.endElement(SCHEMA_URI, "complexContent", "");
} else {
xmlWriter.endElement(SCHEMA_URI, "simpleContent", "");
xsdWriter.endElement(SCHEMA_URI, "simpleContent", "");
}
}
xmlWriter.endElement(SCHEMA_URI, "complexType", "");
xsdWriter.endElement(SCHEMA_URI, "complexType", "");
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
xmlWriter.endElement(SCHEMA_URI, "element", "");
xsdWriter.endElement(SCHEMA_URI, "element", "");
}
}
@ -410,8 +495,8 @@ public class EldXsdWriterElement {
atts.addAttribute ("", "name", "", "", refElement);
atts.addAttribute ("", "type", "", "", prefix+":"+refElement+"Type");
}
xmlWriter.startElement (SCHEMA_URI, "element", "", atts);
xmlWriter.endElement (SCHEMA_URI, "element", "");
xsdWriter.startElement (SCHEMA_URI, "element", "", atts);
xsdWriter.endElement (SCHEMA_URI, "element", "");
}
}
}
@ -424,15 +509,15 @@ public class EldXsdWriterElement {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ec.getId());
atts.addAttribute ("", "type", "", "", "this:"+ec.getId()+"Type");
xmlWriter.startElement(SCHEMA_URI, "element", "", atts);
xsdWriter.startElement(SCHEMA_URI, "element", "", atts);
writeElementMetaBase(ec);
xmlWriter.endElement(SCHEMA_URI, "element", "");
xsdWriter.endElement(SCHEMA_URI, "element", "");
}
private void writeElementAttribute(ElementMetaBase base,AttributesImpl atts) throws SAXException {
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xsdWriter.printTagStart(Tag.attribute,atts);
writeElementMetaBase(base);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
xsdWriter.printTagEnd(Tag.attribute);
}
private void writeElementMetaBase(ElementMetaBase base) throws SAXException {
@ -442,13 +527,9 @@ public class EldXsdWriterElement {
if (base.getDescription()==null) {
return;
}
AttributesImpl atts = new AttributesImpl();
xmlWriter.startElement(SCHEMA_URI, "annotation", "", atts);
atts = new AttributesImpl();
atts.addAttribute ("", "xml:lang", "", "", "en");
xmlWriter.startElement(SCHEMA_URI, "documentation", "", atts);
xmlWriter.characters(base.getDescription());
xmlWriter.endElement(SCHEMA_URI, "documentation", "");
xmlWriter.endElement(SCHEMA_URI, "annotation", "");
if (!propertyConfig.getPropertyBoolean(EldXsdWriter.OUTPUT_DOCUMENTATION)) {
return;
}
xsdWriter.printXsdDocumentation(base.getDescription());
}
}

View file

@ -488,9 +488,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
writeIndent();
write(XMLConstants.COMMENT_START);
write(" ");
write(XMLConstants.escapeCharactersComment(text,getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB),indent));
write(" ");
write(XMLConstants.COMMENT_END);
printReturn = true;
}

View file

@ -43,7 +43,8 @@ public final class PropertyConfig implements Cloneable {
private final String keyPrefix;
// TODO: move to ?
public final static String X4O_PROPERTIES_PREFIX = "http://language.x4o.org/xml/properties/";
// public final static String X4O_PROPERTIES_PREFIX = "http://language.x4o.org/xml/properties/";
public final static String X4O_PROPERTIES_PREFIX = "http://x4o.org/properties/";
public final static String X4O_PROPERTIES_READER = "reader/x4o/";
//public final static String X4O_PROPERTIES_READER_DTD = "reader/dtd/";
public final static String X4O_PROPERTIES_WRITER = "writer/x4o/";
@ -206,6 +207,10 @@ public final class PropertyConfig implements Cloneable {
return keyPrefix;
}
public final boolean isPropertyRequired(String key) {
return getPropertyKeysRequired().contains(key);
}
public final Collection<String> getPropertyKeysRequired() {
return findPropertyKeysRequired(false);
}
@ -244,6 +249,11 @@ public final class PropertyConfig implements Cloneable {
item.setValue(value);
}
public final Object getPropertyDefault(String key) {
PropertyConfigItem item = getPropertyConfigItem(key);
return item.getValueDefault();
}
public final Object getProperty(String key) {
PropertyConfigItem item = getPropertyConfigItem(key);
Object value = item.getValue();

View file

@ -178,7 +178,15 @@ public class X4OTaskCommandLine {
PropertyConfig config = task.createTaskConfig();
for (String key:config.getPropertyKeys()) {
Class<?> keyType = config.getPropertyType(key);
System.out.println(key+"\t\t- "+keyType.getSimpleName());
Object valueDefault = config.getPropertyDefault(key);
String def = "";
if (valueDefault!=null) {
def = "(default=\""+unescapeDefault(valueDefault.toString())+"\")";
}
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();
System.exit(0);
@ -187,6 +195,23 @@ public class X4OTaskCommandLine {
}
}
private String unescapeDefault(String defaultValue) {
StringBuffer buf = new StringBuffer(defaultValue.length()+10);
for (char c:defaultValue.toCharArray()) {
if (c=='\n') {
buf.append("\\n");continue;
}
if (c=='\t') {
buf.append("\\t");continue;
}
if (c=='\r') {
buf.append("\\r");continue;
}
buf.append(c);
}
return buf.toString();
}
private void findDriver(Iterator<String> arguIterator) {
while (arguIterator.hasNext()) {
String arg = arguIterator.next();

View file

@ -57,6 +57,9 @@ public class EldXsdLanguageTaskTest extends TestCase {
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());
task.createTaskExecutor(config).execute(driver.createLanguage());
assertTrue(outputPath.exists());
assertTrue(outputPath.list()!=null);

View file

@ -88,6 +88,7 @@
<element objectClass="javax.swing.JFrame"/>
</namespace>
<namespace id="lang">
<namespaceAttribute attributeName="fxid" bean.class="org.x4o.xml.test.element.TestElementNamespaceAttribute" id="fxid-test"></namespaceAttribute>
<element objectClass="javax.swing.JMenuBar"/>
<element objectClass="javax.swing.JMenu"/>
<element objectClass="javax.swing.JMenuItem">

View file

@ -93,6 +93,10 @@ public class EldDocWriter {
public final static String META_STYLESHEET_THEMA = PROPERTY_CONTEXT_PREFIX+"meta/stylesheet-thema";
public final static String JAVADOC_LINK = PROPERTY_CONTEXT_PREFIX+"javadoc/link";
public final static String JAVADOC_LINK_OFFLINE = PROPERTY_CONTEXT_PREFIX+"javadoc/link-offline";
public final static String PAGE_PRINT_TREE = PROPERTY_CONTEXT_PREFIX+"page/print-tree";
public final static String PAGE_PRINT_XTREE = PROPERTY_CONTEXT_PREFIX+"page/print-xtree";
public final static String PAGE_PRINT_INDEX_ALL = PROPERTY_CONTEXT_PREFIX+"page/print-index-all";
public final static String PAGE_PRINT_HELP = PROPERTY_CONTEXT_PREFIX+"page/print-help";
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
@ -106,7 +110,11 @@ public class EldDocWriter {
new PropertyConfigItem(false,META_STYLESHEET,File.class),
new PropertyConfigItem(false,META_STYLESHEET_THEMA,String.class),
new PropertyConfigItem(false,JAVADOC_LINK,List.class),
new PropertyConfigItem(false,JAVADOC_LINK_OFFLINE,Map.class)
new PropertyConfigItem(false,JAVADOC_LINK_OFFLINE,Map.class),
new PropertyConfigItem(PAGE_PRINT_TREE,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_XTREE,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_INDEX_ALL,Boolean.class,true),
new PropertyConfigItem(PAGE_PRINT_HELP,Boolean.class,true)
);
}
@ -214,10 +222,10 @@ public class EldDocWriter {
adcEc.addChildConcepts(new ApiDocConcept(adcEc,CC_ATTRIBUTE,ElementClassAttribute.class));
// Non-tree pages config
doc.addDocPage(EldDocXTreePageWriter.createDocPage());
doc.addDocPage(DefaultPageWriterTree.createDocPage());
doc.addDocPage(DefaultPageWriterIndexAll.createDocPage());
doc.addDocPage(DefaultPageWriterHelp.createDocPage());
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_XTREE)) { doc.addDocPage(EldDocXTreePageWriter.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_TREE)) { doc.addDocPage(DefaultPageWriterTree.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_INDEX_ALL)) { doc.addDocPage(DefaultPageWriterIndexAll.createDocPage()); }
if (propertyConfig.getPropertyBoolean(PAGE_PRINT_HELP)) { doc.addDocPage(DefaultPageWriterHelp.createDocPage()); }
// Doc tree config
ApiDocNode rootNode = new ApiDocNode(language,"language",getLanguageNameUpperCase()+" Language","The X4O "+getLanguageNameUpperCase()+" Language");