Redone elddoc html writer now via new sax ContentWriter interface.
And implemented jdk7 javadoc compatible html/css for elddoc.
This commit is contained in:
parent
ef5b0a0b8e
commit
92644fd148
27 changed files with 2959 additions and 751 deletions
|
|
@ -37,7 +37,7 @@ import org.x4o.xml.lang.X4OLanguage;
|
|||
import org.x4o.xml.lang.phase.X4OPhaseManager;
|
||||
|
||||
/**
|
||||
* This is the starting point of the XML X4O Language Driver.
|
||||
* X4ODriver Is the x4o language driver to interact with xml.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 11, 2005
|
||||
|
|
@ -83,10 +83,19 @@ public abstract class X4ODriver<T> {
|
|||
|
||||
// =============== SchemaWriter
|
||||
|
||||
/**
|
||||
* Creates a schema writer for the default language version.
|
||||
* @return The schema writer for this language.
|
||||
*/
|
||||
public X4OSchemaWriter createSchemaWriter() {
|
||||
return createSchemaWriter(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a schema writer for a version of the language.
|
||||
* @param version The version of the language.
|
||||
* @return The schema writer for this language.
|
||||
*/
|
||||
public X4OSchemaWriter createSchemaWriter(String version) {
|
||||
return new DefaultX4OSchemaWriter(createLanguageContext(version));
|
||||
}
|
||||
|
|
@ -135,18 +144,36 @@ public abstract class X4ODriver<T> {
|
|||
|
||||
// =============== Language
|
||||
|
||||
/**
|
||||
* Returns the default language which is the latest version.
|
||||
* @return The default language version.
|
||||
*/
|
||||
final public String getLanguageVersionDefault() {
|
||||
return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the X4OLanguage for the specified version.
|
||||
* @param version The language version to create.
|
||||
* @return The created X4OLanguage.
|
||||
*/
|
||||
final public X4OLanguage createLanguage(String version) {
|
||||
return buildLanguage(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the X4OLanguageContext for the default language version.
|
||||
* @return The created X4OLanguageContext.
|
||||
*/
|
||||
final public X4OLanguageContext createLanguageContext() {
|
||||
return createLanguageContext(getLanguageVersionDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the X4OLanguageContext for the specified version.
|
||||
* @param version The language version to create the context for.
|
||||
* @return The created X4OLanguageContext.
|
||||
*/
|
||||
final public X4OLanguageContext createLanguageContext(String version) {
|
||||
return createLanguage(version).createLanguageContext(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class X4OELContext extends ELContext {
|
|||
/**
|
||||
* Creates a X4OELContext.
|
||||
*/
|
||||
public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) {
|
||||
public X4OELContext() {
|
||||
|
||||
CompositeELResolver compositeELResolver = new CompositeELResolver();
|
||||
compositeELResolver.add(new X4OELResolver(new HashMap<Object, Object>(100)));
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ import javax.el.FunctionMapper;
|
|||
* @version 1.0 Sep 14, 2010
|
||||
*/
|
||||
public class X4OELFunctionMapper extends FunctionMapper {
|
||||
|
||||
/**
|
||||
* Stores the el to method function mapping.
|
||||
*/
|
||||
private Map<String,Method> functionMap = null;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +49,12 @@ public class X4OELFunctionMapper extends FunctionMapper {
|
|||
functionMap = new HashMap<String,Method>(50);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves method el functions.
|
||||
* @param prefix The function prefix.
|
||||
* @param localName The local name of function.
|
||||
* @return The resolved function or null is not found.
|
||||
*/
|
||||
@Override
|
||||
public Method resolveFunction(String prefix, String localName) {
|
||||
String key = prefix + ":" + localName;
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ import org.x4o.xml.element.ElementClass;
|
|||
import org.x4o.xml.element.ElementException;
|
||||
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.ContentWriter;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
|
||||
/**
|
||||
* EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver.
|
||||
|
|
@ -84,7 +84,7 @@ public class EldXsdXmlGenerator {
|
|||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
try {
|
||||
XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab);
|
||||
ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
|
|
@ -96,7 +96,7 @@ public class EldXsdXmlGenerator {
|
|||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
try {
|
||||
XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab);
|
||||
ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
|
|
@ -109,7 +109,7 @@ public class EldXsdXmlGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateSchema(String namespaceUri,DefaultHandler2 xmlWriter) throws SAXException {
|
||||
public void generateSchema(String namespaceUri,ContentWriter xmlWriter) throws SAXException {
|
||||
|
||||
ElementNamespaceContext ns = language.findElementNamespaceContext(namespaceUri);
|
||||
if (ns==null) {
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ import org.x4o.xml.element.ElementInterface;
|
|||
import org.x4o.xml.element.ElementMetaBase;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
|
|
@ -60,11 +60,11 @@ public class EldXsdXmlWriter {
|
|||
static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
protected X4OLanguage language = null;
|
||||
protected DefaultHandler2 xmlWriter = null;
|
||||
protected ContentWriter xmlWriter = null;
|
||||
protected String writeNamespace = null;
|
||||
protected Map<String, String> namespaces = null;
|
||||
|
||||
public EldXsdXmlWriter(DefaultHandler2 xmlWriter,X4OLanguage language) {
|
||||
public EldXsdXmlWriter(ContentWriter xmlWriter,X4OLanguage language) {
|
||||
this.xmlWriter=xmlWriter;
|
||||
this.language=language;
|
||||
this.namespaces=new HashMap<String,String>(10);
|
||||
|
|
|
|||
|
|
@ -34,8 +34,9 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.X4ODebugWriter;
|
||||
import org.x4o.xml.io.sax.XMLWriter;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageContextLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
|
@ -43,7 +44,6 @@ import org.x4o.xml.lang.X4OLanguagePropertyKeys;
|
|||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseType;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
|
|
@ -105,11 +105,11 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
Object debugOutputHandler = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER);
|
||||
Object debugOutputStream = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM);
|
||||
if (languageContext.getX4ODebugWriter()==null) {
|
||||
DefaultHandler2 xmlDebugWriter = null;
|
||||
if (debugOutputHandler instanceof DefaultHandler2) {
|
||||
xmlDebugWriter = (DefaultHandler2)debugOutputHandler;
|
||||
ContentWriter xmlDebugWriter = null;
|
||||
if (debugOutputHandler instanceof ContentWriter) {
|
||||
xmlDebugWriter = (ContentWriter)debugOutputHandler;
|
||||
} else if (debugOutputStream instanceof OutputStream) {
|
||||
xmlDebugWriter = new XMLWriter((OutputStream)debugOutputStream);
|
||||
xmlDebugWriter = new ContentWriterXml((OutputStream)debugOutputStream);
|
||||
}
|
||||
if (xmlDebugWriter!=null) {
|
||||
xmlDebugWriter.startDocument();
|
||||
|
|
@ -126,7 +126,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "language", "", "", languageContext.getLanguage().getLanguageName());
|
||||
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+"");
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts);
|
||||
}
|
||||
|
||||
// start parsing language
|
||||
|
|
@ -142,7 +142,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
if (e instanceof X4OPhaseException) {
|
||||
atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId());
|
||||
}
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts);
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter printer = new PrintWriter(writer);
|
||||
printer.append('\n');
|
||||
|
|
@ -152,8 +152,8 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
e.getCause().printStackTrace(printer);
|
||||
}
|
||||
char[] stack = writer.getBuffer().toString().toCharArray();
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length);
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
|
||||
languageContext.getX4ODebugWriter().getContentWriter().characters(stack, 0, stack.length);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
|
||||
} catch (Exception ee) {
|
||||
logger.warning(ee.getMessage());
|
||||
}
|
||||
|
|
@ -176,11 +176,11 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
|
|||
}
|
||||
} finally {
|
||||
if (languageContext.hasX4ODebugWriter()) {
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
|
||||
}
|
||||
if (startedDebugWriter && languageContext.hasX4ODebugWriter()) {
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug");
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endDocument();
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endPrefixMapping("debug");
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endDocument();
|
||||
if (debugOutputStream instanceof OutputStream) {
|
||||
OutputStream outputStream = (OutputStream)debugOutputStream;
|
||||
outputStream.flush();
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ public final class XMLConstants {
|
|||
*/
|
||||
public static final String NULL_NS_URI = "";
|
||||
|
||||
/**
|
||||
* (Start) Definition of DTD doctype.
|
||||
*/
|
||||
public static final String XML_DOCTYPE = "<!DOCTYPE";
|
||||
|
||||
/**
|
||||
* Opens xml element tag.
|
||||
*/
|
||||
|
|
@ -111,6 +116,26 @@ public final class XMLConstants {
|
|||
*/
|
||||
public static final String PROCESS_END = "?>";
|
||||
|
||||
/**
|
||||
* Starts a cdata section.
|
||||
*/
|
||||
public static final String CDATA_START = "<![CDATA[";
|
||||
|
||||
/**
|
||||
* Ends a cdata section.
|
||||
*/
|
||||
public static final String CDATA_END = "]]>";
|
||||
|
||||
/**
|
||||
* The regex expression of a cdata start section.
|
||||
*/
|
||||
public static final String CDATA_START_REGEX = "<!\\x"+Integer.toHexString('[')+"CDATA\\x"+Integer.toHexString('[');
|
||||
|
||||
/**
|
||||
* The regex expression of a cdata end section.
|
||||
*/
|
||||
public static final String CDATA_END_REGEX = "\\x"+Integer.toHexString(']')+"\\x"+Integer.toHexString(']')+">";
|
||||
|
||||
/**
|
||||
* Tab char
|
||||
*/
|
||||
|
|
@ -119,7 +144,7 @@ public final class XMLConstants {
|
|||
/**
|
||||
* Newline char
|
||||
*/
|
||||
public static final String CHAR_NEWLINE = "\r\n";
|
||||
public static final String CHAR_NEWLINE = "\n";
|
||||
|
||||
|
||||
|
||||
|
|
@ -207,29 +232,59 @@ public final class XMLConstants {
|
|||
return true;
|
||||
}
|
||||
|
||||
static public String escapeAttributeValue(String value) {
|
||||
int l = value.length();
|
||||
StringBuffer result = new StringBuffer(l);
|
||||
for (int i=0;i<l;i++) {
|
||||
//static public boolean isCharRef(String c) {
|
||||
// &#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
|
||||
//}
|
||||
|
||||
static private boolean escapeXMLValue(char c,StringBuffer result) {
|
||||
if (c=='<') {
|
||||
result.append("<");
|
||||
return true;
|
||||
}
|
||||
if (c=='>') {
|
||||
result.append(">");
|
||||
return true;
|
||||
}
|
||||
if (c=='&') {
|
||||
result.append("&");
|
||||
return true;
|
||||
}
|
||||
if (c=='\"') {
|
||||
result.append(""e;");
|
||||
return true;
|
||||
}
|
||||
if (c=='\'') {
|
||||
result.append("'");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public String escapeAttributeName(String value) {
|
||||
// Attribute ::= Name Eq AttValue
|
||||
int length = value.length();
|
||||
StringBuffer result = new StringBuffer(length);
|
||||
for (int i=0;i<length;i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c=='<') {
|
||||
result.append("<");
|
||||
continue;
|
||||
if (isNameChar(c)) {
|
||||
result.append(c);
|
||||
} else {
|
||||
result.append("#x");
|
||||
result.append(Integer.toHexString(c));
|
||||
result.append(";");
|
||||
}
|
||||
if (c=='>') {
|
||||
result.append(">");
|
||||
continue;
|
||||
}
|
||||
if (c=='&') {
|
||||
result.append("&");
|
||||
continue;
|
||||
}
|
||||
if (c=='\"') {
|
||||
result.append(""e;");
|
||||
continue;
|
||||
}
|
||||
if (c=='\'') {
|
||||
result.append("'");
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static public String escapeAttributeValue(String value) {
|
||||
// Reference ::= EntityRef | CharRef
|
||||
// AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
|
||||
int length = value.length();
|
||||
StringBuffer result = new StringBuffer(length);
|
||||
for (int i=0;i<length;i++) {
|
||||
char c = value.charAt(i);
|
||||
if (escapeXMLValue(c,result)) {
|
||||
continue;
|
||||
}
|
||||
if (/*isNameChar(c)*/true==false) {// TODO: add correct
|
||||
|
|
@ -243,4 +298,43 @@ public final class XMLConstants {
|
|||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static public String escapeCharacters(String value) {
|
||||
int length = value.length();
|
||||
StringBuffer result = new StringBuffer(length);
|
||||
for (int i=0;i<length;i++) {
|
||||
char c = value.charAt(i);
|
||||
if (escapeXMLValue(c,result)) {
|
||||
continue;
|
||||
}
|
||||
result.append(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static public String escapeCharactersCdata(String value,String replaceCdataStart,String replaceCdataEnd) {
|
||||
value = value.replaceAll(CDATA_START_REGEX, replaceCdataStart);
|
||||
value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd);
|
||||
return value;
|
||||
}
|
||||
|
||||
static public String escapeCharactersComment(String value,String charTab,int indent) {
|
||||
value = value.replaceAll(COMMENT_START, "");
|
||||
value = value.replaceAll(COMMENT_END, "");
|
||||
int length = value.length();
|
||||
StringBuffer result = new StringBuffer(length);
|
||||
for (int i=0;i<length;i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c=='\n') {
|
||||
result.append(c);
|
||||
for (int ii = 0; ii < indent; ii++) {
|
||||
result.append(charTab);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
result.append(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import java.util.Set;
|
|||
* Maps an SAX attributes set to an Map interface.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 17/04/2005
|
||||
* @version 1.0 Apr 17, 2005
|
||||
* @param <K> The key class.
|
||||
* @param <V> The value class.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
|
||||
|
||||
/**
|
||||
* ContentWriter is ContentHandler for writing sax events.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 30, 2013
|
||||
*/
|
||||
public interface ContentWriter extends ContentHandler,LexicalHandler {
|
||||
|
||||
/**
|
||||
* Starts and ends an element in one call.
|
||||
* @param uri The uri of the element.
|
||||
* @param localName The localName of the element.
|
||||
* @param name The name of the element.
|
||||
* @param atts The attributes of the element.
|
||||
* @throws SAXException When IOException is thrown.
|
||||
*/
|
||||
void startElementEnd(String uri, String localName, String name,Attributes atts) throws SAXException;
|
||||
|
||||
void comment(String text) throws SAXException;
|
||||
|
||||
void ignorableWhitespace(String text) throws SAXException;
|
||||
|
||||
void characters(String text) throws SAXException;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* ContentWriterHtml writes HTML events as SAX events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 30, 2013
|
||||
*/
|
||||
public class ContentWriterHtml extends ContentWriterXml {
|
||||
|
||||
public ContentWriterHtml(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out,encoding,charNewLine,charTab);
|
||||
}
|
||||
|
||||
public void printDocType(DocType doc) throws SAXException {
|
||||
startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId());
|
||||
}
|
||||
|
||||
public void printHtmlStart(String language) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
if (language!=null) {
|
||||
atts.addAttribute ("", "lang", "", "", language);
|
||||
}
|
||||
printTagStart(Tag.html,atts);
|
||||
}
|
||||
|
||||
public void printHtmlEnd() throws SAXException {
|
||||
printTagEnd(Tag.html);
|
||||
}
|
||||
|
||||
public void printHeadMetaDate() throws SAXException {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
printHeadMeta("date",cal.get(Calendar.YEAR)+"-"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
public void printHeadTitle(String title) throws SAXException {
|
||||
printTagText("title",title);
|
||||
}
|
||||
|
||||
public void printHeadMetaContentType() throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "http-equiv", "", "", "Content-Type");
|
||||
atts.addAttribute ("", "content", "", "", "text/html");
|
||||
atts.addAttribute ("", "charset", "", "", this.encoding);
|
||||
startElementEnd("", "meta", "", atts);
|
||||
}
|
||||
|
||||
public void printHeadMeta(String name,String content) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", name);
|
||||
atts.addAttribute ("", "content", "", "", content);
|
||||
startElementEnd("", "meta", "", atts);
|
||||
}
|
||||
|
||||
public void printHeadLinkCss(String cssUrl) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "rel", "", "", "stylesheet");
|
||||
atts.addAttribute ("", "type", "", "", "text/css");
|
||||
atts.addAttribute ("", "title", "", "", "Style");
|
||||
atts.addAttribute ("", "href", "", "", cssUrl);
|
||||
startElementEnd("", "link", "", atts);
|
||||
}
|
||||
|
||||
public void printScriptInline(String script) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "type", "", "", "text/javascript");
|
||||
printTagStart(Tag.script,atts);
|
||||
comment(script);
|
||||
printTagEnd(Tag.script);
|
||||
}
|
||||
|
||||
public void printScriptNoDiv() throws SAXException {
|
||||
printScriptNoDiv(null);
|
||||
}
|
||||
|
||||
public void printScriptNoDiv(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
text = "JavaScript is disabled on your browser.";
|
||||
}
|
||||
printTagStart(Tag.noscript);
|
||||
printTagStart(Tag.div);characters(text);printTagEnd(Tag.div);
|
||||
printTagEnd(Tag.noscript);
|
||||
}
|
||||
|
||||
public void printHrefNamed(String name) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", name);
|
||||
printTagStart(Tag.a,atts);
|
||||
comment(" ");
|
||||
printTagEnd(Tag.a);
|
||||
}
|
||||
|
||||
public void printHrefTarget(String href,String title,String target) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "href", "", "", href);
|
||||
atts.addAttribute ("", "target", "", "", target);
|
||||
printTagStart(Tag.a,atts);
|
||||
characters(title);
|
||||
printTagEnd(Tag.a);
|
||||
}
|
||||
|
||||
public void printHref(String href,String title) throws SAXException {
|
||||
printHref(href,title,title);
|
||||
}
|
||||
|
||||
public void printHref(String href,String title,String text) throws SAXException {
|
||||
printHref(href,title,text,null);
|
||||
}
|
||||
|
||||
public void printHref(String href,String title,String text,String spanClass) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "href", "", "", href);
|
||||
if (title!=null) {
|
||||
atts.addAttribute ("", "title", "", "", title);
|
||||
}
|
||||
printTagStart(Tag.a,atts);
|
||||
if (spanClass!=null) {
|
||||
atts = new AttributesImpl();
|
||||
if (spanClass.length()>0) {
|
||||
atts.addAttribute ("", "class", "", "", spanClass);
|
||||
}
|
||||
printTagStart(Tag.span,atts);
|
||||
}
|
||||
characters(text);
|
||||
if (spanClass!=null) {
|
||||
printTagEnd(Tag.span);
|
||||
}
|
||||
printTagEnd(Tag.a);
|
||||
}
|
||||
|
||||
|
||||
private void printTagText(String tag,String text) throws SAXException {
|
||||
startElement ("", tag, "", EMPTY_ATTRIBUTES);
|
||||
characters(text);
|
||||
endElement ("",tag , "");
|
||||
}
|
||||
|
||||
public void printTagText(Tag tag,String text) throws SAXException {
|
||||
printTagText(tag,text,null);
|
||||
}
|
||||
|
||||
public void printTagText(Tag tag,String text,String tagClass) throws SAXException {
|
||||
printTagText(tag,text,tagClass,null);
|
||||
}
|
||||
|
||||
public void printTagText(Tag tag,String text,String tagClass,String tagId) throws SAXException {
|
||||
printTagStart(tag,tagClass,tagId);
|
||||
if (text==null) {
|
||||
text = " ";
|
||||
}
|
||||
characters(text);
|
||||
printTagEnd(tag);
|
||||
}
|
||||
|
||||
public void printTagStartEnd(Tag tag) throws SAXException {
|
||||
printTagStart(tag,null,null);
|
||||
printTagEnd(tag);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag) throws SAXException {
|
||||
printTagStart(tag,null,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,String tagClass) throws SAXException {
|
||||
printTagStart(tag,tagClass,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,String tagClass,String tagId) throws SAXException {
|
||||
printTagStart(tag,tagClass,tagId,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,String tagClass,String tagId,String typeId) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
if (tagId!=null && tagId.length()>0) {
|
||||
atts.addAttribute ("", "id", "", "", tagId);
|
||||
}
|
||||
if (tagClass!=null && tagClass.length()>0) {
|
||||
atts.addAttribute ("", "class", "", "", tagClass);
|
||||
}
|
||||
if (typeId!=null && typeId.length()>0) {
|
||||
atts.addAttribute ("", "type", "", "", typeId);
|
||||
}
|
||||
printTagStart(tag,atts);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,Attributes atts) throws SAXException {
|
||||
startElement ("", tag.name(), "", atts);
|
||||
}
|
||||
|
||||
public void printTagEnd(Tag tag) throws SAXException {
|
||||
endElement ("",tag.name() , "");
|
||||
}
|
||||
|
||||
public enum Tag {
|
||||
|
||||
/* Deprecated TAGS */
|
||||
frameset,frame,noframes,tt,font,dir,center,strike,
|
||||
big,basefont,acronym,applet,iframe,
|
||||
|
||||
/* HTML 4 TAGS */
|
||||
html,head,title,meta,link,base,body,script,style,
|
||||
|
||||
h1,h2,h3,h4,h5,h6,
|
||||
a,div,span,p,pre,img,hr,br,
|
||||
b,em,strong,small,noscript,
|
||||
|
||||
ul,li,dl,dt,dd,ol,
|
||||
table,thead,tfoot,tbody,caption,th,tr,td,
|
||||
|
||||
abbr,address,area,bdo,blockquote,
|
||||
cite,code,col,colgroup,del,dfn,i,ins,
|
||||
kbd,legend,map,menu,object,param,
|
||||
optgroup,q,s,samp,sub,u,var,
|
||||
|
||||
form,fieldset,input,option,
|
||||
label,button,select,textarea,
|
||||
|
||||
/* HTML 5 TAGS */
|
||||
canvas,audio,video,source,embed,track,
|
||||
datalist,keygen,output,
|
||||
article,aside,bdi,command,details,dialog,summary,
|
||||
figure,figcaption,footer,header,hgroup,mark,meter,
|
||||
nav,progress,ruby,rt,rp,section,time,wbr
|
||||
}
|
||||
|
||||
private final static String DOCTYPE_NAME = "HTML PUBLIC";
|
||||
public enum DocType {
|
||||
/* Order from worst to better. */
|
||||
HTML_5("html","",""),
|
||||
|
||||
HTML_4_FRAMESET(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01 Frameset//EN\"","http://www.w3.org/TR/html4/frameset.dtd"),
|
||||
HTML_4_TRANSITIONAL(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01 Transitional//EN\"","http://www.w3.org/TR/html4/loose.dtd"),
|
||||
HTML_4_STRICT(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01//EN\"","http://www.w3.org/TR/html4/strict.dtd"),
|
||||
|
||||
XHTML_1_FRAMESET(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Frameset//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"),
|
||||
XHTML_1_TRANSITIONAL(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Transitional//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"),
|
||||
XHTML_1_STRICT(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Strict//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
|
||||
|
||||
XHTML_11(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.1//EN\"","http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
|
||||
|
||||
private final String name;
|
||||
private final String publicId;
|
||||
private final String systemId;
|
||||
private DocType(String name, String publicId, String systemId) {
|
||||
this.name=name;
|
||||
this.publicId=publicId;
|
||||
this.systemId=systemId;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @return the publicId
|
||||
*/
|
||||
public String getPublicId() {
|
||||
return publicId;
|
||||
}
|
||||
/**
|
||||
* @return the systemId
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,23 +32,24 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* Writes SAX event to XML.
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 17/04/2005
|
||||
* @version 1.0 Apr 17, 2005
|
||||
*/
|
||||
public class XMLWriter extends DefaultHandler2 {
|
||||
public class ContentWriterXml implements ContentWriter {
|
||||
|
||||
private String encoding = null;
|
||||
public final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
protected String encoding = null;
|
||||
private String charNewline = null;
|
||||
private String charTab = null;
|
||||
private Writer out = null;
|
||||
|
|
@ -56,13 +57,16 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
private Map<String,String> prefixMapping = null;
|
||||
private List<String> printedMappings = null;
|
||||
private StringBuffer startElement = null;
|
||||
private boolean printedReturn = false;
|
||||
private boolean printReturn = false;
|
||||
private String lastElement = null;
|
||||
private boolean printCDATA = false;
|
||||
private Stack<String> elements = null;
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public XMLWriter(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
public ContentWriterXml(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
if (out==null) {
|
||||
throw new NullPointerException("Can't write on null writer.");
|
||||
}
|
||||
|
|
@ -81,13 +85,14 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
this.charTab = charTab;
|
||||
prefixMapping = new HashMap<String,String>(15);
|
||||
printedMappings = new ArrayList<String>(15);
|
||||
elements = new Stack<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public XMLWriter(Writer out,String encoding) {
|
||||
public ContentWriterXml(Writer out,String encoding) {
|
||||
this(out,encoding,null,null);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +101,7 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public XMLWriter(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
||||
public ContentWriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding);
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +109,7 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public XMLWriter(Writer out) {
|
||||
public ContentWriterXml(Writer out) {
|
||||
this(out,null);
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +118,7 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public XMLWriter(OutputStream out) throws UnsupportedEncodingException {
|
||||
public ContentWriterXml(OutputStream out) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING);
|
||||
}
|
||||
|
||||
|
|
@ -125,14 +130,29 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @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 {
|
||||
public ContentWriterXml(OutputStream out,String encoding,String charNewLine,String charTab) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding,charNewLine,charTab);
|
||||
}
|
||||
|
||||
// TODO: check location of this. (add to api?)
|
||||
public void closeWriter() throws IOException {
|
||||
if (out==null) {
|
||||
return;
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void closeWriterSafe() {
|
||||
try {
|
||||
closeWriter();
|
||||
} catch (IOException e) {
|
||||
e.getMessage(); // discard exception
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ContentHandler#startDocument()
|
||||
*/
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
indent = 0;
|
||||
write(XMLConstants.getDocumentDeclaration(encoding));
|
||||
|
|
@ -141,9 +161,20 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
/**
|
||||
* @see org.xml.sax.ContentHandler#endDocument()
|
||||
*/
|
||||
@Override
|
||||
public void endDocument() throws SAXException {
|
||||
writeFlush();
|
||||
if (elements.size()>0) {
|
||||
throw new SAXException("Invalid xml still have "+elements.size()+" elements open.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and end then element.
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||
*/
|
||||
public void startElementEnd(String uri, String localName, String name,Attributes atts) throws SAXException {
|
||||
startElement(uri,localName,name,atts);
|
||||
endElement(uri, localName, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,31 +184,31 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param atts The attributes of the xml tag.
|
||||
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||
*/
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String name,Attributes atts) throws SAXException {
|
||||
if (startElement!=null) {
|
||||
write(startElement.toString());
|
||||
startElement=null;
|
||||
if (localName==null) {
|
||||
localName = "null"; // mmm rm ?
|
||||
}
|
||||
if (XMLConstants.isNameString(localName)==false) {
|
||||
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
|
||||
}
|
||||
autoCloseStartElement();
|
||||
startElement = new StringBuffer(200);
|
||||
|
||||
if (printedReturn==false) {
|
||||
startElement.append(charNewline);
|
||||
}
|
||||
printedReturn=false;
|
||||
|
||||
startElement.append(charNewline);
|
||||
for (int i = 0; i < indent; i++) {
|
||||
startElement.append(charTab);
|
||||
}
|
||||
startElement.append(XMLConstants.TAG_OPEN);
|
||||
|
||||
if (localName==null) {
|
||||
localName = "null";
|
||||
}
|
||||
if (XMLConstants.isNameString(localName)==false) {
|
||||
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
|
||||
}
|
||||
|
||||
startElementTag(uri,localName);
|
||||
startElementNamespace(uri);
|
||||
startElementAttributes(atts);
|
||||
startElement.append(XMLConstants.TAG_CLOSE);
|
||||
indent++;
|
||||
lastElement = localName;
|
||||
elements.push(localName);
|
||||
}
|
||||
|
||||
public void startElementTag(String uri,String localName) throws SAXException {
|
||||
if (XMLConstants.NULL_NS_URI.equals(uri) | uri==null) {
|
||||
startElement.append(localName);
|
||||
} else {
|
||||
|
|
@ -191,7 +222,9 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
}
|
||||
startElement.append(localName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void startElementNamespace(String uri) throws SAXException {
|
||||
if ((uri!=null & XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) {
|
||||
String prefix = prefixMapping.get(uri);
|
||||
if (prefix==null) {
|
||||
|
|
@ -209,42 +242,50 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
startElement.append(uri);
|
||||
startElement.append('"');
|
||||
|
||||
boolean first = true;
|
||||
for (String uri2:prefixMapping.keySet()) {
|
||||
if (printedMappings.contains(uri2)==false) {
|
||||
prefix = prefixMapping.get(uri2);
|
||||
if (prefix==null) {
|
||||
throw new SAXException("preFixUri: "+uri+" is not started.");
|
||||
}
|
||||
printedMappings.add(uri2);
|
||||
|
||||
if (first) {
|
||||
startElement.append(charNewline);
|
||||
first = false;
|
||||
}
|
||||
|
||||
startElement.append(' ');
|
||||
startElement.append(XMLConstants.XMLNS_ATTRIBUTE);
|
||||
if ("".equals(prefix)==false) {
|
||||
startElement.append(XMLConstants.XMLNS_ASSIGN);
|
||||
startElement.append(prefix);
|
||||
}
|
||||
startElement.append("=\"");
|
||||
startElement.append(uri2);
|
||||
startElement.append('"');
|
||||
startElement.append(charNewline);
|
||||
startElementNamespaceAll(uri);
|
||||
}
|
||||
}
|
||||
|
||||
public void startElementNamespaceAll(String uri) throws SAXException {
|
||||
String prefix = null;
|
||||
boolean first = true;
|
||||
for (String uri2:prefixMapping.keySet()) {
|
||||
if (printedMappings.contains(uri2)==false) {
|
||||
prefix = prefixMapping.get(uri2);
|
||||
if (prefix==null) {
|
||||
throw new SAXException("preFixUri: "+uri+" is not started.");
|
||||
}
|
||||
printedMappings.add(uri2);
|
||||
|
||||
if (first) {
|
||||
startElement.append(charNewline);
|
||||
first = false;
|
||||
}
|
||||
|
||||
startElement.append(' ');
|
||||
startElement.append(XMLConstants.XMLNS_ATTRIBUTE);
|
||||
if ("".equals(prefix)==false) {
|
||||
startElement.append(XMLConstants.XMLNS_ASSIGN);
|
||||
startElement.append(prefix);
|
||||
}
|
||||
startElement.append("=\"");
|
||||
startElement.append(uri2);
|
||||
startElement.append('"');
|
||||
startElement.append(charNewline);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void startElementAttributes(Attributes atts) throws SAXException {
|
||||
for (int i=0;i<atts.getLength();i++) {
|
||||
String attributeUri = atts.getURI(i);
|
||||
String attributeName = atts.getLocalName(i);
|
||||
String attributeName = XMLConstants.escapeAttributeName(atts.getLocalName(i));
|
||||
String attributeValue = atts.getValue(i);
|
||||
if (attributeValue==null) {
|
||||
attributeValue = "null";
|
||||
}
|
||||
startElement.append(' ');
|
||||
|
||||
if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
|
||||
startElement.append(attributeName);
|
||||
} else {
|
||||
|
|
@ -257,8 +298,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
startElement.append(XMLConstants.escapeAttributeValue(attributeValue));
|
||||
startElement.append('"');
|
||||
}
|
||||
startElement.append(XMLConstants.TAG_CLOSE);
|
||||
indent++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -267,8 +306,13 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param name The (full) name of the xml tag.
|
||||
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||
|
||||
if (elements.size()>0 && elements.peek().equals((localName))==false) {
|
||||
throw new SAXException("Unexpected end tag: "+localName+" should be: "+elements.peek());
|
||||
}
|
||||
elements.pop();
|
||||
|
||||
if (startElement!=null) {
|
||||
String tag = startElement.toString();
|
||||
write(tag.substring(0,tag.length()-1));// rm normal close
|
||||
|
|
@ -278,13 +322,13 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
return;
|
||||
}
|
||||
|
||||
if (printedReturn==false) {
|
||||
write(charNewline);
|
||||
}
|
||||
printedReturn=false;
|
||||
indent--;
|
||||
writeIndent();
|
||||
|
||||
if (printReturn || !localName.equals(lastElement)) {
|
||||
write(charNewline);
|
||||
writeIndent();
|
||||
} else {
|
||||
printReturn = true;
|
||||
}
|
||||
if (localName==null) {
|
||||
localName = "null";
|
||||
}
|
||||
|
|
@ -312,7 +356,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param uri The xml namespace uri to add the prefix for.
|
||||
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||
prefixMapping.put(uri, prefix);
|
||||
}
|
||||
|
|
@ -321,7 +364,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param prefix The xml prefix of this xml namespace uri to be ended.
|
||||
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void endPrefixMapping(String prefix) throws SAXException {
|
||||
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
|
||||
String uri = null;
|
||||
|
|
@ -348,19 +390,35 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @throws SAXException When IOException has happend while printing.
|
||||
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (startElement!=null) {
|
||||
write(startElement.toString());
|
||||
startElement=null;
|
||||
characters(new String(ch,start,length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#characters(java.lang.String)
|
||||
*/
|
||||
public void characters(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
for (int i=start;i<(start+length);i++) {
|
||||
char c = ch[i];
|
||||
write(c);
|
||||
if (c=='\n') {
|
||||
printedReturn=true;
|
||||
}
|
||||
autoCloseStartElement();
|
||||
checkPrintedReturn(text);
|
||||
if (printCDATA) {
|
||||
text = XMLConstants.escapeCharactersCdata(text,"","");
|
||||
} else {
|
||||
text = XMLConstants.escapeCharacters(text);
|
||||
}
|
||||
write(text);
|
||||
}
|
||||
|
||||
// move or remove ?
|
||||
public void charactersRaw(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
autoCloseStartElement();
|
||||
checkPrintedReturn(text);
|
||||
write(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -372,13 +430,19 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @throws SAXException When IOException has happend while printing.
|
||||
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||
if (startElement!=null) {
|
||||
write(startElement.toString());
|
||||
startElement=null;
|
||||
ignorableWhitespace(new String(ch,start,length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||
*/
|
||||
public void ignorableWhitespace(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
write(ch, start, length);
|
||||
autoCloseStartElement();
|
||||
write(text); // TODO: check chars
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -388,7 +452,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @param target The target.
|
||||
* @param data The data.
|
||||
*/
|
||||
@Override
|
||||
public void processingInstruction(String target, String data) throws SAXException {
|
||||
writeIndent();
|
||||
write(XMLConstants.PROCESS_START);
|
||||
|
|
@ -406,7 +469,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
|
||||
* @param locator The DocumentLocator to set.
|
||||
*/
|
||||
@Override
|
||||
public void setDocumentLocator(Locator locator) {
|
||||
}
|
||||
|
||||
|
|
@ -416,7 +478,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
|
||||
* @param name The name of the skipped entity.
|
||||
*/
|
||||
@Override
|
||||
public void skippedEntity(String name) throws SAXException {
|
||||
// is for validating parser support, so not needed in xml writing.
|
||||
}
|
||||
|
|
@ -430,24 +491,106 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
* @throws SAXException When IOException has happend while printing.
|
||||
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void comment(char[] ch, int start, int length) throws SAXException {
|
||||
comment(new String(ch,start,length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#comment(java.lang.String)
|
||||
*/
|
||||
public void comment(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
autoCloseStartElement();
|
||||
checkPrintedReturn(text);
|
||||
write(charNewline);
|
||||
writeIndent();
|
||||
write(XMLConstants.COMMENT_START);
|
||||
|
||||
/// mmm todo improve a bit
|
||||
for (int i=start;i<(start+length);i++) {
|
||||
char c = ch[i];
|
||||
if (c=='\n') {
|
||||
write(c);
|
||||
writeIndent();
|
||||
continue;
|
||||
}
|
||||
write(c);
|
||||
}
|
||||
write(" ");
|
||||
write(XMLConstants.escapeCharactersComment(text,charTab,indent));
|
||||
write(" ");
|
||||
write(XMLConstants.COMMENT_END);
|
||||
printReturn = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
||||
*/
|
||||
public void startCDATA() throws SAXException {
|
||||
autoCloseStartElement();
|
||||
write(XMLConstants.CDATA_START);
|
||||
printCDATA = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
||||
*/
|
||||
public void endCDATA() throws SAXException {
|
||||
write(XMLConstants.CDATA_END);
|
||||
printCDATA = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||
write(XMLConstants.XML_DOCTYPE);
|
||||
write(" ");
|
||||
write(name);
|
||||
if (publicId!=null) {
|
||||
write(" ");
|
||||
write(publicId);
|
||||
}
|
||||
if (systemId!=null) {
|
||||
write(" \"");
|
||||
write(systemId);
|
||||
write("\"");
|
||||
}
|
||||
write(XMLConstants.TAG_CLOSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
||||
*/
|
||||
public void endDTD() throws SAXException {
|
||||
writeFlush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
|
||||
*/
|
||||
public void startEntity(String arg0) throws SAXException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
|
||||
*/
|
||||
public void endEntity(String arg0) throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkPrintedReturn(String value) {
|
||||
if (value.indexOf('\n')>0) {
|
||||
printReturn = true;
|
||||
} else {
|
||||
printReturn = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto close the start element if working in printing event.
|
||||
* @throws IOException When prints gives exception.
|
||||
*/
|
||||
private void autoCloseStartElement() throws SAXException {
|
||||
if (startElement==null) {
|
||||
return;
|
||||
}
|
||||
write(startElement.toString());
|
||||
startElement=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indent the output writer with tabs by indent count.
|
||||
* @throws IOException When prints gives exception.
|
||||
|
|
@ -474,14 +617,6 @@ public class XMLWriter extends DefaultHandler2 {
|
|||
}
|
||||
}
|
||||
|
||||
private void write(char[] ch, int start, int length) throws SAXException {
|
||||
try {
|
||||
out.write(ch,start,length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void write(char c) throws SAXException {
|
||||
try {
|
||||
out.write(c);
|
||||
|
|
@ -48,7 +48,6 @@ import org.x4o.xml.lang.phase.X4OPhase;
|
|||
import org.x4o.xml.lang.phase.X4OPhaseException;
|
||||
import org.x4o.xml.lang.phase.X4OPhaseListener;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
|
|
@ -62,14 +61,14 @@ public class X4ODebugWriter {
|
|||
|
||||
static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output";
|
||||
|
||||
protected DefaultHandler2 debugWriter = null;
|
||||
protected ContentWriter contentWriter = null;
|
||||
|
||||
public X4ODebugWriter(DefaultHandler2 debugWriter) {
|
||||
this.debugWriter=debugWriter;
|
||||
public X4ODebugWriter(ContentWriter debugWriter) {
|
||||
this.contentWriter=debugWriter;
|
||||
}
|
||||
|
||||
public DefaultHandler2 getDebugWriter() {
|
||||
return debugWriter;
|
||||
public ContentWriter getContentWriter() {
|
||||
return contentWriter;
|
||||
}
|
||||
|
||||
public X4OPhaseListener createDebugX4OPhaseListener() {
|
||||
|
|
@ -91,7 +90,7 @@ public class X4ODebugWriter {
|
|||
if (elementLanguage!=null) {
|
||||
atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName());
|
||||
}
|
||||
debugWriter.startElement (DEBUG_URI, "executePhase", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "executePhase", "", atts);
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(phase,e);
|
||||
}
|
||||
|
|
@ -104,10 +103,10 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "id", "", "", phase.getId());
|
||||
atts.addAttribute ("", "speed", "", "", (stopTime-startTime)+" ms");
|
||||
debugWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts);
|
||||
debugWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
|
||||
contentWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts);
|
||||
contentWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
|
||||
|
||||
debugWriter.endElement (DEBUG_URI, "executePhase" , "");
|
||||
contentWriter.endElement (DEBUG_URI, "executePhase" , "");
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(phase,e);
|
||||
}
|
||||
|
|
@ -117,7 +116,7 @@ public class X4ODebugWriter {
|
|||
public void debugLanguageProperties(X4OLanguageContext ec) throws ElementException {
|
||||
try {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts);
|
||||
for (X4OLanguageProperty p:X4OLanguageProperty.values()) {
|
||||
Object value = ec.getLanguageProperty(p);
|
||||
if (value==null) {
|
||||
|
|
@ -126,10 +125,10 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts2 = new AttributesImpl();
|
||||
atts2.addAttribute ("", "uri", "", "", p.toUri());
|
||||
atts2.addAttribute ("", "value", "", "", value.toString());
|
||||
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2);
|
||||
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperty", "");
|
||||
contentWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2);
|
||||
contentWriter.endElement(DEBUG_URI, "X4OLanguageProperty", "");
|
||||
}
|
||||
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperties", "");
|
||||
contentWriter.endElement(DEBUG_URI, "X4OLanguageProperties", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -138,7 +137,7 @@ public class X4ODebugWriter {
|
|||
public void debugLanguageDefaultClasses(X4OLanguageContext ec) throws ElementException {
|
||||
try {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts);
|
||||
X4OLanguageConfiguration conf = ec.getLanguage().getLanguageConfiguration();
|
||||
|
||||
debugLanguageDefaultClass("getDefaultElementNamespaceContext",conf.getDefaultElementNamespaceContext());
|
||||
|
|
@ -155,7 +154,7 @@ public class X4ODebugWriter {
|
|||
debugLanguageDefaultClass("getDefaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue());
|
||||
debugLanguageDefaultClass("getDefaultElementAttributeHandlerComparator",conf.getDefaultElementAttributeHandlerComparator());
|
||||
|
||||
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", "");
|
||||
contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -165,20 +164,20 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", name);
|
||||
atts.addAttribute ("", "className", "", "", clazz.getName());
|
||||
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
|
||||
contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
|
||||
}
|
||||
|
||||
public void debugPhaseOrder(List<X4OPhase> phases) throws X4OPhaseException {
|
||||
X4OPhase phase = null;
|
||||
try {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
debugWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
|
||||
for (X4OPhase phase2:phases) {
|
||||
phase = phase2;
|
||||
debugPhase(phase2);
|
||||
}
|
||||
debugWriter.endElement(DEBUG_URI, "phaseOrder", "");
|
||||
contentWriter.endElement(DEBUG_URI, "phaseOrder", "");
|
||||
} catch (SAXException e) {
|
||||
// fall back...
|
||||
if (phase==null) {
|
||||
|
|
@ -198,14 +197,14 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "runOnce", "", "", phase.isRunOnce()+"");
|
||||
atts.addAttribute ("", "listenersSize", "", "", phase.getPhaseListeners().size()+"");
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "phase", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "phase", "", atts);
|
||||
for (X4OPhaseListener l:phase.getPhaseListeners()) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "className", "", "", l.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
|
||||
contentWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
|
||||
}
|
||||
debugWriter.endElement(DEBUG_URI, "phase", "");
|
||||
contentWriter.endElement(DEBUG_URI, "phase", "");
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(phase,e);
|
||||
}
|
||||
|
|
@ -214,7 +213,7 @@ public class X4ODebugWriter {
|
|||
public void debugElementLanguageModules(X4OLanguageContext elementLanguage) throws ElementException {
|
||||
try {
|
||||
AttributesImpl attsEmpty = new AttributesImpl();
|
||||
debugWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
|
||||
contentWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
|
||||
|
||||
for (X4OLanguageModule module:elementLanguage.getLanguage().getLanguageModules()) {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
|
@ -227,7 +226,7 @@ public class X4ODebugWriter {
|
|||
} else {
|
||||
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", module.getLanguageModuleLoader().getClass().getName());
|
||||
}
|
||||
debugWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts);
|
||||
|
||||
//module.getElementAttributeHandlers();
|
||||
//module.getElementBindingHandlers();
|
||||
|
|
@ -243,14 +242,14 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "attributeName", "", "", p.getAttributeName());
|
||||
atts.addAttribute ("", "description", "", "", p.getDescription());
|
||||
atts.addAttribute ("", "className", "", "", p.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts);
|
||||
for (String para:p.getNextAttributes()) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "attributeName", "", "", para);
|
||||
debugWriter.startElement (DEBUG_URI, "nextAttribute", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "nextAttribute", "");
|
||||
contentWriter.startElement (DEBUG_URI, "nextAttribute", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "nextAttribute", "");
|
||||
}
|
||||
debugWriter.endElement(DEBUG_URI, "elementAttributeHandler", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementAttributeHandler", "");
|
||||
}
|
||||
|
||||
for (ElementInterface elementInterface:module.getElementInterfaces()) {
|
||||
|
|
@ -259,10 +258,10 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "description", "", "", elementInterface.getDescription());
|
||||
atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName());
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "elementInterface", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "elementInterface", "", atts);
|
||||
debugElementBindingHandler(elementInterface.getElementBindingHandlers());
|
||||
debugElementClassBase(elementInterface);
|
||||
debugWriter.endElement(DEBUG_URI, "elementInterface", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementInterface", "");
|
||||
}
|
||||
|
||||
for (ElementNamespaceContext enc:module.getElementNamespaceContexts()) {
|
||||
|
|
@ -273,7 +272,7 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource());
|
||||
atts.addAttribute ("", "className", "", "", enc.getClass().getName());
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "", atts);
|
||||
for (ElementClass ec:enc.getElementClasses()) {
|
||||
debugElementClass(ec);
|
||||
}
|
||||
|
|
@ -281,16 +280,16 @@ public class X4ODebugWriter {
|
|||
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "className", "", "", eip.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "");
|
||||
contentWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "");
|
||||
|
||||
debugWriter.endElement(DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "");
|
||||
contentWriter.endElement(DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "");
|
||||
}
|
||||
|
||||
debugWriter.endElement(DEBUG_URI, "ElementLanguageModule", "");
|
||||
contentWriter.endElement(DEBUG_URI, "ElementLanguageModule", "");
|
||||
}
|
||||
|
||||
debugWriter.endElement(DEBUG_URI, "ElementLanguageModules", "");
|
||||
contentWriter.endElement(DEBUG_URI, "ElementLanguageModules", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -343,15 +342,15 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage());
|
||||
}
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "elementObject", "", atts2);
|
||||
debugWriter.endElement(DEBUG_URI, "elementObject", "");
|
||||
contentWriter.startElement (DEBUG_URI, "elementObject", "", atts2);
|
||||
contentWriter.endElement(DEBUG_URI, "elementObject", "");
|
||||
}
|
||||
|
||||
StringBuffer elementPath = getElementPath(element,new StringBuffer());
|
||||
atts.addAttribute ("", "elementPath", "", "", elementPath.toString());
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "element", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "element", "");
|
||||
contentWriter.startElement (DEBUG_URI, "element", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "element", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -379,10 +378,10 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "class", "", "", clazz.getName()+"");
|
||||
try {
|
||||
debugWriter.startElement (DEBUG_URI, "message", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "message", "", atts);
|
||||
char[] msg = message.toCharArray();
|
||||
debugWriter.characters(msg,0,msg.length);
|
||||
debugWriter.endElement(DEBUG_URI, "message", "");
|
||||
contentWriter.characters(msg,0,msg.length);
|
||||
contentWriter.endElement(DEBUG_URI, "message", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -396,9 +395,9 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "description", "", "", ec.getDescription());
|
||||
atts.addAttribute ("", "className", "", "", ec.getClass().getName());
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts);
|
||||
debugElement(element);
|
||||
debugWriter.endElement(DEBUG_URI, "runElementConfigurator", "");
|
||||
contentWriter.endElement(DEBUG_URI, "runElementConfigurator", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -414,9 +413,9 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+"");
|
||||
atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+"");
|
||||
|
||||
debugWriter.startElement (DEBUG_URI, "doBind", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "doBind", "", atts);
|
||||
debugElement(element);
|
||||
debugWriter.endElement(DEBUG_URI, "doBind", "");
|
||||
contentWriter.endElement(DEBUG_URI, "doBind", "");
|
||||
} catch (SAXException e) {
|
||||
throw new ElementException(e);
|
||||
}
|
||||
|
|
@ -429,8 +428,8 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguage().getLanguageVersion());
|
||||
atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+"");
|
||||
atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentPhase().getId());
|
||||
debugWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "printElementLanguage", "");
|
||||
contentWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "printElementLanguage", "");
|
||||
}
|
||||
|
||||
private void debugElementClass(ElementClass elementClass) throws SAXException {
|
||||
|
|
@ -441,26 +440,26 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "description", "", "", elementClass.getDescription());
|
||||
atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass());
|
||||
atts.addAttribute ("", "className", "", "", elementClass.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementClass", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "elementClass", "", atts);
|
||||
for (String phase:elementClass.getSkipPhases()) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "phase", "", "", ""+phase);
|
||||
debugWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
|
||||
contentWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
|
||||
}
|
||||
debugElementConfigurator(elementClass.getElementConfigurators());
|
||||
debugElementClassBase(elementClass);
|
||||
debugWriter.endElement(DEBUG_URI, "elementClass", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementClass", "");
|
||||
}
|
||||
|
||||
private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "description", "", "", elementClassBase.getDescription());
|
||||
atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementClassBase", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "elementClassBase", "", atts);
|
||||
debugElementConfigurator(elementClassBase.getElementConfigurators());
|
||||
debugElementClassAttributes(elementClassBase.getElementClassAttributes());
|
||||
debugWriter.endElement(DEBUG_URI, "elementClassBase", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementClassBase", "");
|
||||
}
|
||||
|
||||
private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException {
|
||||
|
|
@ -468,8 +467,8 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
|
||||
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "elementConfigurator", "");
|
||||
contentWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "elementConfigurator", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -478,8 +477,8 @@ public class X4ODebugWriter {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
|
||||
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", "");
|
||||
contentWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -494,17 +493,17 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters());
|
||||
//atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces());
|
||||
atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL());
|
||||
debugWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts);
|
||||
contentWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts);
|
||||
if (elementClassAttribute.getObjectConverter()!=null) {
|
||||
debugObjectConverter(elementClassAttribute.getObjectConverter());
|
||||
}
|
||||
for (String alias:elementClassAttribute.getAttributeAliases()) {
|
||||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", ""+alias);
|
||||
debugWriter.startElement(DEBUG_URI, "attributeAlias", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "attributeAlias", "");
|
||||
contentWriter.startElement(DEBUG_URI, "attributeAlias", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "attributeAlias", "");
|
||||
}
|
||||
debugWriter.endElement(DEBUG_URI, "elementClassAttribute", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementClassAttribute", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -513,8 +512,8 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName());
|
||||
atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName());
|
||||
atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName());
|
||||
debugWriter.startElement (DEBUG_URI, "objectConverter", "", atts);
|
||||
debugWriter.endElement(DEBUG_URI, "objectConverter", "");
|
||||
contentWriter.startElement (DEBUG_URI, "objectConverter", "", atts);
|
||||
contentWriter.endElement(DEBUG_URI, "objectConverter", "");
|
||||
}
|
||||
|
||||
private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException {
|
||||
|
|
@ -523,16 +522,16 @@ public class X4ODebugWriter {
|
|||
atts.addAttribute ("", "className", "", "", bind.getClass().getName());
|
||||
atts.addAttribute ("", "description", "", "", bind.getDescription());
|
||||
atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString());
|
||||
debugWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts);
|
||||
contentWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts);
|
||||
|
||||
for (Class<?> clazz:bind.getBindChildClasses()) {
|
||||
AttributesImpl atts2 = new AttributesImpl();
|
||||
atts2.addAttribute ("", "className", "", "", clazz.getName());
|
||||
debugWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2);
|
||||
debugWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
|
||||
contentWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2);
|
||||
contentWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
|
||||
}
|
||||
|
||||
debugWriter.endElement(DEBUG_URI, "elementBindingHandler", "");
|
||||
contentWriter.endElement(DEBUG_URI, "elementBindingHandler", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class handels all the X4O tags.
|
||||
* X4OTagHandler Gets all SAX content handler events and converts to x4o element tree.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.ext.DefaultHandler2;
|
||||
|
||||
/**
|
||||
* X4OLanguageProperty holds the language parser properties keys
|
||||
* X4OLanguageProperty holds the language connection properties keys
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 6 Aug 2012
|
||||
|
|
@ -56,7 +56,7 @@ public enum X4OLanguageProperty {
|
|||
|
||||
|
||||
|
||||
/** The input stream to parse, note is skipped when object is set. */
|
||||
/** The input stream to parse, note is skipped when source is set. */
|
||||
READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
|
||||
|
||||
/** When set it overrides automatic encoding detection of sax parser. */
|
||||
|
|
@ -257,7 +257,7 @@ public enum X4OLanguageProperty {
|
|||
* Returns the uri defined by this property.
|
||||
* @return The uri defined by this property.
|
||||
*/
|
||||
public String toUri() {
|
||||
public final String toUri() {
|
||||
return uriName;
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ public enum X4OLanguageProperty {
|
|||
* Returns the default value for this property.
|
||||
* @return The default value for this property.
|
||||
*/
|
||||
public Object getDefaultValue() {
|
||||
public final Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ public enum X4OLanguageProperty {
|
|||
* @param value The object to check.
|
||||
* @return Returns true when Object value is allowed to be set.
|
||||
*/
|
||||
public boolean isValueValid(Object value) {
|
||||
public final boolean isValueValid(Object value) {
|
||||
if (LANGUAGE_NAME.equals(this) | LANGUAGE_VERSION.equals(this)) {
|
||||
return false; // read only are not valid to set.
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ public enum X4OLanguageProperty {
|
|||
* @return Return the property for the given uri.
|
||||
* @throws IllegalArgumentException when uri is not found.
|
||||
*/
|
||||
static public X4OLanguageProperty valueByUri(String uri) {
|
||||
public static final X4OLanguageProperty valueByUri(String uri) {
|
||||
if (uri==null) {
|
||||
throw new NullPointerException("Can't search null uri.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import org.x4o.xml.element.ElementConfiguratorGlobal;
|
|||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.element.ElementInterface;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.X4ODebugWriter;
|
||||
import org.x4o.xml.io.sax.X4OEntityResolver;
|
||||
import org.x4o.xml.io.sax.X4OErrorHandler;
|
||||
|
|
@ -57,7 +58,6 @@ import org.x4o.xml.lang.X4OLanguageProperty;
|
|||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.ext.DefaultHandler2;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
|
|
@ -852,8 +852,8 @@ public class X4OPhaseLanguageRead {
|
|||
try {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "elements", "", "", elementsReleased+"");
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
|
||||
languageContext.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(phase,e);
|
||||
}
|
||||
|
|
@ -920,13 +920,13 @@ public class X4OPhaseLanguageRead {
|
|||
AttributesImpl atts = new AttributesImpl();
|
||||
//atts.addAttribute ("", key, "", "", value);
|
||||
//atts.addAttribute ("", "verbose", "", "", "true");
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts);
|
||||
startedPrefix.clear();
|
||||
printXML(languageContext.getRootElement());
|
||||
for (String prefix:startedPrefix) {
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endPrefixMapping(prefix);
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endPrefixMapping(prefix);
|
||||
}
|
||||
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "printElementTree", "");
|
||||
languageContext.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "printElementTree", "");
|
||||
languageContext.getX4ODebugWriter().debugLanguageContext(languageContext);
|
||||
} catch (SAXException e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
|
|
@ -951,15 +951,13 @@ public class X4OPhaseLanguageRead {
|
|||
if (element==null) {
|
||||
throw new SAXException("Can't print debug xml of null element.");
|
||||
}
|
||||
DefaultHandler2 handler = element.getLanguageContext().getX4ODebugWriter().getDebugWriter();
|
||||
ContentWriter handler = element.getLanguageContext().getX4ODebugWriter().getContentWriter();
|
||||
if (element.getElementType().equals(Element.ElementType.comment)) {
|
||||
char[] msg = ((String)element.getElementObject()).toCharArray();
|
||||
handler.comment(msg,0,msg.length);
|
||||
handler.comment((String)element.getElementObject());
|
||||
return;
|
||||
}
|
||||
if (element.getElementType().equals(Element.ElementType.characters)) {
|
||||
char[] msg = ((String)element.getElementObject()).toCharArray();
|
||||
handler.characters(msg,0,msg.length);
|
||||
handler.characters((String)element.getElementObject());
|
||||
return;
|
||||
}
|
||||
if (element.getElementClass()==null) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import org.x4o.xml.element.ElementNamespaceContext;
|
|||
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.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
|
@ -212,7 +212,7 @@ public class X4OPhaseLanguageWrite {
|
|||
}
|
||||
}
|
||||
|
||||
XMLWriter writer = new XMLWriter(out,encoding,charNew,charTab);
|
||||
ContentWriterXml writer = new ContentWriterXml(out,encoding,charNew,charTab);
|
||||
writer.startDocument();
|
||||
|
||||
Map<String,String> prefixes = new HashMap<String,String>();
|
||||
|
|
@ -273,7 +273,7 @@ public class X4OPhaseLanguageWrite {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void writeTree(XMLWriter writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
|
||||
private void writeTree(ContentWriterXml writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
if (isRoot && schemaUriPrint) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,295 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* ContentWriterXml test xml escaping.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 26, 2012
|
||||
*/
|
||||
public class ContentWriterXmlTest extends TestCase {
|
||||
|
||||
public void testCDATANone() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.characters("foobar");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar"));
|
||||
}
|
||||
|
||||
public void testCDATANoneTagEscape() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.characters("foobar<test/>");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar<test/>"));
|
||||
}
|
||||
|
||||
public void testCDATANormal() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("foobar");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"));
|
||||
}
|
||||
|
||||
public void testCDATAEscapeTag() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("foobar<test/>");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar<test/>]]>"));
|
||||
}
|
||||
|
||||
public void testCDATAEscapeStart() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("<![CDATA[foobar");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"));
|
||||
}
|
||||
|
||||
public void testCDATAEscapeEnd() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("foobar]]>");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"));
|
||||
}
|
||||
|
||||
public void testCDATAEscapeInvalid() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("<![CDATA[tokens like ']]>' are <invalid>]]>");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \'\' are <invalid>]]>"));
|
||||
}
|
||||
|
||||
public void testCDATAEscapeValid() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.startCDATA();
|
||||
writer.characters("<![CDATA[tokens like ']]]]><![CDATA[>' are <valid>]]>");
|
||||
writer.endCDATA();
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \']]>\' are <valid>]]>"));
|
||||
}
|
||||
|
||||
public void testCharactersNormal() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.characters("test is foobar!");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>test is foobar!"));
|
||||
}
|
||||
|
||||
public void testCharactersEscape() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.characters("<test/> & 'foobar' is \"quoted\"!");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test/> & 'foobar' is "e;quoted"e;!"));
|
||||
}
|
||||
|
||||
public void testAttributeNormal() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "attr", "", "", "foobar");
|
||||
writer.startElementEnd("", "test", "", atts);
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"foobar\"/>"));
|
||||
}
|
||||
|
||||
public void testAttributeEscape() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "attr", "", "", "<test/> & 'foobar' is \"quoted\"!");
|
||||
writer.startElementEnd("", "test", "", atts);
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"<test/> & 'foobar' is "e;quoted"e;!\"/>"));
|
||||
}
|
||||
|
||||
|
||||
public void testCommentNormal() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.comment("foobar");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"));
|
||||
}
|
||||
|
||||
public void testCommentEscape() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
writer.startDocument();
|
||||
writer.comment("<!--foobar-->");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"));
|
||||
}
|
||||
|
||||
public void testXmlInvalid() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.startElement("", "foobar", "", atts);
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
assertNotNull(e);
|
||||
assertEquals(SAXException.class, e.getClass());
|
||||
assertTrue(e.getMessage().contains("tag"));
|
||||
assertTrue(e.getMessage().contains("foobar"));
|
||||
}
|
||||
|
||||
public void testXmlInvalidEnd() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.startElement("", "foobar", "", atts);
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
assertNotNull(e);
|
||||
assertEquals(SAXException.class, e.getClass());
|
||||
assertTrue(e.getMessage().contains("Invalid"));
|
||||
assertTrue(e.getMessage().contains("2"));
|
||||
assertTrue(e.getMessage().contains("open"));
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ import java.io.StringWriter;
|
|||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.io.sax.XMLWriter;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
|
||||
/**
|
||||
* InlinePropertiesElement to test
|
||||
|
|
@ -44,7 +44,7 @@ public class InlinePropertiesElement extends AbstractElement {
|
|||
@Override
|
||||
public void doElementStart() throws ElementException {
|
||||
StringWriter xmlString = new StringWriter();
|
||||
XMLWriter writer = new XMLWriter(xmlString);
|
||||
ContentWriterXml writer = new ContentWriterXml(xmlString);
|
||||
setElementObject(writer);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue