Fixed encoding bug,Added writeString support,Started on config bean.
This commit is contained in:
parent
8d71b63a6f
commit
6f2815491b
20 changed files with 319 additions and 95 deletions
|
|
@ -30,7 +30,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
|
|
@ -102,9 +104,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
|
|||
if (resourceName==null) {
|
||||
throw new NullPointerException("Can't read null resourceName from classpath.");
|
||||
}
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) cl = getClass().getClassLoader(); // fallback
|
||||
URL url = cl.getResource(resourceName);
|
||||
URL url = X4OLanguageClassLoader.getResource(resourceName);
|
||||
if (url==null) {
|
||||
throw new NullPointerException("Could not find resource on classpath: "+resourceName);
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
|
|||
baseUrl = baseUrl.substring(0,lastSlash+1);
|
||||
}
|
||||
URL basePath = new URL(baseUrl);
|
||||
InputStream inputStream = cl.getResourceAsStream(resourceName);
|
||||
InputStream inputStream = X4OLanguageClassLoader.getResourceAsStream(resourceName);
|
||||
try {
|
||||
return readContext(inputStream,url.toExternalForm(),basePath);
|
||||
} finally {
|
||||
|
|
@ -123,8 +123,8 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a InputStream to is can me readd by SAX.
|
||||
* @param xmlString The xml as String to read.
|
||||
* Converts a String to a InputStream to is can me read by SAX.
|
||||
* @param xmlString The xml as (UTF-8) String to read.
|
||||
* @throws X4OConnectionException Is thrown after x4o exception.
|
||||
* @throws SAXException Is thrown after sax xml exception.
|
||||
* @throws IOException Is thrown after io exception.
|
||||
|
|
@ -135,7 +135,8 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
|
|||
throw new NullPointerException("Can't read null xml string.");
|
||||
}
|
||||
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
|
||||
return readContext(new ByteArrayInputStream(xmlString.getBytes()),"inline-xml",basePath);
|
||||
String encoding = getLanguageContext().getLanguagePropertyString(X4OLanguageProperty.READER_INPUT_ENCODING);
|
||||
return readContext(new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -77,4 +77,8 @@ public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> i
|
|||
public void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
|
||||
writeFileContext(toObjectContext(object), file);
|
||||
}
|
||||
|
||||
public String writeString(T object) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
|
||||
return writeStringContext(toObjectContext(object));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@
|
|||
*/
|
||||
package org.x4o.xml.io;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
|
|
@ -60,4 +62,11 @@ public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection
|
|||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
||||
writeContext(context, out);
|
||||
String encoding = context.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_ENCODING);
|
||||
return out.toString(encoding);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,6 @@ public interface X4OWriter<T> extends X4OConnection {
|
|||
void writeFile(T object,String fileName) throws X4OConnectionException,SAXException,IOException;
|
||||
|
||||
void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException;
|
||||
|
||||
String writeString(T object) throws X4OConnectionException,SAXException,IOException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,6 @@ public interface X4OWriterContext<T> extends X4OWriter<T> {
|
|||
void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException;
|
||||
|
||||
void writeFileContext(X4OLanguageContext context,File file) throws X4OConnectionException,SAXException,IOException;
|
||||
|
||||
String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public class X4OContentHandler extends DefaultHandler2 {
|
|||
overrideSaxHandler = (DefaultHandler2)element.getElementObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
|
|
@ -201,7 +201,7 @@ public class X4OContentHandler extends DefaultHandler2 {
|
|||
throw new SAXParseException("Error while configing element: '"+tag+"' "+ee.getMessage(),locator,ee);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets called to pass the text between XML-tags and converts it to a String.
|
||||
* When this string is 0 length then nothing is done.
|
||||
|
|
|
|||
|
|
@ -83,6 +83,14 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
prefixMapping = new HashMap<String,String>(15);
|
||||
printedMappings = new ArrayList<String>(15);
|
||||
elements = new Stack<String>();
|
||||
/*
|
||||
ContentConfig conf = new ContentConfig(
|
||||
new ContentConfigItem("writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
|
||||
new ContentConfigItem("content/writer/output/charTab",String.class)
|
||||
);
|
||||
conf.getPropertyString("");
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// TODO: check location of this. (add to api?)
|
||||
|
|
@ -227,12 +235,8 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
attributeValue = "null"; // TODO: Add null value key to config.
|
||||
}
|
||||
String attributeValueSafe = XMLConstants.escapeAttributeValue(attributeValue);
|
||||
boolean printNewLine = attributeValueSafe.length()>80; // TODO add config
|
||||
if (i==0) {
|
||||
startElement.append(' ');
|
||||
} else if (!printNewLine) {
|
||||
startElement.append(' ');
|
||||
}
|
||||
|
||||
startElement.append(' ');
|
||||
if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
|
||||
startElement.append(attributeName);
|
||||
} else {
|
||||
|
|
@ -243,6 +247,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
startElement.append("=\"");
|
||||
startElement.append(attributeValueSafe);
|
||||
startElement.append('"');
|
||||
boolean printNewLine = attributeValueSafe.length()>80; // TODO add config
|
||||
if (printNewLine) {
|
||||
startElement.append(XMLConstants.CHAR_NEWLINE);
|
||||
for (int ii = 0; ii < indent+1; ii++) {
|
||||
|
|
@ -385,6 +390,10 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints xml ignorable whitespace.
|
||||
*
|
||||
* @param text The text to print.
|
||||
* @throws SAXException When IOException has happend while printing.
|
||||
* @see org.x4o.xml.io.sax.ext.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||
*/
|
||||
public void ignorableWhitespace(String text) throws SAXException {
|
||||
|
|
@ -395,6 +404,12 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
write(text); // TODO: check chars
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints xml ignorable whitespace character.
|
||||
*
|
||||
* @param c The character to print.
|
||||
* @throws SAXException When IOException has happend while printing.
|
||||
*/
|
||||
public void ignorableWhitespace(char c) throws SAXException {
|
||||
ignorableWhitespace(new char[]{c},0,1);
|
||||
}
|
||||
|
|
@ -462,6 +477,8 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints xml comment.
|
||||
*
|
||||
* @see org.x4o.xml.io.sax.ext.ContentWriter#comment(java.lang.String)
|
||||
*/
|
||||
public void comment(String text) throws SAXException {
|
||||
|
|
@ -480,6 +497,11 @@ public class AbstractContentWriterHandler implements ContentHandler {
|
|||
printReturn = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value contains any new lines and sets the printReturn field.
|
||||
*
|
||||
* @param value The value to check.
|
||||
*/
|
||||
private void checkPrintedReturn(String value) {
|
||||
if (value.indexOf(XMLConstants.CHAR_NEWLINE)>0) {
|
||||
printReturn = true;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ContentConfig Defines checked config options.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 1, 2013
|
||||
*/
|
||||
public final class ContentConfig {
|
||||
|
||||
private final ContentConfigItem[] items;
|
||||
private final Map<String,Integer> itemKeys;
|
||||
|
||||
public ContentConfig(ContentConfigItem...items) {
|
||||
this.items=items;
|
||||
itemKeys = new HashMap<String,Integer>(items.length);
|
||||
for (int i=0;i<items.length;i++) {
|
||||
ContentConfigItem item = items[i];
|
||||
itemKeys.put(item.getKey(),i);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ContentConfigItem {
|
||||
private String key = null;
|
||||
private Class<?> valueType = null;
|
||||
private Object defaultValue = null;
|
||||
private Object value = null;
|
||||
|
||||
public ContentConfigItem(String key,Class<?> valueType) {
|
||||
this(key,valueType,null);
|
||||
}
|
||||
public ContentConfigItem(String key,Class<?> valueType,Object defaultValue) {
|
||||
setKey(key);
|
||||
setValueType(valueType);
|
||||
setDefaultValue(defaultValue);
|
||||
}
|
||||
/**
|
||||
* @return the key
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
/**
|
||||
* @param key the key to set
|
||||
*/
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
public Class<?> getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
/**
|
||||
* @param valueType the valueType to set
|
||||
*/
|
||||
public void setValueType(Class<?> valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
/**
|
||||
* @return the defaultValue
|
||||
*/
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
/**
|
||||
* @param defaultValue the defaultValue to set
|
||||
*/
|
||||
public void setDefaultValue(Object defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private final ContentConfigItem getContentConfigItem(String key) {
|
||||
Integer keyIdx = itemKeys.get(key);
|
||||
if (keyIdx==null) {
|
||||
throw new IllegalArgumentException("Could not find config item for: "+key);
|
||||
}
|
||||
ContentConfigItem item = items[keyIdx];
|
||||
return item;
|
||||
}
|
||||
|
||||
public final void setProperty(String key,Object value) {
|
||||
ContentConfigItem item = getContentConfigItem(key);
|
||||
item.setValue(value);
|
||||
}
|
||||
|
||||
public final Object getProperty(String key) {
|
||||
ContentConfigItem item = getContentConfigItem(key);
|
||||
return item.getValue();
|
||||
}
|
||||
|
||||
public final boolean getPropertyBoolean(String key) {
|
||||
ContentConfigItem item = getContentConfigItem(key);
|
||||
Object value = item.getValue();
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean)value;
|
||||
}
|
||||
|
||||
return (Boolean)item.getDefaultValue();
|
||||
}
|
||||
|
||||
public final int getPropertyInteger(String key) {
|
||||
ContentConfigItem item = getContentConfigItem(key);
|
||||
Object value = item.getValue();
|
||||
if (value instanceof Integer) {
|
||||
return (Integer)value;
|
||||
}
|
||||
return (Integer)item.getDefaultValue();
|
||||
}
|
||||
|
||||
public final String getPropertyString(String key) {
|
||||
ContentConfigItem item = getContentConfigItem(key);
|
||||
Object value = item.getValue();
|
||||
if (value instanceof String) {
|
||||
return (String)value;
|
||||
}
|
||||
return (String)item.getDefaultValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
/**
|
||||
* ContentWriterConfig Defines config options for ContentWriter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 1, 2013
|
||||
*/
|
||||
public interface ContentWriterConfig {
|
||||
|
||||
String getCharNewLine();
|
||||
String getCharTab();
|
||||
|
||||
String getReplaceCdataStart();
|
||||
String getReplaceCdataEnd();
|
||||
}
|
||||
|
|
@ -22,6 +22,9 @@
|
|||
*/
|
||||
package org.x4o.xml.lang;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* X4OLanguageClassLoader is short hand for safe class loading.
|
||||
*
|
||||
|
|
@ -82,4 +85,24 @@ public final class X4OLanguageClassLoader {
|
|||
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
return newInstance(loadClass(className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource from the classloader to an url.
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The url to the resource or null if not found.
|
||||
* @see java.lang.ClassLoader#getResource(String)
|
||||
*/
|
||||
public static URL getResource(String resourceName) {
|
||||
return getClassLoader().getResource(resourceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource from the classloader to an inputstream.
|
||||
* @param resourceName The resource to get from the classloader.
|
||||
* @return The inputstream to the resource or null if not found.
|
||||
* @see java.lang.ClassLoader#getResourceAsStream(String)
|
||||
*/
|
||||
public static InputStream getResourceAsStream(String resourceName) {
|
||||
return getClassLoader().getResourceAsStream(resourceName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.Map;
|
|||
import javax.el.ELContext;
|
||||
import javax.el.ExpressionFactory;
|
||||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
|
|
@ -60,7 +61,7 @@ public enum X4OLanguageProperty {
|
|||
READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
|
||||
|
||||
/** When set it overrides automatic encoding detection of sax parser. */
|
||||
READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class),
|
||||
READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
|
||||
|
||||
/** When set use this InputSource instance for parsing. */
|
||||
READER_INPUT_SOURCE(IO.READER,"reader/input/source",InputSource.class),
|
||||
|
|
@ -107,7 +108,7 @@ public enum X4OLanguageProperty {
|
|||
WRITER_OUTPUT_STREAM(IO.WRITER,"writer/output/stream",OutputStream.class),
|
||||
|
||||
/** The writer output encoding. */
|
||||
WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class),
|
||||
WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
|
||||
|
||||
/** The writer output newline. */
|
||||
WRITER_OUTPUT_CHAR_NEWLINE(IO.WRITER,"writer/output/char/newline",String.class),
|
||||
|
|
@ -129,7 +130,7 @@ public enum X4OLanguageProperty {
|
|||
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),
|
||||
SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
|
||||
|
||||
/** The schema writer output newline. */
|
||||
SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE(IO.SCHEMA_WRITER,"schema-writer/output/char/newline",String.class),
|
||||
|
|
|
|||
|
|
@ -630,10 +630,10 @@ public class X4OPhaseLanguageRead {
|
|||
return; // has already runned.
|
||||
}
|
||||
try {
|
||||
//if (parser.hasX4ODebugWriter()) {
|
||||
// parser.getX4ODebugWriter().debugElement(element);
|
||||
//if (element.getLanguageContext().hasX4ODebugWriter()) {
|
||||
// element.getLanguageContext().getX4ODebugWriter().debugElement(element);
|
||||
//}
|
||||
element.doElementRun();
|
||||
element.doElementRun();
|
||||
} catch (ElementException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,15 @@
|
|||
*/
|
||||
package org.x4o.xml.eld;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.X4ODriverManager;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.io.X4OWriter;
|
||||
import org.x4o.xml.lang.DefaultX4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -95,10 +104,27 @@ public class EldParserTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testRunEldParser() throws Exception {
|
||||
//EldDriver parser = new EldDriver(false);
|
||||
//parser.parseResource("META-INF/test/test-lang.eld");
|
||||
//X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
//X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
//reader.readResource("META-INF/test/test-lang.eld");
|
||||
X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
X4OWriter<X4OLanguageModule> writer = driver.createWriter();
|
||||
|
||||
X4OLanguage language = driver.createLanguage(driver.getLanguageVersionDefault());
|
||||
X4OLanguageModule mod = new DefaultX4OLanguageModule();
|
||||
|
||||
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration());
|
||||
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE, language);
|
||||
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE, mod);
|
||||
|
||||
X4OLanguageModule modNew = reader.readResource("META-INF/test/test-lang.eld");
|
||||
|
||||
//int binds = mod.getElementBindingHandlers().size();
|
||||
//System.out.println(binds);
|
||||
|
||||
String output = writer.writeString(mod);
|
||||
assertNotNull(output);
|
||||
|
||||
// TODO; fix element config+event to new interface + reserse for writing.
|
||||
|
||||
//System.out.println(output);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
</eld:classBindingHandler>
|
||||
</eld:elementInterface>
|
||||
|
||||
<!-- TODO: fix writer, run EldParserTest
|
||||
<eld:configuratorGlobal bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfigGlobal">
|
||||
<eld:description>Test the global element configurator.</eld:description>
|
||||
</eld:configuratorGlobal>
|
||||
|
|
@ -83,6 +84,7 @@
|
|||
<eld:description>Test the global element attribute2 handler.</eld:description>
|
||||
<eld:attributeHandlerNextAttribute attributeName="tt.attr1"/>
|
||||
</eld:attributeHandler>
|
||||
-->
|
||||
|
||||
<eld:namespace
|
||||
uri="http://test.x4o.org/xml/ns/test-root"
|
||||
|
|
@ -116,10 +118,12 @@
|
|||
</eld:element>
|
||||
|
||||
<eld:element tag="configBean" objectClass="org.x4o.xml.test.models.TestBean">
|
||||
<!-- TODO: fix writer
|
||||
<eld:configurator bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfig1">
|
||||
<eld:description>The test element config.</eld:description>
|
||||
</eld:configurator>
|
||||
<eld:configurator bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfig2"/>
|
||||
-->
|
||||
<eld:elementSkipPhase name="runAttributesPhase"/>
|
||||
<eld:elementSkipPhase name="transformPhase"/>
|
||||
</eld:element>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue