Moved writer to phases.

Refactored language properties.
Refactored io connection exceptions.
This commit is contained in:
Willem Cazander 2013-04-28 18:51:23 +02:00
parent 8f2408a207
commit ed1732a625
37 changed files with 1131 additions and 739 deletions

View file

@ -23,8 +23,6 @@
package org.x4o.xml; package org.x4o.xml;
import java.util.Collection;
import org.x4o.xml.io.DefaultX4OReader; import org.x4o.xml.io.DefaultX4OReader;
import org.x4o.xml.io.DefaultX4OSchemaWriter; import org.x4o.xml.io.DefaultX4OSchemaWriter;
import org.x4o.xml.io.DefaultX4OWriter; import org.x4o.xml.io.DefaultX4OWriter;
@ -37,7 +35,6 @@ 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.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.x4o.xml.lang.phase.X4OPhaseManager; import org.x4o.xml.lang.phase.X4OPhaseManager;
/** /**
@ -69,6 +66,8 @@ public abstract class X4ODriver<T> {
// =============== build methods to override
protected X4OLanguage buildLanguage(String version) { protected X4OLanguage buildLanguage(String version) {
return X4ODriverManager.getDefaultBuildLanguage(this, version); return X4ODriverManager.getDefaultBuildLanguage(this, version);
} }
@ -83,6 +82,8 @@ public abstract class X4ODriver<T> {
// =============== SchemaWriter
public X4OSchemaWriter createSchemaWriter() { public X4OSchemaWriter createSchemaWriter() {
return createSchemaWriter(getLanguageVersionDefault()); return createSchemaWriter(getLanguageVersionDefault());
} }
@ -93,6 +94,8 @@ public abstract class X4ODriver<T> {
// =============== Reader
public X4OReader<T> createReader() { public X4OReader<T> createReader() {
return createReaderContext(); return createReaderContext();
} }
@ -101,14 +104,6 @@ public abstract class X4ODriver<T> {
return createReaderContext(version); return createReaderContext(version);
} }
public X4OWriter<T> createWriter() {
return createWriterContext();
}
public X4OWriter<T> createWriter(String version) {
return createWriterContext(version);
}
public X4OReaderContext<T> createReaderContext() { public X4OReaderContext<T> createReaderContext() {
return createReaderContext(getLanguageVersionDefault()); return createReaderContext(getLanguageVersionDefault());
} }
@ -117,6 +112,18 @@ public abstract class X4ODriver<T> {
return new DefaultX4OReader<T>(createLanguageContext(version)); return new DefaultX4OReader<T>(createLanguageContext(version));
} }
// =============== Writer
public X4OWriter<T> createWriter() {
return createWriterContext();
}
public X4OWriter<T> createWriter(String version) {
return createWriterContext(version);
}
public X4OWriterContext<T> createWriterContext() { public X4OWriterContext<T> createWriterContext() {
return createWriterContext(getLanguageVersionDefault()); return createWriterContext(getLanguageVersionDefault());
} }
@ -127,16 +134,12 @@ public abstract class X4ODriver<T> {
public String getLanguageVersionDefault() { // =============== Language
final public String getLanguageVersionDefault() {
return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions()); return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions());
} }
public String[] getGlobalPropertyKeySet() {
return X4OLanguagePropertyKeys.DEFAULT_X4O_GLOBAL_KEYS;
}
final public X4OLanguage createLanguage(String version) { final public X4OLanguage createLanguage(String version) {
return buildLanguage(version); return buildLanguage(version);
} }
@ -148,16 +151,4 @@ public abstract class X4ODriver<T> {
final public X4OLanguageContext createLanguageContext(String version) { final public X4OLanguageContext createLanguageContext(String version) {
return createLanguage(version).createLanguageContext(this); return createLanguage(version).createLanguageContext(this);
} }
final public Collection<String> getGlobalPropertyKeys() {
return X4ODriverManager.getGlobalPropertyKeys(this);
}
final public Object getGlobalProperty(String key) {
return X4ODriverManager.getGlobalProperty(this, key);
}
final public void setGlobalProperty(String key,Object value) {
X4ODriverManager.setGlobalProperty(this, key, value);
}
} }

View file

@ -27,7 +27,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
@ -67,14 +66,12 @@ public final class X4ODriverManager {
private Map<String,String> classdrivers = null; private Map<String,String> classdrivers = null;
private Map<String,String> defaultDrivers = null; private Map<String,String> defaultDrivers = null;
private Map<String,X4ODriver<?>> drivers = null; private Map<String,X4ODriver<?>> drivers = null;
private Map<String,Map<String,Object>> globalProperties = null;
private X4ODriverManager() { private X4ODriverManager() {
logger = Logger.getLogger(X4ODriverManager.class.getName()); logger = Logger.getLogger(X4ODriverManager.class.getName());
classdrivers = new HashMap<String,String>(10); classdrivers = new HashMap<String,String>(10);
defaultDrivers = new HashMap<String,String>(10); defaultDrivers = new HashMap<String,String>(10);
drivers = new HashMap<String,X4ODriver<?>>(10); drivers = new HashMap<String,X4ODriver<?>>(10);
globalProperties = new HashMap<String,Map<String,Object>>(20);
} }
static { static {
@ -110,25 +107,13 @@ public final class X4ODriverManager {
} }
static protected X4OLanguageConfiguration getDefaultBuildLanguageConfiguration() { static protected X4OLanguageConfiguration getDefaultBuildLanguageConfiguration() {
return new DefaultX4OLanguageConfiguration(); DefaultX4OLanguageConfiguration config = new DefaultX4OLanguageConfiguration();
} config.fillDefaults();
X4OLanguageConfiguration result = config.createProxy();
static public Collection<String> getGlobalPropertyKeys(X4ODriver<?> driver) { return result;
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
if (driverProperties==null) {
return Collections.emptySet();
}
return driverProperties.keySet();
}
static public Object getGlobalProperty(X4ODriver<?> driver,String key) {
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
if (driverProperties==null) {
return null;
}
return driverProperties.get(key);
} }
/*
static public void setGlobalProperty(X4ODriver<?> driver,String key,Object value) { static public void setGlobalProperty(X4ODriver<?> driver,String key,Object value) {
Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName()); Map<String,Object> driverProperties = instance.globalProperties.get(driver.getLanguageName());
if (driverProperties==null) { if (driverProperties==null) {
@ -145,6 +130,7 @@ public final class X4ODriverManager {
} }
throw new IllegalArgumentException("Property with key: "+key+" is protected by key limit."); throw new IllegalArgumentException("Property with key: "+key+" is protected by key limit.");
} }
*/
static public void registerX4ODriver(X4ODriver<?> driver) { static public void registerX4ODriver(X4ODriver<?> driver) {
if (driver==null) { if (driver==null) {

View file

@ -23,6 +23,7 @@
package org.x4o.xml.el; package org.x4o.xml.el;
import javax.el.ELContext;
import javax.el.ExpressionFactory; import javax.el.ExpressionFactory;
import org.x4o.xml.lang.X4OLanguageClassLoader; import org.x4o.xml.lang.X4OLanguageClassLoader;
@ -40,23 +41,35 @@ 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 elementContext) { static public ExpressionFactory createExpressionFactory(X4OLanguageContext languageContext) {
ExpressionFactory factory = (ExpressionFactory)elementContext.getLanguageProperty(X4OLanguageProperty.EL_FACTORY_INSTANCE); ExpressionFactory result = (ExpressionFactory)languageContext.getLanguageProperty(X4OLanguageProperty.EL_FACTORY_INSTANCE);
if (factory!=null) { if (result!=null) {
return factory; return result;
} }
try { try {
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE); Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_APACHE);
ExpressionFactory expressionFactory = (ExpressionFactory) expressionFactoryClass.newInstance(); result = (ExpressionFactory) expressionFactoryClass.newInstance();
return expressionFactory;
} catch (Exception e) { } catch (Exception e) {
try { try {
Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_ODYSSEUS); Class<?> expressionFactoryClass = X4OLanguageClassLoader.loadClass(EL_FACTORY_IMPL_ODYSSEUS);
ExpressionFactory expressionFactory = (ExpressionFactory) expressionFactoryClass.newInstance(); result = (ExpressionFactory) expressionFactoryClass.newInstance();
return expressionFactory;
} catch (Exception ee) { } catch (Exception ee) {
throw new RuntimeException("Could not load ExpressionFactory tried: "+EL_FACTORY_IMPL_APACHE+" and "+EL_FACTORY_IMPL_ODYSSEUS+" but could not load one of them."); throw new RuntimeException("Could not load ExpressionFactory tried: "+EL_FACTORY_IMPL_APACHE+" and "+EL_FACTORY_IMPL_ODYSSEUS+" but could not load one of them.");
} }
} }
return result;
}
static public ELContext createELContext(X4OLanguageContext languageContext) {
ELContext result = (ELContext)languageContext.getLanguageProperty(X4OLanguageProperty.EL_CONTEXT_INSTANCE);
if (result!=null) {
return result;
}
try {
result = (ELContext)X4OLanguageClassLoader.newInstance(languageContext.getLanguage().getLanguageConfiguration().getDefaultExpressionLanguageContext());
} catch (Exception e) {
throw new RuntimeException("Could not create instance of ELContext: "+e.getMessage(),e);
}
return result;
} }
} }

View file

@ -23,15 +23,13 @@
package org.x4o.xml.eld; package org.x4o.xml.eld;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
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.DefaultX4OReader;
import org.x4o.xml.io.X4OConnectionException;
import org.x4o.xml.io.X4OReader; import org.x4o.xml.io.X4OReader;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
@ -106,13 +104,7 @@ public class EldModuleLoader implements X4OLanguageModuleLoader {
// } // }
reader.readResource(eldResource); reader.readResource(eldResource);
} catch (FileNotFoundException e) { } catch (X4OConnectionException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (SecurityException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (NullPointerException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (ParserConfigurationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e); throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e); throw new X4OLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);

View file

@ -29,9 +29,12 @@ import java.io.FileOutputStream;
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.sax.XMLWriter; import org.x4o.xml.io.sax.XMLWriter;
import org.x4o.xml.lang.X4OLanguageContext;
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;
import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.ext.DefaultHandler2;
@ -44,10 +47,11 @@ import org.xml.sax.ext.DefaultHandler2;
public class EldXsdXmlGenerator { public class EldXsdXmlGenerator {
private X4OLanguage language = null; private X4OLanguage language = null;
private X4OLanguageContext languageContext = null;
public EldXsdXmlGenerator(X4OLanguage language) { public EldXsdXmlGenerator(X4OLanguageContext languageContext) {
this.language=language; this.languageContext=languageContext;
this.language=languageContext.getLanguage();
} }
private void checkNamespace(ElementNamespaceContext ns) { private void checkNamespace(ElementNamespaceContext ns) {
@ -59,8 +63,20 @@ public class EldXsdXmlGenerator {
} }
} }
public void writeSchema(File basePath,String namespace) throws ElementException { public void writeSchema(String namespace) throws ElementException {
File basePath = (File)languageContext.getLanguageProperty(X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_PATH);
String encoding = languageContext.getLanguagePropertyString(X4OLanguageProperty.SCHEMA_WRITER_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) {
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 {
if (namespace!=null) { if (namespace!=null) {
ElementNamespaceContext ns = language.findElementNamespaceContext(namespace); ElementNamespaceContext ns = language.findElementNamespaceContext(namespace);
if (ns==null) { if (ns==null) {
@ -69,7 +85,7 @@ public class EldXsdXmlGenerator {
checkNamespace(ns); checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource())); FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try { try {
XMLWriter out = new XMLWriter(fio); XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
fio.close(); fio.close();
@ -81,7 +97,7 @@ public class EldXsdXmlGenerator {
checkNamespace(ns); checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource())); FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try { try {
XMLWriter out = new XMLWriter(fio); XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
fio.close(); fio.close();
@ -90,7 +106,7 @@ public class EldXsdXmlGenerator {
} }
} catch (Exception e) { } catch (Exception e) {
throw new ElementException(e); // todo rm throw new ElementException(e); // TODO: rm
} }
} }

View file

@ -23,21 +23,18 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; 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.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguagePropertyKeys; import org.x4o.xml.lang.X4OLanguagePropertyKeys;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
/** /**
* This is a base class for building an SAX XML parser. * AbstractX4OReader wraps method to contexted reader.
* It adds methode's for parsing different input types of
* xml data which gets wrapped into an InputStream for parsing.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Aug 11, 2005 * @version 1.0 Aug 11, 2005
@ -56,78 +53,69 @@ abstract public class AbstractX4OReader<T> extends AbstractX4OReaderContext<T> i
return X4OLanguagePropertyKeys.DEFAULT_X4O_READER_KEYS; return X4OLanguagePropertyKeys.DEFAULT_X4O_READER_KEYS;
} }
public T read(InputStream input, String systemId, URL basePath) throws ParserConfigurationException, SAXException, IOException { public T read(InputStream input, String systemId, URL basePath) throws X4OConnectionException,SAXException,IOException {
return (T)readContext(input, systemId, basePath).getRootElement().getElementObject(); return (T)readContext(input, systemId, basePath).getRootElement().getElementObject();
} }
/** /**
* Reads the file fileName and reads it as an InputStream. * Reads the file fileName and reads it as an InputStream.
* @param fileName The file name to read. * @param fileName The file name to read.
* @throws readrConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public T readFile(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public T readFile(String fileName) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
return (T)readFileContext(fileName).getRootElement().getElementObject(); return (T)readFileContext(fileName).getRootElement().getElementObject();
} }
/** /**
* Reads the file and reads it as an InputStream. * Reads the file and reads it as an InputStream.
* @param file The file to read. * @param file The file to read.
* @throws readrConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public T readFile(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public T readFile(File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
return (T)readFileContext(file).getRootElement().getElementObject(); return (T)readFileContext(file).getRootElement().getElementObject();
} }
/** /**
* reads an resource locaction. * reads an resource locaction.
* @param resourceName The resource to readr. * @param resourceName The resource to readr.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws FileNotFoundException * @throws SAXException Is thrown after sax xml exception.
* @throws SecurityException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public T readResource(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public T readResource(String resourceName) throws X4OConnectionException,SAXException,IOException {
return (T)readResourceContext(resourceName).getRootElement().getElementObject(); return (T)readResourceContext(resourceName).getRootElement().getElementObject();
} }
/** /**
* Converts a String to a InputStream to is can me readd by SAX. * Converts a String to a InputStream to is can me readd by SAX.
* @param xmlString The xml as String to read. * @param xmlString The xml as String to read.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public T readString(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException { public T readString(String xmlString) throws X4OConnectionException,SAXException,IOException {
return (T)readStringContext(xmlString).getRootElement().getElementObject(); return (T)readStringContext(xmlString).getRootElement().getElementObject();
} }
/** /**
* Fetched the data direct from remote url to a InputStream to is can me readd by SAX. * Fetched the data direct from remote url to a InputStream to is can me readd by SAX.
* @param url The url to read. * @param url The url to read.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public T readUrl(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException { public T readUrl(URL url) throws X4OConnectionException,SAXException,IOException {
return (T)readUrlContext(url).getRootElement().getElementObject(); return (T)readUrlContext(url).getRootElement().getElementObject();
} }
} }

View file

@ -33,7 +33,6 @@ import java.net.URL;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
/** /**
* AbstractX4OContextReader * AbstractX4OContextReader
@ -51,15 +50,13 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
/** /**
* Reads the file fileName and reads it as an InputStream. * Reads the file fileName and reads it as an InputStream.
* @param fileName The file name to read. * @param fileName The file name to read.
* @throws readrConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public X4OLanguageContext readFileContext(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public X4OLanguageContext readFileContext(String fileName) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
if (fileName==null) { if (fileName==null) {
throw new NullPointerException("Can't convert null fileName to file object."); throw new NullPointerException("Can't convert null fileName to file object.");
} }
@ -69,15 +66,13 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
/** /**
* Reads the file and reads it as an InputStream. * Reads the file and reads it as an InputStream.
* @param file The file to read. * @param file The file to read.
* @throws readrConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public X4OLanguageContext readFileContext(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public X4OLanguageContext readFileContext(File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
if (file==null) { if (file==null) {
throw new NullPointerException("Can't read null file."); throw new NullPointerException("Can't read null file.");
} }
@ -101,15 +96,12 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
/** /**
* reads an resource locaction. * reads an resource locaction.
* @param resourceName The resource to readr. * @param resourceName The resource to readr.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws FileNotFoundException * @throws SAXException Is thrown after sax xml exception.
* @throws SecurityException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public X4OLanguageContext readResourceContext(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public X4OLanguageContext readResourceContext(String resourceName) throws X4OConnectionException,SAXException,IOException {
if (resourceName==null) { if (resourceName==null) {
throw new NullPointerException("Can't read null resourceName from classpath."); throw new NullPointerException("Can't read null resourceName from classpath.");
} }
@ -138,13 +130,12 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
/** /**
* Converts a String to a InputStream to is can me readd by SAX. * Converts a String to a InputStream to is can me readd by SAX.
* @param xmlString The xml as String to read. * @param xmlString The xml as String to read.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public X4OLanguageContext readStringContext(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException { public X4OLanguageContext readStringContext(String xmlString) throws X4OConnectionException,SAXException,IOException {
if (xmlString==null) { if (xmlString==null) {
throw new NullPointerException("Can't read null xml string."); throw new NullPointerException("Can't read null xml string.");
} }
@ -155,13 +146,12 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
/** /**
* Fetched the data direct from remote url to a InputStream to is can me readd by SAX. * Fetched the data direct from remote url to a InputStream to is can me readd by SAX.
* @param url The url to read. * @param url The url to read.
* @throws readrConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
public X4OLanguageContext readUrlContext(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException { public X4OLanguageContext readUrlContext(URL url) throws X4OConnectionException,SAXException,IOException {
if (url==null) { if (url==null) {
throw new NullPointerException("Can't read null url."); throw new NullPointerException("Can't read null url.");
} }

View file

@ -25,12 +25,9 @@ package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.ParserConfigurationException;
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.X4OLanguagePropertyKeys; import org.x4o.xml.lang.X4OLanguagePropertyKeys;
@ -55,7 +52,7 @@ public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> i
return X4OLanguagePropertyKeys.DEFAULT_X4O_WRITER_KEYS; return X4OLanguagePropertyKeys.DEFAULT_X4O_WRITER_KEYS;
} }
public void write(T object,OutputStream output) throws ParserConfigurationException, SAXException, IOException { private X4OLanguageContext toObjectContext(T object) throws SAXException {
X4OLanguageContext context = getLanguageContext(); X4OLanguageContext context = getLanguageContext();
Element rootElement = null; Element rootElement = null;
try { try {
@ -67,30 +64,18 @@ public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> i
} }
rootElement.setElementObject(object); rootElement.setElementObject(object);
context.setRootElement(rootElement); context.setRootElement(rootElement);
writeContext(context,output); return context;
} }
public void writeFile(T object,String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public void write(T object,OutputStream output) throws X4OConnectionException,SAXException,IOException {
if (fileName==null) { writeContext(toObjectContext(object), output);
throw new NullPointerException("Can't convert null fileName to file object.");
}
writeFile(object,new File(fileName));
} }
public void writeFile(T object,File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public void writeFile(T object,String fileName) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
if (file==null) { writeFileContext(toObjectContext(object), fileName);
throw new NullPointerException("Can't read null file."); }
}
if (file.canWrite()==false) { public void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
throw new IOException("Can't write file: "+file); writeFileContext(toObjectContext(object), file);
}
OutputStream outputStream = new FileOutputStream(file);
try {
write(object,outputStream);
} finally {
if(outputStream!=null) {
outputStream.close();
}
}
} }
} }

View file

@ -24,13 +24,10 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -46,23 +43,17 @@ public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection
super(elementLanguage); super(elementLanguage);
} }
public void writeFileContext(X4OLanguageContext context,String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException {
if (fileName==null) { if (fileName==null) {
throw new NullPointerException("Can't convert null fileName to file object."); throw new NullPointerException("Can't convert null fileName to file object.");
} }
writeFileContext(context,new File(fileName)); writeFileContext(context,new File(fileName));
} }
public void writeFileContext(X4OLanguageContext context,File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException { public void writeFileContext(X4OLanguageContext context,File file) throws X4OConnectionException,SAXException,IOException {
if (file==null) { if (file==null) {
throw new NullPointerException("Can't read null file."); throw new NullPointerException("Can't read null file.");
} }
if (file.exists()) {
throw new FileNotFoundException("File does already exists; "+file);
}
if (file.canWrite()==false) {
throw new IOException("Can't write file: "+file);
}
OutputStream outputStream = new FileOutputStream(file); OutputStream outputStream = new FileOutputStream(file);
try { try {
writeContext(context,outputStream); writeContext(context,outputStream);

View file

@ -64,10 +64,10 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
logger = Logger.getLogger(DefaultX4OReader.class.getName()); logger = Logger.getLogger(DefaultX4OReader.class.getName());
} }
public X4OLanguageContext readContext(InputStream input, String systemId, URL basePath) throws ParserConfigurationException, SAXException, IOException { public X4OLanguageContext readContext(InputStream input, String systemId, URL basePath) throws X4OConnectionException, SAXException, IOException {
setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_STREAM, input); setProperty(X4OLanguagePropertyKeys.READER_INPUT_STREAM, input);
setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_SYSTEM_ID, systemId); setProperty(X4OLanguagePropertyKeys.READER_INPUT_SYSTEM_ID, systemId);
setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_BASE_PATH, basePath); setProperty(X4OLanguagePropertyKeys.READER_INPUT_BASE_PATH, basePath);
read(); read();
return getLanguageContext(); return getLanguageContext();
} }
@ -95,17 +95,17 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
/** /**
* Parses the input stream as a X4O document. * Parses the input stream as a X4O document.
*/ */
protected void read() throws ParserConfigurationException,SAXException,IOException { protected void read() throws X4OConnectionException,SAXException,IOException {
X4OLanguageContext elementLanguage = getLanguageContext(); X4OLanguageContext languageContext = getLanguageContext();
if (elementLanguage.getLanguage()==null) { if (languageContext.getLanguage()==null) {
throw new ParserConfigurationException("parserConfig is broken getLanguage() returns null."); throw new X4OConnectionException("languageContext is broken getLanguage() returns null.");
} }
// init debugWriter if enabled // init debugWriter if enabled
boolean startedDebugWriter = false; boolean startedDebugWriter = false;
Object debugOutputHandler = elementLanguage.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER); Object debugOutputHandler = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER);
Object debugOutputStream = elementLanguage.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM); Object debugOutputStream = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM);
if (elementLanguage.getX4ODebugWriter()==null) { if (languageContext.getX4ODebugWriter()==null) {
DefaultHandler2 xmlDebugWriter = null; DefaultHandler2 xmlDebugWriter = null;
if (debugOutputHandler instanceof DefaultHandler2) { if (debugOutputHandler instanceof DefaultHandler2) {
xmlDebugWriter = (DefaultHandler2)debugOutputHandler; xmlDebugWriter = (DefaultHandler2)debugOutputHandler;
@ -116,18 +116,18 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
xmlDebugWriter.startDocument(); xmlDebugWriter.startDocument();
xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI); xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI);
X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter); X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter);
X4OLanguageContextLocal local = (X4OLanguageContextLocal)elementLanguage; X4OLanguageContextLocal local = (X4OLanguageContextLocal)languageContext;
local.setX4ODebugWriter(debugWriter); local.setX4ODebugWriter(debugWriter);
startedDebugWriter = true; startedDebugWriter = true;
} }
} }
// debug language // debug language
if (elementLanguage.hasX4ODebugWriter()) { if (languageContext.hasX4ODebugWriter()) {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguage().getLanguageName()); atts.addAttribute ("", "language", "", "", languageContext.getLanguage().getLanguageName());
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+""); atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+"");
elementLanguage.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts); languageContext.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts);
} }
// start parsing language // start parsing language
@ -136,33 +136,32 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
} catch (Exception e) { } catch (Exception e) {
// also debug exceptions // also debug exceptions
if (elementLanguage.hasX4ODebugWriter()) { if (languageContext.hasX4ODebugWriter()) {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "message", "", "", e.getMessage()); atts.addAttribute ("", "message", "", "", e.getMessage());
if (e instanceof X4OPhaseException) { if (e instanceof X4OPhaseException) {
atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId()); atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId());
} }
elementLanguage.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts); languageContext.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer); PrintWriter printer = new PrintWriter(writer);
printer.append('\n'); printer.append('\n');
if (e.getCause()==null) { if (e.getCause()==null) {
e.printStackTrace(printer); e.printStackTrace(printer);
} else { } else {
e.getCause().printStackTrace(printer); e.getCause().printStackTrace(printer);
} }
char[] stack = writer.getBuffer().toString().toCharArray(); char[] stack = writer.getBuffer().toString().toCharArray();
elementLanguage.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length); languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length);
elementLanguage.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
} catch (Exception ee) { } catch (Exception ee) {
ee.printStackTrace();
} }
} }
// unwrap exception // unwrap exception
if (e.getCause() instanceof ParserConfigurationException) { if (e.getCause() instanceof ParserConfigurationException) {
throw (ParserConfigurationException)e.getCause(); throw new X4OConnectionException((ParserConfigurationException)e.getCause());
} }
if (e.getCause() instanceof SAXException) { if (e.getCause() instanceof SAXException) {
throw (SAXException)e.getCause(); throw (SAXException)e.getCause();
@ -176,16 +175,12 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
throw new SAXException((Exception)e.getCause()); throw new SAXException((Exception)e.getCause());
} }
} finally { } finally {
// close all our resources. if (languageContext.hasX4ODebugWriter()) {
//if (inputStream!=null) { languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
// inputStream.close();
//}
if (elementLanguage.hasX4ODebugWriter()) {
elementLanguage.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
} }
if (startedDebugWriter && elementLanguage.hasX4ODebugWriter()) { if (startedDebugWriter && languageContext.hasX4ODebugWriter()) {
elementLanguage.getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug"); languageContext.getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug");
elementLanguage.getX4ODebugWriter().getDebugWriter().endDocument(); languageContext.getX4ODebugWriter().getDebugWriter().endDocument();
if (debugOutputStream instanceof OutputStream) { if (debugOutputStream instanceof OutputStream) {
OutputStream outputStream = (OutputStream)debugOutputStream; OutputStream outputStream = (OutputStream)debugOutputStream;
outputStream.flush(); outputStream.flush();

View file

@ -60,8 +60,8 @@ public class DefaultX4OSchemaWriter extends AbstractX4OConnection implements X4O
* @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 {
// Start xsd generator setProperty(X4OLanguagePropertyKeys.SCHEMA_WRITER_OUTPUT_PATH, basePath);
EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(getLanguageContext().getLanguage()); EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(getLanguageContext());
xsd.writeSchema(basePath, namespace); xsd.writeSchema(namespace); // Start xsd generator
} }
} }

View file

@ -23,31 +23,14 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.FileNotFoundException;
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.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
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.XMLWriter;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageModule; 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.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** /**
* DefaultX4OWriter can write the xml language. * DefaultX4OWriter can write the xml language.
@ -57,145 +40,23 @@ import org.xml.sax.helpers.AttributesImpl;
*/ */
public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> { public class DefaultX4OWriter<T> extends AbstractX4OWriter<T> {
/**
* Default constructor.
* @param languageContext The language context for this writer.
*/
public DefaultX4OWriter(X4OLanguageContext languageContext) { public DefaultX4OWriter(X4OLanguageContext languageContext) {
super(languageContext); super(languageContext);
} }
public void writeContext(X4OLanguageContext languageContext,OutputStream out) throws ParserConfigurationException, /**
FileNotFoundException, SecurityException, NullPointerException, * @see org.x4o.xml.io.X4OWriterContext#writeContext(org.x4o.xml.lang.X4OLanguageContext, java.io.OutputStream)
SAXException, IOException { */
public void writeContext(X4OLanguageContext languageContext,OutputStream output) throws X4OConnectionException,SAXException,IOException {
setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_STREAM, output);
try { try {
languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE); languageContext.getLanguage().getPhaseManager().runPhases(languageContext, X4OPhaseType.XML_WRITE);
} catch (X4OPhaseException e1) { } catch (X4OPhaseException e) {
throw new SAXException(e1); throw new X4OConnectionException(e);
}
Element root = languageContext.getRootElement();
XMLWriter writer = new XMLWriter(out);
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);
} catch (ElementObjectPropertyValueException e) {
throw new SAXException(e);
}
writer.endDocument();
out.flush();
out.close();
}
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;
}
private void writeTree(XMLWriter writer,Element element) throws SAXException, ElementObjectPropertyValueException {
AttributesImpl atts = new AttributesImpl();
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;
}
atts.addAttribute ("", eca.getId(), "", "", ""+value);
}
} else {
for (String p:getProperties(element.getElementObject().getClass())) {
ElementClassAttribute eca = element.getElementClass().getElementClassAttributeByName(p);
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 && 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
}
atts.addAttribute ("", p, "", "", ""+value);
}
}
String elementUri = findElementUri(element);
writer.startElement(elementUri, element.getElementClass().getId(), "", atts);
for (Element e:element.getChilderen()) {
writeTree(writer,e);
}
writer.endElement(elementUri, element.getElementClass().getId(), "");
}
private String findElementUri(Element e) {
for (X4OLanguageModule mod: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 = getLanguageContext().getLanguage().findElementNamespaceContext(uri);
if (ns.getPrefixMapping()!=null) {
return ns.getPrefixMapping();
}
return ns.getId();
}
} }

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.io;
/**
* X4OConnectionException is top level exception for io connections.
*
* @author Willem Cazander
* @version 1.0 28 Apr, 2013
*/
public class X4OConnectionException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an X4OConnectionException without a detail message.
*/
public X4OConnectionException() {
super();
}
/**
* Constructs an X4OConnectionException with a detail message.
* @param message The message of this Exception
*/
public X4OConnectionException(String message) {
super(message);
}
/**
* Creates an X4OConnectionException from a parent exception.
* @param e The error exception.
*/
public X4OConnectionException(Exception e) {
super(e);
}
/**
* Constructs an X4OConnectionException with a detail message.
* @param message The message of this Exception
* @param e The error exception.
*/
public X4OConnectionException(String message,Exception e) {
super(message,e);
}
}

View file

@ -29,8 +29,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -46,70 +44,61 @@ public interface X4OReader<T> extends X4OConnection {
/** /**
* Method to parse the xml data. * Method to parse the xml data.
* @param input The inputStream to parse. * @param input The inputStream to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
*/ */
T read(InputStream input,String systemId,URL basePath) throws ParserConfigurationException,SAXException,IOException; T read(InputStream input,String systemId,URL basePath) throws X4OConnectionException,SAXException,IOException;
/** /**
* Reads the file fileName and parses it as an InputStream. * Reads the file fileName and parses it as an InputStream.
* @param fileName The file name to parse. * @param fileName The file name to parse.
* @throws ParserConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
T readFile(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; T readFile(String fileName) throws X4OConnectionException,SAXException,IOException,FileNotFoundException;
/** /**
* Reads the file and parses it as an InputStream. * Reads the file and parses it as an InputStream.
* @param file The file to parse. * @param file The file to parse.
* @throws ParserConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
T readFile(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; T readFile(File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException;
/** /**
* Parses an resource locaction. * Parses an resource locaction.
* @param resourceName The resource to parser. * @param resourceName The resource to parser.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws FileNotFoundException * @throws SAXException Is thrown after sax xml exception.
* @throws SecurityException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
T readResource(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; T readResource(String resourceName) throws X4OConnectionException,SAXException,IOException;
/** /**
* Converts a String to a InputStream to is can me parsed by SAX. * Converts a String to a InputStream to is can me parsed by SAX.
* @param xmlString The xml as String to parse. * @param xmlString The xml as String to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
T readString(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException; T readString(String xmlString) throws X4OConnectionException,SAXException,IOException;
/** /**
* Fetched the data direct from remote url to a InputStream to is can me parsed by SAX. * Fetched the data direct from remote url to a InputStream to is can me parsed by SAX.
* @param url The url to parse. * @param url The url to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
T readUrl(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException; T readUrl(URL url) throws X4OConnectionException,SAXException,IOException;
} }

View file

@ -29,8 +29,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.phase.X4OPhaseException; import org.x4o.xml.lang.phase.X4OPhaseException;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -48,70 +46,61 @@ public interface X4OReaderContext<T> extends X4OReader<T> {
/** /**
* Method to parse the xml data. * Method to parse the xml data.
* @param input The inputStream to parse. * @param input The inputStream to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
*/ */
X4OLanguageContext readContext(InputStream input,String systemId,URL basePath) throws ParserConfigurationException,SAXException,IOException; X4OLanguageContext readContext(InputStream input,String systemId,URL basePath) throws X4OConnectionException,SAXException,IOException;
/** /**
* Reads the file fileName and parses it as an InputStream. * Reads the file fileName and parses it as an InputStream.
* @param fileName The file name to parse. * @param fileName The file name to parse.
* @throws ParserConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
X4OLanguageContext readFileContext(String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; X4OLanguageContext readFileContext(String fileName) throws X4OConnectionException,SAXException,IOException,FileNotFoundException;
/** /**
* Reads the file and parses it as an InputStream. * Reads the file and parses it as an InputStream.
* @param file The file to parse. * @param file The file to parse.
* @throws ParserConfigurationException * @throws FileNotFoundException Is thrown is file is not found.
* @throws FileNotFoundException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SecurityException * @throws SAXException Is thrown after sax xml exception.
* @throws NullPointerException * @throws IOException Is thrown after io exception.
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
X4OLanguageContext readFileContext(File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; X4OLanguageContext readFileContext(File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException;
/** /**
* Parses an resource locaction. * Parses an resource locaction.
* @param resourceName The resource to parser. * @param resourceName The resource to parser.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws FileNotFoundException * @throws SAXException Is thrown after sax xml exception.
* @throws SecurityException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @throws SAXException
* @throws IOException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
X4OLanguageContext readResourceContext(String resourceName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; X4OLanguageContext readResourceContext(String resourceName) throws X4OConnectionException,SAXException,IOException;
/** /**
* Converts a String to a InputStream to is can me parsed by SAX. * Converts a String to a InputStream to is can me parsed by SAX.
* @param xmlString The xml as String to parse. * @param xmlString The xml as String to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
X4OLanguageContext readStringContext(String xmlString) throws ParserConfigurationException,SAXException,IOException,NullPointerException; X4OLanguageContext readStringContext(String xmlString) throws X4OConnectionException,SAXException,IOException;
/** /**
* Fetched the data direct from remote url to a InputStream to is can me parsed by SAX. * Fetched the data direct from remote url to a InputStream to is can me parsed by SAX.
* @param url The url to parse. * @param url The url to parse.
* @throws ParserConfigurationException * @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException * @throws SAXException Is thrown after sax xml exception.
* @throws IOException * @throws IOException Is thrown after io exception.
* @throws NullPointerException
* @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL) * @see org.x4o.xml.io.X4OReaderContext#readContext(java.io.InputStream,java.lang.String,java.net.URL)
*/ */
X4OLanguageContext readUrlContext(URL url) throws ParserConfigurationException,SAXException,IOException,NullPointerException; X4OLanguageContext readUrlContext(URL url) throws X4OConnectionException,SAXException,IOException;
} }

View file

@ -24,12 +24,9 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -40,9 +37,9 @@ import org.xml.sax.SAXException;
*/ */
public interface X4OWriter<T> extends X4OConnection { public interface X4OWriter<T> extends X4OConnection {
void write(T object,OutputStream out) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void write(T object,OutputStream out) throws X4OConnectionException,SAXException,IOException;
void writeFile(T object,String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void writeFile(T object,String fileName) throws X4OConnectionException,SAXException,IOException;
void writeFile(T object,File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException;
} }

View file

@ -24,12 +24,9 @@
package org.x4o.xml.io; package org.x4o.xml.io;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -41,9 +38,9 @@ import org.xml.sax.SAXException;
*/ */
public interface X4OWriterContext<T> extends X4OWriter<T> { public interface X4OWriterContext<T> extends X4OWriter<T> {
void writeContext(X4OLanguageContext context,OutputStream out) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void writeContext(X4OLanguageContext context,OutputStream out) throws X4OConnectionException,SAXException,IOException;
void writeFileContext(X4OLanguageContext context,String fileName) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException;
void writeFileContext(X4OLanguageContext context,File file) throws ParserConfigurationException,FileNotFoundException,SecurityException,NullPointerException,SAXException,IOException; void writeFileContext(X4OLanguageContext context,File file) throws X4OConnectionException,SAXException,IOException;
} }

View file

@ -70,7 +70,7 @@ public class X4OEntityResolver implements EntityResolver {
} }
this.logger=Logger.getLogger(X4OEntityResolver.class.getName()); this.logger=Logger.getLogger(X4OEntityResolver.class.getName());
this.elementContext=elementContext; this.elementContext=elementContext;
this.basePath=(URL)elementContext.getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_BASE_PATH); this.basePath=(URL)elementContext.getLanguageProperty(X4OLanguageProperty.READER_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()) {
@ -110,7 +110,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.CONFIG_ENTITY_RESOLVER); EntityResolver resolver = (EntityResolver)elementContext.getLanguageProperty(X4OLanguageProperty.READER_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) {
@ -120,7 +120,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.VALIDATION_SCHEMA_PATH); File schemaBasePath = (File)elementContext.getLanguageProperty(X4OLanguageProperty.READER_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

@ -50,7 +50,7 @@ public class X4OErrorHandler implements ErrorHandler {
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.CONFIG_ERROR_HANDLER); this.errorHandler=(ErrorHandler)languageContext.getLanguageProperty(X4OLanguageProperty.READER_ERROR_HANDLER);
} }
/** /**

View file

@ -124,7 +124,7 @@ public class X4OTagHandler 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.INPUT_EMPTY_NAMESPACE_URI); String configEmptryUri = (String)elementLanguage.getLanguageProperty(X4OLanguageProperty.READER_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

@ -118,6 +118,18 @@ public class XMLWriter extends DefaultHandler2 {
this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING); this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING);
} }
/**
* Creates XmlWriter which prints to the OutputStream interface.
* @param out The OutputStream to write to.
* @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.
*/
public XMLWriter(OutputStream out,String encoding,String charNewLine,String charTab) throws UnsupportedEncodingException {
this(new OutputStreamWriter(out, encoding),encoding,charNewLine,charTab);
}
/** /**
* @see org.xml.sax.ContentHandler#startDocument() * @see org.xml.sax.ContentHandler#startDocument()
*/ */

View file

@ -0,0 +1,324 @@
package org.x4o.xml.lang;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractX4OLanguageConfiguration implements X4OLanguageConfigurationLocal {
private String languageResourcePathPrefix = null;
private String languageResourceModulesFileName = null;
private Class<?> defaultElementNamespaceContext = null;
private Class<?> defaultElementInterface = null;
private Class<?> defaultElement = null;
private Class<?> defaultElementClass = null;
private Class<?> defaultElementClassAttribute = null;
private Class<?> defaultElementLanguageModule = null;
private Class<?> defaultElementBodyComment = null;
private Class<?> defaultElementBodyCharacters = null;
private Class<?> defaultElementBodyWhitespace = null;
private Class<?> defaultElementNamespaceInstanceProvider = null;
private Class<?> defaultElementAttributeValueParser = null;
private Class<?> defaultElementObjectPropertyValue = null;
private Class<?> defaultElementAttributeHandlerComparator = null;
private Class<?> defaultLanguageVersionFilter = null;
private Class<?> defaultLanguageLoader = null;
private Class<?> defaultExpressionLanguageContext = null;
private Map<String,Object> globalProperties = null;
/**
* Default constructor.
*/
public AbstractX4OLanguageConfiguration() {
globalProperties = new HashMap<String,Object>(10);
}
/**
* @return the languageResourcePathPrefix
*/
public String getLanguageResourcePathPrefix() {
return languageResourcePathPrefix;
}
/**
* @param languageResourcePathPrefix the languageResourcePathPrefix to set
*/
public void setLanguageResourcePathPrefix(String languageResourcePathPrefix) {
this.languageResourcePathPrefix = languageResourcePathPrefix;
}
/**
* @return the languageResourceModulesFileName
*/
public String getLanguageResourceModulesFileName() {
return languageResourceModulesFileName;
}
/**
* @param languageResourceModulesFileName the languageResourceModulesFileName to set
*/
public void setLanguageResourceModulesFileName(
String languageResourceModulesFileName) {
this.languageResourceModulesFileName = languageResourceModulesFileName;
}
/**
* @return the defaultElementNamespaceContext
*/
public Class<?> getDefaultElementNamespaceContext() {
return defaultElementNamespaceContext;
}
/**
* @param defaultElementNamespaceContext the defaultElementNamespaceContext to set
*/
public void setDefaultElementNamespaceContext(
Class<?> defaultElementNamespaceContext) {
this.defaultElementNamespaceContext = defaultElementNamespaceContext;
}
/**
* @return the defaultElementInterface
*/
public Class<?> getDefaultElementInterface() {
return defaultElementInterface;
}
/**
* @param defaultElementInterface the defaultElementInterface to set
*/
public void setDefaultElementInterface(Class<?> defaultElementInterface) {
this.defaultElementInterface = defaultElementInterface;
}
/**
* @return the defaultElement
*/
public Class<?> getDefaultElement() {
return defaultElement;
}
/**
* @param defaultElement the defaultElement to set
*/
public void setDefaultElement(Class<?> defaultElement) {
this.defaultElement = defaultElement;
}
/**
* @return the defaultElementClass
*/
public Class<?> getDefaultElementClass() {
return defaultElementClass;
}
/**
* @param defaultElementClass the defaultElementClass to set
*/
public void setDefaultElementClass(Class<?> defaultElementClass) {
this.defaultElementClass = defaultElementClass;
}
/**
* @return the defaultElementClassAttribute
*/
public Class<?> getDefaultElementClassAttribute() {
return defaultElementClassAttribute;
}
/**
* @param defaultElementClassAttribute the defaultElementClassAttribute to set
*/
public void setDefaultElementClassAttribute(
Class<?> defaultElementClassAttribute) {
this.defaultElementClassAttribute = defaultElementClassAttribute;
}
/**
* @return the defaultElementLanguageModule
*/
public Class<?> getDefaultElementLanguageModule() {
return defaultElementLanguageModule;
}
/**
* @param defaultElementLanguageModule the defaultElementLanguageModule to set
*/
public void setDefaultElementLanguageModule(
Class<?> defaultElementLanguageModule) {
this.defaultElementLanguageModule = defaultElementLanguageModule;
}
/**
* @return the defaultElementBodyComment
*/
public Class<?> getDefaultElementBodyComment() {
return defaultElementBodyComment;
}
/**
* @param defaultElementBodyComment the defaultElementBodyComment to set
*/
public void setDefaultElementBodyComment(Class<?> defaultElementBodyComment) {
this.defaultElementBodyComment = defaultElementBodyComment;
}
/**
* @return the defaultElementBodyCharacters
*/
public Class<?> getDefaultElementBodyCharacters() {
return defaultElementBodyCharacters;
}
/**
* @param defaultElementBodyCharacters the defaultElementBodyCharacters to set
*/
public void setDefaultElementBodyCharacters(
Class<?> defaultElementBodyCharacters) {
this.defaultElementBodyCharacters = defaultElementBodyCharacters;
}
/**
* @return the defaultElementBodyWhitespace
*/
public Class<?> getDefaultElementBodyWhitespace() {
return defaultElementBodyWhitespace;
}
/**
* @param defaultElementBodyWhitespace the defaultElementBodyWhitespace to set
*/
public void setDefaultElementBodyWhitespace(
Class<?> defaultElementBodyWhitespace) {
this.defaultElementBodyWhitespace = defaultElementBodyWhitespace;
}
/**
* @return the defaultElementNamespaceInstanceProvider
*/
public Class<?> getDefaultElementNamespaceInstanceProvider() {
return defaultElementNamespaceInstanceProvider;
}
/**
* @param defaultElementNamespaceInstanceProvider the defaultElementNamespaceInstanceProvider to set
*/
public void setDefaultElementNamespaceInstanceProvider(
Class<?> defaultElementNamespaceInstanceProvider) {
this.defaultElementNamespaceInstanceProvider = defaultElementNamespaceInstanceProvider;
}
/**
* @return the defaultElementAttributeValueParser
*/
public Class<?> getDefaultElementAttributeValueParser() {
return defaultElementAttributeValueParser;
}
/**
* @param defaultElementAttributeValueParser the defaultElementAttributeValueParser to set
*/
public void setDefaultElementAttributeValueParser(
Class<?> defaultElementAttributeValueParser) {
this.defaultElementAttributeValueParser = defaultElementAttributeValueParser;
}
/**
* @return the defaultElementObjectPropertyValue
*/
public Class<?> getDefaultElementObjectPropertyValue() {
return defaultElementObjectPropertyValue;
}
/**
* @param defaultElementObjectPropertyValue the defaultElementObjectPropertyValue to set
*/
public void setDefaultElementObjectPropertyValue(
Class<?> defaultElementObjectPropertyValue) {
this.defaultElementObjectPropertyValue = defaultElementObjectPropertyValue;
}
/**
* @return the defaultElementAttributeHandlerComparator
*/
public Class<?> getDefaultElementAttributeHandlerComparator() {
return defaultElementAttributeHandlerComparator;
}
/**
* @param defaultElementAttributeHandlerComparator the defaultElementAttributeHandlerComparator to set
*/
public void setDefaultElementAttributeHandlerComparator(
Class<?> defaultElementAttributeHandlerComparator) {
this.defaultElementAttributeHandlerComparator = defaultElementAttributeHandlerComparator;
}
/**
* @return the defaultLanguageVersionFilter
*/
public Class<?> getDefaultLanguageVersionFilter() {
return defaultLanguageVersionFilter;
}
/**
* @param defaultLanguageVersionFilter the defaultLanguageVersionFilter to set
*/
public void setDefaultLanguageVersionFilter(
Class<?> defaultLanguageVersionFilter) {
this.defaultLanguageVersionFilter = defaultLanguageVersionFilter;
}
/**
* @return the defaultLanguageLoader
*/
public Class<?> getDefaultLanguageLoader() {
return defaultLanguageLoader;
}
/**
* @param defaultLanguageLoader the defaultLanguageLoader to set
*/
public void setDefaultLanguageLoader(Class<?> defaultLanguageLoader) {
this.defaultLanguageLoader = defaultLanguageLoader;
}
/**
* @return the defaultExpressionLanguageContext
*/
public Class<?> getDefaultExpressionLanguageContext() {
return defaultExpressionLanguageContext;
}
/**
* @param defaultExpressionLanguageContext the defaultExpressionLanguageContext to set
*/
public void setDefaultExpressionLanguageContext(
Class<?> 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

@ -4,8 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.el.ELContext;
import org.x4o.xml.X4ODriver; 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;
@ -20,6 +18,12 @@ import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseManager; import org.x4o.xml.lang.phase.X4OPhaseManager;
import org.x4o.xml.lang.phase.X4OPhaseType; import org.x4o.xml.lang.phase.X4OPhaseType;
/**
* DefaultX4OLanguage holds all information about the x4o xml language.
*
* @author Willem Cazander
* @version 1.0 30 apr 2013
*/
public class DefaultX4OLanguage implements X4OLanguageLocal { public class DefaultX4OLanguage implements X4OLanguageLocal {
private Logger logger = null; private Logger logger = null;
@ -108,8 +112,8 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
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:driver.getGlobalPropertyKeys()) { for (String key:languageContext.getLanguage().getLanguageConfiguration().getGlobalPropertyKeys()) {
Object value = driver.getGlobalProperty(key); Object value = languageContext.getLanguage().getLanguageConfiguration().getGlobalProperty(key);
contextInit.setLanguageProperty(key, value); contextInit.setLanguageProperty(key, value);
} }
try { try {
@ -117,7 +121,7 @@ public class DefaultX4OLanguage implements X4OLanguageLocal {
contextInit.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory(contextInit)); contextInit.setExpressionLanguageFactory(X4OExpressionFactory.createExpressionFactory(contextInit));
} }
if (contextInit.getExpressionLanguageContext()==null) { if (contextInit.getExpressionLanguageContext()==null) {
contextInit.setExpressionLanguageContext((ELContext)X4OLanguageClassLoader.newInstance(getLanguageConfiguration().getDefaultExpressionLanguageContext())); contextInit.setExpressionLanguageContext(X4OExpressionFactory.createELContext(contextInit));
} }
if (contextInit.getElementAttributeValueParser()==null) { if (contextInit.getElementAttributeValueParser()==null) {
contextInit.setElementAttributeValueParser((ElementAttributeValueParser)X4OLanguageClassLoader.newInstance(getLanguageConfiguration().getDefaultElementAttributeValueParser())); contextInit.setElementAttributeValueParser((ElementAttributeValueParser)X4OLanguageClassLoader.newInstance(getLanguageConfiguration().getDefaultElementAttributeValueParser()));

View file

@ -23,6 +23,9 @@
package org.x4o.xml.lang; package org.x4o.xml.lang;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -49,135 +52,57 @@ import org.x4o.xml.element.DefaultGlobalAttributeHandlerComparator;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 27 Oct 2009 * @version 1.0 27 Oct 2009
*/ */
public class DefaultX4OLanguageConfiguration implements X4OLanguageConfiguration { public class DefaultX4OLanguageConfiguration extends AbstractX4OLanguageConfiguration {
/**
* Default constructor.
*/
public DefaultX4OLanguageConfiguration() { public DefaultX4OLanguageConfiguration() {
} }
/** public void fillDefaults() {
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getLanguageResourcePathPrefix() if (getLanguageResourcePathPrefix()==null) { setLanguageResourcePathPrefix( X4OLanguageConfiguration.DEFAULT_LANG_PATH_PREFIX); }
*/ if (getLanguageResourceModulesFileName()==null) { setLanguageResourceModulesFileName( X4OLanguageConfiguration.DEFAULT_LANG_MODULES_FILE);}
public String getLanguageResourcePathPrefix() { if (getDefaultElementNamespaceContext()==null) { setDefaultElementNamespaceContext( DefaultElementNamespaceContext.class); }
return X4OLanguageConfiguration.DEFAULT_LANG_PATH_PREFIX; if (getDefaultElementInterface()==null) { setDefaultElementInterface( DefaultElementInterface.class); }
if (getDefaultElement()==null) { setDefaultElement( DefaultElement.class); }
if (getDefaultElementClass()==null) { setDefaultElementClass( DefaultElementClass.class); }
if (getDefaultElementClassAttribute()==null) { setDefaultElementClassAttribute( DefaultElementClassAttribute.class); }
if (getDefaultElementLanguageModule()==null) { setDefaultElementLanguageModule( DefaultX4OLanguageModule.class); }
if (getDefaultElementBodyComment()==null) { setDefaultElementBodyComment( DefaultElementBodyComment.class); }
if (getDefaultElementBodyCharacters()==null) { setDefaultElementBodyCharacters( DefaultElementBodyCharacters.class); }
if (getDefaultElementBodyWhitespace()==null) { setDefaultElementBodyWhitespace( DefaultElementBodyWhitespace.class); }
if (getDefaultElementNamespaceInstanceProvider()==null) { setDefaultElementNamespaceInstanceProvider( DefaultElementNamespaceInstanceProvider.class); }
if (getDefaultElementAttributeValueParser()==null) { setDefaultElementAttributeValueParser( DefaultElementAttributeValueParser.class); }
if (getDefaultElementObjectPropertyValue()==null) { setDefaultElementObjectPropertyValue( DefaultElementObjectPropertyValue.class); }
if (getDefaultElementAttributeHandlerComparator()==null) { setDefaultElementAttributeHandlerComparator( DefaultGlobalAttributeHandlerComparator.class); }
if (getDefaultLanguageVersionFilter()==null) { setDefaultLanguageVersionFilter( DefaultX4OLanguageVersionFilter.class); }
if (getDefaultLanguageLoader()==null) { setDefaultLanguageLoader( DefaultX4OLanguageLoader.class); }
if (getDefaultExpressionLanguageContext()==null) { setDefaultExpressionLanguageContext( X4OELContext.class); }
} }
/** /**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getLanguageResourceModulesFileName() * @see org.x4o.xml.lang.X4OLanguageConfigurationLocal#createProxy()
*/ */
public String getLanguageResourceModulesFileName() { public X4OLanguageConfiguration createProxy() {
return X4OLanguageConfiguration.DEFAULT_LANG_MODULES_FILE; Object proxy = Proxy.newProxyInstance(X4OLanguageClassLoader.getClassLoader(), new Class[]{X4OLanguageConfiguration.class}, new InvocationHandler() {
} public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
X4OLanguageConfigurationLocal local = DefaultX4OLanguageConfiguration.this;
/** int argsLength = 0;
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementNamespaceContext() if (args!=null) {
*/ argsLength = args.length;
public Class<?> getDefaultElementNamespaceContext() { }
return DefaultElementNamespaceContext.class; Class<?>[] invokeArgs = new Class[argsLength];
} for (int i=0;i<argsLength;i++) {
//Object o = args[i];
/** invokeArgs[i] = X4OLanguageContext.class; //o.getClass(); todo fix
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementInterface() }
*/ Method localMethod = local.getClass().getMethod(method.getName(), invokeArgs);
public Class<?> getDefaultElementInterface() { Object result = localMethod.invoke(local, args);
return DefaultElementInterface.class; return result; // result is reflection safe interface hiding.
} }
});
/** return (X4OLanguageConfiguration)proxy;
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElement()
*/
public Class<?> getDefaultElement() {
return DefaultElement.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementClass()
*/
public Class<?> getDefaultElementClass() {
return DefaultElementClass.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementClassAttribute()
*/
public Class<?> getDefaultElementClassAttribute() {
return DefaultElementClassAttribute.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementLanguageModule()
*/
public Class<?> getDefaultElementLanguageModule() {
return DefaultX4OLanguageModule.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementBodyComment()
*/
public Class<?> getDefaultElementBodyComment() {
return DefaultElementBodyComment.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementBodyCharacters()
*/
public Class<?> getDefaultElementBodyCharacters() {
return DefaultElementBodyCharacters.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementBodyWhitespace()
*/
public Class<?> getDefaultElementBodyWhitespace() {
return DefaultElementBodyWhitespace.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementNamespaceInstanceProvider()
*/
public Class<?> getDefaultElementNamespaceInstanceProvider() {
return DefaultElementNamespaceInstanceProvider.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementAttributeValueParser()
*/
public Class<?> getDefaultElementAttributeValueParser() {
return DefaultElementAttributeValueParser.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementObjectPropertyValue()
*/
public Class<?> getDefaultElementObjectPropertyValue() {
return DefaultElementObjectPropertyValue.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultElementAttributeHandlerComparator()
*/
public Class<?> getDefaultElementAttributeHandlerComparator() {
return DefaultGlobalAttributeHandlerComparator.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultLanguageVersionFilter()
*/
public Class<?> getDefaultLanguageVersionFilter() {
return DefaultX4OLanguageVersionFilter.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultLanguageLoader()
*/
public Class<?> getDefaultLanguageLoader() {
return DefaultX4OLanguageLoader.class;
}
/**
* @see org.x4o.xml.lang.X4OLanguageConfiguration#getDefaultExpressionLanguageContext()
*/
public Class<?> getDefaultExpressionLanguageContext() {
return X4OELContext.class;
} }
/** /**
@ -193,7 +118,7 @@ public class DefaultX4OLanguageConfiguration implements X4OLanguageConfiguration
*/ */
public Map<String, Object> getSAXParserPropertiesOptional(X4OLanguageContext elementContext) { public Map<String, Object> getSAXParserPropertiesOptional(X4OLanguageContext elementContext) {
Map<String,Object> saxParserProperties = new HashMap<String,Object>(1); Map<String,Object> saxParserProperties = new HashMap<String,Object>(1);
saxParserProperties.put("http://apache.org/xml/properties/input-buffer-size",elementContext.getLanguagePropertyInteger(X4OLanguageProperty.INPUT_BUFFER_SIZE)); // Increase buffer to 8KB saxParserProperties.put("http://apache.org/xml/properties/input-buffer-size",elementContext.getLanguagePropertyInteger(X4OLanguageProperty.READER_BUFFER_SIZE)); // Increase buffer to 8KB
return saxParserProperties; return saxParserProperties;
} }
@ -223,11 +148,11 @@ public class DefaultX4OLanguageConfiguration implements X4OLanguageConfiguration
boolean validation = false; boolean validation = false;
boolean validationXsd = false; boolean validationXsd = false;
if (EldDriver.LANGUAGE_NAME.equals(elementContext.getLanguage().getLanguageName())) { if (EldDriver.LANGUAGE_NAME.equals(elementContext.getLanguage().getLanguageName())) {
validation = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD); validation = false; //TODO: elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD);
validationXsd = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD_XSD); validationXsd = false; //elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_ELD_XSD);
} else { } else {
validation = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_INPUT); validation = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.READER_VALIDATION_INPUT);
validationXsd = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.VALIDATION_INPUT_XSD); validationXsd = elementContext.getLanguagePropertyBoolean(X4OLanguageProperty.READER_VALIDATION_INPUT_XSD);
} }
if (validation) { if (validation) {
saxParserFeatures.put("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors. saxParserFeatures.put("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors.

View file

@ -23,11 +23,12 @@
package org.x4o.xml.lang; package org.x4o.xml.lang;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* X4OLanguageConfiguration first used interface in x4o parser which does the hard config of the x4o xml parsing. * X4OLanguageConfiguration is base configuration of language used iin x4o parser.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 27 Oct 2009 * @version 1.0 27 Oct 2009
@ -82,6 +83,10 @@ public interface X4OLanguageConfiguration {
*/ */
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. * @return Returns Map of SAX properties which are set.
*/ */

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.lang;
/**
* X4OLanguageConfigurationLocal is for safe dynamic configuration.
*
* @author Willem Cazander
* @version 1.0 28 Apr 2013
*/
public interface X4OLanguageConfigurationLocal extends X4OLanguageConfiguration {
X4OLanguageConfiguration createProxy();
void setLanguageResourcePathPrefix(String value);
void setLanguageResourceModulesFileName(String value);
void setDefaultElementNamespaceContext(Class<?> value);
void setDefaultElementInterface(Class<?> value);
void setDefaultElement(Class<?> value);
void setDefaultElementClass(Class<?> value);
void setDefaultElementClassAttribute(Class<?> value);
void setDefaultElementLanguageModule(Class<?> value);
void setDefaultElementBodyComment(Class<?> value);
void setDefaultElementBodyCharacters(Class<?> value);
void setDefaultElementBodyWhitespace(Class<?> value);
void setDefaultElementNamespaceInstanceProvider(Class<?> value);
void setDefaultElementAttributeValueParser(Class<?> value);
void setDefaultElementObjectPropertyValue(Class<?> value);
void setDefaultElementAttributeHandlerComparator(Class<?> value);
void setDefaultLanguageVersionFilter(Class<?> value);
void setDefaultLanguageLoader(Class<?> value);
void setDefaultExpressionLanguageContext(Class<?> value);
void setGlobalProperty(String key,Object value);
}

View file

@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory; import javax.el.ExpressionFactory;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
@ -46,13 +47,6 @@ import org.xml.sax.ext.DefaultHandler2;
*/ */
public enum X4OLanguageProperty { public enum X4OLanguageProperty {
/* TODO: refactor all keys ?
private final static String ENCODING = "http://writer.x4o.org/xml/properties/encoding";
private final static String CHAR_NEWLINE = "http://writer.x4o.org/xml/properties/char/newline";
private final static String CHAR_TAB = "http://writer.x4o.org/xml/properties/char/tab";
private final static String URI_PREFX = "http://writer.x4o.org/xml/properties/char/";
*/
/** Read-Only property returning the language we are working with. */ /** Read-Only property returning the language we are working with. */
LANGUAGE_NAME(IO.GLOBAL,"language/name"), LANGUAGE_NAME(IO.GLOBAL,"language/name"),
@ -61,117 +55,167 @@ public enum X4OLanguageProperty {
/** When set to OutputStream xml debug is written to it. note: when output-handler is set this property is ignored. */
DEBUG_OUTPUT_STREAM(IO.GLOBAL,"debug/output-stream",OutputStream.class),
/** When set to DefaultHandler2 xml debug events are fired to the object. */
DEBUG_OUTPUT_HANDLER(IO.GLOBAL,"debug/output-handler",DefaultHandler2.class),
/** When set to true print also phases for parsing eld files. */
DEBUG_OUTPUT_ELD_PARSER(IO.GLOBAL,"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),
/** SAX parser input buffer size: 512-16k defaults to 8k. */
INPUT_BUFFER_SIZE(IO.READER,"input/buffer-size",Integer.class,4096*2),
/** When set it allows parsing of non-namespace aware documents. */
INPUT_EMPTY_NAMESPACE_URI(IO.READER,"input/empty-namespace-uri"),
/** The input stream to parse, note is skipped when object is set. */ /** The input stream to parse, note is skipped when object is set. */
INPUT_SOURCE_STREAM(IO.READER,"input/source/stream",InputStream.class), READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */ /** When set it overrides automatic encoding detection of sax parser. */
INPUT_SOURCE_ENCODING(IO.READER,"input/source/encoding"), READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class),
/** When set use this InputSource instance for parsing. */ /** When set use this InputSource instance for parsing. */
INPUT_SOURCE_OBJECT(IO.READER,"input/source/object",InputSource.class), READER_INPUT_SOURCE(IO.READER,"reader/input/source",InputSource.class),
/** Sets the system-id to the input source. */ /** Sets the system-id to the input source. */
INPUT_SOURCE_SYSTEM_ID(IO.READER,"input/source/system-id",String.class), READER_INPUT_SYSTEM_ID(IO.READER,"reader/input/system-id",String.class),
/** Sets the base path to resolve external input sources. */ /** Sets the base path to resolve external input sources. */
INPUT_SOURCE_BASE_PATH(IO.READER,"input/source/base-path",URL.class), 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. */ /** Set for custom handling of validation errors. */
CONFIG_ERROR_HANDLER(IO.GLOBAL,"config/error-handler",ErrorHandler.class), READER_ERROR_HANDLER(IO.READER,"reader/error-handler",ErrorHandler.class),
/** Resolve more entities from local sources. */ /** Resolve more entities from local sources. */
CONFIG_ENTITY_RESOLVER(IO.GLOBAL,"config/entity-resolver",EntityResolver.class), 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),
/** 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),
/** 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),
//CONFIG_CACHE_HANDLER("config/cache-handler"),
//CONFIG_MODULE_PROVIDER("config/module-provider"),
//CONFIG_LOCK_PROPERTIES("config/lock-properties"),
/** The beans in this map are set into the EL context for reference. */ /** The beans in this map are set into the EL context for reference. */
EL_BEAN_INSTANCE_MAP(IO.READER,"el/bean-instance-map",Map.class), EL_BEAN_INSTANCE_MAP(IO.READER_WRITER,"el/bean-instance-map",Map.class),
//EL_CONTEXT_INSTANCE("el/context-instance"),
/** 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 this instance is used in ElementLanguage. */
EL_FACTORY_INSTANCE(IO.READER,"el/factory-instance",ExpressionFactory.class),
//EL_INSTANCE_FACTORY("phase/skip-elb-init",Boolean.class),
/** When set to an X4OPhase then parsing stops after completing the set phase. */ /** When set to an X4OPhase then parsing stops after completing the set phase. */
PHASE_STOP_AFTER(IO.READER,"phase/stop-after",String.class), PHASE_STOP_AFTER(IO.READER_WRITER,"phase/stop-after",String.class),
/** When set to true skip the release phase. */ /** When set to true skip the release phase. */
PHASE_SKIP_RELEASE(IO.READER,"phase/skip-release",Boolean.class,false), PHASE_SKIP_RELEASE(IO.READER_WRITER,"phase/skip-release",Boolean.class,false),
/** When set to true skip the run phase. */ /** When set to true skip the run phase. */
PHASE_SKIP_RUN(IO.READER,"phase/skip-run",Boolean.class,false), PHASE_SKIP_RUN(IO.READER_WRITER,"phase/skip-run",Boolean.class,false);
/** When set to true skip the load siblings language phase. */
PHASE_SKIP_SIBLINGS(IO.READER,"phase/skip-siblings",Boolean.class,false),
/** When set this path is searched for xsd schema files in the language sub directory. */
VALIDATION_SCHEMA_PATH(IO.READER,"validation/schema-path",File.class),
/** When set to true then input xml is validated. */
VALIDATION_INPUT(IO.READER,"validation/input",Boolean.class,false),
/** When set to true then input xsd xml grammer is validated. */
VALIDATION_INPUT_XSD(IO.READER,"validation/input/xsd",Boolean.class,false),
/** When set to true then eld xml is validated. */ // (temp) removed because init is now in driver manager
VALIDATION_ELD(IO.READER,"validation/eld",Boolean.class,false),
/** When set to true than eld xsd xml grammer is also validated. */ /* When set to true skip the load siblings language phase. */
VALIDATION_ELD_XSD(IO.GLOBAL, "validation/eld/xsd",Boolean.class,false); //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_GLOBAL_KEYS;
public final static X4OLanguageProperty[] DEFAULT_X4O_READER_KEYS; public final static X4OLanguageProperty[] DEFAULT_X4O_READER_KEYS;
public final static X4OLanguageProperty[] DEFAULT_X4O_WRITER_KEYS; public final static X4OLanguageProperty[] DEFAULT_X4O_WRITER_KEYS;
public final static X4OLanguageProperty[] DEFAULT_X4O_SCHEMA_WRITER_KEYS; public final static X4OLanguageProperty[] DEFAULT_X4O_SCHEMA_WRITER_KEYS;
static { static {
List<X4OLanguageProperty> globalResultKeys = new ArrayList<X4OLanguageProperty>();
List<X4OLanguageProperty> readerResultKeys = new ArrayList<X4OLanguageProperty>(); List<X4OLanguageProperty> readerResultKeys = new ArrayList<X4OLanguageProperty>();
List<X4OLanguageProperty> writerResultKeys = new ArrayList<X4OLanguageProperty>(); List<X4OLanguageProperty> writerResultKeys = new ArrayList<X4OLanguageProperty>();
List<X4OLanguageProperty> schemaWriterResultKeys = new ArrayList<X4OLanguageProperty>(); List<X4OLanguageProperty> schemaWriterResultKeys = new ArrayList<X4OLanguageProperty>();
X4OLanguageProperty[] keys = X4OLanguageProperty.values(); X4OLanguageProperty[] keys = X4OLanguageProperty.values();
for (int i=0;i<keys.length;i++) { for (int i=0;i<keys.length;i++) {
X4OLanguageProperty key = keys[i]; X4OLanguageProperty key = keys[i];
if (IO.GLOBAL.equals(key.type)) { if (IO.GLOBAL.equals(key.type) || IO.READER.equals(key.type) || IO.READER_WRITER.equals(key.type)) {
globalResultKeys.add(key);
readerResultKeys.add(key); readerResultKeys.add(key);
}
if (IO.GLOBAL.equals(key.type) || IO.WRITER.equals(key.type) || IO.READER_WRITER.equals(key.type)) {
writerResultKeys.add(key); writerResultKeys.add(key);
}
if (IO.GLOBAL.equals(key.type) || IO.SCHEMA_WRITER.equals(key.type)) {
schemaWriterResultKeys.add(key); schemaWriterResultKeys.add(key);
} }
if (IO.READER.equals(key.type)) {
readerResultKeys.add(key);
}
if (IO.WRITER.equals(key.type)) {
writerResultKeys.add(key);
}
} }
DEFAULT_X4O_GLOBAL_KEYS = globalResultKeys.toArray(new X4OLanguageProperty[globalResultKeys.size()]);
DEFAULT_X4O_READER_KEYS = readerResultKeys.toArray(new X4OLanguageProperty[readerResultKeys.size()]); DEFAULT_X4O_READER_KEYS = readerResultKeys.toArray(new X4OLanguageProperty[readerResultKeys.size()]);
DEFAULT_X4O_WRITER_KEYS = writerResultKeys.toArray(new X4OLanguageProperty[writerResultKeys.size()]); DEFAULT_X4O_WRITER_KEYS = writerResultKeys.toArray(new X4OLanguageProperty[writerResultKeys.size()]);
DEFAULT_X4O_SCHEMA_WRITER_KEYS = schemaWriterResultKeys.toArray(new X4OLanguageProperty[schemaWriterResultKeys.size()]); DEFAULT_X4O_SCHEMA_WRITER_KEYS = schemaWriterResultKeys.toArray(new X4OLanguageProperty[schemaWriterResultKeys.size()]);
@ -181,6 +225,7 @@ public enum X4OLanguageProperty {
GLOBAL, GLOBAL,
READER, READER,
WRITER, WRITER,
READER_WRITER,
SCHEMA_WRITER SCHEMA_WRITER
}; };

View file

@ -31,52 +31,51 @@ package org.x4o.xml.lang;
*/ */
public class X4OLanguagePropertyKeys { public class X4OLanguagePropertyKeys {
public static final String LANGUAGE_NAME = X4OLanguageProperty.LANGUAGE_NAME.toUri(); public static final String LANGUAGE_NAME = X4OLanguageProperty.LANGUAGE_NAME.toUri();
public static final String LANGUAGE_VERSION = X4OLanguageProperty.LANGUAGE_VERSION.toUri(); public static final String LANGUAGE_VERSION = X4OLanguageProperty.LANGUAGE_VERSION.toUri();
public static final String DEBUG_OUTPUT_STREAM = X4OLanguageProperty.DEBUG_OUTPUT_STREAM.toUri(); public static final String READER_INPUT_STREAM = X4OLanguageProperty.READER_INPUT_STREAM.toUri();
public static final String DEBUG_OUTPUT_HANDLER = X4OLanguageProperty.DEBUG_OUTPUT_HANDLER.toUri(); public static final String READER_INPUT_ENCODING = X4OLanguageProperty.READER_INPUT_ENCODING.toUri();
public static final String DEBUG_OUTPUT_ELD_PARSER = X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER.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 INPUT_BUFFER_SIZE = X4OLanguageProperty.INPUT_BUFFER_SIZE.toUri(); public static final String WRITER_OUTPUT_STREAM = X4OLanguageProperty.WRITER_OUTPUT_STREAM.toUri();
public static final String INPUT_EMPTY_NAMESPACE_URI = X4OLanguageProperty.INPUT_EMPTY_NAMESPACE_URI.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 INPUT_SOURCE_STREAM = X4OLanguageProperty.INPUT_SOURCE_STREAM.toUri(); public static final String SCHEMA_WRITER_OUTPUT_PATH = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_PATH.toUri();
public static final String INPUT_SOURCE_ENCODING = X4OLanguageProperty.INPUT_SOURCE_ENCODING.toUri(); public static final String SCHEMA_WRITER_OUTPUT_ENCODING = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_ENCODING.toUri();
public static final String INPUT_SOURCE_OBJECT = X4OLanguageProperty.INPUT_SOURCE_OBJECT.toUri(); public static final String SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE.toUri();
public static final String INPUT_SOURCE_SYSTEM_ID = X4OLanguageProperty.INPUT_SOURCE_SYSTEM_ID.toUri(); public static final String SCHEMA_WRITER_OUTPUT_CHAR_TAB = X4OLanguageProperty.SCHEMA_WRITER_OUTPUT_CHAR_TAB.toUri();
public static final String INPUT_SOURCE_BASE_PATH = X4OLanguageProperty.INPUT_SOURCE_BASE_PATH.toUri();
public static final String CONFIG_ERROR_HANDLER = X4OLanguageProperty.CONFIG_ERROR_HANDLER.toUri(); public static final String DEBUG_OUTPUT_STREAM = X4OLanguageProperty.DEBUG_OUTPUT_STREAM.toUri();
public static final String CONFIG_ENTITY_RESOLVER = X4OLanguageProperty.CONFIG_ENTITY_RESOLVER.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_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 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_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_RELEASE = X4OLanguageProperty.PHASE_SKIP_RELEASE.toUri();
public static final String PHASE_SKIP_RUN = X4OLanguageProperty.PHASE_SKIP_RUN.toUri(); public static final String PHASE_SKIP_RUN = X4OLanguageProperty.PHASE_SKIP_RUN.toUri();
public static final String PHASE_SKIP_SIBLINGS = X4OLanguageProperty.PHASE_SKIP_SIBLINGS.toUri();
public static final String VALIDATION_SCHEMA_PATH = X4OLanguageProperty.VALIDATION_SCHEMA_PATH.toUri();
public static final String VALIDATION_INPUT = X4OLanguageProperty.VALIDATION_INPUT.toUri();
public static final String VALIDATION_INPUT_XSD = X4OLanguageProperty.VALIDATION_INPUT_XSD.toUri();
public static final String VALIDATION_ELD = X4OLanguageProperty.VALIDATION_ELD.toUri();
public static final String VALIDATION_ELD_XSD = X4OLanguageProperty.VALIDATION_ELD_XSD.toUri();
public final static String[] DEFAULT_X4O_GLOBAL_KEYS;
public final static String[] DEFAULT_X4O_READER_KEYS; public final static String[] DEFAULT_X4O_READER_KEYS;
public final static String[] DEFAULT_X4O_WRITER_KEYS; public final static String[] DEFAULT_X4O_WRITER_KEYS;
public final static String[] DEFAULT_X4O_SCHEMA_WRITER_KEYS; public final static String[] DEFAULT_X4O_SCHEMA_WRITER_KEYS;
static { static {
X4OLanguageProperty[] globalKeys = X4OLanguageProperty.DEFAULT_X4O_GLOBAL_KEYS;
String[] globalResultKeys = new String[globalKeys.length];
for (int i=0;i<globalResultKeys.length;i++) {
globalResultKeys[i] = globalKeys[i].toUri();
}
DEFAULT_X4O_GLOBAL_KEYS = globalResultKeys;
X4OLanguageProperty[] readerKeys = X4OLanguageProperty.DEFAULT_X4O_READER_KEYS; X4OLanguageProperty[] readerKeys = X4OLanguageProperty.DEFAULT_X4O_READER_KEYS;
String[] readerResultKeys = new String[readerKeys.length]; String[] readerResultKeys = new String[readerKeys.length];
for (int i=0;i<readerResultKeys.length;i++) { for (int i=0;i<readerResultKeys.length;i++) {

View file

@ -149,7 +149,7 @@ PHASE_ORDER = { *startupX4OPhase,
boolean skipReleasePhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE); boolean skipReleasePhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE);
boolean skipRunPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN); boolean skipRunPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN);
boolean skipSiblingsPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_SIBLINGS); //boolean skipSiblingsPhase = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_SIBLINGS);
String stopPhase = languageContext.getLanguagePropertyString(X4OLanguageProperty.PHASE_STOP_AFTER); String stopPhase = languageContext.getLanguagePropertyString(X4OLanguageProperty.PHASE_STOP_AFTER);
// run the phases in ordered order // run the phases in ordered order
@ -161,9 +161,9 @@ PHASE_ORDER = { *startupX4OPhase,
if (skipRunPhase && phase.getId().equals("READ_RUN")) { if (skipRunPhase && phase.getId().equals("READ_RUN")) {
continue; // skip run phase on request continue; // skip run phase on request
} }
if (skipSiblingsPhase && phase.getId().equals("INIT_LANG_SIB")) { // if (skipSiblingsPhase && phase.getId().equals("INIT_LANG_SIB")) {
continue; // skip loading sibling languages // continue; // skip loading sibling languages
} // }
// debug output // debug output
((X4OLanguageContextLocal)languageContext).setCurrentPhase(phase); ((X4OLanguageContextLocal)languageContext).setCurrentPhase(phase);

View file

@ -261,21 +261,21 @@ public class X4OPhaseLanguageRead {
} }
// Finally start parsing the xml input stream // Finally start parsing the xml input stream
Object requestInputSource = languageContext.getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_OBJECT); Object requestInputSource = languageContext.getLanguageProperty(X4OLanguageProperty.READER_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.INPUT_SOURCE_STREAM); inputStream = (InputStream)languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_STREAM);
input = new InputSource(inputStream); input = new InputSource(inputStream);
} }
Object requestInputEncoding = languageContext.getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_ENCODING); Object requestInputEncoding = languageContext.getLanguageProperty(X4OLanguageProperty.READER_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.INPUT_SOURCE_SYSTEM_ID); Object requestSystemId = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SYSTEM_ID);
if (requestSystemId!=null && requestSystemId instanceof String) { if (requestSystemId!=null && requestSystemId instanceof String) {
input.setSystemId(requestSystemId.toString()); input.setSystemId(requestSystemId.toString());
} }

View file

@ -23,23 +23,32 @@
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.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List; 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.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.XMLWriter;
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.X4OLanguageModuleLoaderSibling; import org.x4o.xml.lang.X4OLanguageProperty;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageLoader;
import org.x4o.xml.lang.X4OLanguageLocal;
import org.xml.sax.SAXException; 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.
@ -58,7 +67,7 @@ public class X4OPhaseLanguageWrite {
public void createPhases(DefaultX4OPhaseManager manager) { public void createPhases(DefaultX4OPhaseManager manager) {
manager.addX4OPhase(new X4OPhaseWriteStart()); manager.addX4OPhase(new X4OPhaseWriteStart());
manager.addX4OPhase(new X4OPhaseWriteFillTree()); manager.addX4OPhase(new X4OPhaseWriteFillTree());
//manager.addX4OPhase(new X4OPhaseInitLanguageSiblings()); manager.addX4OPhase(new X4OPhaseWriteXml());
manager.addX4OPhase(new X4OPhaseWriteEnd()); manager.addX4OPhase(new X4OPhaseWriteEnd());
} }
@ -164,30 +173,185 @@ public class X4OPhaseLanguageWrite {
}; };
/** /**
* Loads all sibling languages. * Write xml to output.
*/ */
class X4OPhaseInitLanguageSiblings extends AbstractX4OPhase { class X4OPhaseWriteXml extends AbstractX4OPhase {
public X4OPhaseType getType() { public X4OPhaseType getType() {
return X4OPhaseType.XML_WRITE; return X4OPhaseType.XML_WRITE;
} }
public String getId() { public String getId() {
return "WRITE_TREE_VALUES"; return "WRITE_XML";
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[] {"INIT_LANG"}; return new String[] {"WRITE_FILL_TREE"};
} }
public boolean isElementPhase() { public boolean isElementPhase() {
return false; return false;
} }
public void runElementPhase(Element element) throws X4OPhaseException { public void runElementPhase(Element element) throws X4OPhaseException {
} }
public void runPhase(X4OLanguageContext elementLanguage) throws X4OPhaseException { boolean schemaUriPrint;
String schemaUriRoot;
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
OutputStream out = (OutputStream)languageContext.getLanguageProperty(X4OLanguageProperty.WRITER_OUTPUT_STREAM);
try { 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();
}
}
XMLWriter writer = new XMLWriter(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) { } catch (Exception e) {
throw new X4OPhaseException(this,e); throw new X4OPhaseException(this,e);
} finally {
if (out!=null) {
try {
out.close();
} catch (IOException e) {
}
}
} }
} }
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;
}
private void writeTree(XMLWriter writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
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);
}
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;
}
atts.addAttribute ("", eca.getId(), "", "", ""+value);
}
} else {
for (String p:getProperties(element.getElementObject().getClass())) {
ElementClassAttribute eca = element.getElementClass().getElementClassAttributeByName(p);
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 && 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
}
atts.addAttribute ("", p, "", "", ""+value);
}
}
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(), "");
}
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();
}
}; };
/** /**
@ -201,7 +365,7 @@ public class X4OPhaseLanguageWrite {
return "WRITE_END"; return "WRITE_END";
} }
public String[] getPhaseDependencies() { public String[] getPhaseDependencies() {
return new String[]{"WRITE_FILL_TREE"}; return new String[]{"WRITE_XML"};
} }
public boolean isElementPhase() { public boolean isElementPhase() {
return false; return false;

View file

@ -57,7 +57,7 @@ public class NamespaceUriTest extends TestCase {
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.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
reader.setProperty(X4OLanguagePropertyKeys.INPUT_EMPTY_NAMESPACE_URI, "http://test.x4o.org/xml/ns/test-lang"); reader.setProperty(X4OLanguagePropertyKeys.READER_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);

View file

@ -66,7 +66,7 @@ public class X4ODebugWriterTest extends TestCase {
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");
assertTrue("Debug file does not exists.",debugFile.exists()); assertTrue("Debug file does not exists.",debugFile.exists());

View file

@ -82,7 +82,7 @@ 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.createLanguageContext();
language.setLanguageProperty(X4OLanguageProperty.CONFIG_ENTITY_RESOLVER, new TestEntityResolver()); language.setLanguageProperty(X4OLanguageProperty.READER_ENTITY_RESOLVER, new TestEntityResolver());
X4OEntityResolver resolver = new X4OEntityResolver(language); X4OEntityResolver resolver = new X4OEntityResolver(language);
Exception e = null; Exception e = null;
InputSource input = null; InputSource input = null;
@ -98,7 +98,7 @@ 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.createLanguageContext();
language.setLanguageProperty(X4OLanguageProperty.CONFIG_ENTITY_RESOLVER, new TestEntityResolver()); language.setLanguageProperty(X4OLanguageProperty.READER_ENTITY_RESOLVER, new TestEntityResolver());
X4OEntityResolver resolver = new X4OEntityResolver(language); X4OEntityResolver resolver = new X4OEntityResolver(language);
Exception e = null; Exception e = null;
try { try {

View file

@ -44,7 +44,7 @@ public class EldValidatingTest extends TestCase {
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.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
reader.setProperty(X4OLanguagePropertyKeys.VALIDATION_INPUT, true); reader.setProperty(X4OLanguagePropertyKeys.READER_VALIDATION_INPUT, true);
//parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_SCHEMA_PATH, "/tmp"); //parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_SCHEMA_PATH, "/tmp");
try { try {
// TODO: reader.readResource("META-INF/eld/eld-lang.eld"); // TODO: reader.readResource("META-INF/eld/eld-lang.eld");

View file

@ -30,6 +30,7 @@ import java.util.Scanner;
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;
import org.x4o.xml.test.swixml.Accelerator3; import org.x4o.xml.test.swixml.Accelerator3;
@ -59,12 +60,15 @@ public class X4OWriterTest extends TestCase {
X4OReader<TestObjectRoot> reader = driver.createReader(); X4OReader<TestObjectRoot> reader = driver.createReader();
X4OWriter<TestObjectRoot> writer = driver.createWriter(); X4OWriter<TestObjectRoot> writer = driver.createWriter();
writer.setProperty(X4OLanguagePropertyKeys.WRITER_OUTPUT_CHAR_TAB, " ");
writer.setProperty(X4OLanguagePropertyKeys.WRITER_SCHEMA_URI_PRINT, false);
TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml");
writer.writeFile(root, outputFile); writer.writeFile(root, outputFile);
String text = new Scanner( outputFile ).useDelimiter("\\A").next(); String text = new Scanner( outputFile ).useDelimiter("\\A").next();
outputFile.delete(); outputFile.delete();
//System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath()); System.out.println("Output: '\n"+text+"\n' end in "+outputFile.getAbsolutePath());
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root")); assertTrue(text.contains("http://test.x4o.org/xml/ns/test-root"));
@ -84,6 +88,9 @@ public class X4OWriterTest extends TestCase {
X4OReader<Component> reader = driver.createReader(); X4OReader<Component> reader = driver.createReader();
X4OWriter<Component> writer = driver.createWriter(); X4OWriter<Component> writer = driver.createWriter();
//reader.setProperty(key, value);
//writer.setProperty(key, value);
reader.addELBeanInstance(SwiXmlDriver.LANGUAGE_EL_SWING_ENGINE, engine); reader.addELBeanInstance(SwiXmlDriver.LANGUAGE_EL_SWING_ENGINE, engine);
Component root = reader.readResource("tests/swixml/swixml-accelerator-3.0.xml"); Component root = reader.readResource("tests/swixml/swixml-accelerator-3.0.xml");
writer.writeFile(root, outputFile); writer.writeFile(root, outputFile);

View file

@ -52,7 +52,7 @@ public class SwingTests extends TestCase {
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);
} }