Refactored all property keys with PropertyConfig bean.

This commit is contained in:
Willem Cazander 2013-08-24 01:30:48 +02:00
parent 024865084a
commit b922b0fd81
74 changed files with 1252 additions and 1699 deletions

View file

@ -32,7 +32,6 @@ import org.x4o.xml.io.X4OWriter;
import org.x4o.xml.io.X4OWriterContext; import org.x4o.xml.io.X4OWriterContext;
import org.x4o.xml.lang.X4OLanguageConfiguration; import org.x4o.xml.lang.X4OLanguageConfiguration;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.phase.X4OPhaseManager; import org.x4o.xml.lang.phase.X4OPhaseManager;
@ -97,7 +96,7 @@ public abstract class X4ODriver<T> {
* @return The schema writer for this language. * @return The schema writer for this language.
*/ */
public X4OSchemaWriter createSchemaWriter(String version) { public X4OSchemaWriter createSchemaWriter(String version) {
return new DefaultX4OSchemaWriter(createLanguageContext(version)); return new DefaultX4OSchemaWriter(createLanguage(version));
} }
@ -117,7 +116,7 @@ public abstract class X4ODriver<T> {
} }
public X4OReaderContext<T> createReaderContext(String version) { public X4OReaderContext<T> createReaderContext(String version) {
return new DefaultX4OReader<T>(createLanguageContext(version)); return new DefaultX4OReader<T>(createLanguage(version));
} }
@ -137,7 +136,7 @@ public abstract class X4ODriver<T> {
} }
public X4OWriterContext<T> createWriterContext(String version) { public X4OWriterContext<T> createWriterContext(String version) {
return new DefaultX4OWriter<T>(createLanguageContext(version)); return new DefaultX4OWriter<T>(createLanguage(version));
} }
@ -162,19 +161,27 @@ public abstract class X4ODriver<T> {
} }
/** /**
* Creates the X4OLanguage for the default version.
* @return The created X4OLanguage.
*/
final public X4OLanguage createLanguage() {
return buildLanguage(getLanguageVersionDefault());
}
/*
* Creates the X4OLanguageContext for the default language version. * Creates the X4OLanguageContext for the default language version.
* @return The created X4OLanguageContext. * @return The created X4OLanguageContext.
*/ *
final public X4OLanguageContext createLanguageContext() { final public X4OLanguageContext createLanguageContext() {
return createLanguageContext(getLanguageVersionDefault()); return createLanguageContext(getLanguageVersionDefault());
} }
/** *
* Creates the X4OLanguageContext for the specified version. * Creates the X4OLanguageContext for the specified version.
* @param version The language version to create the context for. * @param version The language version to create the context for.
* @return The created X4OLanguageContext. * @return The created X4OLanguageContext.
*/ *
final public X4OLanguageContext createLanguageContext(String version) { final public X4OLanguageContext createLanguageContext(String version) {
return createLanguage(version).createLanguageContext(this); return createLanguage(version).createLanguageContext();
} }*/
} }

View file

@ -26,8 +26,6 @@ import javax.el.ELContext;
import javax.el.ExpressionFactory; import javax.el.ExpressionFactory;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
/** /**
* X4OExpressionFactory finds and loads the needed impl. * X4OExpressionFactory finds and loads the needed impl.
@ -40,11 +38,8 @@ public class X4OExpressionFactory {
static public final String EL_FACTORY_IMPL_APACHE = "org.apache.el.ExpressionFactoryImpl"; static public final String EL_FACTORY_IMPL_APACHE = "org.apache.el.ExpressionFactoryImpl";
static public final String EL_FACTORY_IMPL_ODYSSEUS = "de.odysseus.el.ExpressionFactoryImpl"; static public final String EL_FACTORY_IMPL_ODYSSEUS = "de.odysseus.el.ExpressionFactoryImpl";
static public ExpressionFactory createExpressionFactory(X4OLanguageContext languageContext) { static public ExpressionFactory createExpressionFactory() {
ExpressionFactory result = (ExpressionFactory)languageContext.getLanguageProperty(X4OLanguageProperty.EL_FACTORY_INSTANCE); ExpressionFactory result = null;
if (result!=null) {
return result;
}
try { try {
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE); Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE);
result = (ExpressionFactory) expressionFactoryClass.newInstance(); result = (ExpressionFactory) expressionFactoryClass.newInstance();
@ -59,13 +54,10 @@ public class X4OExpressionFactory {
return result; return result;
} }
static public ELContext createELContext(X4OLanguageContext languageContext) { static public ELContext createELContext(Class<?> elContextClass) {
ELContext result = (ELContext)languageContext.getLanguageProperty(X4OLanguageProperty.EL_CONTEXT_INSTANCE); ELContext result = null;
if (result!=null) {
return result;
}
try { try {
result = (ELContext)X4OLanguageClassLoader.newInstance(languageContext.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()); result = (ELContext)X4OLanguageClassLoader.newInstance(elContextClass);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Could not create instance of ELContext: "+e.getMessage(),e); throw new RuntimeException("Could not create instance of ELContext: "+e.getMessage(),e);
} }

View file

@ -25,11 +25,13 @@ package org.x4o.xml.eld;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager; import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.X4OConnectionException; import org.x4o.xml.io.X4OConnectionException;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageModuleLoader; import org.x4o.xml.lang.X4OLanguageModuleLoader;
@ -38,7 +40,7 @@ import org.x4o.xml.lang.X4OLanguageLocal;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* De default X4OElementConfigurator. * EldModuleLoader loads the child eld language and proxies the parent language into the child so to the parent langauge is configured.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Aug 17, 2005 * @version 1.0 Aug 17, 2005
@ -49,11 +51,8 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
private String eldResource = null; private String eldResource = null;
private boolean isEldCore = false; private boolean isEldCore = false;
/** The EL key to access the parent language configuration. */
public static final String EL_PARENT_LANGUAGE_CONFIGURATION = "parentLanguageConfiguration";
/** The EL key to access the parent language module. */ /** The EL key to access the parent language module. */
public static final String EL_PARENT_ELEMENT_LANGUAGE_MODULE = "parentElementLanguageModule"; public static final String EL_PARENT_LANGUAGE_MODULE = "parentLanguageModule";
/** The EL key to access the parent language element langauge. */ /** The EL key to access the parent language element langauge. */
public static final String EL_PARENT_LANGUAGE = "parentLanguage"; public static final String EL_PARENT_LANGUAGE = "parentLanguage";
@ -79,11 +78,9 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
* @throws X4OLanguageModuleLoaderException When eld language could not be loaded. * @throws X4OLanguageModuleLoaderException When eld language could not be loaded.
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModule) * @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.lang.X4OLanguageLocal, org.x4o.xml.lang.X4OLanguageModule)
*/ */
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule elementLanguageModule) throws X4OLanguageModuleLoaderException { public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule languageModule) throws X4OLanguageModuleLoaderException {
logger.fine("Loading name eld file from resource: "+eldResource); logger.fine("Loading name eld file from resource: "+eldResource);
try { try {
//EldDriver parser = new EldDriver(elementLanguage,elementLanguageModule,isEldCore);
X4ODriver<?> driver = null; X4ODriver<?> driver = null;
if (isEldCore) { if (isEldCore) {
driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME); driver = X4ODriverManager.getX4ODriver(CelDriver.LANGUAGE_NAME);
@ -91,12 +88,13 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
driver = X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME); driver = X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
} }
X4OLanguageContext eldLang = driver.createLanguageContext(driver.getLanguageVersionDefault()); X4OReader<?> reader = driver.createReader();
X4OReader<?> reader = new DefaultX4OReader<Object>(eldLang);
//X4OLanguageContext eldLang = driver.createLanguageContext(driver.getLanguageVersionDefault());
//X4OReader<?> reader = new DefaultX4OReader<Object>(eldLang);
reader.addELBeanInstance(EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration());
reader.addELBeanInstance(EL_PARENT_LANGUAGE, language); reader.addELBeanInstance(EL_PARENT_LANGUAGE, language);
reader.addELBeanInstance(EL_PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule); reader.addELBeanInstance(EL_PARENT_LANGUAGE_MODULE, languageModule);
//TODO: if (language.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) { //TODO: if (language.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
// eldLang.setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter()); // eldLang.setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
@ -111,4 +109,14 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e); throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} }
} }
public static X4OLanguage getLanguage(X4OLanguageContext context) {
ValueExpression ee = context.getExpressionLanguageFactory().createValueExpression(context.getExpressionLanguageContext(),"${"+EL_PARENT_LANGUAGE+"}", X4OLanguage.class);
return (X4OLanguage)ee.getValue(context.getExpressionLanguageContext());
}
public static X4OLanguageModule getLanguageModule(X4OLanguageContext context) {
ValueExpression ee = context.getExpressionLanguageFactory().createValueExpression(context.getExpressionLanguageContext(),"${"+EL_PARENT_LANGUAGE_MODULE+"}", X4OLanguageModule.class);
return (X4OLanguageModule)ee.getValue(context.getExpressionLanguageContext());
}
} }

View file

@ -22,8 +22,6 @@
*/ */
package org.x4o.xml.eld.lang; package org.x4o.xml.eld.lang;
import java.util.Map;
import org.x4o.xml.eld.EldModuleLoader; import org.x4o.xml.eld.EldModuleLoader;
import org.x4o.xml.element.AbstractElementBindingHandler; import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
@ -38,7 +36,6 @@ import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageProperty;
/** /**
* An ParentLanguageElementConfigurator. * An ParentLanguageElementConfigurator.
@ -78,13 +75,7 @@ public class ElementModuleBindingHandler extends AbstractElementBindingHandler<
*/ */
public void bindChild(Element childElement,X4OLanguageModule languageModule, Object childObject) throws ElementBindingHandlerException { public void bindChild(Element childElement,X4OLanguageModule languageModule, Object childObject) throws ElementBindingHandlerException {
@SuppressWarnings("rawtypes") X4OLanguage x4oParsingContext = EldModuleLoader.getLanguage(childElement.getLanguageContext());
Map m = (Map)childElement.getLanguageContext().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
X4OLanguage x4oParsingContext = (X4OLanguage)m.get(EldModuleLoader.EL_PARENT_LANGUAGE);
//ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
if (x4oParsingContext==null) { if (x4oParsingContext==null) {
return; return;
} }

View file

@ -22,13 +22,10 @@
*/ */
package org.x4o.xml.eld.lang; package org.x4o.xml.eld.lang;
import java.util.Map;
import org.x4o.xml.eld.EldModuleLoader; import org.x4o.xml.eld.EldModuleLoader;
import org.x4o.xml.element.AbstractElement; import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageProperty;
/** /**
* ModuleElement put in an instance from parent language module. * ModuleElement put in an instance from parent language module.
@ -48,12 +45,7 @@ public class ModuleElement extends AbstractElement {
if (getParent()!=null) { if (getParent()!=null) {
throw new ElementException("Need to be root tag"); throw new ElementException("Need to be root tag");
} }
@SuppressWarnings("rawtypes") X4OLanguageModule elementLanguageModule = EldModuleLoader.getLanguageModule(getLanguageContext());
Map m = (Map)getLanguageContext().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
X4OLanguageModule elementLanguageModule = (X4OLanguageModule)m.get(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE);
setElementObject(elementLanguageModule); setElementObject(elementLanguageModule);
} }
} }

View file

@ -30,12 +30,12 @@ import java.io.Writer;
import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.DefaultX4OSchemaWriter;
import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.io.sax.ext.ContentWriterXsd; import org.x4o.xml.io.sax.ext.ContentWriterXsd;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -46,12 +46,12 @@ import org.xml.sax.SAXException;
*/ */
public class EldXsdXmlGenerator { public class EldXsdXmlGenerator {
private X4OLanguage language = null; private final X4OLanguage language;
private X4OLanguageContext languageContext = null; private final PropertyConfig propertyConfig;
public EldXsdXmlGenerator(X4OLanguageContext languageContext) { public EldXsdXmlGenerator(X4OLanguage language,PropertyConfig propertyConfig) {
this.languageContext=languageContext; this.language=language;
this.language=languageContext.getLanguage(); this.propertyConfig=propertyConfig;
} }
private void checkNamespace(ElementNamespaceContext ns) { private void checkNamespace(ElementNamespaceContext ns) {
@ -64,16 +64,11 @@ public class EldXsdXmlGenerator {
} }
public void writeSchema(String namespace) throws ElementException { public void writeSchema(String namespace) throws ElementException {
File basePath = (File)languageContext.getLanguageProperty(X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_PATH); File basePath = (File)propertyConfig.getProperty(DefaultX4OSchemaWriter.OUTPUT_PATH);
String encoding = languageContext.getLanguagePropertyString(X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_ENCODING); String encoding = propertyConfig.getPropertyString(ContentWriterXml.OUTPUT_ENCODING);
String charNew = languageContext.getLanguagePropertyString(X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE);
String charTab = languageContext.getLanguagePropertyString(X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_TAB);
if (basePath==null) { if (basePath==null) {
throw new ElementException("Can't write schema to null output path."); throw new ElementException("Can't write schema to null output path.");
} }
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE+""; }
if (charTab==null) { charTab = XMLConstants.CHAR_TAB+""; }
try { try {
@ -86,7 +81,8 @@ public class EldXsdXmlGenerator {
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()); File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding); Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try { try {
ContentWriterXsd out = new ContentWriterXsd(wr,encoding,charNew,charTab); ContentWriterXsd out = new ContentWriterXsd(wr,encoding);
out.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
wr.close(); wr.close();
@ -99,7 +95,8 @@ public class EldXsdXmlGenerator {
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()); File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding); Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
try { try {
ContentWriterXsd out = new ContentWriterXsd(wr,encoding,charNew,charTab); ContentWriterXsd out = new ContentWriterXsd(wr,encoding);
out.getPropertyConfig().copyParentProperties(propertyConfig);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
wr.close(); wr.close();

View file

@ -43,7 +43,7 @@ public abstract class AbstractElement implements Element {
/** The config object */ /** The config object */
private Object elementObject = null; private Object elementObject = null;
/** The language parsing context */ /** The language parsing context */
private X4OLanguageContext elementLanguage = null; private X4OLanguageContext languageContext = null;
/** The ElementClass */ /** The ElementClass */
private ElementClass elementClass = null; private ElementClass elementClass = null;
/** The attributes */ /** The attributes */
@ -116,15 +116,15 @@ public abstract class AbstractElement implements Element {
/** /**
* @see Element#setLanguageContext(X4OLanguageContext) * @see Element#setLanguageContext(X4OLanguageContext)
*/ */
public void setLanguageContext(X4OLanguageContext elementLanguage) { public void setLanguageContext(X4OLanguageContext languageContext) {
this.elementLanguage=elementLanguage; this.languageContext=languageContext;
} }
/** /**
* @see Element#getLanguageContext() * @see Element#getLanguageContext()
*/ */
public X4OLanguageContext getLanguageContext() { public X4OLanguageContext getLanguageContext() {
return elementLanguage; return languageContext;
} }
/** /**

View file

@ -31,12 +31,6 @@ import java.util.List;
* @version 1.0 Oct 28, 2009 * @version 1.0 Oct 28, 2009
*/ */
public interface ElementNamespaceContext extends ElementMetaBase { public interface ElementNamespaceContext extends ElementMetaBase {
//void init(ElementLanguageModuleLoader elementProvider,String language);
//String getNamespace();
//String getNamespaceResourceFile();
//String getNamespaceLanguage();
/** /**
* Sets the prefix mapping. * Sets the prefix mapping.

View file

@ -22,8 +22,12 @@
*/ */
package org.x4o.xml.io; package org.x4o.xml.io;
import org.x4o.xml.lang.X4OLanguageContext; import java.util.ArrayList;
import org.x4o.xml.lang.X4OLanguageProperty; import java.util.Collection;
import java.util.List;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguage;
/** /**
* AbstractX4OConnection is the read/write interface for the classes. * AbstractX4OConnection is the read/write interface for the classes.
@ -33,49 +37,43 @@ import org.x4o.xml.lang.X4OLanguageProperty;
*/ */
public abstract class AbstractX4OConnection implements X4OConnection { public abstract class AbstractX4OConnection implements X4OConnection {
private X4OLanguageContext languageContext = null; private final X4OLanguage language;
protected String phaseStop = null;
protected List<String> phaseSkip = null;
/** public AbstractX4OConnection(X4OLanguage language) {
* Creates a AbstractX4OConnection. this.language=language;
* @param languageContext The language context of this connection. this.phaseSkip = new ArrayList<String>(2);
*/
public AbstractX4OConnection(X4OLanguageContext languageContext) {
this.languageContext=languageContext;
} }
/** protected X4OLanguage getLanguage() {
* @return Returns the language context. return language;
*/
protected X4OLanguageContext getLanguageContext() {
return languageContext;
} }
abstract PropertyConfig getPropertyConfig();
/** /**
* Sets an X4O Language property. * Sets an X4O Language property.
* @param key The key of the property to set. * @param key The key of the property to set.
* @param value The vlue of the property to set. * @param value The vlue of the property to set.
*/ */
public void setProperty(String key,Object value) { public void setProperty(String key,Object value) {
String[] keyLimits = getPropertyKeySet(); getPropertyConfig().setProperty(key, value);
for (int i=0;i<keyLimits.length;i++) {
String keyLimit = keyLimits[i];
if (keyLimit.equals(key)) {
//if (phaseManager!=null) {
// TODO: throw new IllegalStateException("Can't set property after phaseManager is created.");
//}
languageContext.setLanguageProperty(X4OLanguageProperty.valueByUri(key), value);
return;
}
}
throw new IllegalArgumentException("Property with key: "+key+" is protected by key limit.");
} }
/**
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
public Object getProperty(String key) { public Object getProperty(String key) {
return languageContext.getLanguageProperty(X4OLanguageProperty.valueByUri(key)); return getPropertyConfig().getProperty(key);
}
public Collection<String> getPropertyKeys() {
return getPropertyConfig().getPropertyKeys();
}
public void setPhaseStop(String phaseId) {
phaseStop = phaseId;
}
public void addPhaseSkip(String phaseId) {
phaseSkip.add( phaseId );
} }
} }

View file

@ -28,8 +28,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -41,15 +40,8 @@ import org.xml.sax.SAXException;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
abstract public class AbstractX4OReader<T> extends AbstractX4OReaderContext<T> implements X4OReader<T> { abstract public class AbstractX4OReader<T> extends AbstractX4OReaderContext<T> implements X4OReader<T> {
public AbstractX4OReader(X4OLanguageContext elementLanguage) { public AbstractX4OReader(X4OLanguage language) {
super(elementLanguage); super(language);
}
/**
* @see org.x4o.xml.io.X4OConnection#getPropertyKeySet()
*/
public String[] getPropertyKeySet() {
return X4OLanguagePropertyKeys.DEFAULT_X4O_READER_KEYS;
} }
public T read(InputStream input, String systemId, URL basePath) throws X4OConnectionException,SAXException,IOException { public T read(InputStream input, String systemId, URL basePath) throws X4OConnectionException,SAXException,IOException {

View file

@ -30,9 +30,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -44,8 +44,8 @@ import org.xml.sax.SAXException;
*/ */
abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection implements X4OReaderContext<T> { abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection implements X4OReaderContext<T> {
public AbstractX4OReaderContext(X4OLanguageContext languageContext) { public AbstractX4OReaderContext(X4OLanguage language) {
super(languageContext); super(language);
} }
/** /**
@ -135,7 +135,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
throw new NullPointerException("Can't read null xml string."); throw new NullPointerException("Can't read null xml string.");
} }
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL(); URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
String encoding = getLanguageContext().getLanguagePropertyString(X4OLanguageProperty.READER_INPUT_ENCODING); String encoding = (String)getProperty(DefaultX4OReader.INPUT_ENCODING);
return readContext(new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath); return readContext(new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath);
} }

View file

@ -28,8 +28,8 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -40,16 +40,11 @@ import org.xml.sax.SAXException;
*/ */
public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> implements X4OWriter<T> { public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> implements X4OWriter<T> {
public AbstractX4OWriter(X4OLanguageContext elementLanguage) { public AbstractX4OWriter(X4OLanguage language) {
super(elementLanguage); super(language);
} }
/** abstract X4OLanguageContext getLanguageContext();
* @see org.x4o.xml.io.X4OConnection#getPropertyKeySet()
*/
public String[] getPropertyKeySet() {
return X4OLanguagePropertyKeys.DEFAULT_X4O_WRITER_KEYS;
}
private X4OLanguageContext toObjectContext(T object) throws SAXException { private X4OLanguageContext toObjectContext(T object) throws SAXException {
X4OLanguageContext context = getLanguageContext(); X4OLanguageContext context = getLanguageContext();
@ -62,6 +57,7 @@ public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> i
throw new SAXException(e); throw new SAXException(e);
} }
rootElement.setElementObject(object); rootElement.setElementObject(object);
rootElement.setLanguageContext(context);
context.setRootElement(rootElement); context.setRootElement(rootElement);
return context; return context;
} }

View file

@ -28,8 +28,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -40,8 +41,8 @@ import org.xml.sax.SAXException;
*/ */
public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection implements X4OWriterContext<T> { public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection implements X4OWriterContext<T> {
public AbstractX4OWriterContext(X4OLanguageContext elementLanguage) { public AbstractX4OWriterContext(X4OLanguage language) {
super(elementLanguage); super(language);
} }
public void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException { public void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException {
@ -66,7 +67,7 @@ public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection
public String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException { public String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(4096); ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
writeContext(context, out); writeContext(context, out);
String encoding = context.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_ENCODING); String encoding = (String)getProperty(ContentWriterXml.OUTPUT_ENCODING);
return out.toString(encoding); return out.toString(encoding);
} }
} }

View file

@ -22,27 +22,32 @@
*/ */
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.el.ValueExpression;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.io.sax.X4OContentParser;
import org.x4o.xml.io.sax.X4ODebugWriter; import org.x4o.xml.io.sax.X4ODebugWriter;
import org.x4o.xml.io.sax.ext.ContentWriter; import org.x4o.xml.io.sax.ext.ContentWriter;
import org.x4o.xml.io.sax.ext.ContentWriterXml; import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.io.sax.ext.PropertyConfig.PropertyConfigItem;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageContextLocal; import org.x4o.xml.lang.X4OLanguageContextLocal;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.lang.phase.X4OPhaseException; import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseType; import org.x4o.xml.lang.phase.X4OPhaseType;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -53,25 +58,82 @@ import org.xml.sax.helpers.AttributesImpl;
* @version 1.0 Aug 9, 2012 * @version 1.0 Aug 9, 2012
*/ */
public class DefaultX4OReader<T> extends AbstractX4OReader<T> { public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
/** The logger to log to. */ /** The logger to log to. */
private Logger logger = null; private Logger logger = null;
public DefaultX4OReader(X4OLanguageContext elementLanguage) { private X4OLanguageContext languageContext = null;
super(elementLanguage);
private PropertyConfig propertyConfig;
private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_READER;
private final static String PROPERTY_SAX_ERROR_HANDLER = "sax/error-handler";
private final static String PROPERTY_SAX_ENTITY_RESOLVER = "sax/entity-resolver";
private final static String PROPERTY_DOC_EMPTY_NAMESPACE_URI = "doc/empty-namespace-uri";
private final static String PROPERTY_DOC_BUFFER_SIZE = "doc/buffer-size";
private final static String PROPERTY_INPUT_STREAM = "input/stream";
private final static String PROPERTY_INPUT_ENCODING = "input/encoding";
private final static String PROPERTY_INPUT_SOURCE = "input/source";
private final static String PROPERTY_INPUT_SYSTEM_ID = "input/system-id";
private final static String PROPERTY_INPUT_BASE_PATH = "input/base-path";
private final static String PROPERTY_VALIDATION_SCHEMA_AUTO_WRITE = "validation/schema-auto-write";
private final static String PROPERTY_VALIDATION_SCHEMA_PATH = "validation/schema-path";
private final static String PROPERTY_VALIDATION_INPUT_DOC = "validation/input-doc";
private final static String PROPERTY_VALIDATION_INPUT_SCHEMA = "validation/input-schema";
public final static PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String SAX_ERROR_HANDLER = PROPERTY_CONTEXT_PREFIX+PROPERTY_SAX_ERROR_HANDLER;
public final static String SAX_ENTITY_RESOLVER = PROPERTY_CONTEXT_PREFIX+PROPERTY_SAX_ENTITY_RESOLVER;
public final static String DOC_EMPTY_NAMESPACE_URI = PROPERTY_CONTEXT_PREFIX+PROPERTY_DOC_EMPTY_NAMESPACE_URI;
public final static String DOC_BUFFER_SIZE = PROPERTY_CONTEXT_PREFIX+PROPERTY_DOC_BUFFER_SIZE;
public final static String INPUT_STREAM = PROPERTY_CONTEXT_PREFIX+PROPERTY_INPUT_STREAM;
public final static String INPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+PROPERTY_INPUT_ENCODING;
public final static String INPUT_SOURCE = PROPERTY_CONTEXT_PREFIX+PROPERTY_INPUT_SOURCE;
public final static String INPUT_SYSTEM_ID = PROPERTY_CONTEXT_PREFIX+PROPERTY_INPUT_SYSTEM_ID;
public final static String INPUT_BASE_PATH = PROPERTY_CONTEXT_PREFIX+PROPERTY_INPUT_BASE_PATH;
public final static String VALIDATION_SCHEMA_AUTO_WRITE = PROPERTY_CONTEXT_PREFIX+PROPERTY_VALIDATION_SCHEMA_AUTO_WRITE;
public final static String VALIDATION_SCHEMA_PATH = PROPERTY_CONTEXT_PREFIX+PROPERTY_VALIDATION_SCHEMA_PATH;
public final static String VALIDATION_INPUT_DOC = PROPERTY_CONTEXT_PREFIX+PROPERTY_VALIDATION_INPUT_DOC;
public final static String VALIDATION_INPUT_SCHEMA = PROPERTY_CONTEXT_PREFIX+PROPERTY_VALIDATION_INPUT_SCHEMA;
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(PROPERTY_SAX_ERROR_HANDLER,ErrorHandler.class),
new PropertyConfigItem(PROPERTY_SAX_ENTITY_RESOLVER,EntityResolver.class),
new PropertyConfigItem(PROPERTY_DOC_EMPTY_NAMESPACE_URI,String.class),
new PropertyConfigItem(PROPERTY_DOC_BUFFER_SIZE,Integer.class,4096*2),
new PropertyConfigItem(PROPERTY_INPUT_STREAM,InputStream.class),
new PropertyConfigItem(PROPERTY_INPUT_ENCODING,String.class,XMLConstants.XML_DEFAULT_ENCODING),
new PropertyConfigItem(PROPERTY_INPUT_SOURCE,InputSource.class),
new PropertyConfigItem(PROPERTY_INPUT_SYSTEM_ID,String.class),
new PropertyConfigItem(PROPERTY_INPUT_BASE_PATH,URL.class),
new PropertyConfigItem(PROPERTY_VALIDATION_SCHEMA_AUTO_WRITE,Boolean.class,true),
new PropertyConfigItem(PROPERTY_VALIDATION_SCHEMA_PATH,File.class),
new PropertyConfigItem(PROPERTY_VALIDATION_INPUT_DOC,Boolean.class,false),
new PropertyConfigItem(PROPERTY_VALIDATION_INPUT_SCHEMA,Boolean.class,false)
);
}
public DefaultX4OReader(X4OLanguage language) {
super(language);
logger = Logger.getLogger(DefaultX4OReader.class.getName()); logger = Logger.getLogger(DefaultX4OReader.class.getName());
languageContext = language.createLanguageContext();
propertyConfig = new PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
}
@Override
PropertyConfig getPropertyConfig() {
return propertyConfig;
} }
public X4OLanguageContext readContext(InputStream input, String systemId, URL basePath) throws X4OConnectionException, SAXException, IOException { public X4OLanguageContext readContext(InputStream input, String systemId, URL basePath) throws X4OConnectionException, SAXException, IOException {
setProperty(X4OLanguagePropertyKeys.READER_INPUT_STREAM, input); setProperty(INPUT_STREAM, input);
setProperty(X4OLanguagePropertyKeys.READER_INPUT_SYSTEM_ID, systemId); setProperty(INPUT_SYSTEM_ID, systemId);
setProperty(X4OLanguagePropertyKeys.READER_INPUT_BASE_PATH, basePath); setProperty(INPUT_BASE_PATH, basePath);
read(); read();
return getLanguageContext(); return languageContext;
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addELBeanInstance(String name,Object bean) { public void addELBeanInstance(String name,Object bean) {
if (name==null) { if (name==null) {
throw new NullPointerException("Can't add null name."); throw new NullPointerException("Can't add null name.");
@ -82,28 +144,33 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
if (bean==null) { if (bean==null) {
throw new NullPointerException("Can't add null bean."); throw new NullPointerException("Can't add null bean.");
} }
Map map = (Map)getProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP); ValueExpression ve = languageContext.getExpressionLanguageFactory().createValueExpression(languageContext.getExpressionLanguageContext(),"${"+name+"}", bean.getClass());
if (map==null) { ve.setValue(languageContext.getExpressionLanguageContext(), bean);
map = new HashMap<String,Object>(20);
setProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP, map);
}
logger.finer("Adding el bean: "+name+" type: "+bean.getClass());
map.put(name,bean);
} }
/** /**
* Parses the input stream as a X4O document. * Parses the input stream as a X4O document.
*/ */
protected void read() throws X4OConnectionException,SAXException,IOException { protected void read() throws X4OConnectionException,SAXException,IOException {
X4OLanguageContext languageContext = getLanguageContext();
if (languageContext.getLanguage()==null) { if (languageContext.getLanguage()==null) {
throw new X4OConnectionException("languageContext is broken getLanguage() returns null."); throw new X4OConnectionException("languageContext is broken getLanguage() returns null.");
} }
if (languageContext instanceof X4OLanguageContextLocal) {
X4OLanguageContextLocal ll = (X4OLanguageContextLocal)languageContext;
if (phaseStop!=null) {
ll.setPhaseStop(phaseStop);
}
for (String phaseId:phaseSkip) {
ll.addPhaseSkip(phaseId);
}
}
// init debugWriter if enabled // init debugWriter if enabled
boolean startedDebugWriter = false; boolean startedDebugWriter = false;
Object debugOutputHandler = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER); Object debugOutputHandler = null; //TODO: getProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER.name());
Object debugOutputStream = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM); Object debugOutputStream = null; //getProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM.name());
if (languageContext.getX4ODebugWriter()==null) { if (languageContext.getX4ODebugWriter()==null) {
ContentWriter xmlDebugWriter = null; ContentWriter xmlDebugWriter = null;
if (debugOutputHandler instanceof ContentWriter) { if (debugOutputHandler instanceof ContentWriter) {
@ -131,7 +198,10 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
// start parsing language // start parsing language
try { try {
getLanguageContext().getLanguage().getPhaseManager().runPhases(getLanguageContext(), X4OPhaseType.XML_READ); X4OContentParser parser = new X4OContentParser(propertyConfig);
parser.parse(languageContext);
getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_READ);
} catch (Exception e) { } catch (Exception e) {
// also debug exceptions // also debug exceptions

View file

@ -26,8 +26,10 @@ import java.io.File;
import org.x4o.xml.eld.xsd.EldXsdXmlGenerator; import org.x4o.xml.eld.xsd.EldXsdXmlGenerator;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.io.sax.ext.PropertyConfig.PropertyConfigItem;
import org.x4o.xml.lang.X4OLanguage;
/** /**
* DefaultX4OSchemaWriter can write the schema of a x4o language. * DefaultX4OSchemaWriter can write the schema of a x4o language.
@ -37,15 +39,28 @@ import org.x4o.xml.lang.X4OLanguagePropertyKeys;
*/ */
public class DefaultX4OSchemaWriter extends AbstractX4OConnection implements X4OSchemaWriter { public class DefaultX4OSchemaWriter extends AbstractX4OConnection implements X4OSchemaWriter {
public DefaultX4OSchemaWriter(X4OLanguageContext languageContext) { private PropertyConfig propertyConfig;
super(languageContext);
private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_WRITER;
private final static String PROPERTY_OUTPUT_PATH = "output/path";
public final static PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_PATH = PROPERTY_CONTEXT_PREFIX+PROPERTY_OUTPUT_PATH;
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(PROPERTY_OUTPUT_PATH,File.class)
);
} }
/** public DefaultX4OSchemaWriter(X4OLanguage language) {
* @see org.x4o.xml.io.X4OConnection#getPropertyKeySet() super(language);
*/ propertyConfig = new PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
public String[] getPropertyKeySet() { }
return X4OLanguagePropertyKeys.DEFAULT_X4O_SCHEMA_WRITER_KEYS;
@Override
PropertyConfig getPropertyConfig() {
return propertyConfig;
} }
/** /**
@ -54,13 +69,14 @@ public class DefaultX4OSchemaWriter extends AbstractX4OConnection implements X4O
public void writeSchema(File basePath) throws ElementException { public void writeSchema(File basePath) throws ElementException {
writeSchema(basePath, null); writeSchema(basePath, null);
} }
/** /**
* @see org.x4o.xml.io.X4OSchemaWriter#writeSchema(java.io.File, java.lang.String) * @see org.x4o.xml.io.X4OSchemaWriter#writeSchema(java.io.File, java.lang.String)
*/ */
public void writeSchema(File basePath, String namespace) throws ElementException { public void writeSchema(File basePath, String namespace) throws ElementException {
setProperty(X4OLanguagePropertyKeys.SCHEMA_WRITER_OUTPUT_PATH, basePath); setProperty(OUTPUT_PATH, basePath);
EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(getLanguageContext()); // TODO: fix create context
EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(getLanguage().createLanguageContext().getLanguage(),getPropertyConfig());
xsd.writeSchema(namespace); // Start xsd generator xsd.writeSchema(namespace); // Start xsd generator
} }
} }

View file

@ -24,12 +24,32 @@ package org.x4o.xml.io;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementObjectPropertyValueException;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.io.sax.ext.PropertyConfig.PropertyConfigItem;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseException; import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseType; import org.x4o.xml.lang.phase.X4OPhaseType;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** /**
* DefaultX4OWriter can write the xml language. * DefaultX4OWriter can write the xml language.
@ -39,23 +59,278 @@ import org.xml.sax.SAXException;
*/ */
public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> { public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
private PropertyConfig propertyConfig;
private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_WRITER;
private final static String PROPERTY_OUTPUT_STREAM = "output/stream";
private final static String PROPERTY_SCHEMA_PRINT = "schema/print";
private final static String PROPERTY_SCHEMA_ROOT_URI = "schema/root-uri";
public final static PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_STREAM = PROPERTY_CONTEXT_PREFIX+PROPERTY_OUTPUT_STREAM;
public final static String SCHEMA_PRINT = PROPERTY_CONTEXT_PREFIX+PROPERTY_SCHEMA_PRINT;
public final static String SCHEMA_ROOT_URI = PROPERTY_CONTEXT_PREFIX+PROPERTY_SCHEMA_ROOT_URI;
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,ContentWriterXml.DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(PROPERTY_OUTPUT_STREAM,OutputStream.class),
new PropertyConfigItem(PROPERTY_SCHEMA_PRINT,Boolean.class,true),
new PropertyConfigItem(PROPERTY_SCHEMA_ROOT_URI,String.class)
);
}
/** /**
* Default constructor. * Default constructor.
* @param languageContext The language context for this writer. * @param languageContext The language context for this writer.
*/ */
public DefaultX4OWriter(X4OLanguageContext languageContext) { public DefaultX4OWriter(X4OLanguage language) {
super(languageContext); super(language);
propertyConfig = new PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
}
/**
* @see org.x4o.xml.lang.X4OLanguageContext#getPropertyConfig()
*/
public PropertyConfig getPropertyConfig() {
return propertyConfig;
}
X4OLanguageContext getLanguageContext() {
return getLanguage().createLanguageContext();
} }
/** /**
* @see org.x4o.xml.io.X4OWriterContext#writeContext(org.x4o.xml.lang.X4OLanguageContext, java.io.OutputStream) * @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 { public void writeContext(X4OLanguageContext languageContext,OutputStream output) throws X4OConnectionException,SAXException,IOException {
languageContext.setLanguageProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output); setProperty(OUTPUT_STREAM, output);
addPhaseSkip(X4OPhase.WRITE_RELEASE);
try { try {
languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE); languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE);
} catch (X4OPhaseException e) { } catch (X4OPhaseException e) {
throw new X4OConnectionException(e); throw new X4OConnectionException(e);
} }
runWrite(languageContext);
}
private AttributeEntryComparator attributeEntryComparator = new AttributeEntryComparator();
private boolean schemaUriPrint;
private String schemaUriRoot;
private void runWrite(X4OLanguageContext languageContext) throws X4OConnectionException {
OutputStream out = (OutputStream)getProperty(OUTPUT_STREAM);
try {
String encoding = getPropertyConfig().getPropertyString(ContentWriterXml.OUTPUT_ENCODING);
schemaUriPrint = getPropertyConfig().getPropertyBoolean(SCHEMA_PRINT);
schemaUriRoot = getPropertyConfig().getPropertyString(SCHEMA_ROOT_URI);
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
Element root = languageContext.getRootElement();
if (schemaUriRoot==null) {
String rootUri = findElementUri(root);
ElementNamespaceContext ns = languageContext.getLanguage().findElementNamespaceContext(rootUri);
if (ns!=null) {
schemaUriRoot = ns.getSchemaUri();
}
}
ContentWriterXml writer = new ContentWriterXml(out,encoding);
writer.getPropertyConfig().copyParentProperties(getPropertyConfig());
writer.startDocument();
Map<String,String> prefixes = new HashMap<String,String>();
startPrefixTree(root,prefixes);
for (String uri:prefixes.keySet()) {
String prefix = prefixes.get(uri);
writer.startPrefixMapping(prefix, uri);
}
try {
writeTree(writer,root,true);
} catch (ElementObjectPropertyValueException e) {
throw new SAXException(e);
}
writer.endDocument();
out.flush();
} catch (Exception e) {
throw new X4OConnectionException(e);
} finally {
if (out!=null) {
try {
out.close();
} catch (IOException e) {
//logger.warning(e.getMessage());
}
}
}
}
private void startPrefixTree(Element element,Map<String,String> result) throws SAXException {
String elementUri = findElementUri(element);
if (result.containsKey(elementUri)==false) {
String elementUriPrefix = findNamespacePrefix(element,elementUri);
result.put(elementUri, elementUriPrefix);
}
for (Element e:element.getChilderen()) {
startPrefixTree(e,result);
}
}
private List<String> getProperties(Class<?> objectClass) {
List<String> result = new ArrayList<String>();
for (Method m:objectClass.getMethods()) {
Class<?>[] types = m.getParameterTypes();
if (types.length != 0) {
continue;
}
if (m.getName().equals("getClass")) {
continue;
}
if (m.getName().startsWith("get")==false) {
continue;
}
String name = m.getName().substring(3,4).toLowerCase()+m.getName().substring(4);
result.add(name);
}
return result;
}
class AttributeEntry {
String id;
String value;
Integer writeOrder;
}
class AttributeEntryComparator implements Comparator<AttributeEntry> {
public int compare(AttributeEntry o1, AttributeEntry o2) {
return o1.writeOrder.compareTo(o2.writeOrder);
}
}
private void writeTree(ContentWriterXml writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
List<AttributeEntry> attr = new ArrayList<AttributeEntry>(20);
if (element.getElementClass().getAutoAttributes()!=null && element.getElementClass().getAutoAttributes()==false) {
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
if (eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
continue;
}
Object value = element.getLanguageContext().getElementObjectPropertyValue().getProperty(element.getElementObject(),eca.getId());
if (value==null) {
continue;
}
AttributeEntry e = new AttributeEntry();
e.id = eca.getId();
e.value = ""+value;
e.writeOrder = calcOrderNumber(e.id,eca.getWriteOrder());
attr.add(e);
}
} else {
for (String p:getProperties(element.getElementObject().getClass())) {
Integer writeOrder = null;
ElementClassAttribute eca = element.getElementClass().getElementClassAttributeByName(p);
if (eca!=null) {
writeOrder = eca.getWriteOrder();
}
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()) {
continue;
}
boolean writeValue = true;
for (ElementInterface ei:element.getLanguageContext().getLanguage().findElementInterfaces(element.getElementObject().getClass())) {
eca = ei.getElementClassAttributeByName(p);
if (eca!=null && writeOrder==null) {
writeOrder = eca.getWriteOrder(); // add interface but allow override local
}
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
writeValue = false;
break;
}
}
if (writeValue==false) {
continue;
}
// TODO: check attr see reader
Object value = element.getLanguageContext().getElementObjectPropertyValue().getProperty(element.getElementObject(),p);
if (value==null) {
continue;
}
if (value instanceof List || value instanceof Collection) {
continue; // TODO; filter on type of childeren
}
AttributeEntry e = new AttributeEntry();
e.id = p;
e.value = ""+value;
e.writeOrder = calcOrderNumber(e.id,writeOrder);
attr.add(e);
}
}
// Create atts to write and append schema first.
AttributesImpl atts = new AttributesImpl();
if (isRoot && schemaUriPrint) {
String rootUri = findElementUri(element);
writer.startPrefixMapping("xsi", XMLConstants.XML_SCHEMA_INSTANCE_NS_URI);
atts.addAttribute ("xsi", "schemaLocation", "", "", rootUri+" "+schemaUriRoot);
}
// Sort attributes in natural order of localName and add to attributes
Collections.sort(attr, attributeEntryComparator);
for (int i=0;i<attr.size();i++) {
AttributeEntry a = attr.get(i);
atts.addAttribute ("", a.id, "", "", a.value);
}
// Write Element tree recursive.
String elementUri = findElementUri(element);
writer.startElement(elementUri, element.getElementClass().getId(), "", atts);
for (Element e:element.getChilderen()) {
writeTree(writer,e,false);
}
writer.endElement(elementUri, element.getElementClass().getId(), "");
}
// TODO: move to defaults layer so visible in docs.
private Integer calcOrderNumber(String name,Integer orderNumberOverride) {
if (orderNumberOverride!=null) {
return orderNumberOverride;
}
if (name==null) {
throw new NullPointerException("Can't calculate order of null name.");
}
int nameSize = name.length();
if (nameSize==1) {
return (name.charAt(0) * 1000);
}
if (nameSize==2) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100);
}
if (nameSize==3) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10);
}
if (nameSize>3) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10) + (name.charAt(3) * 1);
}
throw new IllegalArgumentException("Can't calculate order of empty name.");
}
private String findElementUri(Element e) {
for (X4OLanguageModule mod:e.getLanguageContext().getLanguage().getLanguageModules()) {
for (ElementNamespaceContext c:mod.getElementNamespaceContexts()) {
ElementClass ec = c.getElementClass(e.getElementClass().getId());
if (ec!=null) {
return c.getUri();
}
}
}
return null;
}
private String findNamespacePrefix(Element e,String uri) {
ElementNamespaceContext ns = e.getLanguageContext().getLanguage().findElementNamespaceContext(uri);
if (ns.getPrefixMapping()!=null) {
return ns.getPrefixMapping();
}
return ns.getId();
} }
} }

View file

@ -22,6 +22,8 @@
*/ */
package org.x4o.xml.io; package org.x4o.xml.io;
import java.util.Collection;
/** /**
* X4OConnection interface for config the io drivers. * X4OConnection interface for config the io drivers.
* *
@ -37,15 +39,11 @@ public interface X4OConnection {
*/ */
void setProperty(String key,Object value); void setProperty(String key,Object value);
/** public Object getProperty(String key);
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
Object getProperty(String key);
/** public Collection<String> getPropertyKeys();
* @return Returns the propery keys which can be set.
*/ public void setPhaseStop(String phaseId);
String[] getPropertyKeySet();
public void addPhaseSkip(String phaseId);
} }

View file

@ -27,9 +27,10 @@ import org.x4o.xml.element.Element.ElementType;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider; import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.sax.ext.AttributeMap; import org.x4o.xml.io.sax.ext.AttributeMap;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -67,16 +68,19 @@ public class X4OContentHandler extends DefaultHandler2 {
/** Store the override element handler */ /** Store the override element handler */
private DefaultHandler2 overrideSaxHandler = null; private DefaultHandler2 overrideSaxHandler = null;
private final PropertyConfig propertyConfig;
/** /**
* Creates an X4OTagHandler * Creates an X4OTagHandler
* which can receice sax xml events and converts them into the Element* interfaces events. * which can receice sax xml events and converts them into the Element* interfaces events.
*/ */
public X4OContentHandler(X4OLanguageContext elementLanguage) { public X4OContentHandler(X4OLanguageContext elementLanguage,PropertyConfig propertyConfig) {
logger = Logger.getLogger(X4OContentHandler.class.getName()); logger = Logger.getLogger(X4OContentHandler.class.getName());
loggerFinest = logger.isLoggable(Level.FINEST); loggerFinest = logger.isLoggable(Level.FINEST);
elementStack = new Stack<Element>(); elementStack = new Stack<Element>();
this.elementLanguage = elementLanguage; this.elementLanguage = elementLanguage;
this.propertyConfig = propertyConfig;
} }
/** /**
@ -124,7 +128,7 @@ public class X4OContentHandler extends DefaultHandler2 {
ElementNamespaceContext enc = elementLanguage.getLanguage().findElementNamespaceContext(namespaceUri); ElementNamespaceContext enc = elementLanguage.getLanguage().findElementNamespaceContext(namespaceUri);
if (enc==null) { if (enc==null) {
if ("".equals(namespaceUri)) { if ("".equals(namespaceUri)) {
String configEmptryUri = (String)elementLanguage.getLanguageProperty(X4OLanguageProperty.READER_EMPTY_NAMESPACE_URI); String configEmptryUri = propertyConfig.getPropertyString(DefaultX4OReader.DOC_EMPTY_NAMESPACE_URI);
if (configEmptryUri!=null) { if (configEmptryUri!=null) {
namespaceUri = configEmptryUri; namespaceUri = configEmptryUri;
enc = elementLanguage.getLanguage().findElementNamespaceContext(namespaceUri); enc = elementLanguage.getLanguage().findElementNamespaceContext(namespaceUri);

View file

@ -22,9 +22,11 @@
*/ */
package org.x4o.xml.io.sax; package org.x4o.xml.io.sax;
import org.x4o.xml.eld.EldDriver;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@ -32,6 +34,8 @@ import org.xml.sax.helpers.XMLReaderFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -43,6 +47,16 @@ import java.util.Map;
*/ */
public class X4OContentParser { public class X4OContentParser {
private final PropertyConfig propertyConfig;
public X4OContentParser(PropertyConfig propertyConfig) {
this.propertyConfig=propertyConfig;
}
private PropertyConfig getPropertyConfig() {
return propertyConfig;
}
public void parse(X4OLanguageContext languageContext) throws SAXException, IOException { public void parse(X4OLanguageContext languageContext) throws SAXException, IOException {
// If xsd caching is needed this should be the way // If xsd caching is needed this should be the way
@ -51,23 +65,23 @@ public class X4OContentParser {
//SAXParser parser = new SAXParser(config); //SAXParser parser = new SAXParser(config);
// Create Sax parser with x4o tag handler // Create Sax parser with x4o tag handler
X4OContentHandler xth = new X4OContentHandler(languageContext); X4OContentHandler xth = new X4OContentHandler(languageContext,getPropertyConfig());
XMLReader saxParser = XMLReaderFactory.createXMLReader(); XMLReader saxParser = XMLReaderFactory.createXMLReader();
saxParser.setErrorHandler(new X4OErrorHandler(languageContext)); saxParser.setErrorHandler(new X4OErrorHandler(languageContext,getPropertyConfig()));
saxParser.setEntityResolver(new X4OEntityResolver(languageContext)); saxParser.setEntityResolver(new X4OEntityResolver(languageContext,getPropertyConfig()));
saxParser.setContentHandler(xth); saxParser.setContentHandler(xth);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth); saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth); saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
// Set properties and optional // Set properties and optional
Map<String,Object> saxParserProperties = languageContext.getLanguage().getLanguageConfiguration().getSAXParserProperties(languageContext); Map<String,Object> saxParserProperties = getSAXParserProperties(languageContext);
for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) { for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Object value= entry.getValue(); Object value= entry.getValue();
saxParser.setProperty(name, value); saxParser.setProperty(name, value);
debugMessage("Set SAX property: "+name+" to: "+value,languageContext); debugMessage("Set SAX property: "+name+" to: "+value,languageContext);
} }
Map<String,Object> saxParserPropertiesOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserPropertiesOptional(languageContext); Map<String,Object> saxParserPropertiesOptional = getSAXParserPropertiesOptional(languageContext);
for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) { for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Object value= entry.getValue(); Object value= entry.getValue();
@ -80,13 +94,13 @@ public class X4OContentParser {
} }
// Set sax features and optional // Set sax features and optional
Map<String, Boolean> features = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeatures(languageContext); Map<String, Boolean> features = getSAXParserFeatures(languageContext);
for (String key:features.keySet()) { for (String key:features.keySet()) {
Boolean value=features.get(key); Boolean value=features.get(key);
saxParser.setFeature(key, value); saxParser.setFeature(key, value);
debugMessage("Set SAX feature: "+key+" to: "+value,languageContext); debugMessage("Set SAX feature: "+key+" to: "+value,languageContext);
} }
Map<String, Boolean> featuresOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesOptional(languageContext); Map<String, Boolean> featuresOptional = getSAXParserFeaturesOptional(languageContext);
for (String key:featuresOptional.keySet()) { for (String key:featuresOptional.keySet()) {
Boolean value=featuresOptional.get(key); Boolean value=featuresOptional.get(key);
try { try {
@ -98,7 +112,7 @@ public class X4OContentParser {
} }
// check for required features // check for required features
List<String> requiredFeatures = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesRequired(languageContext); List<String> requiredFeatures = getSAXParserFeaturesRequired(languageContext);
for (String requiredFeature:requiredFeatures) { for (String requiredFeature:requiredFeatures) {
debugMessage("Checking required SAX feature: "+requiredFeature,languageContext); debugMessage("Checking required SAX feature: "+requiredFeature,languageContext);
if (saxParser.getFeature(requiredFeature)==false) { if (saxParser.getFeature(requiredFeature)==false) {
@ -107,21 +121,21 @@ public class X4OContentParser {
} }
// Finally start parsing the xml input stream // Finally start parsing the xml input stream
Object requestInputSource = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SOURCE); Object requestInputSource = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_SOURCE);
InputSource input = null; InputSource input = null;
InputStream inputStream = null; InputStream inputStream = null;
if (requestInputSource instanceof InputSource) { if (requestInputSource instanceof InputSource) {
input = (InputSource)requestInputSource; input = (InputSource)requestInputSource;
} else { } else {
inputStream = (InputStream)languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_STREAM); inputStream = (InputStream)getPropertyConfig().getProperty(DefaultX4OReader.INPUT_STREAM);
input = new InputSource(inputStream); input = new InputSource(inputStream);
} }
Object requestInputEncoding = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_ENCODING); Object requestInputEncoding = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_ENCODING);
if (requestInputEncoding!=null && requestInputEncoding instanceof String) { if (requestInputEncoding!=null && requestInputEncoding instanceof String) {
input.setEncoding(requestInputEncoding.toString()); input.setEncoding(requestInputEncoding.toString());
} }
Object requestSystemId = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SYSTEM_ID); Object requestSystemId = getPropertyConfig().getProperty(DefaultX4OReader.INPUT_SYSTEM_ID);
if (requestSystemId!=null && requestSystemId instanceof String) { if (requestSystemId!=null && requestSystemId instanceof String) {
input.setSystemId(requestSystemId.toString()); input.setSystemId(requestSystemId.toString());
} }
@ -144,4 +158,105 @@ public class X4OContentParser {
} }
} }
} }
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserProperties(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Object> getSAXParserProperties(X4OLanguageContext elementContext) {
Map<String,Object> saxParserProperties = new HashMap<String,Object>(1);
return saxParserProperties;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserPropertiesOptional(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Object> getSAXParserPropertiesOptional(X4OLanguageContext elementContext) {
Map<String,Object> saxParserProperties = new HashMap<String,Object>(1);
saxParserProperties.put("http://apache.org/xml/properties/input-buffer-size",getPropertyConfig().getProperty(DefaultX4OReader.DOC_BUFFER_SIZE)); // Increase buffer to 8KB
return saxParserProperties;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeatures(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Boolean> getSAXParserFeatures(X4OLanguageContext elementContext) {
// see example: http://xerces.apache.org/xerces2-j/features.html
Map<String,Boolean> saxParserFeatures = new HashMap<String,Boolean>(20);
// Tune Sax Parser
saxParserFeatures.put("http://xml.org/sax/features/namespaces", true); // Perform namespace processing
saxParserFeatures.put("http://xml.org/sax/features/use-entity-resolver2", true); // Use EntityResolver2 interface
saxParserFeatures.put("http://xml.org/sax/features/lexical-handler/parameter-entities", true); // Report parameter entities to a the LexicalHandler.
saxParserFeatures.put("http://xml.org/sax/features/xmlns-uris", false); // Namespace declaration attributes are reported as having no namespace.
saxParserFeatures.put("http://xml.org/sax/features/namespace-prefixes", false); // Do not report attributes used for Namespace declarations
saxParserFeatures.put("http://xml.org/sax/features/external-general-entities", false); // Never include the external general entries.
saxParserFeatures.put("http://xml.org/sax/features/external-parameter-entities", false); // Never include the external parameter or DTD subset.
saxParserFeatures.put("http://apache.org/xml/features/xinclude", true); // Perform XInclude processing
saxParserFeatures.put("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
saxParserFeatures.put("http://apache.org/xml/features/xinclude/fixup-language", false);
boolean validation = false;
boolean validationXsd = false;
if (EldDriver.LANGUAGE_NAME.equals(elementContext.getLanguage().getLanguageName())) {
validation = false; //TODO: elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD);
validationXsd = false; //elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD_XSD);
} else {
validation = getPropertyConfig().getPropertyBoolean(DefaultX4OReader.VALIDATION_INPUT_DOC);
validationXsd = getPropertyConfig().getPropertyBoolean(DefaultX4OReader.VALIDATION_INPUT_SCHEMA);
}
if (validation) {
saxParserFeatures.put("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors.
saxParserFeatures.put("http://apache.org/xml/features/validation/schema", true); // Insert an XML Schema validator into the pipeline.
} else {
saxParserFeatures.put("http://xml.org/sax/features/validation", false);
saxParserFeatures.put("http://apache.org/xml/features/validation/schema", false);
}
if (validation && validationXsd) {
saxParserFeatures.put("http://apache.org/xml/features/validation/schema-full-checking", true); // Enable validation of the schema grammar itself for errors.
} else {
saxParserFeatures.put("http://apache.org/xml/features/validation/schema-full-checking", false); // Disable validation of the schema grammar itself for errors.
}
return saxParserFeatures;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeaturesOptional(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Boolean> getSAXParserFeaturesOptional(X4OLanguageContext elementContext) {
Map<String,Boolean> saxParserFeatures = new HashMap<String,Boolean>(20);
// Make Sax Impl more strict.
saxParserFeatures.put("http://apache.org/xml/features/disallow-doctype-decl", true); // Throws error if document contains a DOCTYPE declaration.
saxParserFeatures.put("http://apache.org/xml/features/validation/schema/normalized-value", true); // Expose normalized values for attributes and elements.
saxParserFeatures.put("http://apache.org/xml/features/validation/warn-on-duplicate-attdef", true); // Report a warning when a duplicate attribute is re-declared.
saxParserFeatures.put("http://apache.org/xml/features/warn-on-duplicate-entitydef", true); // Report a warning for duplicate entity declaration.
saxParserFeatures.put("http://apache.org/xml/features/validation/dynamic", false); // Validation is determined by the state of the validation feature.
saxParserFeatures.put("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); // Do not use the default DTD grammer
saxParserFeatures.put("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); // Ignore the external DTD completely.
// need newer version
//saxParserFeatures.put("http://apache.org/xml/features/standard-uri-conformant", true); // Requires that a URI has to be provided where a URI is expected.
//saxParserFeatures.put("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", true); // Report a warning if an element referenced in a content model is not declared.
//saxParserFeatures.put("http://apache.org/xml/features/validation/balance-syntax-trees", false); // No optimize DTD content models.
//saxParserFeatures.put("http://apache.org/xml/features/validation/unparsed-entity-checking", false); // Do not check that each value of type ENTITY in DTD.
return saxParserFeatures;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeaturesRequired(org.x4o.xml.lang.X4OLanguageContext)
*/
public List<String> getSAXParserFeaturesRequired(X4OLanguageContext elementContext) {
List<String> result = new ArrayList<String>(5);
result.add("http://xml.org/sax/features/use-attributes2"); // Attributes objects passed by the parser are ext.Attributes2 interface.
result.add("http://xml.org/sax/features/use-locator2"); // Locator objects passed by the parser are org.xml.sax.ext.Locator2 interface.
result.add("http://xml.org/sax/features/xml-1.1"); // The parser supports both XML 1.0 and XML 1.1.
return result;
}
} }

View file

@ -44,7 +44,6 @@ import org.x4o.xml.io.sax.ext.ContentWriter;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageConfiguration; import org.x4o.xml.lang.X4OLanguageConfiguration;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.x4o.xml.lang.phase.X4OPhase; import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseException; import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseListener; import org.x4o.xml.lang.phase.X4OPhaseListener;
@ -114,6 +113,7 @@ public class X4ODebugWriter {
} }
} }
/*
public void debugLanguageProperties(X4OLanguageContext ec) throws ElementException { public void debugLanguageProperties(X4OLanguageContext ec) throws ElementException {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
@ -134,6 +134,7 @@ public class X4ODebugWriter {
throw new ElementException(e); throw new ElementException(e);
} }
} }
*/
public void debugLanguageDefaultClasses(X4OLanguageContext ec) throws ElementException { public void debugLanguageDefaultClasses(X4OLanguageContext ec) throws ElementException {
try { try {
@ -428,7 +429,7 @@ public class X4ODebugWriter {
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguage().getLanguageName()); atts.addAttribute ("", "language", "", "", elementLanguage.getLanguage().getLanguageName());
atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguage().getLanguageVersion()); atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguage().getLanguageVersion());
atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+""); atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+"");
atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentPhase().getId()); atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getPhaseCurrent().getId());
contentWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts); contentWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
contentWriter.endElement(DEBUG_URI, "printElementLanguage", ""); contentWriter.endElement(DEBUG_URI, "printElementLanguage", "");
} }

View file

@ -31,10 +31,11 @@ import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -55,21 +56,21 @@ public class X4OEntityResolver implements EntityResolver {
private Logger logger = null; private Logger logger = null;
private URL basePath = null; private URL basePath = null;
private X4OLanguageContext elementContext = null;
private Map<String,String> schemaResources = null; private Map<String,String> schemaResources = null;
private Map<String,String> schemaPathResources = null; private Map<String,String> schemaPathResources = null;
private final PropertyConfig propertyConfig;
/** /**
* Creates an X4OEntityResolver for a language. * Creates an X4OEntityResolver for a language.
* @param elementContext The x4o language to resolve entities for. * @param elementContext The x4o language to resolve entities for.
*/ */
public X4OEntityResolver(X4OLanguageContext elementContext) { public X4OEntityResolver(X4OLanguageContext elementContext,PropertyConfig propertyConfig) {
if (elementContext==null) { if (elementContext==null) {
throw new NullPointerException("Can't provide entities with null elementContext."); throw new NullPointerException("Can't provide entities with null elementContext.");
} }
this.logger=Logger.getLogger(X4OEntityResolver.class.getName()); this.logger=Logger.getLogger(X4OEntityResolver.class.getName());
this.elementContext=elementContext; this.propertyConfig=propertyConfig;
this.basePath=(URL)elementContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_BASE_PATH); this.basePath=(URL)propertyConfig.getProperty(DefaultX4OReader.INPUT_BASE_PATH);
this.schemaResources=new HashMap<String,String>(20); this.schemaResources=new HashMap<String,String>(20);
this.schemaPathResources=new HashMap<String,String>(20); this.schemaPathResources=new HashMap<String,String>(20);
for (X4OLanguageModule mod:elementContext.getLanguage().getLanguageModules()) { for (X4OLanguageModule mod:elementContext.getLanguage().getLanguageModules()) {
@ -111,7 +112,7 @@ public class X4OEntityResolver implements EntityResolver {
logger.finer("Fetch sysId: "+systemId+" pubId: "+publicId); logger.finer("Fetch sysId: "+systemId+" pubId: "+publicId);
// Check if other resolver has resource // Check if other resolver has resource
EntityResolver resolver = (EntityResolver)elementContext.getLanguageProperty(X4OLanguageProperty.READER_ENTITY_RESOLVER); EntityResolver resolver = (EntityResolver)propertyConfig.getProperty(DefaultX4OReader.SAX_ENTITY_RESOLVER);
if (resolver!=null) { if (resolver!=null) {
InputSource result = resolver.resolveEntity(publicId, systemId); InputSource result = resolver.resolveEntity(publicId, systemId);
if (result!=null) { if (result!=null) {
@ -121,7 +122,7 @@ public class X4OEntityResolver implements EntityResolver {
// Check if we have it on user defined schema base path // Check if we have it on user defined schema base path
if (schemaPathResources.containsKey(systemId)) { if (schemaPathResources.containsKey(systemId)) {
File schemaBasePath = (File)elementContext.getLanguageProperty(X4OLanguageProperty.READER_VALIDATION_SCHEMA_PATH); File schemaBasePath = (File)propertyConfig.getProperty(DefaultX4OReader.VALIDATION_SCHEMA_PATH);
if (schemaBasePath!=null && schemaBasePath.exists()) { if (schemaBasePath!=null && schemaBasePath.exists()) {
String schemeResource = schemaResources.get(systemId); String schemeResource = schemaResources.get(systemId);
File schemaFile = new File(schemaBasePath.getAbsolutePath()+File.separatorChar+schemeResource); File schemaFile = new File(schemaBasePath.getAbsolutePath()+File.separatorChar+schemeResource);

View file

@ -23,8 +23,9 @@
package org.x4o.xml.io.sax; package org.x4o.xml.io.sax;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.ErrorHandler; import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
@ -44,12 +45,12 @@ public class X4OErrorHandler implements ErrorHandler {
* Construct a new SAXErrorPrinter * Construct a new SAXErrorPrinter
* @param languageContext The language to get errors to. * @param languageContext The language to get errors to.
*/ */
public X4OErrorHandler(X4OLanguageContext languageContext) { public X4OErrorHandler(X4OLanguageContext languageContext,PropertyConfig propertyConfig) {
if (languageContext==null) { if (languageContext==null) {
throw new NullPointerException("Can't debug and proxy errors with null languageContext."); throw new NullPointerException("Can't debug and proxy errors with null languageContext.");
} }
this.languageContext=languageContext; this.languageContext=languageContext;
this.errorHandler=(ErrorHandler)languageContext.getLanguageProperty(X4OLanguageProperty.READER_ERROR_HANDLER); this.errorHandler=(ErrorHandler)propertyConfig.getProperty(DefaultX4OReader.SAX_ERROR_HANDLER);
} }
/** /**

View file

@ -35,8 +35,8 @@ import org.xml.sax.SAXException;
*/ */
public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter { public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter {
public AbstractContentWriter(Writer out, String encoding,String charNewLine, String charTab) { public AbstractContentWriter(Writer out) {
super(out, encoding, charNewLine, charTab); super(out);
} }
/** /**

View file

@ -32,6 +32,7 @@ import java.util.Set;
import java.util.Stack; import java.util.Stack;
import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.XMLConstants;
import org.x4o.xml.io.sax.ext.PropertyConfig.PropertyConfigItem;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.Locator; import org.xml.sax.Locator;
@ -47,9 +48,7 @@ import org.xml.sax.helpers.AttributesImpl;
public class AbstractContentWriterHandler implements ContentHandler { public class AbstractContentWriterHandler implements ContentHandler {
protected final Attributes EMPTY_ATTRIBUTES = new AttributesImpl(); protected final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
protected String encoding = null; private final PropertyConfig propertyConfig;
private String charNewline = null;
private String charTab = null;
private Writer out = null; private Writer out = null;
private int indent = 0; private int indent = 0;
private Map<String,String> prefixMapping = null; private Map<String,String> prefixMapping = null;
@ -59,38 +58,41 @@ public class AbstractContentWriterHandler implements ContentHandler {
private String lastElement = null; private String lastElement = null;
private Stack<String> elements = null; private Stack<String> elements = null;
private final static String PROPERTY_CONTEXT_PREFIX = PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_WRITER_XML;
private final static String PROPERTY_ENCODING = "output/encoding";
private final static String PROPERTY_CHAR_TAB = "output/charTab";
private final static String PROPERTY_CHAR_NEWLINE = "output/newLine";
public final static PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+PROPERTY_ENCODING;
public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX+PROPERTY_CHAR_TAB;
public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX+PROPERTY_CHAR_NEWLINE;
static {
DEFAULT_PROPERTY_CONFIG = new PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX,
new PropertyConfigItem(PROPERTY_ENCODING,String.class,XMLConstants.XML_DEFAULT_ENCODING),
new PropertyConfigItem(PROPERTY_CHAR_TAB,String.class,XMLConstants.CHAR_TAB+""),
new PropertyConfigItem(PROPERTY_CHAR_NEWLINE,String.class,XMLConstants.CHAR_NEWLINE+"")
);
}
/** /**
* Creates XmlWriter which prints to the Writer interface. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public AbstractContentWriterHandler(Writer out,String encoding,String charNewLine,String charTab) { public AbstractContentWriterHandler(Writer out) {
if (out==null) { if (out==null) {
throw new NullPointerException("Can't write on null writer."); throw new NullPointerException("Can't write on null writer.");
} }
if (encoding==null) {
encoding = XMLConstants.XML_DEFAULT_ENCODING;
}
if (charNewLine==null) {
charNewLine = XMLConstants.CHAR_NEWLINE+"";
}
if (charTab==null) {
charTab = XMLConstants.CHAR_TAB+"";
}
this.out = out; this.out = out;
this.encoding = encoding;
this.charNewline = charNewLine;
this.charTab = charTab;
prefixMapping = new HashMap<String,String>(15); prefixMapping = new HashMap<String,String>(15);
printedMappings = new ArrayList<String>(15); printedMappings = new ArrayList<String>(15);
elements = new Stack<String>(); elements = new Stack<String>();
/* propertyConfig = new PropertyConfig(DEFAULT_PROPERTY_CONFIG,PROPERTY_CONTEXT_PREFIX);
ContentConfig conf = new ContentConfig( }
new ContentConfigItem("writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
new ContentConfigItem("content/writer/output/charTab",String.class) public PropertyConfig getPropertyConfig() {
); return propertyConfig;
conf.getPropertyString("");
*/
} }
// TODO: check location of this. (add to api?) // TODO: check location of this. (add to api?)
@ -114,7 +116,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
*/ */
public void startDocument() throws SAXException { public void startDocument() throws SAXException {
indent = 0; indent = 0;
write(XMLConstants.getDocumentDeclaration(encoding)); write(XMLConstants.getDocumentDeclaration(getPropertyConfig().getPropertyString(OUTPUT_ENCODING)));
} }
/** /**
@ -143,9 +145,9 @@ public class AbstractContentWriterHandler implements ContentHandler {
} }
autoCloseStartElement(); autoCloseStartElement();
startElement = new StringBuffer(200); startElement = new StringBuffer(200);
startElement.append(charNewline); startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
startElement.append(charTab); startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
} }
startElement.append(XMLConstants.TAG_OPEN); startElement.append(XMLConstants.TAG_OPEN);
@ -208,7 +210,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
printedMappings.add(uri2); printedMappings.add(uri2);
if (first) { if (first) {
startElement.append(charNewline); startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
first = false; first = false;
} }
@ -221,7 +223,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
startElement.append("=\""); startElement.append("=\"");
startElement.append(uri2); startElement.append(uri2);
startElement.append('"'); startElement.append('"');
startElement.append(charNewline); startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
} }
} }
} }
@ -251,7 +253,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
if (printNewLine) { if (printNewLine) {
startElement.append(XMLConstants.CHAR_NEWLINE); startElement.append(XMLConstants.CHAR_NEWLINE);
for (int ii = 0; ii < indent+1; ii++) { for (int ii = 0; ii < indent+1; ii++) {
startElement.append(charTab); startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
} }
} }
} }
@ -281,7 +283,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
indent--; indent--;
if (printReturn || !localName.equals(lastElement)) { if (printReturn || !localName.equals(lastElement)) {
write(charNewline); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
writeIndent(); writeIndent();
} else { } else {
printReturn = true; printReturn = true;
@ -433,7 +435,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
throw new SAXException("Processing instruction data is invalid char; '"+data+"'"); throw new SAXException("Processing instruction data is invalid char; '"+data+"'");
} }
autoCloseStartElement(); autoCloseStartElement();
write(charNewline); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
writeIndent(); writeIndent();
write(XMLConstants.PROCESS_START); write(XMLConstants.PROCESS_START);
write(target); write(target);
@ -487,11 +489,11 @@ public class AbstractContentWriterHandler implements ContentHandler {
} }
autoCloseStartElement(); autoCloseStartElement();
checkPrintedReturn(text); checkPrintedReturn(text);
write(charNewline); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
writeIndent(); writeIndent();
write(XMLConstants.COMMENT_START); write(XMLConstants.COMMENT_START);
write(" "); write(" ");
write(XMLConstants.escapeCharactersComment(text,charTab,indent)); write(XMLConstants.escapeCharactersComment(text,getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB),indent));
write(" "); write(" ");
write(XMLConstants.COMMENT_END); write(XMLConstants.COMMENT_END);
printReturn = true; printReturn = true;
@ -528,7 +530,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
*/ */
private void writeIndent() throws SAXException { private void writeIndent() throws SAXException {
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
write(charTab); write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
} }
} }

View file

@ -42,8 +42,8 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
* Creates XmlWriter which prints to the Writer interface. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public AbstractContentWriterLexical(Writer out,String encoding,String charNewLine,String charTab) { public AbstractContentWriterLexical(Writer out) {
super(out, encoding, charNewLine, charTab); super(out);
} }
/** /**

View file

@ -1,158 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.io.sax.ext;
import java.util.HashMap;
import java.util.Map;
/**
* ContentConfig Defines checked config options.
*
* @author Willem Cazander
* @version 1.0 May 1, 2013
*/
public final class ContentConfig {
private final ContentConfigItem[] items;
private final Map<String,Integer> itemKeys;
public ContentConfig(ContentConfigItem...items) {
this.items=items;
itemKeys = new HashMap<String,Integer>(items.length);
for (int i=0;i<items.length;i++) {
ContentConfigItem item = items[i];
itemKeys.put(item.getKey(),i);
}
}
public static final class ContentConfigItem {
private String key = null;
private Class<?> valueType = null;
private Object defaultValue = null;
private Object value = null;
public ContentConfigItem(String key,Class<?> valueType) {
this(key,valueType,null);
}
public ContentConfigItem(String key,Class<?> valueType,Object defaultValue) {
setKey(key);
setValueType(valueType);
setDefaultValue(defaultValue);
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return the valueType
*/
public Class<?> getValueType() {
return valueType;
}
/**
* @param valueType the valueType to set
*/
public void setValueType(Class<?> valueType) {
this.valueType = valueType;
}
/**
* @return the defaultValue
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* @param defaultValue the defaultValue to set
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
/**
* @return the value
*/
public Object getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(Object value) {
this.value = value;
}
}
private final ContentConfigItem getContentConfigItem(String key) {
Integer keyIdx = itemKeys.get(key);
if (keyIdx==null) {
throw new IllegalArgumentException("Could not find config item for: "+key);
}
ContentConfigItem item = items[keyIdx];
return item;
}
public final void setProperty(String key,Object value) {
ContentConfigItem item = getContentConfigItem(key);
item.setValue(value);
}
public final Object getProperty(String key) {
ContentConfigItem item = getContentConfigItem(key);
return item.getValue();
}
public final boolean getPropertyBoolean(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof Boolean) {
return (Boolean)value;
}
return (Boolean)item.getDefaultValue();
}
public final int getPropertyInteger(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof Integer) {
return (Integer)value;
}
return (Integer)item.getDefaultValue();
}
public final String getPropertyString(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof String) {
return (String)value;
}
return (String)item.getDefaultValue();
}
}

View file

@ -36,8 +36,8 @@ import org.xml.sax.helpers.AttributesImpl;
*/ */
public class ContentWriterHtml extends ContentWriterXmlTag<ContentWriterHtml.Tag> { public class ContentWriterHtml extends ContentWriterXmlTag<ContentWriterHtml.Tag> {
public ContentWriterHtml(Writer out,String encoding,String charNewLine,String charTab) { public ContentWriterHtml(Writer out,String encoding) {
super(out,encoding,charNewLine,charTab); super(out,encoding);
} }
public void printDocType(DocType doc) throws SAXException { public void printDocType(DocType doc) throws SAXException {
@ -69,7 +69,7 @@ public class ContentWriterHtml extends ContentWriterXmlTag<ContentWriterHtml.Tag
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "http-equiv", "", "", "Content-Type"); atts.addAttribute ("", "http-equiv", "", "", "Content-Type");
atts.addAttribute ("", "content", "", "", "text/html"); atts.addAttribute ("", "content", "", "", "text/html");
atts.addAttribute ("", "charset", "", "", this.encoding); atts.addAttribute ("", "charset", "", "", getPropertyConfig().getPropertyString(OUTPUT_ENCODING));
startElementEnd("", "meta", "", atts); startElementEnd("", "meta", "", atts);
} }

View file

@ -37,29 +37,13 @@ import org.x4o.xml.io.XMLConstants;
*/ */
public class ContentWriterXml extends AbstractContentWriter { public class ContentWriterXml extends AbstractContentWriter {
/**
* Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to.
*/
public ContentWriterXml(Writer out,String encoding,String charNewLine,String charTab) {
super(out, encoding, charNewLine, charTab);
}
/** /**
* Creates XmlWriter which prints to the Writer interface. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public ContentWriterXml(Writer out,String encoding) { public ContentWriterXml(Writer out,String encoding) {
this(out,encoding,null,null); super(out);
} getPropertyConfig().setProperty(OUTPUT_ENCODING, encoding);
/**
* Creates XmlWriter which prints to the OutputStream interface.
* @param out The OutputStream to write to.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
*/
public ContentWriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
this(new OutputStreamWriter(out, encoding),encoding);
} }
/** /**
@ -83,11 +67,9 @@ public class ContentWriterXml extends AbstractContentWriter {
* Creates XmlWriter which prints to the OutputStream interface. * Creates XmlWriter which prints to the OutputStream interface.
* @param out The OutputStream to write to. * @param out The OutputStream to write to.
* @param encoding The OutputStream encoding. * @param encoding The OutputStream encoding.
* @param charNewLine The newline char.
* @param charTab The tab char.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed. * @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
*/ */
public ContentWriterXml(OutputStream out,String encoding,String charNewLine,String charTab) throws UnsupportedEncodingException { public ContentWriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
this(new OutputStreamWriter(out, encoding),encoding,charNewLine,charTab); this(new OutputStreamWriter(out, encoding),encoding);
} }
} }

View file

@ -35,8 +35,8 @@ import org.xml.sax.SAXException;
*/ */
public class ContentWriterXmlTag<T extends Enum<?>> extends ContentWriterXml implements ContentWriterTag<T> { public class ContentWriterXmlTag<T extends Enum<?>> extends ContentWriterXml implements ContentWriterTag<T> {
public ContentWriterXmlTag(Writer out,String encoding,String charNewLine,String charTab) { public ContentWriterXmlTag(Writer out,String encoding) {
super(out, encoding, charNewLine, charTab); super(out, encoding);
} }
public String getTagNamespaceUri() { public String getTagNamespaceUri() {

View file

@ -36,8 +36,8 @@ import org.xml.sax.helpers.AttributesImpl;
*/ */
public class ContentWriterXsd extends ContentWriterXmlTag<ContentWriterXsd.Tag> { public class ContentWriterXsd extends ContentWriterXmlTag<ContentWriterXsd.Tag> {
public ContentWriterXsd(Writer out,String encoding,String charNewLine,String charTab) { public ContentWriterXsd(Writer out,String encoding) {
super(out,encoding,charNewLine,charTab); super(out,encoding);
} }
public String getTagNamespaceUri() { public String getTagNamespaceUri() {

View file

@ -0,0 +1,248 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.io.sax.ext;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* ContentConfig Defines checked config options.
*
* @author Willem Cazander
* @version 1.0 May 1, 2013
*/
public final class PropertyConfig {
private final Map<String,PropertyConfigItem> items;
private final boolean readOnly;
// TODO: move to ?
public final static String X4O_PROPERTIES_PREFIX = "http://language.x4o.org/xml/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/";
public final static String X4O_PROPERTIES_WRITER_XML = "writer/xml/";
public final static String X4O_PROPERTIES_WRITER_XSD = "writer/xsd/";
public final static String X4O_PROPERTIES_WRITER_DTD = "writer/dtd/";
public final static String X4O_PROPERTIES_WRITER_HTML = "writer/html/";
public PropertyConfig(String prefix,PropertyConfigItem...items) {
this(false,null,prefix,items);
}
public PropertyConfig(PropertyConfig parentPropertyConfig,String prefix,PropertyConfigItem...items) {
this(false,parentPropertyConfig,prefix,items);
}
public PropertyConfig(boolean readOnly,PropertyConfig parentPropertyConfig,String prefix,PropertyConfigItem...itemConfig) {
if (prefix==null) {
throw new NullPointerException("Can't create PropertyConfig with null prefix.");
}
this.readOnly=readOnly;
Map<String,PropertyConfigItem> fillItems = new HashMap<String,PropertyConfigItem>(itemConfig.length);
fillPropertyConfigItems(fillItems,appendSlashIfMissing(prefix),itemConfig);
copyParentPropertyConfig(fillItems,parentPropertyConfig);
if (fillItems.isEmpty()) {
throw new IllegalArgumentException("Can't create PropertyConfig with zero PropertyConfigItems.");
}
for (String key:fillItems.keySet()) {
fillItems.put(key,fillItems.get(key).clone());
}
items = Collections.unmodifiableMap(fillItems);
}
private final String appendSlashIfMissing(String prefix) {
if (prefix.endsWith("/")==false) {
prefix += "/";
}
return prefix;
}
private final void fillPropertyConfigItems(Map<String,PropertyConfigItem> fillItems,String prefix,PropertyConfigItem...itemConfig) {
for (int i=0;i<itemConfig.length;i++) {
PropertyConfigItem item = itemConfig[i];
fillItems.put(prefix+item.getValueKey(),item);
}
}
private final void copyParentPropertyConfig(Map<String,PropertyConfigItem> fillItems,PropertyConfig parentPropertyConfig) {
if (parentPropertyConfig==null) {
return;
}
for (String key:parentPropertyConfig.getPropertyKeys()) {
fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key));
}
}
public static final class PropertyConfigItem implements Cloneable {
private final String valueKey;
private final Class<?> valueType;
private final Object valueDefault;
private final boolean valueLock; // TODO: check if possible
private Object value = null;
public PropertyConfigItem(String valueKey,Class<?> valueType) {
this(valueKey,valueType,null,false);
}
public PropertyConfigItem(String valueKey,Class<?> valueType,Object valueDefault) {
this(valueKey,valueType,valueDefault,false);
}
private PropertyConfigItem(String valueKey,Class<?> valueType,Object valueDefault,boolean valueLock) {
this.valueKey=valueKey;
this.valueType=valueType;
this.valueLock=valueLock;
this.valueDefault=valueDefault;
}
/**
* @return the value key.
*/
public String getValueKey() {
return valueKey;
}
/**
* @return the valueType
*/
public Class<?> getValueType() {
return valueType;
}
/**
* @return the value default.
*/
public Object getValueDefault() {
return valueDefault;
}
/**
* @return the valueLock
*/
public boolean isValueLock() {
return valueLock;
}
/**
* @return the value
*/
public Object getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(Object value) {
this.value = value;
}
/**
* @see java.lang.Object#clone()
*/
@Override
protected PropertyConfigItem clone() {
PropertyConfigItem clone = new PropertyConfigItem(valueKey,valueType,valueDefault,valueLock);
clone.setValue(getValue());
return clone;
}
}
private final PropertyConfigItem getPropertyConfigItem(String key) {
if (key==null) {
throw new NullPointerException("Can't search with null key.");
}
PropertyConfigItem item = items.get(key);
if (item==null) {
throw new IllegalArgumentException("No config item found for key: "+key);
}
return item;
}
public final Collection<String> getPropertyKeys() {
return Collections.unmodifiableCollection(items.keySet());
}
public final void setProperty(String key,Object value) {
if (readOnly) {
throw new IllegalStateException("This property is readonly for key:"+key);
}
PropertyConfigItem item = getPropertyConfigItem(key);
item.setValue(value);
}
public final Object getProperty(String key) {
PropertyConfigItem item = getPropertyConfigItem(key);
Object value = item.getValue();
if (value==null) {
value = item.getValueDefault();
}
return value;
}
public final Boolean getPropertyBoolean(String key) {
Object value = getProperty(key);
if (value instanceof Boolean) {
return (Boolean)value;
}
if (value==null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
}
public final Integer getPropertyInteger(String key) {
Object value = getProperty(key);
if (value instanceof Integer) {
return (Integer)value;
}
if (value==null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
}
public final String getPropertyString(String key) {
Object value = getProperty(key);
if (value instanceof String) {
return (String)value;
}
if (value==null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
}
public final void copyParentProperties(PropertyConfig config) {
for (String key:getPropertyKeys()) {
Object value = config.getProperty(key);
if (value==null) {
continue;
}
setProperty(key, value);
}
}
}

View file

@ -56,13 +56,10 @@ public abstract class AbstractX4OLanguageConfiguration implements X4OLanguageCon
private Class<?> defaultLanguageLoader = null; private Class<?> defaultLanguageLoader = null;
private Class<?> defaultExpressionLanguageContext = null; private Class<?> defaultExpressionLanguageContext = null;
private Map<String,Object> globalProperties = null;
/** /**
* Default constructor. * Default constructor.
*/ */
public AbstractX4OLanguageConfiguration() { public AbstractX4OLanguageConfiguration() {
globalProperties = new HashMap<String,Object>(10);
} }
/** /**
@ -328,25 +325,4 @@ public abstract class AbstractX4OLanguageConfiguration implements X4OLanguageCon
Class<?> defaultExpressionLanguageContext) { Class<?> defaultExpressionLanguageContext) {
this.defaultExpressionLanguageContext = defaultExpressionLanguageContext; this.defaultExpressionLanguageContext = defaultExpressionLanguageContext;
} }
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getGlobalPropertyKeys()
*/
public Collection<String> getGlobalPropertyKeys() {
return globalProperties.keySet();
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getGlobalProperty(java.lang.String)
*/
public Object getGlobalProperty(String key) {
return globalProperties.get(key);
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfigurationLocal#setGlobalProperty(java.lang.String, java.lang.Object)
*/
public void setGlobalProperty(String key, Object value) {
globalProperties.put(key,value);
}
} }

View file

@ -22,6 +22,8 @@
*/ */
package org.x4o.xml.lang; package org.x4o.xml.lang;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -49,12 +51,13 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
private ELContext eLContext = null; private ELContext eLContext = null;
private ElementAttributeValueParser elementAttributeValueParser = null; private ElementAttributeValueParser elementAttributeValueParser = null;
private ElementObjectPropertyValue elementObjectPropertyValue = null; private ElementObjectPropertyValue elementObjectPropertyValue = null;
private X4OPhase currentX4OPhase = null;
private Map<Element, X4OPhase> dirtyElements = null; private Map<Element, X4OPhase> dirtyElements = null;
private Element rootElement = null; private Element rootElement = null;
private X4ODebugWriter debugWriter; private X4ODebugWriter debugWriter = null;
private Map<String,Object> languageProperties; private X4OPhase phaseCurrent = null;
private String phaseStop = null;
private List<String> phaseSkip = null;
/** /**
* Creates a new empty language context. * Creates a new empty language context.
*/ */
@ -66,11 +69,9 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
logger.finest("Creating new ParsingContext"); logger.finest("Creating new ParsingContext");
this.language=language; this.language=language;
dirtyElements = new HashMap<Element, X4OPhase>(40); dirtyElements = new HashMap<Element, X4OPhase>(40);
languageProperties = new HashMap<String,Object>(20); phaseSkip = new ArrayList<String>(5);
languageProperties.put(X4OLanguageProperty.LANGUAGE_NAME.toUri(), language.getLanguageName());
languageProperties.put(X4OLanguageProperty.LANGUAGE_VERSION.toUri(), language.getLanguageVersion());
} }
public X4OLanguage getLanguage() { public X4OLanguage getLanguage() {
return language; return language;
} }
@ -81,7 +82,7 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
public ELContext getExpressionLanguageContext() { public ELContext getExpressionLanguageContext() {
return eLContext; return eLContext;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setExpressionLanguageContext(javax.el.ELContext) * @see org.x4o.xml.lang.X4OLanguageContextLocal#setExpressionLanguageContext(javax.el.ELContext)
*/ */
@ -91,14 +92,14 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
} }
eLContext = context; eLContext = context;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#getExpressionLanguageFactory() * @see org.x4o.xml.lang.X4OLanguageContext#getExpressionLanguageFactory()
*/ */
public ExpressionFactory getExpressionLanguageFactory() { public ExpressionFactory getExpressionLanguageFactory() {
return expressionFactory; return expressionFactory;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setExpressionLanguageFactory(javax.el.ExpressionFactory) * @see org.x4o.xml.lang.X4OLanguageContextLocal#setExpressionLanguageFactory(javax.el.ExpressionFactory)
*/ */
@ -115,7 +116,7 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
public ElementAttributeValueParser getElementAttributeValueParser() { public ElementAttributeValueParser getElementAttributeValueParser() {
return elementAttributeValueParser; return elementAttributeValueParser;
} }
/** /**
* @param elementAttributeValueParser the elementAttributeValueParser to set * @param elementAttributeValueParser the elementAttributeValueParser to set
*/ */
@ -125,14 +126,14 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
} }
this.elementAttributeValueParser = elementAttributeValueParser; this.elementAttributeValueParser = elementAttributeValueParser;
} }
/** /**
* @return the elementObjectPropertyValue * @return the elementObjectPropertyValue
*/ */
public ElementObjectPropertyValue getElementObjectPropertyValue() { public ElementObjectPropertyValue getElementObjectPropertyValue() {
return elementObjectPropertyValue; return elementObjectPropertyValue;
} }
/** /**
* @param elementObjectPropertyValue the elementObjectPropertyValue to set * @param elementObjectPropertyValue the elementObjectPropertyValue to set
*/ */
@ -142,21 +143,7 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
} }
this.elementObjectPropertyValue = elementObjectPropertyValue; this.elementObjectPropertyValue = elementObjectPropertyValue;
} }
/**
* @see org.x4o.xml.lang.X4OLanguageContext#getCurrentPhase()
*/
public X4OPhase getCurrentPhase() {
return currentX4OPhase;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setCurrentPhase(org.x4o.xml.lang.phase.X4OPhase)
*/
public void setCurrentPhase(X4OPhase currentX4OPhase) {
this.currentX4OPhase = currentX4OPhase;
}
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#addDirtyElement(org.x4o.xml.element.Element, org.x4o.xml.lang.phase.X4OPhase) * @see org.x4o.xml.lang.X4OLanguageContext#addDirtyElement(org.x4o.xml.element.Element, org.x4o.xml.lang.phase.X4OPhase)
*/ */
@ -166,21 +153,21 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
} }
dirtyElements.put(element,phase); dirtyElements.put(element,phase);
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#getDirtyElements() * @see org.x4o.xml.lang.X4OLanguageContext#getDirtyElements()
*/ */
public Map<Element, X4OPhase> getDirtyElements() { public Map<Element, X4OPhase> getDirtyElements() {
return dirtyElements; return dirtyElements;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#getRootElement() * @see org.x4o.xml.lang.X4OLanguageContext#getRootElement()
*/ */
public Element getRootElement() { public Element getRootElement() {
return rootElement; return rootElement;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#setRootElement(org.x4o.xml.element.Element) * @see org.x4o.xml.lang.X4OLanguageContext#setRootElement(org.x4o.xml.element.Element)
*/ */
@ -188,86 +175,69 @@ public abstract class AbstractX4OLanguageContext implements X4OLanguageContextLo
if (element==null) { if (element==null) {
throw new NullPointerException("May not set rootElement to null"); throw new NullPointerException("May not set rootElement to null");
} }
// allowed for reusing this context in multiple parse sessions.
//if (rootElement!=null) {
// throw new IllegalStateException("Can't set rootElement when it is already set.");
//}
rootElement=element; rootElement=element;
} }
public Object getLanguageProperty(String key) {
return languageProperties.get(key);
}
public void setLanguageProperty(String key,Object value) {
languageProperties.put(key, value);
}
/**
*
*/
public Object getLanguageProperty(X4OLanguageProperty property) {
return getLanguageProperty(property.toUri());
}
/**
*
*/
public void setLanguageProperty(X4OLanguageProperty property, Object value) {
if (property.isValueValid(value)==false) {
throw new IllegalArgumentException("Now allowed to set value: "+value+" in property: "+property.name());
}
setLanguageProperty(property.toUri(), value);
}
/**
*
*/
public boolean getLanguagePropertyBoolean(X4OLanguageProperty property) {
Object value = getLanguageProperty(property);
if (value instanceof Boolean) {
return (Boolean)value;
}
return (Boolean)property.getDefaultValue();
}
/**
*
*/
public int getLanguagePropertyInteger(X4OLanguageProperty property) {
Object value = getLanguageProperty(property);
if (value instanceof Integer) {
return (Integer)value;
}
return (Integer)property.getDefaultValue();
}
public String getLanguagePropertyString(X4OLanguageProperty property) {
Object value = getLanguageProperty(property);
if (value instanceof String) {
return (String)value;
}
return (String)property.getDefaultValue();
}
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#getX4ODebugWriter() * @see org.x4o.xml.lang.X4OLanguageContext#getX4ODebugWriter()
*/ */
public X4ODebugWriter getX4ODebugWriter() { public X4ODebugWriter getX4ODebugWriter() {
return debugWriter; return debugWriter;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContext#hasX4ODebugWriter() * @see org.x4o.xml.lang.X4OLanguageContext#hasX4ODebugWriter()
*/ */
public boolean hasX4ODebugWriter() { public boolean hasX4ODebugWriter() {
return debugWriter!=null; return debugWriter!=null;
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setX4ODebugWriter(org.x4o.xml.io.sax.X4ODebugWriter) * @see org.x4o.xml.lang.X4OLanguageContextLocal#setX4ODebugWriter(org.x4o.xml.io.sax.X4ODebugWriter)
*/ */
public void setX4ODebugWriter(X4ODebugWriter debugWriter) { public void setX4ODebugWriter(X4ODebugWriter debugWriter) {
this.debugWriter=debugWriter; this.debugWriter=debugWriter;
} }
/**
* @see org.x4o.xml.lang.X4OLanguageContext#getPhaseCurrent()
*/
public X4OPhase getPhaseCurrent() {
return phaseCurrent;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setPhaseCurrent(org.x4o.xml.lang.phase.X4OPhase)
*/
public void setPhaseCurrent(X4OPhase phaseCurrent) {
this.phaseCurrent = phaseCurrent;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContext#getPhaseStop()
*/
public String getPhaseStop() {
return phaseStop;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContext#getPhaseSkip()
*/
public List<String> getPhaseSkip() {
return phaseSkip;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#setPhaseStop(java.lang.String)
*/
public void setPhaseStop(String phaseId) {
this.phaseStop=phaseId;
}
/**
* @see org.x4o.xml.lang.X4OLanguageContextLocal#addPhaseSkip(java.lang.String)
*/
public void addPhaseSkip(String phaseId) {
phaseSkip.add(phaseId);
}
} }

View file

@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.el.X4OExpressionFactory; import org.x4o.xml.el.X4OExpressionFactory;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeValueParser; import org.x4o.xml.element.ElementAttributeValueParser;
@ -119,8 +118,8 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
* @throws X4OPhaseException * @throws X4OPhaseException
* @see org.x4o.xml.lang.X4OLanguage#createLanguageContext(org.x4o.xml.X4ODriver) * @see org.x4o.xml.lang.X4OLanguage#createLanguageContext(org.x4o.xml.X4ODriver)
*/ */
public X4OLanguageContext createLanguageContext(X4ODriver<?> driver){ public X4OLanguageContext createLanguageContext() {
X4OLanguageContext result = buildElementLanguage(new DefaultX4OLanguageContext(this),driver); X4OLanguageContext result = buildElementLanguage(new DefaultX4OLanguageContext(this));
try { try {
getPhaseManager().runPhases(result, X4OPhaseType.INIT); getPhaseManager().runPhases(result, X4OPhaseType.INIT);
} catch (X4OPhaseException e) { } catch (X4OPhaseException e) {
@ -129,21 +128,17 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
return result; return result;
} }
protected X4OLanguageContext buildElementLanguage(X4OLanguageContext languageContext,X4ODriver<?> driver) { protected X4OLanguageContext buildElementLanguage(X4OLanguageContext languageContext) {
if ((languageContext instanceof X4OLanguageContextLocal)==false) { if ((languageContext instanceof X4OLanguageContextLocal)==false) {
throw new RuntimeException("Can't init X4OLanguageContext which has not X4OLanguageContextLocal interface obj: "+languageContext); throw new RuntimeException("Can't init X4OLanguageContext which has not X4OLanguageContextLocal interface obj: "+languageContext);
} }
X4OLanguageContextLocal contextInit = (X4OLanguageContextLocal)languageContext; X4OLanguageContextLocal contextInit = (X4OLanguageContextLocal)languageContext;
for (String key:languageContext.getLanguage().getLanguageConfiguration().getGlobalPropertyKeys()) {
Object value = languageContext.getLanguage().getLanguageConfiguration().getGlobalProperty(key);
contextInit.setLanguageProperty(key, value);
}
try { try {
if (contextInit.getExpressionLanguageFactory()==null) { if (contextInit.getExpressionLanguageFactory()==null) {
contextInit.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory(contextInit)); contextInit.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory());
} }
if (contextInit.getExpressionLanguageContext()==null) { if (contextInit.getExpressionLanguageContext()==null) {
contextInit.setExpressionLanguageContext(X4OExpressionFactory.createELContext(contextInit)); contextInit.setExpressionLanguageContext(X4OExpressionFactory.createELContext(contextInit.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext()));
} }
if (contextInit.getElementAttributeValueParser()==null) { if (contextInit.getElementAttributeValueParser()==null) {
contextInit.setElementAttributeValueParser((ElementAttributeValueParser)X4OLanguageClassLoader.newInstance(getLanguageConfiguration().getDefaultElementAttributeValueParser())); contextInit.setElementAttributeValueParser((ElementAttributeValueParser)X4OLanguageClassLoader.newInstance(getLanguageConfiguration().getDefaultElementAttributeValueParser()));

View file

@ -25,13 +25,8 @@ package org.x4o.xml.lang;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.x4o.xml.el.X4OELContext; import org.x4o.xml.el.X4OELContext;
import org.x4o.xml.eld.EldDriver;
import org.x4o.xml.element.DefaultElement; import org.x4o.xml.element.DefaultElement;
import org.x4o.xml.element.DefaultElementAttributeValueParser; import org.x4o.xml.element.DefaultElementAttributeValueParser;
import org.x4o.xml.element.DefaultElementBodyCharacters; import org.x4o.xml.element.DefaultElementBodyCharacters;
@ -79,7 +74,7 @@ public class DefaultX4OLanguageConfiguration extends AbstractX4OLanguageConfigur
if (getDefaultLanguageLoader()==null) { setDefaultLanguageLoader( DefaultX4OLanguageLoader.class); } if (getDefaultLanguageLoader()==null) { setDefaultLanguageLoader( DefaultX4OLanguageLoader.class); }
if (getDefaultExpressionLanguageContext()==null) { setDefaultExpressionLanguageContext( X4OELContext.class); } if (getDefaultExpressionLanguageContext()==null) { setDefaultExpressionLanguageContext( X4OELContext.class); }
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageConfigurationLocal#createProxy() * @see org.x4o.xml.lang.X4OLanguageConfigurationLocal#createProxy()
*/ */
@ -103,106 +98,4 @@ public class DefaultX4OLanguageConfiguration extends AbstractX4OLanguageConfigur
}); });
return (X4OLanguageConfiguration)proxy; return (X4OLanguageConfiguration)proxy;
} }
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserProperties(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Object> getSAXParserProperties(X4OLanguageContext elementContext) {
Map<String,Object> saxParserProperties = new HashMap<String,Object>(1);
return saxParserProperties;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserPropertiesOptional(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Object> getSAXParserPropertiesOptional(X4OLanguageContext elementContext) {
Map<String,Object> saxParserProperties = new HashMap<String,Object>(1);
saxParserProperties.put("http://apache.org/xml/properties/input-buffer-size",elementContext.getLanguagePropertyInteger(X4OLanguageProperty.READER_BUFFER_SIZE)); // Increase buffer to 8KB
return saxParserProperties;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeatures(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Boolean> getSAXParserFeatures(X4OLanguageContext elementContext) {
// see example: http://xerces.apache.org/xerces2-j/features.html
Map<String,Boolean> saxParserFeatures = new HashMap<String,Boolean>(20);
// Tune Sax Parser
saxParserFeatures.put("http://xml.org/sax/features/namespaces", true); // Perform namespace processing
saxParserFeatures.put("http://xml.org/sax/features/use-entity-resolver2", true); // Use EntityResolver2 interface
saxParserFeatures.put("http://xml.org/sax/features/lexical-handler/parameter-entities", true); // Report parameter entities to a the LexicalHandler.
saxParserFeatures.put("http://xml.org/sax/features/xmlns-uris", false); // Namespace declaration attributes are reported as having no namespace.
saxParserFeatures.put("http://xml.org/sax/features/namespace-prefixes", false); // Do not report attributes used for Namespace declarations
saxParserFeatures.put("http://xml.org/sax/features/external-general-entities", false); // Never include the external general entries.
saxParserFeatures.put("http://xml.org/sax/features/external-parameter-entities", false); // Never include the external parameter or DTD subset.
saxParserFeatures.put("http://apache.org/xml/features/xinclude", true); // Perform XInclude processing
saxParserFeatures.put("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
saxParserFeatures.put("http://apache.org/xml/features/xinclude/fixup-language", false);
boolean validation = false;
boolean validationXsd = false;
if (EldDriver.LANGUAGE_NAME.equals(elementContext.getLanguage().getLanguageName())) {
validation = false; //TODO: elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD);
validationXsd = false; //elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD_XSD);
} else {
validation = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.READER_VALIDATION_INPUT);
validationXsd = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.READER_VALIDATION_INPUT_XSD);
}
if (validation) {
saxParserFeatures.put("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors.
saxParserFeatures.put("http://apache.org/xml/features/validation/schema", true); // Insert an XML Schema validator into the pipeline.
} else {
saxParserFeatures.put("http://xml.org/sax/features/validation", false);
saxParserFeatures.put("http://apache.org/xml/features/validation/schema", false);
}
if (validation && validationXsd) {
saxParserFeatures.put("http://apache.org/xml/features/validation/schema-full-checking", true); // Enable validation of the schema grammar itself for errors.
} else {
saxParserFeatures.put("http://apache.org/xml/features/validation/schema-full-checking", false); // Disable validation of the schema grammar itself for errors.
}
return saxParserFeatures;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeaturesOptional(org.x4o.xml.lang.X4OLanguageContext)
*/
public Map<String, Boolean> getSAXParserFeaturesOptional(X4OLanguageContext elementContext) {
Map<String,Boolean> saxParserFeatures = new HashMap<String,Boolean>(20);
// Make Sax Impl more strict.
saxParserFeatures.put("http://apache.org/xml/features/disallow-doctype-decl", true); // Throws error if document contains a DOCTYPE declaration.
saxParserFeatures.put("http://apache.org/xml/features/validation/schema/normalized-value", true); // Expose normalized values for attributes and elements.
saxParserFeatures.put("http://apache.org/xml/features/validation/warn-on-duplicate-attdef", true); // Report a warning when a duplicate attribute is re-declared.
saxParserFeatures.put("http://apache.org/xml/features/warn-on-duplicate-entitydef", true); // Report a warning for duplicate entity declaration.
saxParserFeatures.put("http://apache.org/xml/features/validation/dynamic", false); // Validation is determined by the state of the validation feature.
saxParserFeatures.put("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); // Do not use the default DTD grammer
saxParserFeatures.put("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); // Ignore the external DTD completely.
// need newer version
//saxParserFeatures.put("http://apache.org/xml/features/standard-uri-conformant", true); // Requires that a URI has to be provided where a URI is expected.
//saxParserFeatures.put("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", true); // Report a warning if an element referenced in a content model is not declared.
//saxParserFeatures.put("http://apache.org/xml/features/validation/balance-syntax-trees", false); // No optimize DTD content models.
//saxParserFeatures.put("http://apache.org/xml/features/validation/unparsed-entity-checking", false); // Do not check that each value of type ENTITY in DTD.
return saxParserFeatures;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getSAXParserFeaturesRequired(org.x4o.xml.lang.X4OLanguageContext)
*/
public List<String> getSAXParserFeaturesRequired(X4OLanguageContext elementContext) {
List<String> result = new ArrayList<String>(5);
result.add("http://xml.org/sax/features/use-attributes2"); // Attributes objects passed by the parser are ext.Attributes2 interface.
result.add("http://xml.org/sax/features/use-locator2"); // Locator objects passed by the parser are org.xml.sax.ext.Locator2 interface.
result.add("http://xml.org/sax/features/xml-1.1"); // The parser supports both XML 1.0 and XML 1.1.
return result;
}
} }

View file

@ -24,7 +24,6 @@ package org.x4o.xml.lang;
import java.util.List; import java.util.List;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementInterface;
@ -62,10 +61,9 @@ public interface X4OLanguage {
/** /**
* Creates and fills the initial element language used to store the language. * 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. * @return The newly created ElementLanguage.
*/ */
X4OLanguageContext createLanguageContext(X4ODriver<?> driver); X4OLanguageContext createLanguageContext();
/** /**
* Search language for object and create element for it. * Search language for object and create element for it.

View file

@ -22,10 +22,6 @@
*/ */
package org.x4o.xml.lang; package org.x4o.xml.lang;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* X4OLanguageConfiguration is base configuration of language used iin x4o parser. * X4OLanguageConfiguration is base configuration of language used iin x4o parser.
* *
@ -76,38 +72,9 @@ public interface X4OLanguageConfiguration {
* @return Returns the X4OLanguageLoader which loads languages into the element context. * @return Returns the X4OLanguageLoader which loads languages into the element context.
*/ */
Class<?> getDefaultLanguageLoader(); Class<?> getDefaultLanguageLoader();
/** /**
* @return Returns the Expression Language Context which holds the el objects. * @return Returns the Expression Language Context which holds the el objects.
*/ */
Class<?> getDefaultExpressionLanguageContext(); Class<?> getDefaultExpressionLanguageContext();
Collection<String> getGlobalPropertyKeys();
Object getGlobalProperty(String key);
void setGlobalProperty(String key,Object value);
/**
* @return Returns Map of SAX properties which are set.
*/
Map<String,Object> getSAXParserProperties(X4OLanguageContext elementContext);
/**
* @return Returns Map of SAX properties which are optional set.
*/
Map<String,Object> getSAXParserPropertiesOptional(X4OLanguageContext elementContext);
/**
* @return Returns Map of SAX features which are set on the xml parser.
*/
Map<String,Boolean> getSAXParserFeatures(X4OLanguageContext elementContext);
/**
* @return Returns Map of SAX features which are optional set.
*/
Map<String, Boolean> getSAXParserFeaturesOptional(X4OLanguageContext elementContext);
/**
* @return Returns List of SAX features which are required for xml parsing.
*/
List<String> getSAXParserFeaturesRequired(X4OLanguageContext elementContext);
} }

View file

@ -53,6 +53,4 @@ public interface X4OLanguageConfigurationLocal extends X4OLanguageConfiguration
void setDefaultLanguageVersionFilter(Class<?> value); void setDefaultLanguageVersionFilter(Class<?> value);
void setDefaultLanguageLoader(Class<?> value); void setDefaultLanguageLoader(Class<?> value);
void setDefaultExpressionLanguageContext(Class<?> value); void setDefaultExpressionLanguageContext(Class<?> value);
void setGlobalProperty(String key,Object value);
} }

View file

@ -22,6 +22,7 @@
*/ */
package org.x4o.xml.lang; package org.x4o.xml.lang;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.el.ELContext; import javax.el.ELContext;
@ -54,7 +55,7 @@ public interface X4OLanguageContext {
* @return Returns the ExpressionFactory. * @return Returns the ExpressionFactory.
*/ */
ExpressionFactory getExpressionLanguageFactory(); ExpressionFactory getExpressionLanguageFactory();
/** /**
* @return Returns the ElementAttributeValueParser. * @return Returns the ElementAttributeValueParser.
*/ */
@ -65,12 +66,6 @@ public interface X4OLanguageContext {
*/ */
ElementObjectPropertyValue getElementObjectPropertyValue(); ElementObjectPropertyValue getElementObjectPropertyValue();
/**
* Returns the current X4OPhase of the parser.
* @return Returns the current phase.
*/
X4OPhase getCurrentPhase();
/** /**
* Marks an (new) Element as dirty and run the phases from this start phase. * Marks an (new) Element as dirty and run the phases from this start phase.
* *
@ -108,12 +103,13 @@ public interface X4OLanguageContext {
*/ */
boolean hasX4ODebugWriter(); boolean hasX4ODebugWriter();
Object getLanguageProperty(String key); /**
void setLanguageProperty(String key,Object value); * Returns the current X4OPhase of the parser.
* @return Returns the current phase.
*/
X4OPhase getPhaseCurrent();
Object getLanguageProperty(X4OLanguageProperty property); public String getPhaseStop();
void setLanguageProperty(X4OLanguageProperty property,Object value);
boolean getLanguagePropertyBoolean(X4OLanguageProperty property); public List<String> getPhaseSkip();
int getLanguagePropertyInteger(X4OLanguageProperty property);
String getLanguagePropertyString(X4OLanguageProperty property);
} }

View file

@ -60,14 +60,18 @@ public interface X4OLanguageContextLocal extends X4OLanguageContext {
*/ */
void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue); void setElementObjectPropertyValue(ElementObjectPropertyValue elementObjectPropertyValue);
/**
* Sets the phase of the context.
* @param phase The current phase to set.
*/
void setCurrentPhase(X4OPhase phase);
/** /**
* @param debugWriter The debug writer to set * @param debugWriter The debug writer to set
*/ */
void setX4ODebugWriter(X4ODebugWriter debugWriter); void setX4ODebugWriter(X4ODebugWriter debugWriter);
/**
* Sets the phase of the context.
* @param phase The current phase to set.
*/
void setPhaseCurrent(X4OPhase phase);
void setPhaseStop(String phaseId);
void addPhaseSkip(String phaseId);
} }

View file

@ -1,318 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.lang;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.io.XMLConstants;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.ext.DefaultHandler2;
/**
* X4OLanguageProperty holds the language connection properties keys
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public enum X4OLanguageProperty {
/** Read-Only property returning the language we are working with. */
LANGUAGE_NAME(IO.GLOBAL,"language/name"),
/** Read-Only property returning the version of the language. */
LANGUAGE_VERSION(IO.GLOBAL,"language/version"),
/** The input stream to parse, note is skipped when source is set. */
READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */
READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** When set use this InputSource instance for parsing. */
READER_INPUT_SOURCE(IO.READER,"reader/input/source",InputSource.class),
/** Sets the system-id to the input source. */
READER_INPUT_SYSTEM_ID(IO.READER,"reader/input/system-id",String.class),
/** Sets the base path to resolve external input sources. */
READER_INPUT_BASE_PATH(IO.READER,"reader/input/base-path",URL.class),
/** SAX parser input buffer size: 512-16k defaults to 8k. */
READER_BUFFER_SIZE(IO.READER,"reader/buffer-size",Integer.class,4096*2),
/** When set it allows parsing of non-namespace aware documents. */
READER_EMPTY_NAMESPACE_URI(IO.READER,"reader/empty-namespace-uri"),
/** Set for custom handling of validation errors. */
READER_ERROR_HANDLER(IO.READER,"reader/error-handler",ErrorHandler.class),
/** Resolve more entities from local sources. */
READER_ENTITY_RESOLVER(IO.READER,"reader/entity-resolver",EntityResolver.class),
/** When set to true then input xml is validated. */
READER_VALIDATION_SCHEMA_AUTO_WRITE(IO.READER,"reader/validation/schema-auto-write",Boolean.class,true),
/** When set this path is searched for xsd schema files in the language sub directory. */
READER_VALIDATION_SCHEMA_PATH(IO.READER,"reader/validation/schema-path",File.class),
/** When set to true then input xml is validated. */
READER_VALIDATION_INPUT(IO.READER,"reader/validation/input",Boolean.class,false),
/** When set to true then input xsd xml grammer is validated. */
READER_VALIDATION_INPUT_XSD(IO.READER,"reader/validation/input/xsd",Boolean.class,false),
/** The writer output stream to write to. */
WRITER_OUTPUT_STREAM(IO.WRITER,"writer/output/stream",OutputStream.class),
/** The writer output encoding. */
WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** The writer output newline. */
WRITER_OUTPUT_CHAR_NEWLINE(IO.WRITER,"writer/output/char/newline",String.class),
/** The writer output tab char. */
WRITER_OUTPUT_CHAR_TAB(IO.WRITER,"writer/output/char/tab",String.class),
/** When writing print schema uri. */
WRITER_SCHEMA_URI_PRINT(IO.WRITER,"writer/schema/uri-print",Boolean.class,true),
/** Override eld root schema uri. */
WRITER_SCHEMA_URI_ROOT(IO.WRITER,"writer/schema/uri-root",String.class),
/** The schema writer output path to write to. */
SCHEMA_WRITER_OUTPUT_PATH(IO.SCHEMA_WRITER,"schema-writer/output/path",File.class),
/** The schema writer output encoding. */
SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** The schema writer output newline. */
SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE(IO.SCHEMA_WRITER,"schema-writer/output/char/newline",String.class),
/** The schema writer output tab char. */
SCHEMA_WRITER_OUTPUT_CHAR_TAB(IO.SCHEMA_WRITER,"schema-writer/output/char/tab",String.class),
/** When set to OutputStream xml debug is written to it. note: when output-handler is set this property is ignored. */
DEBUG_OUTPUT_STREAM(IO.READER_WRITER,"debug/output-stream",OutputStream.class),
/** When set to DefaultHandler2 xml debug events are fired to the object. */
DEBUG_OUTPUT_HANDLER(IO.READER_WRITER,"debug/output-handler",DefaultHandler2.class),
/* When set to true print also phases for parsing eld files. */
//DEBUG_OUTPUT_ELD_PARSER(IO.READER_WRITER,"debug/output-eld-parser",Boolean.class,false),
/* When set to true print full element tree per phase. */
//DEBUG_OUTPUT_TREE_PER_PHASE("debug/output-tree-per-phase",Boolean.class),
/** The beans in this map are set into the EL context for reference. */
EL_BEAN_INSTANCE_MAP(IO.READER_WRITER,"el/bean-instance-map",Map.class),
/** When set use this instance for the ELContext. */
EL_CONTEXT_INSTANCE(IO.READER_WRITER,"el/context-instance",ELContext.class),
/** When set use this instance as the ExpressionFactory. */
EL_FACTORY_INSTANCE(IO.READER_WRITER,"el/factory-instance",ExpressionFactory.class),
/** When set to an X4OPhase then parsing stops after completing the set phase. */
PHASE_STOP_AFTER(IO.READER_WRITER,"phase/stop-after",String.class),
/** When set to true skip the release phase. */
PHASE_SKIP_RELEASE(IO.READER_WRITER,"phase/skip-release",Boolean.class,false),
/** When set to true skip the run phase. */
PHASE_SKIP_RUN(IO.READER_WRITER,"phase/skip-run",Boolean.class,false);
// (temp) removed because init is now in driver manager
/* When set to true skip the load siblings language phase. */
//PHASE_SKIP_SIBLINGS(IO.READER,"phase/skip-siblings",Boolean.class,false);
/* When set to true then eld xml is validated. */
//VALIDATION_ELD(IO.INIT,"validation/eld",Boolean.class,false),
/* When set to true than eld xsd xml grammer is also validated. */
//VALIDATION_ELD_XSD(IO.INIT, "validation/eld/xsd",Boolean.class,false);
public final static X4OLanguageProperty[] DEFAULT_X4O_READER_KEYS;
public final static X4OLanguageProperty[] DEFAULT_X4O_WRITER_KEYS;
public final static X4OLanguageProperty[] DEFAULT_X4O_SCHEMA_WRITER_KEYS;
static {
List<X4OLanguageProperty> readerResultKeys = new ArrayList<X4OLanguageProperty>();
List<X4OLanguageProperty> writerResultKeys = new ArrayList<X4OLanguageProperty>();
List<X4OLanguageProperty> schemaWriterResultKeys = new ArrayList<X4OLanguageProperty>();
X4OLanguageProperty[] keys = X4OLanguageProperty.values();
for (int i=0;i<keys.length;i++) {
X4OLanguageProperty key = keys[i];
if (IO.GLOBAL.equals(key.type) || IO.READER.equals(key.type) || IO.READER_WRITER.equals(key.type)) {
readerResultKeys.add(key);
}
if (IO.GLOBAL.equals(key.type) || IO.WRITER.equals(key.type) || IO.READER_WRITER.equals(key.type)) {
writerResultKeys.add(key);
}
if (IO.GLOBAL.equals(key.type) || IO.SCHEMA_WRITER.equals(key.type)) {
schemaWriterResultKeys.add(key);
}
}
DEFAULT_X4O_READER_KEYS = readerResultKeys.toArray(new X4OLanguageProperty[readerResultKeys.size()]);
DEFAULT_X4O_WRITER_KEYS = writerResultKeys.toArray(new X4OLanguageProperty[writerResultKeys.size()]);
DEFAULT_X4O_SCHEMA_WRITER_KEYS = schemaWriterResultKeys.toArray(new X4OLanguageProperty[schemaWriterResultKeys.size()]);
}
enum IO {
GLOBAL,
READER,
WRITER,
READER_WRITER,
SCHEMA_WRITER
};
private final static String URI_PREFIX = "http://language.x4o.org/xml/properties/";
private final String uriName;
private final Class<?>[] classTypes;
private final Object defaultValue;
private final X4OLanguageProperty.IO type;
private X4OLanguageProperty(X4OLanguageProperty.IO type,String uriName) {
this(type,uriName,String.class);
}
private X4OLanguageProperty(X4OLanguageProperty.IO type,String uriName,Class<?> classType) {
this(type,uriName,new Class[]{classType},null);
}
private X4OLanguageProperty(X4OLanguageProperty.IO type,String uriName,Class<?> classType,Object defaultValue) {
this(type,uriName,new Class[]{classType},defaultValue);
}
private X4OLanguageProperty(X4OLanguageProperty.IO type,String uriName,Class<?>[] classTypes,Object defaultValue) {
this.type=type;
this.uriName=URI_PREFIX+uriName;
this.classTypes=classTypes;
this.defaultValue=defaultValue;
}
/**
* Returns the uri defined by this property.
* @return The uri defined by this property.
*/
public final String toUri() {
return uriName;
}
/**
* Returns the default value for this property.
* @return The default value for this property.
*/
public final Object getDefaultValue() {
return defaultValue;
}
/**
* Checks if the object is valid to set on this property.
* This is done by checking the allowed class types if they are assignable from the value class.
* @param value The object to check.
* @return Returns true when Object value is allowed to be set.
*/
public final boolean isValueValid(Object value) {
if (LANGUAGE_NAME.equals(this) | LANGUAGE_VERSION.equals(this)) {
return false; // read only are not valid to set.
}
if (value==null) {
return true;
}
Class<?> valueClass = value.getClass();
for (Class<?> c:classTypes) {
if (c.isAssignableFrom(valueClass)) {
return true;
}
}
return false;
}
/**
* Search the enum for the value defined by the given uri.
* @param uri The uri to search for.
* @return Return the property for the given uri.
* @throws IllegalArgumentException when uri is not found.
*/
public static final X4OLanguageProperty valueByUri(String uri) {
if (uri==null) {
throw new NullPointerException("Can't search null uri.");
}
if (uri.length()==0) {
throw new IllegalArgumentException("Can't search empty uri.");
}
if (uri.startsWith(URI_PREFIX)==false) {
throw new IllegalArgumentException("Can't search for other name local prefix: "+URI_PREFIX+" found: "+uri);
}
for (X4OLanguageProperty p:values()) {
if (uri.equals(p.toUri())) {
return p;
}
}
throw new IllegalArgumentException("Could not find language property for uri key: "+uri);
}
}

View file

@ -1,99 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.lang;
/**
* X4OLanguagePropertyKeys is shortcut to the the properties by uri.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public class X4OLanguagePropertyKeys {
public static final String LANGUAGE_NAME = X4OLanguageProperty.LANGUAGE_NAME.toUri();
public static final String LANGUAGE_VERSION = X4OLanguageProperty.LANGUAGE_VERSION.toUri();
public static final String READER_INPUT_STREAM = X4OLanguageProperty.READER_INPUT_STREAM.toUri();
public static final String READER_INPUT_ENCODING = X4OLanguageProperty.READER_INPUT_ENCODING.toUri();
public static final String READER_INPUT_SOURCE = X4OLanguageProperty.READER_INPUT_SOURCE.toUri();
public static final String READER_INPUT_SYSTEM_ID = X4OLanguageProperty.READER_INPUT_SYSTEM_ID.toUri();
public static final String READER_INPUT_BASE_PATH = X4OLanguageProperty.READER_INPUT_BASE_PATH.toUri();
public static final String READER_BUFFER_SIZE = X4OLanguageProperty.READER_BUFFER_SIZE.toUri();
public static final String READER_EMPTY_NAMESPACE_URI = X4OLanguageProperty.READER_EMPTY_NAMESPACE_URI.toUri();
public static final String READER_ERROR_HANDLER = X4OLanguageProperty.READER_ERROR_HANDLER.toUri();
public static final String READER_ENTITY_RESOLVER = X4OLanguageProperty.READER_ENTITY_RESOLVER.toUri();
public static final String READER_VALIDATION_SCHEMA_AUTO_WRITE = X4OLanguageProperty.READER_VALIDATION_SCHEMA_AUTO_WRITE.toUri();
public static final String READER_VALIDATION_SCHEMA_PATH = X4OLanguageProperty.READER_VALIDATION_SCHEMA_PATH.toUri();
public static final String READER_VALIDATION_INPUT = X4OLanguageProperty.READER_VALIDATION_INPUT.toUri();
public static final String READER_VALIDATION_INPUT_XSD = X4OLanguageProperty.READER_VALIDATION_INPUT_XSD.toUri();
public static final String WRITER_OUTPUT_STREAM = X4OLanguageProperty.WRITER_OUTPUT_STREAM.toUri();
public static final String WRITER_OUTPUT_ENCODING = X4OLanguageProperty.WRITER_OUTPUT_ENCODING.toUri();
public static final String WRITER_OUTPUT_CHAR_NEWLINE = X4OLanguageProperty.WRITER_OUTPUT_CHAR_NEWLINE.toUri();
public static final String WRITER_OUTPUT_CHAR_TAB = X4OLanguageProperty.WRITER_OUTPUT_CHAR_TAB.toUri();
public static final String WRITER_SCHEMA_URI_PRINT = X4OLanguageProperty.WRITER_SCHEMA_URI_PRINT.toUri();
public static final String WRITER_SCHEMA_URI_ROOT = X4OLanguageProperty.WRITER_SCHEMA_URI_ROOT.toUri();
public static final String SCHEMA_WRITER_OUTPUT_PATH = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_PATH.toUri();
public static final String SCHEMA_WRITER_OUTPUT_ENCODING = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_ENCODING.toUri();
public static final String SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE.toUri();
public static final String SCHEMA_WRITER_OUTPUT_CHAR_TAB = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_TAB.toUri();
public static final String DEBUG_OUTPUT_STREAM = X4OLanguageProperty.DEBUG_OUTPUT_STREAM.toUri();
public static final String DEBUG_OUTPUT_HANDLER = X4OLanguageProperty.DEBUG_OUTPUT_HANDLER.toUri();
public static final String EL_BEAN_INSTANCE_MAP = X4OLanguageProperty.EL_BEAN_INSTANCE_MAP.toUri();
public static final String EL_FACTORY_INSTANCE = X4OLanguageProperty.EL_FACTORY_INSTANCE.toUri();
public static final String PHASE_STOP_AFTER = X4OLanguageProperty.PHASE_STOP_AFTER.toUri();
public static final String PHASE_SKIP_RELEASE = X4OLanguageProperty.PHASE_SKIP_RELEASE.toUri();
public static final String PHASE_SKIP_RUN = X4OLanguageProperty.PHASE_SKIP_RUN.toUri();
public final static String[] DEFAULT_X4O_READER_KEYS;
public final static String[] DEFAULT_X4O_WRITER_KEYS;
public final static String[] DEFAULT_X4O_SCHEMA_WRITER_KEYS;
static {
X4OLanguageProperty[] readerKeys = X4OLanguageProperty.DEFAULT_X4O_READER_KEYS;
String[] readerResultKeys = new String[readerKeys.length];
for (int i=0;i<readerResultKeys.length;i++) {
readerResultKeys[i] = readerKeys[i].toUri();
}
DEFAULT_X4O_READER_KEYS = readerResultKeys;
X4OLanguageProperty[] writerKeys = X4OLanguageProperty.DEFAULT_X4O_WRITER_KEYS;
String[] writerResultKeys = new String[writerKeys.length];
for (int i=0;i<writerResultKeys.length;i++) {
writerResultKeys[i] = writerKeys[i].toUri();
}
DEFAULT_X4O_WRITER_KEYS = writerResultKeys;
X4OLanguageProperty[] schemaWriterKeys = X4OLanguageProperty.DEFAULT_X4O_SCHEMA_WRITER_KEYS;
String[] schemaWriterResultKeys = new String[schemaWriterKeys.length];
for (int i=0;i<schemaWriterResultKeys.length;i++) {
schemaWriterResultKeys[i] = schemaWriterKeys[i].toUri();
}
DEFAULT_X4O_SCHEMA_WRITER_KEYS = schemaWriterResultKeys;
}
}

View file

@ -30,7 +30,6 @@ import java.util.List;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageContextLocal; import org.x4o.xml.lang.X4OLanguageContextLocal;
import org.x4o.xml.lang.X4OLanguageProperty;
/** /**
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order. * X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order.
@ -110,12 +109,6 @@ PHASE_ORDER = { *startupX4OPhase,
if (p.getType().equals(type)) { if (p.getType().equals(type)) {
result.add(p); result.add(p);
} }
if (X4OPhaseType.XML_READ.equals(type) && X4OPhaseType.XML_RW.equals(p.getType())) {
result.add(p);
}
if (X4OPhaseType.XML_WRITE.equals(type) && X4OPhaseType.XML_RW.equals(p.getType())) {
result.add(p);
}
} }
Collections.sort(result,new X4OPhaseComparator()); Collections.sort(result,new X4OPhaseComparator());
return result; return result;
@ -126,47 +119,28 @@ PHASE_ORDER = { *startupX4OPhase,
* @throws X4OPhaseException When a running handlers throws one. * @throws X4OPhaseException When a running handlers throws one.
*/ */
public void runPhases(X4OLanguageContext languageContext,X4OPhaseType type) throws X4OPhaseException { public void runPhases(X4OLanguageContext languageContext,X4OPhaseType type) throws X4OPhaseException {
// sort for the order // sort for the order
List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type); List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type);
/*
System.out.println("------ phases type: "+type+" for: "+languageContext.getLanguage().getLanguageName());
for (X4OPhase p:x4oPhasesOrder) {
System.out.print("Exec phase; "+p.getId()+" deps: [");
for (String dep:p.getPhaseDependencies()) {
System.out.print(dep+",");
}
System.out.println("]");
}
*/
// debug output // debug output
if (languageContext.getX4ODebugWriter()!=null) { if (languageContext.getX4ODebugWriter()!=null) {
languageContext.getX4ODebugWriter().debugPhaseOrder(x4oPhases); languageContext.getX4ODebugWriter().debugPhaseOrder(x4oPhases);
} }
boolean skipReleasePhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE); List<String> phaseSkip = languageContext.getPhaseSkip();
boolean skipRunPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN); String phaseStop = languageContext.getPhaseStop();
//boolean skipSiblingsPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_SIBLINGS);
String stopPhase = languageContext.getLanguagePropertyString(X4OLanguageProperty.PHASE_STOP_AFTER);
// run the phases in ordered order // run the phases in ordered order
for (X4OPhase phase:x4oPhasesOrder) { for (X4OPhase phase:x4oPhasesOrder) {
if (skipReleasePhase && phase.getId().equals("X4O_RELEASE")) { if (phaseSkip.contains(phase.getId())) {
continue; // skip always release phase when requested by property continue; // skip phase when requested by context
} }
if (skipRunPhase && phase.getId().equals("READ_RUN")) {
continue; // skip run phase on request
}
// if (skipSiblingsPhase && phase.getId().equals("INIT_LANG_SIB")) {
// continue; // skip loading sibling languages
// }
// debug output // debug output
((X4OLanguageContextLocal)languageContext).setCurrentPhase(phase); ((X4OLanguageContextLocal)languageContext).setPhaseCurrent(phase);
// run listeners // run listeners
for (X4OPhaseListener l:phase.getPhaseListeners()) { for (X4OPhaseListener l:phase.getPhaseListeners()) {
l.preRunPhase(phase, languageContext); l.preRunPhase(phase, languageContext);
@ -186,7 +160,7 @@ PHASE_ORDER = { *startupX4OPhase,
} }
} }
if (stopPhase!=null && stopPhase.equals(phase.getId())) { if (phaseStop!=null && phaseStop.equals(phase.getId())) {
return; // we are done return; // we are done
} }
} }
@ -200,8 +174,8 @@ PHASE_ORDER = { *startupX4OPhase,
*/ */
public void runPhasesForElement(Element e,X4OPhaseType type,X4OPhase p) throws X4OPhaseException { public void runPhasesForElement(Element e,X4OPhaseType type,X4OPhase p) throws X4OPhaseException {
X4OLanguageContext languageContext = e.getLanguageContext(); X4OLanguageContext languageContext = e.getLanguageContext();
boolean skipRunPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN); List<String> phaseSkip = languageContext.getPhaseSkip();
String stopPhase = languageContext.getLanguagePropertyString(X4OLanguageProperty.PHASE_STOP_AFTER); String phaseStop = languageContext.getPhaseStop();
// sort for the order // sort for the order
List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type); List<X4OPhase> x4oPhasesOrder = getOrderedPhases(type);
@ -209,15 +183,12 @@ PHASE_ORDER = { *startupX4OPhase,
if (phase.getId().equals(p.getId())==false) { if (phase.getId().equals(p.getId())==false) {
continue; // we start running all phases from specified phase continue; // we start running all phases from specified phase
} }
if (phase.getId().equals("RELEASE")) { if (phaseSkip.contains(phase.getId())) {
continue; // skip always release phase in dirty extra runs. continue; // skip phase when requested by context
}
if (skipRunPhase && phase.getId().equals("READ_RUN")) {
continue; // skip run phase on request
} }
// set phase // set phase
((X4OLanguageContextLocal)languageContext).setCurrentPhase(phase); ((X4OLanguageContextLocal)languageContext).setPhaseCurrent(phase);
// do the run interface // do the run interface
phase.runPhase(languageContext); phase.runPhase(languageContext);
@ -225,7 +196,7 @@ PHASE_ORDER = { *startupX4OPhase,
// run the element phase if possible // run the element phase if possible
executePhaseRoot(languageContext,phase); executePhaseRoot(languageContext,phase);
if (stopPhase!=null && stopPhase.equals(phase.getId())) { if (phaseStop!=null && phaseStop.equals(phase.getId())) {
return; // we are done return; // we are done
} }
} }
@ -236,8 +207,15 @@ PHASE_ORDER = { *startupX4OPhase,
* @throws X4OPhaseException When a running handlers throws one. * @throws X4OPhaseException When a running handlers throws one.
*/ */
public void doReleasePhaseManual(X4OLanguageContext languageContext) throws X4OPhaseException { public void doReleasePhaseManual(X4OLanguageContext languageContext) throws X4OPhaseException {
boolean skipReleasePhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE); List<String> phaseSkip = languageContext.getPhaseSkip();
if (skipReleasePhase==false) { String releaseRequested = null;
if (phaseSkip.contains(X4OPhase.READ_RELEASE)) {
releaseRequested = X4OPhase.READ_RELEASE;
}
if (phaseSkip.contains(X4OPhase.WRITE_RELEASE)) {
releaseRequested = X4OPhase.WRITE_RELEASE;
}
if (releaseRequested==null) {
throw new IllegalStateException("No manual release requested."); throw new IllegalStateException("No manual release requested.");
} }
if (languageContext.getRootElement()==null) { if (languageContext.getRootElement()==null) {
@ -249,7 +227,7 @@ PHASE_ORDER = { *startupX4OPhase,
X4OPhase h = null; X4OPhase h = null;
for (X4OPhase phase:x4oPhases) { for (X4OPhase phase:x4oPhases) {
if (phase.getId().equals("X4O_RELEASE")) { if (phase.getId().equals(releaseRequested)) {
h = phase; h = phase;
break; break;
} }
@ -259,7 +237,7 @@ PHASE_ORDER = { *startupX4OPhase,
} }
// set phase // set phase
((X4OLanguageContextLocal)languageContext).setCurrentPhase(h); ((X4OLanguageContextLocal)languageContext).setPhaseCurrent(h);
// do the run interface // do the run interface
h.runPhase(languageContext); h.runPhase(languageContext);

View file

@ -36,6 +36,17 @@ import org.x4o.xml.lang.X4OLanguageContext;
*/ */
public interface X4OPhase { public interface X4OPhase {
public final static String INIT_BEGIN = "INIT_BEGIN";
public final static String INIT_END = "INIT_END";
public final static String READ_BEGIN = "READ_BEGIN";
public final static String READ_END = "READ_END";
public final static String READ_RELEASE = "READ_RELEASE";
public final static String WRITE_BEGIN = "WRITE_BEGIN";
public final static String WRITE_END = "WRITE_END";
public final static String WRITE_RELEASE = "WRITE_RELEASE";
X4OPhaseType getType(); X4OPhaseType getType();
/** /**

View file

@ -29,10 +29,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.conv.ObjectConverterException; import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeHandler; import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementAttributeValueParser; import org.x4o.xml.element.ElementAttributeValueParser;
@ -44,14 +41,11 @@ import org.x4o.xml.element.ElementConfiguratorGlobal;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.sax.X4OContentParser;
import org.x4o.xml.io.sax.X4ODebugWriter; import org.x4o.xml.io.sax.X4ODebugWriter;
import org.x4o.xml.io.sax.ext.ContentWriter; import org.x4o.xml.io.sax.ext.ContentWriter;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -71,11 +65,7 @@ public class X4OPhaseLanguageRead {
public void createPhases(DefaultX4OPhaseManager manager) { public void createPhases(DefaultX4OPhaseManager manager) {
manager.addX4OPhase(new X4OPhaseReadStart()); manager.addX4OPhase(new X4OPhaseReadBegin());
manager.addX4OPhase(new X4OPhaseReadXml());
manager.addX4OPhase(new X4OPhaseReadConfigELBeans());
// if (languageContext.hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// meta start point // meta start point
// manager.addX4OPhase(factory.startX4OPhase()); // manager.addX4OPhase(factory.startX4OPhase());
@ -141,12 +131,12 @@ public class X4OPhaseLanguageRead {
/** /**
* Creates the startX4OPhase which is a empty meta phase. * Creates the startX4OPhase which is a empty meta phase.
*/ */
class X4OPhaseReadStart extends AbstractX4OPhase { class X4OPhaseReadBegin extends AbstractX4OPhase {
public X4OPhaseType getType() { public X4OPhaseType getType() {
return X4OPhaseType.XML_READ; return X4OPhaseType.XML_READ;
} }
public String getId() { public String getId() {
return "READ_START"; return X4OPhase.READ_BEGIN;
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{}; return new String[]{};
@ -161,7 +151,7 @@ public class X4OPhaseLanguageRead {
// print the properties and classes for this language/config // print the properties and classes for this language/config
if (languageContext.hasX4ODebugWriter()) { if (languageContext.hasX4ODebugWriter()) {
try { try {
languageContext.getX4ODebugWriter().debugLanguageProperties(languageContext); //languageContext.getX4ODebugWriter().debugLanguageProperties(languageContext);
languageContext.getX4ODebugWriter().debugLanguageDefaultClasses(languageContext); languageContext.getX4ODebugWriter().debugLanguageDefaultClasses(languageContext);
} catch (ElementException e) { } catch (ElementException e) {
throw new X4OPhaseException(this,e); throw new X4OPhaseException(this,e);
@ -170,72 +160,6 @@ public class X4OPhaseLanguageRead {
} }
}; };
/**
* Parses the xml resource(s) and creates an Element tree.
*/
class X4OPhaseReadXml extends AbstractX4OPhase {
public X4OPhaseType getType() {
return X4OPhaseType.XML_READ;
}
public String getId() {
return "READ_XML";
}
public String[] getPhaseDependencies() {
return new String[]{"READ_START"};
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
try {
X4OContentParser parser = new X4OContentParser();
parser.parse(languageContext);
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
/**
* Creates the configGlobalElBeansPhase which adds beans to the el context.
*/
class X4OPhaseReadConfigELBeans extends AbstractX4OPhase {
public X4OPhaseType getType() {
return X4OPhaseType.XML_RW;
}
public String getId() {
return "READ_CONFIG_EL_BEANS";
}
public String[] getPhaseDependencies() {
return new String[] {"READ_XML"};
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
@SuppressWarnings("rawtypes")
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
try {
Map beanMap = (Map)languageContext.getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (beanMap==null) {
return;
}
for (Object elName:beanMap.keySet()) {
Object o = beanMap.get(elName);
ValueExpression ve = languageContext.getExpressionLanguageFactory().createValueExpression(languageContext.getExpressionLanguageContext(),"${"+elName+"}", o.getClass());
ve.setValue(languageContext.getExpressionLanguageContext(), o);
debugPhaseMessage("Setting el bean: ${"+elName+"} to: "+o.getClass().getName(),this,languageContext);
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
/** /**
* X4OPhaseReadConfigElement * X4OPhaseReadConfigElement
*/ */
@ -251,7 +175,7 @@ public class X4OPhaseLanguageRead {
return "READ_CONFIG_ELEMENT"; return "READ_CONFIG_ELEMENT";
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_EL_BEANS"}; return new String[] {X4OPhase.READ_BEGIN};
} }
public void runElementPhase(Element element) throws X4OPhaseException { public void runElementPhase(Element element) throws X4OPhaseException {
@ -292,7 +216,7 @@ public class X4OPhaseLanguageRead {
return "READ_CONFIG_ELEMENT_INTERFACE"; return "READ_CONFIG_ELEMENT_INTERFACE";
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[] {"READ_CONFIG_EL_BEANS"}; return new String[] {"READ_CONFIG_ELEMENT"};
} }
public void runElementPhase(Element element) throws X4OPhaseException { public void runElementPhase(Element element) throws X4OPhaseException {
if (element.getElementObject()==null) { if (element.getElementObject()==null) {
@ -709,7 +633,7 @@ public class X4OPhaseLanguageRead {
return X4OPhaseType.XML_READ; return X4OPhaseType.XML_READ;
} }
public String getId() { public String getId() {
return "READ_END"; return X4OPhase.READ_END;
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{"READ_RUN_CONFIGURATOR"}; return new String[]{"READ_RUN_CONFIGURATOR"};
@ -724,7 +648,7 @@ public class X4OPhaseLanguageRead {
// print the properties and classes for this language/config // print the properties and classes for this language/config
if (languageContext.hasX4ODebugWriter()) { if (languageContext.hasX4ODebugWriter()) {
try { try {
languageContext.getX4ODebugWriter().debugLanguageProperties(languageContext); //languageContext.getX4ODebugWriter().debugLanguageProperties(languageContext);
languageContext.getX4ODebugWriter().debugLanguageDefaultClasses(languageContext); languageContext.getX4ODebugWriter().debugLanguageDefaultClasses(languageContext);
} catch (ElementException e) { } catch (ElementException e) {
throw new X4OPhaseException(this,e); throw new X4OPhaseException(this,e);
@ -773,13 +697,13 @@ public class X4OPhaseLanguageRead {
final ReleasePhaseListener releaseCounter = new ReleasePhaseListener(); final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
X4OPhase result = new AbstractX4OPhase() { X4OPhase result = new AbstractX4OPhase() {
public X4OPhaseType getType() { public X4OPhaseType getType() {
return X4OPhaseType.XML_RW; return X4OPhaseType.XML_READ;
} }
public String getId() { public String getId() {
return "X4O_RELEASE"; return X4OPhase.READ_RELEASE;
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[] {"READ_END"}; return new String[] {X4OPhase.READ_END};
} }
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException { public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
} }
@ -804,7 +728,7 @@ public class X4OPhaseLanguageRead {
public X4OPhase debugPhase(final X4OPhase afterPhase) { public X4OPhase debugPhase(final X4OPhase afterPhase) {
X4OPhase result = new AbstractX4OPhase() { X4OPhase result = new AbstractX4OPhase() {
public X4OPhaseType getType() { public X4OPhaseType getType() {
return X4OPhaseType.XML_RW; return X4OPhaseType.XML_READ;
} }
public String getId() { public String getId() {
return "X4O_DEBUG_"+afterPhase.getId(); return "X4O_DEBUG_"+afterPhase.getId();

View file

@ -22,34 +22,17 @@
*/ */
package org.x4o.xml.lang.phase; package org.x4o.xml.lang.phase;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandler; import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementBindingHandlerException; import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClass; import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException; import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.element.ElementObjectPropertyValueException;
import org.x4o.xml.io.XMLConstants;
import org.x4o.xml.io.sax.ext.ContentWriterXml;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** /**
* X4OPhaseLanguageWrite defines all phases to write the language. * X4OPhaseLanguageWrite defines all phases to write the language.
@ -66,21 +49,21 @@ public class X4OPhaseLanguageWrite {
} }
public void createPhases(DefaultX4OPhaseManager manager) { public void createPhases(DefaultX4OPhaseManager manager) {
manager.addX4OPhase(new X4OPhaseWriteStart()); manager.addX4OPhase(new X4OPhaseWriteBegin());
manager.addX4OPhase(new X4OPhaseWriteFillTree()); manager.addX4OPhase(new X4OPhaseWriteFillTree());
manager.addX4OPhase(new X4OPhaseWriteXml());
manager.addX4OPhase(new X4OPhaseWriteEnd()); manager.addX4OPhase(new X4OPhaseWriteEnd());
//manager.addX4OPhase(new X4OPhaseWriteRelease());
} }
/** /**
* Creates the X4OPhaseWriteStart which is a empty meta phase. * Creates the X4OPhaseWriteBegin which is a empty meta phase.
*/ */
class X4OPhaseWriteStart extends AbstractX4OPhase { class X4OPhaseWriteBegin extends AbstractX4OPhase {
public X4OPhaseType getType() { public X4OPhaseType getType() {
return X4OPhaseType.XML_WRITE; return X4OPhaseType.XML_WRITE;
} }
public String getId() { public String getId() {
return "WRITE_START"; return X4OPhase.WRITE_BEGIN;
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{}; return new String[]{};
@ -91,7 +74,7 @@ public class X4OPhaseLanguageWrite {
public void runElementPhase(Element element) throws X4OPhaseException { public void runElementPhase(Element element) throws X4OPhaseException {
} }
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException { public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
logger.finest("Run init start phase"); logger.finest("Run init begin phase");
} }
}; };
@ -106,7 +89,7 @@ public class X4OPhaseLanguageWrite {
return "WRITE_FILL_TREE"; return "WRITE_FILL_TREE";
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{"WRITE_START"}; return new String[]{X4OPhase.WRITE_BEGIN};
} }
public boolean isElementPhase() { public boolean isElementPhase() {
return false; return false;
@ -173,249 +156,6 @@ public class X4OPhaseLanguageWrite {
} }
}; };
/**
* Write xml to output.
*/
class X4OPhaseWriteXml extends AbstractX4OPhase {
public X4OPhaseType getType() {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return "WRITE_XML";
}
public String[] getPhaseDependencies() {
return new String[] {"WRITE_FILL_TREE"};
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
private AttributeEntryComparator attributeEntryComparator = new AttributeEntryComparator();
private boolean schemaUriPrint;
private String schemaUriRoot;
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
OutputStream out = (OutputStream)languageContext.getLanguageProperty(X4OLanguageProperty.WRITER_OUTPUT_STREAM);
try {
String encoding = languageContext.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_ENCODING);
String charNew = languageContext.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_CHAR_NEWLINE);
String charTab = languageContext.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_CHAR_TAB);
schemaUriPrint = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.WRITER_SCHEMA_URI_PRINT);
schemaUriRoot = languageContext.getLanguagePropertyString(X4OLanguageProperty.WRITER_SCHEMA_URI_ROOT);
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE+""; }
if (charTab==null) { charTab = XMLConstants.CHAR_TAB+""; }
Element root = languageContext.getRootElement();
if (schemaUriRoot==null) {
String rootUri = findElementUri(root);
ElementNamespaceContext ns = languageContext.getLanguage().findElementNamespaceContext(rootUri);
if (ns!=null) {
schemaUriRoot = ns.getSchemaUri();
}
}
ContentWriterXml writer = new ContentWriterXml(out,encoding,charNew,charTab);
writer.startDocument();
Map<String,String> prefixes = new HashMap<String,String>();
startPrefixTree(root,prefixes);
for (String uri:prefixes.keySet()) {
String prefix = prefixes.get(uri);
writer.startPrefixMapping(prefix, uri);
}
try {
writeTree(writer,root,true);
} catch (ElementObjectPropertyValueException e) {
throw new SAXException(e);
}
writer.endDocument();
out.flush();
} catch (Exception e) {
throw new X4OPhaseException(this,e);
} finally {
if (out!=null) {
try {
out.close();
} catch (IOException e) {
logger.warning(e.getMessage());
}
}
}
}
private void startPrefixTree(Element element,Map<String,String> result) throws SAXException {
String elementUri = findElementUri(element);
if (result.containsKey(elementUri)==false) {
String elementUriPrefix = findNamespacePrefix(element,elementUri);
result.put(elementUri, elementUriPrefix);
}
for (Element e:element.getChilderen()) {
startPrefixTree(e,result);
}
}
private List<String> getProperties(Class<?> objectClass) {
List<String> result = new ArrayList<String>();
for (Method m:objectClass.getMethods()) {
Class<?>[] types = m.getParameterTypes();
if (types.length != 0) {
continue;
}
if (m.getName().equals("getClass")) {
continue;
}
if (m.getName().startsWith("get")==false) {
continue;
}
String name = m.getName().substring(3,4).toLowerCase()+m.getName().substring(4);
result.add(name);
}
return result;
}
class AttributeEntry {
String id;
String value;
Integer writeOrder;
}
class AttributeEntryComparator implements Comparator<AttributeEntry> {
public int compare(AttributeEntry o1, AttributeEntry o2) {
return o1.writeOrder.compareTo(o2.writeOrder);
}
}
private void writeTree(ContentWriterXml writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
List<AttributeEntry> attr = new ArrayList<AttributeEntry>(20);
if (element.getElementClass().getAutoAttributes()!=null && element.getElementClass().getAutoAttributes()==false) {
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
if (eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
continue;
}
Object value = element.getLanguageContext().getElementObjectPropertyValue().getProperty(element.getElementObject(),eca.getId());
if (value==null) {
continue;
}
AttributeEntry e = new AttributeEntry();
e.id = eca.getId();
e.value = ""+value;
e.writeOrder = calcOrderNumber(e.id,eca.getWriteOrder());
attr.add(e);
}
} else {
for (String p:getProperties(element.getElementObject().getClass())) {
Integer writeOrder = null;
ElementClassAttribute eca = element.getElementClass().getElementClassAttributeByName(p);
if (eca!=null) {
writeOrder = eca.getWriteOrder();
}
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()) {
continue;
}
boolean writeValue = true;
for (ElementInterface ei:element.getLanguageContext().getLanguage().findElementInterfaces(element.getElementObject().getClass())) {
eca = ei.getElementClassAttributeByName(p);
if (eca!=null && writeOrder==null) {
writeOrder = eca.getWriteOrder(); // add interface but allow override local
}
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
writeValue = false;
break;
}
}
if (writeValue==false) {
continue;
}
// TODO: check attr see reader
Object value = element.getLanguageContext().getElementObjectPropertyValue().getProperty(element.getElementObject(),p);
if (value==null) {
continue;
}
if (value instanceof List || value instanceof Collection) {
continue; // TODO; filter on type of childeren
}
AttributeEntry e = new AttributeEntry();
e.id = p;
e.value = ""+value;
e.writeOrder = calcOrderNumber(e.id,writeOrder);
attr.add(e);
}
}
// Create atts to write and append schema first.
AttributesImpl atts = new AttributesImpl();
if (isRoot && schemaUriPrint) {
String rootUri = findElementUri(element);
writer.startPrefixMapping("xsi", XMLConstants.XML_SCHEMA_INSTANCE_NS_URI);
atts.addAttribute ("xsi", "schemaLocation", "", "", rootUri+" "+schemaUriRoot);
}
// Sort attributes in natural order of localName and add to attributes
Collections.sort(attr, attributeEntryComparator);
for (int i=0;i<attr.size();i++) {
AttributeEntry a = attr.get(i);
atts.addAttribute ("", a.id, "", "", a.value);
}
// Write Element tree recursive.
String elementUri = findElementUri(element);
writer.startElement(elementUri, element.getElementClass().getId(), "", atts);
for (Element e:element.getChilderen()) {
writeTree(writer,e,false);
}
writer.endElement(elementUri, element.getElementClass().getId(), "");
}
// TODO: move to defaults layer so visible in docs.
private Integer calcOrderNumber(String name,Integer orderNumberOverride) {
if (orderNumberOverride!=null) {
return orderNumberOverride;
}
if (name==null) {
throw new NullPointerException("Can't calculate order of null name.");
}
int nameSize = name.length();
if (nameSize==1) {
return (name.charAt(0) * 1000);
}
if (nameSize==2) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100);
}
if (nameSize==3) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10);
}
if (nameSize>3) {
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10) + (name.charAt(3) * 1);
}
throw new IllegalArgumentException("Can't calculate order of empty name.");
}
private String findElementUri(Element e) {
for (X4OLanguageModule mod:e.getLanguageContext().getLanguage().getLanguageModules()) {
for (ElementNamespaceContext c:mod.getElementNamespaceContexts()) {
ElementClass ec = c.getElementClass(e.getElementClass().getId());
if (ec!=null) {
return c.getUri();
}
}
}
return null;
}
private String findNamespacePrefix(Element e,String uri) {
ElementNamespaceContext ns = e.getLanguageContext().getLanguage().findElementNamespaceContext(uri);
if (ns.getPrefixMapping()!=null) {
return ns.getPrefixMapping();
}
return ns.getId();
}
};
/** /**
* Creates the X4OPhaseWriteEnd which is a empty meta phase. * Creates the X4OPhaseWriteEnd which is a empty meta phase.
*/ */
@ -424,10 +164,10 @@ public class X4OPhaseLanguageWrite {
return X4OPhaseType.XML_WRITE; return X4OPhaseType.XML_WRITE;
} }
public String getId() { public String getId() {
return "WRITE_END"; return X4OPhase.WRITE_END;
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{"WRITE_XML"}; return new String[]{"WRITE_FILL_TREE"};
} }
public boolean isElementPhase() { public boolean isElementPhase() {
return false; return false;
@ -438,4 +178,27 @@ public class X4OPhaseLanguageWrite {
logger.finest("Run init end phase"); logger.finest("Run init end phase");
} }
}; };
class X4OPhaseWriteRelease extends AbstractX4OPhase {
public X4OPhaseType getType() {
return X4OPhaseType.XML_WRITE;
}
public String getId() {
return X4OPhase.WRITE_RELEASE;
}
public String[] getPhaseDependencies() {
return new String[] {X4OPhase.WRITE_END};
}
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
}
public void runElementPhase(Element element) throws X4OPhaseException {
try {
element.release();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}/* finally {
releaseCounter.addReleasedElement();
}*/
}
}
} }

View file

@ -33,15 +33,9 @@ public enum X4OPhaseType {
/** Language init. */ /** Language init. */
INIT, INIT,
/** Read/Write xml.(not used) */
XML_RW,
/** XML Reading. */ /** XML Reading. */
XML_READ, XML_READ,
/** XML Writing. */ /** XML Writing. */
XML_WRITE, XML_WRITE;
/** XML Schema writing. */
XML_WRITE_SCHEMA
} }

View file

@ -52,7 +52,7 @@
id="eld-root" id="eld-root"
> >
<description>Single root namespace so xsd schema generation works correct.</description> <description>Single root namespace so xsd schema generation works correct.</description>
<element id="module" objectClass="${parentLanguageConfiguration.defaultElementLanguageModule}" elementClass="org.x4o.xml.eld.lang.ModuleElement"> <element id="module" objectClass="${parentLanguage.languageConfiguration.defaultElementLanguageModule}" elementClass="org.x4o.xml.eld.lang.ModuleElement">
<description>The module root element.</description> <description>The module root element.</description>
<attribute id="id" required="true"> <attribute id="id" required="true">
<description>The module id.</description> <description>The module id.</description>
@ -77,13 +77,13 @@
<description>Some basic language definitions and some helper tags.</description> <description>Some basic language definitions and some helper tags.</description>
<!-- First copy some core elements over from parent config --> <!-- First copy some core elements over from parent config -->
<element id="namespace" objectClass="${parentLanguageConfiguration.defaultElementNamespaceContext}"> <element id="namespace" objectClass="${parentLanguage.languageConfiguration.defaultElementNamespaceContext}">
<description>Defines an namespace for the language.</description> <description>Defines an namespace for the language.</description>
<attribute id="id" required="true"> <attribute id="id" required="true">
<description>The namespace id.</description> <description>The namespace id.</description>
</attribute> </attribute>
</element> </element>
<element id="element" objectClass="${parentLanguageConfiguration.defaultElementClass}"> <element id="element" objectClass="${parentLanguage.languageConfiguration.defaultElementClass}">
<description>The xml element.</description> <description>The xml element.</description>
<attribute id="id"> <attribute id="id">
<attributeAlias name="tag"/> <attributeAlias name="tag"/>
@ -98,7 +98,7 @@
<classConverter/> <classConverter/>
</attribute> </attribute>
</element> </element>
<element id="elementInterface" objectClass="${parentLanguageConfiguration.defaultElementInterface}"> <element id="elementInterface" objectClass="${parentLanguage.languageConfiguration.defaultElementInterface}">
<description>Config element objects by java interface.</description> <description>Config element objects by java interface.</description>
<attribute id="id" required="true"> <attribute id="id" required="true">
<description>The interface id.</description> <description>The interface id.</description>
@ -108,7 +108,7 @@
<classConverter/> <classConverter/>
</attribute> </attribute>
</element> </element>
<element id="attribute" objectClass="${parentLanguageConfiguration.defaultElementClassAttribute}"> <element id="attribute" objectClass="${parentLanguage.languageConfiguration.defaultElementClassAttribute}">
<description>XML Element Attribute tag.</description> <description>XML Element Attribute tag.</description>
<attribute id="id"> <attribute id="id">
<attributeAlias name="name"/> <attributeAlias name="name"/>

View file

@ -86,7 +86,7 @@ public class X4ODriverManagerTest extends TestCase {
Throwable e = null; Throwable e = null;
try { try {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(language); X4ODriver<?> driver = X4ODriverManager.getX4ODriver(language);
driver.createLanguageContext(version); driver.createLanguage(version).createLanguageContext();
} catch (Throwable catchE) { } catch (Throwable catchE) {
e = catchE; e = catchE;
} }

View file

@ -69,7 +69,7 @@ public class EmptyXmlTest extends TestCase {
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
try { try {
reader.readResource("tests/empty-xml/empty-test.xml"); reader.readResource("tests/empty-xml/empty-test.xml");
} catch (SAXParseException e) { } catch (SAXException e) {
assertEquals("No ElementNamespaceContext found for empty namespace.", e.getMessage()); assertEquals("No ElementNamespaceContext found for empty namespace.", e.getMessage());
return; return;
} }

View file

@ -22,9 +22,10 @@
*/ */
package org.x4o.xml.core; package org.x4o.xml.core;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.X4OReaderContext; import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
@ -42,7 +43,7 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
TestDriver driver = TestDriver.getInstance(); TestDriver driver = TestDriver.getInstance();
X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext(); X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("tests/namespace/uri-simple.xml"); context = reader.readResourceContext("tests/namespace/uri-simple.xml");
assertEquals(true,context.getRootElement().getChilderen().size()==1); assertEquals(true,context.getRootElement().getChilderen().size()==1);
@ -55,8 +56,8 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
TestDriver driver = TestDriver.getInstance(); TestDriver driver = TestDriver.getInstance();
X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext(); X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
reader.setProperty(X4OLanguagePropertyKeys.READER_EMPTY_NAMESPACE_URI, "http://test.x4o.org/xml/ns/test-lang"); reader.setProperty(DefaultX4OReader.DOC_EMPTY_NAMESPACE_URI, "http://test.x4o.org/xml/ns/test-lang");
try { try {
context = reader.readResourceContext("tests/namespace/uri-empty.xml"); context = reader.readResourceContext("tests/namespace/uri-empty.xml");
assertEquals(true,context.getRootElement().getChilderen().size()==1); assertEquals(true,context.getRootElement().getChilderen().size()==1);
@ -69,7 +70,7 @@ public class NamespaceUriTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
TestDriver driver = TestDriver.getInstance(); TestDriver driver = TestDriver.getInstance();
X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext(); X4OReaderContext<TestObjectRoot> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("tests/namespace/uri-schema.xml"); context = reader.readResourceContext("tests/namespace/uri-schema.xml");
assertEquals(true,context.getRootElement().getChilderen().size()==1); assertEquals(true,context.getRootElement().getChilderen().size()==1);

View file

@ -23,12 +23,10 @@
package org.x4o.xml.core; package org.x4o.xml.core;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
@ -53,7 +51,7 @@ public class X4ODebugWriterTest extends TestCase {
File debugFile = createDebugFile(); File debugFile = createDebugFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile)); //reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile));
reader.readResource("tests/attributes/test-bean.xml"); reader.readResource("tests/attributes/test-bean.xml");
assertTrue("Debug file does not exists.",debugFile.exists()); assertTrue("Debug file does not exists.",debugFile.exists());
@ -64,7 +62,7 @@ public class X4ODebugWriterTest extends TestCase {
File debugFile = createDebugFile(); File debugFile = createDebugFile();
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile)); //reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile));
//reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_ELD_PARSER, true); //reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_ELD_PARSER, true);
reader.readResource("tests/attributes/test-bean.xml"); reader.readResource("tests/attributes/test-bean.xml");

View file

@ -26,9 +26,10 @@ import java.io.IOException;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.eld.CelDriver; import org.x4o.xml.eld.CelDriver;
import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.sax.X4OEntityResolver; import org.x4o.xml.io.sax.X4OEntityResolver;
import org.x4o.xml.io.sax.ext.PropertyConfig;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
@ -48,7 +49,7 @@ public class X4OEntityResolverTest extends TestCase {
public void testElementLangugeNull() throws Exception { public void testElementLangugeNull() throws Exception {
Exception e = null; Exception e = null;
try { try {
new X4OEntityResolver(null); new X4OEntityResolver(null,null);
} catch (Exception catchE) { } catch (Exception catchE) {
e = catchE; e = catchE;
} }
@ -59,14 +60,14 @@ public class X4OEntityResolverTest extends TestCase {
public void testResolve() throws Exception { public void testResolve() throws Exception {
X4ODriver<?> driver = new CelDriver(); X4ODriver<?> driver = new CelDriver();
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguageContext()); X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageContext(),DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
InputSource input = resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd"); InputSource input = resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd");
assertNotNull(input); assertNotNull(input);
} }
public void testResolveMissing() throws Exception { public void testResolveMissing() throws Exception {
X4ODriver<TestObjectRoot> driver = new TestDriver(); X4ODriver<TestObjectRoot> driver = new TestDriver();
X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguageContext()); X4OEntityResolver resolver = new X4OEntityResolver(driver.createLanguage().createLanguageContext(),DefaultX4OReader.DEFAULT_PROPERTY_CONFIG);
Exception e = null; Exception e = null;
try { try {
resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-missing-resource"); resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-missing-resource");
@ -80,9 +81,10 @@ public class X4OEntityResolverTest extends TestCase {
public void testResolveProperty() throws Exception { public void testResolveProperty() throws Exception {
X4ODriver<TestObjectRoot> driver = new TestDriver(); X4ODriver<TestObjectRoot> driver = new TestDriver();
X4OLanguageContext language = driver.createLanguageContext(); X4OLanguageContext language = driver.createLanguage().createLanguageContext();
language.setLanguageProperty(X4OLanguageProperty.READER_ENTITY_RESOLVER, new TestEntityResolver()); PropertyConfig conf = new PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG,PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_READER);
X4OEntityResolver resolver = new X4OEntityResolver(language); conf.setProperty(DefaultX4OReader.SAX_ENTITY_RESOLVER, new TestEntityResolver());
X4OEntityResolver resolver = new X4OEntityResolver(language,conf);
Exception e = null; Exception e = null;
InputSource input = null; InputSource input = null;
try { try {
@ -96,9 +98,10 @@ public class X4OEntityResolverTest extends TestCase {
public void testResolvePropertyNull() throws Exception { public void testResolvePropertyNull() throws Exception {
X4ODriver<TestObjectRoot> driver = new TestDriver(); X4ODriver<TestObjectRoot> driver = new TestDriver();
X4OLanguageContext language = driver.createLanguageContext(); X4OLanguageContext language = driver.createLanguage().createLanguageContext();
language.setLanguageProperty(X4OLanguageProperty.READER_ENTITY_RESOLVER, new TestEntityResolver()); PropertyConfig conf = new PropertyConfig(DefaultX4OReader.DEFAULT_PROPERTY_CONFIG,PropertyConfig.X4O_PROPERTIES_PREFIX+PropertyConfig.X4O_PROPERTIES_READER);
X4OEntityResolver resolver = new X4OEntityResolver(language); conf.setProperty(DefaultX4OReader.SAX_ENTITY_RESOLVER, new TestEntityResolver());
X4OEntityResolver resolver = new X4OEntityResolver(language,conf);
Exception e = null; Exception e = null;
try { try {
resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-null"); resolver.resolveEntity("","http://cel.x4o.org/xml/ns/cel-root-1.0.xsd-null");

View file

@ -43,7 +43,7 @@ public class X4OParserConfigurationTest extends TestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
driver = TestDriver.getInstance(); driver = TestDriver.getInstance();
config = driver.createLanguageContext().getLanguage().getLanguageConfiguration(); config = driver.createLanguage().getLanguageConfiguration();
} }
public void testParserConfigurationLanguage() { public void testParserConfigurationLanguage() {

View file

@ -50,7 +50,7 @@ public class X4OPhaseManagerTest extends TestCase {
public void testPhases() throws Exception { public void testPhases() throws Exception {
TestDriver driver = TestDriver.getInstance(); TestDriver driver = TestDriver.getInstance();
X4OLanguageContext context = driver.createLanguageContext(); X4OLanguageContext context = driver.createLanguage().createLanguageContext();
X4OPhaseManager manager = context.getLanguage().getPhaseManager(); X4OPhaseManager manager = context.getLanguage().getPhaseManager();
Collection<X4OPhase> phasesAll = manager.getAllPhases(); Collection<X4OPhase> phasesAll = manager.getAllPhases();
List<X4OPhase> phases = manager.getOrderedPhases(X4OPhaseType.XML_READ); List<X4OPhase> phases = manager.getOrderedPhases(X4OPhaseType.XML_READ);

View file

@ -111,9 +111,8 @@ public class EldParserTest extends TestCase {
X4OLanguage language = driver.createLanguage(driver.getLanguageVersionDefault()); X4OLanguage language = driver.createLanguage(driver.getLanguageVersionDefault());
X4OLanguageModule mod = new DefaultX4OLanguageModule(); X4OLanguageModule mod = new DefaultX4OLanguageModule();
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration());
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE, language); reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE, language);
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE, mod); reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE_MODULE, mod);
X4OLanguageModule modNew = reader.readResource("META-INF/test/test-lang.eld"); X4OLanguageModule modNew = reader.readResource("META-INF/test/test-lang.eld");

View file

@ -23,9 +23,8 @@
package org.x4o.xml.eld; package org.x4o.xml.eld;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.eld.EldDriver; import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
@ -42,13 +41,12 @@ public class EldValidatingTest extends TestCase {
public void testValidation() throws Exception { public void testValidation() throws Exception {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); //reader.getContentConfig().setProperty("",true);
reader.setProperty(X4OLanguagePropertyKeys.READER_VALIDATION_INPUT, true); reader.setProperty(DefaultX4OReader.VALIDATION_INPUT_DOC, true);
//parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_SCHEMA_PATH, "/tmp"); //parser.setProperty(DefaultX4OReader.VALIDATION_SCHEMA_PATH, "/tmp");
try { try {
// TODO: reader.readResource("META-INF/eld/eld-lang.eld"); // TODO: reader.readResource("META-INF/eld/eld-lang.eld");
} finally { } finally {
} }
} }
} }

View file

@ -24,7 +24,6 @@ package org.x4o.xml.io;
import org.x4o.xml.X4ODriver; import org.x4o.xml.X4ODriver;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.TestDriver; import org.x4o.xml.test.TestDriver;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
@ -38,19 +37,34 @@ import junit.framework.TestCase;
*/ */
public class X4OConnectionTest extends TestCase { public class X4OConnectionTest extends TestCase {
public void testReaderPropertyFail() throws Exception { public void testReaderPropertyFailRead() throws Exception {
Exception e = null; Exception e = null;
try { try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test"); reader.getProperty("test");
} catch (Exception catchE) { } catch (Exception catchE) {
e = catchE; e = catchE;
} }
assertNotNull("No exception",e); assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key")); assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected")); assertTrue("Wrong exception message",e.getMessage().contains("No"));
}
public void testReaderPropertyFail() throws Exception {
Exception e = null;
try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader();
reader.setProperty("test", "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("No"));
} }
public void testWriterPropertyFail() throws Exception { public void testWriterPropertyFail() throws Exception {
@ -58,14 +72,14 @@ public class X4OConnectionTest extends TestCase {
try { try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OWriter<TestObjectRoot> writer = driver.createWriter(); X4OWriter<TestObjectRoot> writer = driver.createWriter();
writer.setProperty(X4OLanguagePropertyKeys.READER_INPUT_ENCODING, "test"); writer.setProperty("test", "test");
} catch (Exception catchE) { } catch (Exception catchE) {
e = catchE; e = catchE;
} }
assertNotNull("No exception",e); assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key")); assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected")); assertTrue("Wrong exception message",e.getMessage().contains("No"));
} }
public void testSchemaWriterPropertyFail() throws Exception { public void testSchemaWriterPropertyFail() throws Exception {
@ -73,13 +87,13 @@ public class X4OConnectionTest extends TestCase {
try { try {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OSchemaWriter schemaWriter = driver.createSchemaWriter(); X4OSchemaWriter schemaWriter = driver.createSchemaWriter();
schemaWriter.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_ENCODING, "test"); schemaWriter.setProperty("test", "test");
} catch (Exception catchE) { } catch (Exception catchE) {
e = catchE; e = catchE;
} }
assertNotNull("No exception",e); assertNotNull("No exception",e);
assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass()); assertEquals("Wrong exception class",IllegalArgumentException.class, e.getClass());
assertTrue("Wrong exception message",e.getMessage().contains("key")); assertTrue("Wrong exception message",e.getMessage().contains("key"));
assertTrue("Wrong exception message",e.getMessage().contains("protected")); assertTrue("Wrong exception message",e.getMessage().contains("No"));
} }
} }

View file

@ -55,7 +55,7 @@ public class X4OWriterContextTest extends TestCase {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
X4OLanguageContext context = driver.createLanguageContext(); X4OLanguageContext context = driver.createLanguage().createLanguageContext();
Element rootElement = null; Element rootElement = null;
try { try {
rootElement = (Element)context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance(); rootElement = (Element)context.getLanguage().getLanguageConfiguration().getDefaultElement().newInstance();

View file

@ -46,7 +46,7 @@ public class DefaultX4OLanguageLoaderTest extends TestCase {
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance(); X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
//X4OReader<TestObjectRoot> reader = driver.createReader(); //X4OReader<TestObjectRoot> reader = driver.createReader();
//reader.readResource("tests/namespace/uri-simple.xml"); //reader.readResource("tests/namespace/uri-simple.xml");
language = driver.createLanguageContext().getLanguage(); language = driver.createLanguage();
loader = (X4OLanguageLoader)language.getLanguageConfiguration().getDefaultLanguageLoader().newInstance(); loader = (X4OLanguageLoader)language.getLanguageConfiguration().getDefaultLanguageLoader().newInstance();
} }

View file

@ -22,8 +22,6 @@
*/ */
package org.x4o.xml.lang; package org.x4o.xml.lang;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -34,7 +32,12 @@ import junit.framework.TestCase;
* @version 1.0 Aug 27, 2012 * @version 1.0 Aug 27, 2012
*/ */
public class X4OLanguagePropertyTest extends TestCase { public class X4OLanguagePropertyTest extends TestCase {
public void testUriValue() throws Exception {
assertEquals(1,1);
}
/*
public void testUriValue() throws Exception { public void testUriValue() throws Exception {
new X4OLanguagePropertyKeys(); new X4OLanguagePropertyKeys();
X4OLanguageProperty prop = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.LANGUAGE_NAME); X4OLanguageProperty prop = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.LANGUAGE_NAME);
@ -106,4 +109,5 @@ public class X4OLanguagePropertyTest extends TestCase {
X4OLanguageProperty elMap = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP); X4OLanguageProperty elMap = X4OLanguageProperty.valueByUri(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP);
assertEquals(false, elMap.isValueValid("string-object")); assertEquals(false, elMap.isValueValid("string-object"));
} }
*/
} }

View file

@ -26,7 +26,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.test.models.TestObjectRoot; import org.x4o.xml.test.models.TestObjectRoot;
@ -50,7 +49,7 @@ public class SwingTests extends TestCase {
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
File f = File.createTempFile("test-swing", ".xml"); File f = File.createTempFile("test-swing", ".xml");
//f.deleteOnExit(); //f.deleteOnExit();
reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(f)); //reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(f));
//reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_ELD_PARSER, true); //reader.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_ELD_PARSER, true);
//reader.readResource("tests/test-swing.xml"); //reader.readResource("tests/test-swing.xml");
//Thread.sleep(30000); //Thread.sleep(30000);

View file

@ -69,12 +69,12 @@ public class EldDocWriterElementClass extends AbstractApiDocWriter {
printApiTableBean(event, "Element", "class","id","description"); printApiTableBean(event, "Element", "class","id","description");
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementClass.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary")
public void writeElementClassAttribute(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementClassAttribute(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class); printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementClass.class},nodeBodyOrders={3},contentGroup="configurator",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementClass.class},nodeBodyOrders={3},contentGroup="configurator",contentGroupType="summary")
public void writeElementConfigurator(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementConfigurator(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Configurator Summary",ElementConfigurator.class); printApiTable(event,"Element Configurator Summary",ElementConfigurator.class);
} }

View file

@ -52,22 +52,22 @@ public class EldDocWriterElementInterface extends AbstractApiDocWriter {
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementInterface.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary")
public void writeElementNamespaceBeanProperties(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementNamespaceBeanProperties(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTableBean(event,"Interface","description"); printApiTableBean(event,"Interface","description");
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementInterface.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={2},contentGroup="attribute",contentGroupType="summary")
public void writeElementClassAttribute(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementClassAttribute(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class); printApiTable(event,"Element Class Attribute Summary",ElementClassAttribute.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementInterface.class},nodeBodyOrders={3},contentGroup="binding",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={3},contentGroup="binding",contentGroupType="summary")
public void writeElementBindingHandler(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementBindingHandler(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Binding Handler Summary",ElementBindingHandler.class); printApiTable(event,"Element Binding Handler Summary",ElementBindingHandler.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementInterface.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementInterface.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary")
public void writeElementConfigurator(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementConfigurator(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Configurator Summary",ElementConfigurator.class); printApiTable(event,"Element Configurator Summary",ElementConfigurator.class);
} }

View file

@ -47,12 +47,12 @@ public class EldDocWriterElementNamespace extends AbstractApiDocWriter {
clearHrefContentGroup(doc,node,"summary","element",ElementClass.class); clearHrefContentGroup(doc,node,"summary","element",ElementClass.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementNamespaceContext.class},nodeBodyOrders={1},contentGroup="namespace",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementNamespaceContext.class},nodeBodyOrders={1},contentGroup="namespace",contentGroupType="summary")
public void writeElementNamespaceBeanProperties(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementNamespaceBeanProperties(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTableBean(event,"Namespace","description","elementClasses","elementNamespaceInstanceProvider","prefixMapping"); printApiTableBean(event,"Namespace","description","elementClasses","elementNamespaceInstanceProvider","prefixMapping");
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={ElementNamespaceContext.class},nodeBodyOrders={2},contentGroup="element",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={ElementNamespaceContext.class},nodeBodyOrders={2},contentGroup="element",contentGroupType="summary")
public void writeElementNamespaceElements(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeElementNamespaceElements(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Element Summary",ElementClass.class); printApiTable(event,"Element Summary",ElementClass.class);
} }

View file

@ -64,7 +64,7 @@ public class EldDocWriterLanguage extends AbstractApiDocWriter {
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageContext.class},nodeBodyOrders={1}) @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageContext.class},nodeBodyOrders={1})
public void writeLanguageSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeLanguageSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
ApiDocContentWriter writer = event.getWriter(); ApiDocContentWriter writer = event.getWriter();
ApiDocNode node = event.getEventObject(); ApiDocNode node = event.getEventObject();
@ -99,12 +99,12 @@ public class EldDocWriterLanguage extends AbstractApiDocWriter {
writer.docTableEnd(); writer.docTableEnd();
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageContext.class},nodeBodyOrders={2}) @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageContext.class},nodeBodyOrders={2})
public void writeModulesSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeModulesSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Module Summary",X4OLanguageModule.class); printApiTable(event,"Module Summary",X4OLanguageModule.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageContext.class},nodeBodyOrders={3}) @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageContext.class},nodeBodyOrders={3})
public void writeNamespaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeNamespaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
ApiDocContentWriter writer = event.getWriter(); ApiDocContentWriter writer = event.getWriter();
ApiDocNode node = event.getEventObject(); ApiDocNode node = event.getEventObject();

View file

@ -55,27 +55,27 @@ public class EldDocWriterLanguageModule extends AbstractApiDocWriter {
clearHrefContentGroup(doc,node,"summary","namespace",ElementNamespaceContext.class); clearHrefContentGroup(doc,node,"summary","namespace",ElementNamespaceContext.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageModule.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={1},contentGroup="interface",contentGroupType="summary")
public void writeInterfaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeInterfaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Interface Summary",ElementInterface.class); printApiTable(event,"Interface Summary",ElementInterface.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageModule.class},nodeBodyOrders={2},contentGroup="binding",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={2},contentGroup="binding",contentGroupType="summary")
public void writeBindingSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeBindingSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Binding Summary",ElementBindingHandler.class); printApiTable(event,"Binding Summary",ElementBindingHandler.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageModule.class},nodeBodyOrders={3},contentGroup="attribute",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={3},contentGroup="attribute",contentGroupType="summary")
public void writeAttributeSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeAttributeSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Attribute Summary",ElementAttributeHandler.class); printApiTable(event,"Attribute Summary",ElementAttributeHandler.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageModule.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={4},contentGroup="configurator",contentGroupType="summary")
public void writeConfigutorSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeConfigutorSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Configurator Summary",ElementConfigurator.class); printApiTable(event,"Configurator Summary",ElementConfigurator.class);
} }
@ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY_PAGE,targetClasses={X4OLanguageModule.class},nodeBodyOrders={5},contentGroup="namespace",contentGroupType="summary") @ApiDocNodeWriterMethod(nodeBody=ApiDocNodeBody.SUMMARY,targetClasses={X4OLanguageModule.class},nodeBodyOrders={5},contentGroup="namespace",contentGroupType="summary")
public void writeNamespaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException { public void writeNamespaceSummary(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
printApiTable(event,"Namespace Summary",ElementNamespaceContext.class); printApiTable(event,"Namespace Summary",ElementNamespaceContext.class);
} }

View file

@ -95,7 +95,7 @@ public class X4OWriteLanguageDocExecutor {
*/ */
public void execute() throws ElementException { public void execute() throws ElementException {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName()); X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName());
X4OLanguageContext context = driver.createLanguageContext(getLanguageVersion()); X4OLanguageContext context = driver.createLanguage(getLanguageVersion()).createLanguageContext();
// Run doc writer // Run doc writer
EldDocWriter docWriter = new EldDocWriter(context); EldDocWriter docWriter = new EldDocWriter(context);

View file

@ -40,8 +40,8 @@ public class ApiDocContentWriter extends ContentWriterHtml {
private boolean isAltRow = true; private boolean isAltRow = true;
public ApiDocContentWriter(Writer out,String encoding,String charNewLine,String charTab) { public ApiDocContentWriter(Writer out,String encoding) {
super(out,encoding,charNewLine,charTab); super(out,encoding);
} }
public void docCommentGenerated() throws SAXException { public void docCommentGenerated() throws SAXException {

View file

@ -172,8 +172,7 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writeNodeTreePath(bodyEvent); writeNodeTreePath(bodyEvent);
} }
writeNodeDescription(bodyEvent,isNodePageMode); writeNodeDescription(bodyEvent,isNodePageMode);
writeNodeSummary(bodyEvent,true); // print without div and block lists writeNodeSummary(bodyEvent,isNodePageMode);
writeNodeSummary(bodyEvent,false);
writeNodeDetails(bodyEvent); writeNodeDetails(bodyEvent);
writer.docPageContentEnd(); writer.docPageContentEnd();
writer.docPageClassEnd(); writer.docPageClassEnd();
@ -240,35 +239,28 @@ public class ApiDocWriter extends AbstractApiDocWriter {
writer.printTagEnd(Tag.div); // description writer.printTagEnd(Tag.div); // description
} }
private void writeNodeSummary(ApiDocWriteEvent<ApiDocNode> event,boolean isPage) throws SAXException { private void writeNodeSummary(ApiDocWriteEvent<ApiDocNode> event,boolean isPageMode) throws SAXException {
ApiDocContentWriter writer = event.getWriter(); ApiDocContentWriter writer = event.getWriter();
List<ApiDocNodeWriter> bodyWriterSummary = null; List<ApiDocNodeWriter> bodyWriterSummary = findNodeBodyWriters(event.getEventObject(),ApiDocNodeBody.SUMMARY);
List<ApiDocNodeWriter> bodyWriterSummaryPage = findNodeBodyWriters(event.getEventObject(),ApiDocNodeBody.SUMMARY_PAGE); if (!isPageMode) {
List<ApiDocNodeWriter> bodyWriterSummaryNormal = findNodeBodyWriters(event.getEventObject(),ApiDocNodeBody.SUMMARY);
if (isPage) {
bodyWriterSummary = bodyWriterSummaryPage;
} else {
bodyWriterSummary = bodyWriterSummaryNormal;
}
if (!isPage) {
writer.printTagStart(Tag.div, ApiDocContentCss.summary); writer.printTagStart(Tag.div, ApiDocContentCss.summary);
writer.docPageBlockStart(); writer.docPageBlockStart();
} }
if (bodyWriterSummary.isEmpty() && !isPage && bodyWriterSummaryPage.isEmpty()) { if (bodyWriterSummary.isEmpty() && event.getEventObject().getNodes().isEmpty()==false) {
writer.docPageBlockStart(); if (!isPageMode) { writer.docPageBlockStart(); }
defaultWriteSummary(event.getEventObject(),writer); defaultWriteSummary(event.getEventObject(),writer);
writer.docPageBlockEnd(); if (!isPageMode) { writer.docPageBlockEnd(); }
} }
for (int i=0;i<bodyWriterSummary.size();i++) { for (int i=0;i<bodyWriterSummary.size();i++) {
ApiDocNodeWriter nodeWriter = bodyWriterSummary.get(i); ApiDocNodeWriter nodeWriter = bodyWriterSummary.get(i);
if (!isPage) { writer.docPageBlockStart(); } if (!isPageMode) { writer.docPageBlockStart(); }
writeSubNavNamedHref(event,nodeWriter); writeSubNavNamedHref(event,nodeWriter);
if (!isPage) { writer.printTagCharacters(Tag.h3, "Summary"); } if (!isPageMode) { writer.printTagCharacters(Tag.h3, "Summary"); }
nodeWriter.writeNodeContent(event); nodeWriter.writeNodeContent(event);
if (!isPage) { writer.docPageBlockEnd(); } if (!isPageMode) { writer.docPageBlockEnd(); }
if (isPage) { writer.printTagStartEnd(Tag.br); } // mm .. mm if (isPageMode) { writer.printTagStartEnd(Tag.br); } // mm .. mm
} }
if (!isPage) { if (!isPageMode) {
writer.docPageBlockEnd(); writer.docPageBlockEnd();
writer.printTagEnd(Tag.div); // Summary writer.printTagEnd(Tag.div); // Summary
} }
@ -459,9 +451,9 @@ public class ApiDocWriter extends AbstractApiDocWriter {
String encoding = XMLConstants.XML_DEFAULT_ENCODING; String encoding = XMLConstants.XML_DEFAULT_ENCODING;
try { try {
Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), encoding); Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
String charNewLine = XMLConstants.CHAR_NEWLINE+""; ApiDocContentWriter result = new ApiDocContentWriter(out,encoding);
String charTab = " "; result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_NEWLINE, XMLConstants.CHAR_NEWLINE+"");
ApiDocContentWriter result = new ApiDocContentWriter(out,encoding,charNewLine,charTab); result.getPropertyConfig().setProperty(ApiDocContentWriter.OUTPUT_CHAR_TAB, " ");
return result; return result;
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new SAXException(e); throw new SAXException(e);

View file

@ -23,10 +23,7 @@
package org.x4o.xml.eld.doc.api.dom; package org.x4o.xml.eld.doc.api.dom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* ApiDocNode defines the concept impl data tree nodes for which we write documents. * ApiDocNode defines the concept impl data tree nodes for which we write documents.
@ -42,11 +39,9 @@ public class ApiDocNode {
private String description = null; private String description = null;
private ApiDocNode parent = null; private ApiDocNode parent = null;
private List<ApiDocNode> nodes = null; private List<ApiDocNode> nodes = null;
private Map<String,String> contentGroupTypes = null;
public ApiDocNode() { public ApiDocNode() {
nodes = new ArrayList<ApiDocNode>(30); nodes = new ArrayList<ApiDocNode>(30);
contentGroupTypes = new HashMap<String,String>(3);
} }
public ApiDocNode(Object userData,String id,String name,String description) { public ApiDocNode(Object userData,String id,String name,String description) {
@ -74,22 +69,6 @@ public class ApiDocNode {
return nodes; return nodes;
} }
public void addContentGroupType(String id,String name) {
contentGroupTypes.put(id, name);
}
public void removeContentGroupType(String id) {
contentGroupTypes.remove(id);
}
public String getContentGroupTypeName(String id) {
return contentGroupTypes.get(id);
}
public Set<String> getContentGroupTypeKeys() {
return contentGroupTypes.keySet();
}
/** /**
* @return the userData * @return the userData
*/ */
@ -104,8 +83,6 @@ public class ApiDocNode {
this.userData = userData; this.userData = userData;
} }
/** /**
* @return the id * @return the id
*/ */

View file

@ -34,10 +34,5 @@ public enum ApiDocNodeBody {
DESCRIPTION_LINKS, DESCRIPTION_LINKS,
DESCRIPTION_NODE, DESCRIPTION_NODE,
SUMMARY, SUMMARY,
DETAIL, DETAIL
/**
* Summary page blocks had no div and no block lists around content.
*/
SUMMARY_PAGE
} }

View file

@ -28,7 +28,7 @@ import org.x4o.xml.element.DefaultElement;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
import org.x4o.xml.io.X4OReaderContext; import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.lang.phase.X4OPhase;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -44,7 +44,7 @@ public class ParentObjectTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
MTestDriver driver = new MTestDriver(); MTestDriver driver = new MTestDriver();
X4OReaderContext<?> reader = driver.createReaderContext(); X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("junit/test-meta-parent-element.xml"); context = reader.readResourceContext("junit/test-meta-parent-element.xml");
assertEquals(1,context.getRootElement().getChilderen().size()); assertEquals(1,context.getRootElement().getChilderen().size());

View file

@ -26,7 +26,7 @@ import java.util.Date;
import org.x4o.xml.io.X4OReaderContext; import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.lang.phase.X4OPhase;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -42,7 +42,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
MTestDriver driver = new MTestDriver(); MTestDriver driver = new MTestDriver();
X4OReaderContext<?> reader = driver.createReaderContext(); X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("junit/test-meta-generic.xml"); context = reader.readResourceContext("junit/test-meta-generic.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName()); assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
@ -55,7 +55,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
MTestDriver driver = new MTestDriver(); MTestDriver driver = new MTestDriver();
X4OReaderContext<?> reader = driver.createReaderContext(); X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("junit/test-meta-reference.xml"); context = reader.readResourceContext("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName()); assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());
@ -68,7 +68,7 @@ public class ReferenceStoreTest extends TestCase {
X4OLanguageContext context = null; X4OLanguageContext context = null;
MTestDriver driver = new MTestDriver(); MTestDriver driver = new MTestDriver();
X4OReaderContext<?> reader = driver.createReaderContext(); X4OReaderContext<?> reader = driver.createReaderContext();
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true); reader.addPhaseSkip(X4OPhase.READ_RELEASE);
try { try {
context = reader.readResourceContext("junit/test-meta-reference.xml"); context = reader.readResourceContext("junit/test-meta-reference.xml");
assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName()); assertEquals(Date.class.getName(),context.getRootElement().getChilderen().get(0).getElementObject().getClass().getName());