Redone elddoc html writer now via new sax ContentWriter interface.

And implemented jdk7 javadoc compatible html/css for elddoc.
This commit is contained in:
Willem Cazander 2013-05-01 23:23:31 +02:00
parent ef5b0a0b8e
commit 92644fd148
27 changed files with 2959 additions and 751 deletions

View file

@ -37,7 +37,7 @@ import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.phase.X4OPhaseManager; 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 * @author Willem Cazander
* @version 1.0 Aug 11, 2005 * @version 1.0 Aug 11, 2005
@ -83,10 +83,19 @@ public abstract class X4ODriver<T> {
// =============== SchemaWriter // =============== SchemaWriter
/**
* Creates a schema writer for the default language version.
* @return The schema writer for this language.
*/
public X4OSchemaWriter createSchemaWriter() { public X4OSchemaWriter createSchemaWriter() {
return createSchemaWriter(getLanguageVersionDefault()); 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) { public X4OSchemaWriter createSchemaWriter(String version) {
return new DefaultX4OSchemaWriter(createLanguageContext(version)); return new DefaultX4OSchemaWriter(createLanguageContext(version));
} }
@ -135,18 +144,36 @@ public abstract class X4ODriver<T> {
// =============== Language // =============== Language
/**
* Returns the default language which is the latest version.
* @return The default language version.
*/
final public String getLanguageVersionDefault() { final public String getLanguageVersionDefault() {
return X4ODriverManager.getDefaultLanguageVersion(getLanguageVersions()); 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) { final public X4OLanguage createLanguage(String version) {
return buildLanguage(version); return buildLanguage(version);
} }
/**
* Creates the X4OLanguageContext for the default language version.
* @return The created X4OLanguageContext.
*/
final public X4OLanguageContext createLanguageContext() { final public X4OLanguageContext createLanguageContext() {
return createLanguageContext(getLanguageVersionDefault()); return createLanguageContext(getLanguageVersionDefault());
} }
/**
* Creates the X4OLanguageContext for the specified version.
* @param version The language version to create the context for.
* @return The created X4OLanguageContext.
*/
final public X4OLanguageContext createLanguageContext(String version) { final public X4OLanguageContext createLanguageContext(String version) {
return createLanguage(version).createLanguageContext(this); return createLanguage(version).createLanguageContext(this);
} }

View file

@ -49,7 +49,7 @@ public class X4OELContext extends ELContext {
/** /**
* Creates a X4OELContext. * Creates a X4OELContext.
*/ */
public X4OELContext(/* X4OLanguageConfiguration x4oParserConfig */) { public X4OELContext() {
CompositeELResolver compositeELResolver = new CompositeELResolver(); CompositeELResolver compositeELResolver = new CompositeELResolver();
compositeELResolver.add(new X4OELResolver(new HashMap<Object, Object>(100))); compositeELResolver.add(new X4OELResolver(new HashMap<Object, Object>(100)));

View file

@ -36,6 +36,10 @@ import javax.el.FunctionMapper;
* @version 1.0 Sep 14, 2010 * @version 1.0 Sep 14, 2010
*/ */
public class X4OELFunctionMapper extends FunctionMapper { public class X4OELFunctionMapper extends FunctionMapper {
/**
* Stores the el to method function mapping.
*/
private Map<String,Method> functionMap = null; private Map<String,Method> functionMap = null;
/** /**
@ -45,6 +49,12 @@ public class X4OELFunctionMapper extends FunctionMapper {
functionMap = new HashMap<String,Method>(50); 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 @Override
public Method resolveFunction(String prefix, String localName) { public Method resolveFunction(String prefix, String localName) {
String key = prefix + ":" + localName; String key = prefix + ":" + localName;

View file

@ -29,13 +29,13 @@ import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.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.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageProperty; import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
/** /**
* EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver. * EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver.
@ -84,7 +84,7 @@ public class EldXsdXmlGenerator {
checkNamespace(ns); checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource())); FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try { try {
XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab); ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
fio.close(); fio.close();
@ -96,7 +96,7 @@ public class EldXsdXmlGenerator {
checkNamespace(ns); checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource())); FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try { try {
XMLWriter out = new XMLWriter(fio,encoding,charNew,charTab); ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
generateSchema(ns.getUri(), out); generateSchema(ns.getUri(), out);
} finally { } finally {
fio.close(); 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); ElementNamespaceContext ns = language.findElementNamespaceContext(namespaceUri);
if (ns==null) { if (ns==null) {

View file

@ -40,10 +40,10 @@ import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementMetaBase; import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.XMLConstants;
import org.x4o.xml.io.sax.ContentWriter;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage; import org.x4o.xml.lang.X4OLanguage;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl; 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"; static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
protected X4OLanguage language = null; protected X4OLanguage language = null;
protected DefaultHandler2 xmlWriter = null; protected ContentWriter xmlWriter = null;
protected String writeNamespace = null; protected String writeNamespace = null;
protected Map<String, String> namespaces = null; protected Map<String, String> namespaces = null;
public EldXsdXmlWriter(DefaultHandler2 xmlWriter,X4OLanguage language) { public EldXsdXmlWriter(ContentWriter xmlWriter,X4OLanguage language) {
this.xmlWriter=xmlWriter; this.xmlWriter=xmlWriter;
this.language=language; this.language=language;
this.namespaces=new HashMap<String,String>(10); this.namespaces=new HashMap<String,String>(10);

View file

@ -34,8 +34,9 @@ import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException; 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.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.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageContextLocal; import org.x4o.xml.lang.X4OLanguageContextLocal;
import org.x4o.xml.lang.X4OLanguageProperty; 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.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseType; import org.x4o.xml.lang.phase.X4OPhaseType;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl; 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 debugOutputHandler = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER);
Object debugOutputStream = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM); Object debugOutputStream = languageContext.getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM);
if (languageContext.getX4ODebugWriter()==null) { if (languageContext.getX4ODebugWriter()==null) {
DefaultHandler2 xmlDebugWriter = null; ContentWriter xmlDebugWriter = null;
if (debugOutputHandler instanceof DefaultHandler2) { if (debugOutputHandler instanceof ContentWriter) {
xmlDebugWriter = (DefaultHandler2)debugOutputHandler; xmlDebugWriter = (ContentWriter)debugOutputHandler;
} else if (debugOutputStream instanceof OutputStream) { } else if (debugOutputStream instanceof OutputStream) {
xmlDebugWriter = new XMLWriter((OutputStream)debugOutputStream); xmlDebugWriter = new ContentWriterXml((OutputStream)debugOutputStream);
} }
if (xmlDebugWriter!=null) { if (xmlDebugWriter!=null) {
xmlDebugWriter.startDocument(); xmlDebugWriter.startDocument();
@ -126,7 +126,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "language", "", "", languageContext.getLanguage().getLanguageName()); atts.addAttribute ("", "language", "", "", languageContext.getLanguage().getLanguageName());
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+""); 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 // start parsing language
@ -142,7 +142,7 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
if (e instanceof X4OPhaseException) { if (e instanceof X4OPhaseException) {
atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getId()); 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(); StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer); PrintWriter printer = new PrintWriter(writer);
printer.append('\n'); printer.append('\n');
@ -152,8 +152,8 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
e.getCause().printStackTrace(printer); e.getCause().printStackTrace(printer);
} }
char[] stack = writer.getBuffer().toString().toCharArray(); char[] stack = writer.getBuffer().toString().toCharArray();
languageContext.getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length); languageContext.getX4ODebugWriter().getContentWriter().characters(stack, 0, stack.length);
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", ""); languageContext.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
} catch (Exception ee) { } catch (Exception ee) {
logger.warning(ee.getMessage()); logger.warning(ee.getMessage());
} }
@ -176,11 +176,11 @@ public class DefaultX4OReader<T> extends AbstractX4OReader<T> {
} }
} finally { } finally {
if (languageContext.hasX4ODebugWriter()) { if (languageContext.hasX4ODebugWriter()) {
languageContext.getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", ""); languageContext.getX4ODebugWriter().getContentWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
} }
if (startedDebugWriter && languageContext.hasX4ODebugWriter()) { if (startedDebugWriter && languageContext.hasX4ODebugWriter()) {
languageContext.getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug"); languageContext.getX4ODebugWriter().getContentWriter().endPrefixMapping("debug");
languageContext.getX4ODebugWriter().getDebugWriter().endDocument(); languageContext.getX4ODebugWriter().getContentWriter().endDocument();
if (debugOutputStream instanceof OutputStream) { if (debugOutputStream instanceof OutputStream) {
OutputStream outputStream = (OutputStream)debugOutputStream; OutputStream outputStream = (OutputStream)debugOutputStream;
outputStream.flush(); outputStream.flush();

View file

@ -71,6 +71,11 @@ public final class XMLConstants {
*/ */
public static final String NULL_NS_URI = ""; public static final String NULL_NS_URI = "";
/**
* (Start) Definition of DTD doctype.
*/
public static final String XML_DOCTYPE = "<!DOCTYPE";
/** /**
* Opens xml element tag. * Opens xml element tag.
*/ */
@ -111,6 +116,26 @@ public final class XMLConstants {
*/ */
public static final String PROCESS_END = "?>"; 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 * Tab char
*/ */
@ -119,7 +144,7 @@ public final class XMLConstants {
/** /**
* Newline char * 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; return true;
} }
static public String escapeAttributeValue(String value) { //static public boolean isCharRef(String c) {
int l = value.length(); // &#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
StringBuffer result = new StringBuffer(l); //}
for (int i=0;i<l;i++) {
static private boolean escapeXMLValue(char c,StringBuffer result) {
if (c=='<') {
result.append("&lt;");
return true;
}
if (c=='>') {
result.append("&gt;");
return true;
}
if (c=='&') {
result.append("&amp;");
return true;
}
if (c=='\"') {
result.append("&quote;");
return true;
}
if (c=='\'') {
result.append("&apos;");
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); char c = value.charAt(i);
if (c=='<') { if (isNameChar(c)) {
result.append("&lt;"); result.append(c);
continue; } else {
result.append("#x");
result.append(Integer.toHexString(c));
result.append(";");
} }
if (c=='>') { }
result.append("&gt;"); return result.toString();
continue; }
}
if (c=='&') { static public String escapeAttributeValue(String value) {
result.append("&amp;"); // Reference ::= EntityRef | CharRef
continue; // AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
} int length = value.length();
if (c=='\"') { StringBuffer result = new StringBuffer(length);
result.append("&quote;"); for (int i=0;i<length;i++) {
continue; char c = value.charAt(i);
} if (escapeXMLValue(c,result)) {
if (c=='\'') {
result.append("&apos;");
continue; continue;
} }
if (/*isNameChar(c)*/true==false) {// TODO: add correct if (/*isNameChar(c)*/true==false) {// TODO: add correct
@ -243,4 +298,43 @@ public final class XMLConstants {
} }
return result.toString(); 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();
}
} }

View file

@ -33,7 +33,7 @@ import java.util.Set;
* Maps an SAX attributes set to an Map interface. * Maps an SAX attributes set to an Map interface.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 17/04/2005 * @version 1.0 Apr 17, 2005
* @param <K> The key class. * @param <K> The key class.
* @param <V> The value class. * @param <V> The value class.
*/ */

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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;
}
}
}

View file

@ -32,23 +32,24 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack;
import org.x4o.xml.io.XMLConstants; import org.x4o.xml.io.XMLConstants;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
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 * @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 charNewline = null;
private String charTab = null; private String charTab = null;
private Writer out = null; private Writer out = null;
@ -56,13 +57,16 @@ public class XMLWriter extends DefaultHandler2 {
private Map<String,String> prefixMapping = null; private Map<String,String> prefixMapping = null;
private List<String> printedMappings = null; private List<String> printedMappings = null;
private StringBuffer startElement = 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. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public XMLWriter(Writer out,String encoding,String charNewLine,String charTab) { public ContentWriterXml(Writer out,String encoding,String charNewLine,String charTab) {
if (out==null) { if (out==null) {
throw new NullPointerException("Can't write on null writer."); throw new NullPointerException("Can't write on null writer.");
} }
@ -81,13 +85,14 @@ public class XMLWriter extends DefaultHandler2 {
this.charTab = charTab; this.charTab = charTab;
prefixMapping = new HashMap<String,String>(15); prefixMapping = new HashMap<String,String>(15);
printedMappings = new ArrayList<String>(15); printedMappings = new ArrayList<String>(15);
elements = new Stack<String>();
} }
/** /**
* Creates XmlWriter which prints to the Writer interface. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public XMLWriter(Writer out,String encoding) { public ContentWriterXml(Writer out,String encoding) {
this(out,encoding,null,null); this(out,encoding,null,null);
} }
@ -96,7 +101,7 @@ public class XMLWriter extends DefaultHandler2 {
* @param out The OutputStream to write to. * @param out The OutputStream to write to.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed. * @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); this(new OutputStreamWriter(out, encoding),encoding);
} }
@ -104,7 +109,7 @@ public class XMLWriter extends DefaultHandler2 {
* Creates XmlWriter which prints to the Writer interface. * Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to. * @param out The writer to print the xml to.
*/ */
public XMLWriter(Writer out) { public ContentWriterXml(Writer out) {
this(out,null); this(out,null);
} }
@ -113,7 +118,7 @@ public class XMLWriter extends DefaultHandler2 {
* @param out The OutputStream to write to. * @param out The OutputStream to write to.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed. * @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); 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. * @param charTab The tab char.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed. * @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
*/ */
public 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); 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() * @see org.xml.sax.ContentHandler#startDocument()
*/ */
@Override
public void startDocument() throws SAXException { public void startDocument() throws SAXException {
indent = 0; indent = 0;
write(XMLConstants.getDocumentDeclaration(encoding)); write(XMLConstants.getDocumentDeclaration(encoding));
@ -141,9 +161,20 @@ public class XMLWriter extends DefaultHandler2 {
/** /**
* @see org.xml.sax.ContentHandler#endDocument() * @see org.xml.sax.ContentHandler#endDocument()
*/ */
@Override
public void endDocument() throws SAXException { public void endDocument() throws SAXException {
writeFlush(); 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. * @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) * @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 { public void startElement(String uri, String localName, String name,Attributes atts) throws SAXException {
if (startElement!=null) { if (localName==null) {
write(startElement.toString()); localName = "null"; // mmm rm ?
startElement=null;
} }
if (XMLConstants.isNameString(localName)==false) {
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
}
autoCloseStartElement();
startElement = new StringBuffer(200); startElement = new StringBuffer(200);
startElement.append(charNewline);
if (printedReturn==false) {
startElement.append(charNewline);
}
printedReturn=false;
for (int i = 0; i < indent; i++) { for (int i = 0; i < indent; i++) {
startElement.append(charTab); startElement.append(charTab);
} }
startElement.append(XMLConstants.TAG_OPEN); startElement.append(XMLConstants.TAG_OPEN);
if (localName==null) { startElementTag(uri,localName);
localName = "null"; startElementNamespace(uri);
} startElementAttributes(atts);
if (XMLConstants.isNameString(localName)==false) { startElement.append(XMLConstants.TAG_CLOSE);
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'"); indent++;
} lastElement = localName;
elements.push(localName);
}
public void startElementTag(String uri,String localName) throws SAXException {
if (XMLConstants.NULL_NS_URI.equals(uri) | uri==null) { if (XMLConstants.NULL_NS_URI.equals(uri) | uri==null) {
startElement.append(localName); startElement.append(localName);
} else { } else {
@ -191,7 +222,9 @@ public class XMLWriter extends DefaultHandler2 {
} }
startElement.append(localName); startElement.append(localName);
} }
}
public void startElementNamespace(String uri) throws SAXException {
if ((uri!=null & XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) { if ((uri!=null & XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) {
String prefix = prefixMapping.get(uri); String prefix = prefixMapping.get(uri);
if (prefix==null) { if (prefix==null) {
@ -209,42 +242,50 @@ public class XMLWriter extends DefaultHandler2 {
startElement.append(uri); startElement.append(uri);
startElement.append('"'); startElement.append('"');
boolean first = true; startElementNamespaceAll(uri);
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) { public void startElementNamespaceAll(String uri) throws SAXException {
startElement.append(charNewline); String prefix = null;
first = false; boolean first = true;
} for (String uri2:prefixMapping.keySet()) {
if (printedMappings.contains(uri2)==false) {
startElement.append(' '); prefix = prefixMapping.get(uri2);
startElement.append(XMLConstants.XMLNS_ATTRIBUTE); if (prefix==null) {
if ("".equals(prefix)==false) { throw new SAXException("preFixUri: "+uri+" is not started.");
startElement.append(XMLConstants.XMLNS_ASSIGN);
startElement.append(prefix);
}
startElement.append("=\"");
startElement.append(uri2);
startElement.append('"');
startElement.append(charNewline);
} }
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++) { for (int i=0;i<atts.getLength();i++) {
String attributeUri = atts.getURI(i); String attributeUri = atts.getURI(i);
String attributeName = atts.getLocalName(i); String attributeName = XMLConstants.escapeAttributeName(atts.getLocalName(i));
String attributeValue = atts.getValue(i); String attributeValue = atts.getValue(i);
if (attributeValue==null) { if (attributeValue==null) {
attributeValue = "null"; attributeValue = "null";
} }
startElement.append(' '); startElement.append(' ');
if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) { if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
startElement.append(attributeName); startElement.append(attributeName);
} else { } else {
@ -257,8 +298,6 @@ public class XMLWriter extends DefaultHandler2 {
startElement.append(XMLConstants.escapeAttributeValue(attributeValue)); startElement.append(XMLConstants.escapeAttributeValue(attributeValue));
startElement.append('"'); 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. * @param name The (full) name of the xml tag.
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) * @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 { 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) { if (startElement!=null) {
String tag = startElement.toString(); String tag = startElement.toString();
write(tag.substring(0,tag.length()-1));// rm normal close write(tag.substring(0,tag.length()-1));// rm normal close
@ -278,13 +322,13 @@ public class XMLWriter extends DefaultHandler2 {
return; return;
} }
if (printedReturn==false) {
write(charNewline);
}
printedReturn=false;
indent--; indent--;
writeIndent(); if (printReturn || !localName.equals(lastElement)) {
write(charNewline);
writeIndent();
} else {
printReturn = true;
}
if (localName==null) { if (localName==null) {
localName = "null"; localName = "null";
} }
@ -312,7 +356,6 @@ public class XMLWriter extends DefaultHandler2 {
* @param uri The xml namespace uri to add the prefix for. * @param uri The xml namespace uri to add the prefix for.
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
*/ */
@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException { public void startPrefixMapping(String prefix, String uri) throws SAXException {
prefixMapping.put(uri, prefix); 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. * @param prefix The xml prefix of this xml namespace uri to be ended.
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
*/ */
@Override
public void endPrefixMapping(String prefix) throws SAXException { public void endPrefixMapping(String prefix) throws SAXException {
Set<Map.Entry<String,String>> s = prefixMapping.entrySet(); Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
String uri = null; String uri = null;
@ -348,19 +390,35 @@ public class XMLWriter extends DefaultHandler2 {
* @throws SAXException When IOException has happend while printing. * @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#characters(char[], int, int) * @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/ */
@Override
public void characters(char[] ch, int start, int length) throws SAXException { public void characters(char[] ch, int start, int length) throws SAXException {
if (startElement!=null) { characters(new String(ch,start,length));
write(startElement.toString()); }
startElement=null;
/**
* @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++) { autoCloseStartElement();
char c = ch[i]; checkPrintedReturn(text);
write(c); if (printCDATA) {
if (c=='\n') { text = XMLConstants.escapeCharactersCdata(text,"","");
printedReturn=true; } 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. * @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
*/ */
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
if (startElement!=null) { ignorableWhitespace(new String(ch,start,length));
write(startElement.toString()); }
startElement=null;
/**
* @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 target The target.
* @param data The data. * @param data The data.
*/ */
@Override
public void processingInstruction(String target, String data) throws SAXException { public void processingInstruction(String target, String data) throws SAXException {
writeIndent(); writeIndent();
write(XMLConstants.PROCESS_START); write(XMLConstants.PROCESS_START);
@ -406,7 +469,6 @@ public class XMLWriter extends DefaultHandler2 {
* @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
* @param locator The DocumentLocator to set. * @param locator The DocumentLocator to set.
*/ */
@Override
public void setDocumentLocator(Locator locator) { public void setDocumentLocator(Locator locator) {
} }
@ -416,7 +478,6 @@ public class XMLWriter extends DefaultHandler2 {
* @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
* @param name The name of the skipped entity. * @param name The name of the skipped entity.
*/ */
@Override
public void skippedEntity(String name) throws SAXException { public void skippedEntity(String name) throws SAXException {
// is for validating parser support, so not needed in xml writing. // is for validating parser support, so not needed in xml writing.
} }
@ -430,22 +491,104 @@ public class XMLWriter extends DefaultHandler2 {
* @throws SAXException When IOException has happend while printing. * @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int) * @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
*/ */
@Override
public void comment(char[] ch, int start, int length) throws SAXException { 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(); writeIndent();
write(XMLConstants.COMMENT_START); write(XMLConstants.COMMENT_START);
write(" ");
/// mmm todo improve a bit write(XMLConstants.escapeCharactersComment(text,charTab,indent));
for (int i=start;i<(start+length);i++) { write(" ");
char c = ch[i];
if (c=='\n') {
write(c);
writeIndent();
continue;
}
write(c);
}
write(XMLConstants.COMMENT_END); 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;
} }
/** /**
@ -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 { private void write(char c) throws SAXException {
try { try {
out.write(c); out.write(c);

View file

@ -48,7 +48,6 @@ import org.x4o.xml.lang.phase.X4OPhase;
import org.x4o.xml.lang.phase.X4OPhaseException; import org.x4o.xml.lang.phase.X4OPhaseException;
import org.x4o.xml.lang.phase.X4OPhaseListener; import org.x4o.xml.lang.phase.X4OPhaseListener;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl; 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"; 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) { public X4ODebugWriter(ContentWriter debugWriter) {
this.debugWriter=debugWriter; this.contentWriter=debugWriter;
} }
public DefaultHandler2 getDebugWriter() { public ContentWriter getContentWriter() {
return debugWriter; return contentWriter;
} }
public X4OPhaseListener createDebugX4OPhaseListener() { public X4OPhaseListener createDebugX4OPhaseListener() {
@ -91,7 +90,7 @@ public class X4ODebugWriter {
if (elementLanguage!=null) { if (elementLanguage!=null) {
atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName()); atts.addAttribute("", "language","","", elementLanguage.getLanguage().getLanguageName());
} }
debugWriter.startElement (DEBUG_URI, "executePhase", "", atts); contentWriter.startElement (DEBUG_URI, "executePhase", "", atts);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -104,10 +103,10 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "id", "", "", phase.getId()); atts.addAttribute ("", "id", "", "", phase.getId());
atts.addAttribute ("", "speed", "", "", (stopTime-startTime)+" ms"); atts.addAttribute ("", "speed", "", "", (stopTime-startTime)+" ms");
debugWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts); contentWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts);
debugWriter.endElement (DEBUG_URI, "executePhaseDone" , ""); contentWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
debugWriter.endElement (DEBUG_URI, "executePhase" , ""); contentWriter.endElement (DEBUG_URI, "executePhase" , "");
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -117,7 +116,7 @@ public class X4ODebugWriter {
public void debugLanguageProperties(X4OLanguageContext ec) throws ElementException { public void debugLanguageProperties(X4OLanguageContext ec) throws ElementException {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts); contentWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts);
for (X4OLanguageProperty p:X4OLanguageProperty.values()) { for (X4OLanguageProperty p:X4OLanguageProperty.values()) {
Object value = ec.getLanguageProperty(p); Object value = ec.getLanguageProperty(p);
if (value==null) { if (value==null) {
@ -126,10 +125,10 @@ public class X4ODebugWriter {
AttributesImpl atts2 = new AttributesImpl(); AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "uri", "", "", p.toUri()); atts2.addAttribute ("", "uri", "", "", p.toUri());
atts2.addAttribute ("", "value", "", "", value.toString()); atts2.addAttribute ("", "value", "", "", value.toString());
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2); contentWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2);
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperty", ""); contentWriter.endElement(DEBUG_URI, "X4OLanguageProperty", "");
} }
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperties", ""); contentWriter.endElement(DEBUG_URI, "X4OLanguageProperties", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -138,7 +137,7 @@ public class X4ODebugWriter {
public void debugLanguageDefaultClasses(X4OLanguageContext ec) throws ElementException { public void debugLanguageDefaultClasses(X4OLanguageContext ec) throws ElementException {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts); contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts);
X4OLanguageConfiguration conf = ec.getLanguage().getLanguageConfiguration(); X4OLanguageConfiguration conf = ec.getLanguage().getLanguageConfiguration();
debugLanguageDefaultClass("getDefaultElementNamespaceContext",conf.getDefaultElementNamespaceContext()); debugLanguageDefaultClass("getDefaultElementNamespaceContext",conf.getDefaultElementNamespaceContext());
@ -155,7 +154,7 @@ public class X4ODebugWriter {
debugLanguageDefaultClass("getDefaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue()); debugLanguageDefaultClass("getDefaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue());
debugLanguageDefaultClass("getDefaultElementAttributeHandlerComparator",conf.getDefaultElementAttributeHandlerComparator()); debugLanguageDefaultClass("getDefaultElementAttributeHandlerComparator",conf.getDefaultElementAttributeHandlerComparator());
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", ""); contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -165,20 +164,20 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", name); atts.addAttribute ("", "name", "", "", name);
atts.addAttribute ("", "className", "", "", clazz.getName()); atts.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts); contentWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", ""); contentWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
} }
public void debugPhaseOrder(List<X4OPhase> phases) throws X4OPhaseException { public void debugPhaseOrder(List<X4OPhase> phases) throws X4OPhaseException {
X4OPhase phase = null; X4OPhase phase = null;
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "phaseOrder", "", atts); contentWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
for (X4OPhase phase2:phases) { for (X4OPhase phase2:phases) {
phase = phase2; phase = phase2;
debugPhase(phase2); debugPhase(phase2);
} }
debugWriter.endElement(DEBUG_URI, "phaseOrder", ""); contentWriter.endElement(DEBUG_URI, "phaseOrder", "");
} catch (SAXException e) { } catch (SAXException e) {
// fall back... // fall back...
if (phase==null) { if (phase==null) {
@ -198,14 +197,14 @@ public class X4ODebugWriter {
atts.addAttribute ("", "runOnce", "", "", phase.isRunOnce()+""); atts.addAttribute ("", "runOnce", "", "", phase.isRunOnce()+"");
atts.addAttribute ("", "listenersSize", "", "", phase.getPhaseListeners().size()+""); atts.addAttribute ("", "listenersSize", "", "", phase.getPhaseListeners().size()+"");
debugWriter.startElement (DEBUG_URI, "phase", "", atts); contentWriter.startElement (DEBUG_URI, "phase", "", atts);
for (X4OPhaseListener l:phase.getPhaseListeners()) { for (X4OPhaseListener l:phase.getPhaseListeners()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", l.getClass().getName()); atts.addAttribute ("", "className", "", "", l.getClass().getName());
debugWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts); contentWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OPhaseListener", ""); contentWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
} }
debugWriter.endElement(DEBUG_URI, "phase", ""); contentWriter.endElement(DEBUG_URI, "phase", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -214,7 +213,7 @@ public class X4ODebugWriter {
public void debugElementLanguageModules(X4OLanguageContext elementLanguage) throws ElementException { public void debugElementLanguageModules(X4OLanguageContext elementLanguage) throws ElementException {
try { try {
AttributesImpl attsEmpty = new AttributesImpl(); AttributesImpl attsEmpty = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty); contentWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
for (X4OLanguageModule module:elementLanguage.getLanguage().getLanguageModules()) { for (X4OLanguageModule module:elementLanguage.getLanguage().getLanguageModules()) {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
@ -227,7 +226,7 @@ public class X4ODebugWriter {
} else { } else {
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", module.getLanguageModuleLoader().getClass().getName()); atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", module.getLanguageModuleLoader().getClass().getName());
} }
debugWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts); contentWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts);
//module.getElementAttributeHandlers(); //module.getElementAttributeHandlers();
//module.getElementBindingHandlers(); //module.getElementBindingHandlers();
@ -243,14 +242,14 @@ public class X4ODebugWriter {
atts.addAttribute ("", "attributeName", "", "", p.getAttributeName()); atts.addAttribute ("", "attributeName", "", "", p.getAttributeName());
atts.addAttribute ("", "description", "", "", p.getDescription()); atts.addAttribute ("", "description", "", "", p.getDescription());
atts.addAttribute ("", "className", "", "", p.getClass().getName()); atts.addAttribute ("", "className", "", "", p.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts); contentWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts);
for (String para:p.getNextAttributes()) { for (String para:p.getNextAttributes()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", para); atts.addAttribute ("", "attributeName", "", "", para);
debugWriter.startElement (DEBUG_URI, "nextAttribute", "", atts); contentWriter.startElement (DEBUG_URI, "nextAttribute", "", atts);
debugWriter.endElement(DEBUG_URI, "nextAttribute", ""); contentWriter.endElement(DEBUG_URI, "nextAttribute", "");
} }
debugWriter.endElement(DEBUG_URI, "elementAttributeHandler", ""); contentWriter.endElement(DEBUG_URI, "elementAttributeHandler", "");
} }
for (ElementInterface elementInterface:module.getElementInterfaces()) { for (ElementInterface elementInterface:module.getElementInterfaces()) {
@ -259,10 +258,10 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", elementInterface.getDescription()); atts.addAttribute ("", "description", "", "", elementInterface.getDescription());
atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName()); atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName());
debugWriter.startElement (DEBUG_URI, "elementInterface", "", atts); contentWriter.startElement (DEBUG_URI, "elementInterface", "", atts);
debugElementBindingHandler(elementInterface.getElementBindingHandlers()); debugElementBindingHandler(elementInterface.getElementBindingHandlers());
debugElementClassBase(elementInterface); debugElementClassBase(elementInterface);
debugWriter.endElement(DEBUG_URI, "elementInterface", ""); contentWriter.endElement(DEBUG_URI, "elementInterface", "");
} }
for (ElementNamespaceContext enc:module.getElementNamespaceContexts()) { for (ElementNamespaceContext enc:module.getElementNamespaceContexts()) {
@ -273,7 +272,7 @@ public class X4ODebugWriter {
atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource()); atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource());
atts.addAttribute ("", "className", "", "", enc.getClass().getName()); 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()) { for (ElementClass ec:enc.getElementClasses()) {
debugElementClass(ec); debugElementClass(ec);
} }
@ -281,16 +280,16 @@ public class X4ODebugWriter {
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider(); ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", eip.getClass().getName()); atts.addAttribute ("", "className", "", "", eip.getClass().getName());
debugWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts); contentWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts);
debugWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), ""); 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) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -343,15 +342,15 @@ public class X4ODebugWriter {
atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage()); atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage());
} }
debugWriter.startElement (DEBUG_URI, "elementObject", "", atts2); contentWriter.startElement (DEBUG_URI, "elementObject", "", atts2);
debugWriter.endElement(DEBUG_URI, "elementObject", ""); contentWriter.endElement(DEBUG_URI, "elementObject", "");
} }
StringBuffer elementPath = getElementPath(element,new StringBuffer()); StringBuffer elementPath = getElementPath(element,new StringBuffer());
atts.addAttribute ("", "elementPath", "", "", elementPath.toString()); atts.addAttribute ("", "elementPath", "", "", elementPath.toString());
debugWriter.startElement (DEBUG_URI, "element", "", atts); contentWriter.startElement (DEBUG_URI, "element", "", atts);
debugWriter.endElement(DEBUG_URI, "element", ""); contentWriter.endElement(DEBUG_URI, "element", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -379,10 +378,10 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", clazz.getName()+""); atts.addAttribute ("", "class", "", "", clazz.getName()+"");
try { try {
debugWriter.startElement (DEBUG_URI, "message", "", atts); contentWriter.startElement (DEBUG_URI, "message", "", atts);
char[] msg = message.toCharArray(); char[] msg = message.toCharArray();
debugWriter.characters(msg,0,msg.length); contentWriter.characters(msg,0,msg.length);
debugWriter.endElement(DEBUG_URI, "message", ""); contentWriter.endElement(DEBUG_URI, "message", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -396,9 +395,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", ec.getDescription()); atts.addAttribute ("", "description", "", "", ec.getDescription());
atts.addAttribute ("", "className", "", "", ec.getClass().getName()); atts.addAttribute ("", "className", "", "", ec.getClass().getName());
debugWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts); contentWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts);
debugElement(element); debugElement(element);
debugWriter.endElement(DEBUG_URI, "runElementConfigurator", ""); contentWriter.endElement(DEBUG_URI, "runElementConfigurator", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -414,9 +413,9 @@ public class X4ODebugWriter {
atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+""); atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+"");
atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+""); atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+"");
debugWriter.startElement (DEBUG_URI, "doBind", "", atts); contentWriter.startElement (DEBUG_URI, "doBind", "", atts);
debugElement(element); debugElement(element);
debugWriter.endElement(DEBUG_URI, "doBind", ""); contentWriter.endElement(DEBUG_URI, "doBind", "");
} catch (SAXException e) { } catch (SAXException e) {
throw new ElementException(e); throw new ElementException(e);
} }
@ -429,8 +428,8 @@ public class X4ODebugWriter {
atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguage().getLanguageVersion()); atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguage().getLanguageVersion());
atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+""); atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+"");
atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentPhase().getId()); atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentPhase().getId());
debugWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts); contentWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
debugWriter.endElement(DEBUG_URI, "printElementLanguage", ""); contentWriter.endElement(DEBUG_URI, "printElementLanguage", "");
} }
private void debugElementClass(ElementClass elementClass) throws SAXException { private void debugElementClass(ElementClass elementClass) throws SAXException {
@ -441,26 +440,26 @@ public class X4ODebugWriter {
atts.addAttribute ("", "description", "", "", elementClass.getDescription()); atts.addAttribute ("", "description", "", "", elementClass.getDescription());
atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass()); atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass());
atts.addAttribute ("", "className", "", "", elementClass.getClass().getName()); atts.addAttribute ("", "className", "", "", elementClass.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClass", "", atts); contentWriter.startElement (DEBUG_URI, "elementClass", "", atts);
for (String phase:elementClass.getSkipPhases()) { for (String phase:elementClass.getSkipPhases()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "phase", "", "", ""+phase); atts.addAttribute ("", "phase", "", "", ""+phase);
debugWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts); contentWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts);
debugWriter.endElement(DEBUG_URI, "elementSkipPhase", ""); contentWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
} }
debugElementConfigurator(elementClass.getElementConfigurators()); debugElementConfigurator(elementClass.getElementConfigurators());
debugElementClassBase(elementClass); debugElementClassBase(elementClass);
debugWriter.endElement(DEBUG_URI, "elementClass", ""); contentWriter.endElement(DEBUG_URI, "elementClass", "");
} }
private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException { private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementClassBase.getDescription()); atts.addAttribute ("", "description", "", "", elementClassBase.getDescription());
atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName()); atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClassBase", "", atts); contentWriter.startElement (DEBUG_URI, "elementClassBase", "", atts);
debugElementConfigurator(elementClassBase.getElementConfigurators()); debugElementConfigurator(elementClassBase.getElementConfigurators());
debugElementClassAttributes(elementClassBase.getElementClassAttributes()); debugElementClassAttributes(elementClassBase.getElementClassAttributes());
debugWriter.endElement(DEBUG_URI, "elementClassBase", ""); contentWriter.endElement(DEBUG_URI, "elementClassBase", "");
} }
private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException { private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException {
@ -468,8 +467,8 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription()); atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName()); atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts); contentWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts);
debugWriter.endElement(DEBUG_URI, "elementConfigurator", ""); contentWriter.endElement(DEBUG_URI, "elementConfigurator", "");
} }
} }
@ -478,8 +477,8 @@ public class X4ODebugWriter {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription()); atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName()); atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts); contentWriter.startElement (DEBUG_URI, "elementConfiguratorGlobal", "", atts);
debugWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", ""); contentWriter.endElement(DEBUG_URI, "elementConfiguratorGlobal", "");
} }
} }
@ -494,17 +493,17 @@ public class X4ODebugWriter {
atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters()); atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters());
//atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces()); //atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces());
atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL()); atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL());
debugWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts); contentWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts);
if (elementClassAttribute.getObjectConverter()!=null) { if (elementClassAttribute.getObjectConverter()!=null) {
debugObjectConverter(elementClassAttribute.getObjectConverter()); debugObjectConverter(elementClassAttribute.getObjectConverter());
} }
for (String alias:elementClassAttribute.getAttributeAliases()) { for (String alias:elementClassAttribute.getAttributeAliases()) {
atts = new AttributesImpl(); atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ""+alias); atts.addAttribute ("", "name", "", "", ""+alias);
debugWriter.startElement(DEBUG_URI, "attributeAlias", "", atts); contentWriter.startElement(DEBUG_URI, "attributeAlias", "", atts);
debugWriter.endElement(DEBUG_URI, "attributeAlias", ""); 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 ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName());
atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName()); atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName());
atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName()); atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName());
debugWriter.startElement (DEBUG_URI, "objectConverter", "", atts); contentWriter.startElement (DEBUG_URI, "objectConverter", "", atts);
debugWriter.endElement(DEBUG_URI, "objectConverter", ""); contentWriter.endElement(DEBUG_URI, "objectConverter", "");
} }
private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException { private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException {
@ -523,16 +522,16 @@ public class X4ODebugWriter {
atts.addAttribute ("", "className", "", "", bind.getClass().getName()); atts.addAttribute ("", "className", "", "", bind.getClass().getName());
atts.addAttribute ("", "description", "", "", bind.getDescription()); atts.addAttribute ("", "description", "", "", bind.getDescription());
atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString()); atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString());
debugWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts); contentWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts);
for (Class<?> clazz:bind.getBindChildClasses()) { for (Class<?> clazz:bind.getBindChildClasses()) {
AttributesImpl atts2 = new AttributesImpl(); AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "className", "", "", clazz.getName()); atts2.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2); contentWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2);
debugWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", ""); contentWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
} }
debugWriter.endElement(DEBUG_URI, "elementBindingHandler", ""); contentWriter.endElement(DEBUG_URI, "elementBindingHandler", "");
} }
} }
} }

View file

@ -41,7 +41,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; 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 * @author Willem Cazander
* @version 1.0 Aug 20, 2005 * @version 1.0 Aug 20, 2005

View file

@ -39,7 +39,7 @@ import org.xml.sax.InputSource;
import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.ext.DefaultHandler2;
/** /**
* X4OLanguageProperty holds the language parser properties keys * X4OLanguageProperty holds the language connection properties keys
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 6 Aug 2012 * @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), READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */ /** When set it overrides automatic encoding detection of sax parser. */
@ -257,7 +257,7 @@ public enum X4OLanguageProperty {
* Returns the uri defined by this property. * Returns the uri defined by this property.
* @return The uri defined by this property. * @return The uri defined by this property.
*/ */
public String toUri() { public final String toUri() {
return uriName; return uriName;
} }
@ -265,7 +265,7 @@ public enum X4OLanguageProperty {
* Returns the default value for this property. * Returns the default value for this property.
* @return The default value for this property. * @return The default value for this property.
*/ */
public Object getDefaultValue() { public final Object getDefaultValue() {
return defaultValue; return defaultValue;
} }
@ -275,7 +275,7 @@ public enum X4OLanguageProperty {
* @param value The object to check. * @param value The object to check.
* @return Returns true when Object value is allowed to be set. * @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)) { if (LANGUAGE_NAME.equals(this) | LANGUAGE_VERSION.equals(this)) {
return false; // read only are not valid to set. return false; // read only are not valid to set.
} }
@ -297,7 +297,7 @@ public enum X4OLanguageProperty {
* @return Return the property for the given uri. * @return Return the property for the given uri.
* @throws IllegalArgumentException when uri is not found. * @throws IllegalArgumentException when uri is not found.
*/ */
static public X4OLanguageProperty valueByUri(String uri) { public static final X4OLanguageProperty valueByUri(String uri) {
if (uri==null) { if (uri==null) {
throw new NullPointerException("Can't search null uri."); throw new NullPointerException("Can't search null uri.");
} }

View file

@ -45,6 +45,7 @@ import org.x4o.xml.element.ElementConfiguratorGlobal;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface; import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.io.sax.ContentWriter;
import org.x4o.xml.io.sax.X4ODebugWriter; import org.x4o.xml.io.sax.X4ODebugWriter;
import org.x4o.xml.io.sax.X4OEntityResolver; import org.x4o.xml.io.sax.X4OEntityResolver;
import org.x4o.xml.io.sax.X4OErrorHandler; 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.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLReaderFactory; import org.xml.sax.helpers.XMLReaderFactory;
@ -852,8 +852,8 @@ public class X4OPhaseLanguageRead {
try { try {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "elements", "", "", elementsReleased+""); atts.addAttribute ("", "elements", "", "", elementsReleased+"");
languageContext.getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts); languageContext.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
languageContext.getX4ODebugWriter().getDebugWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , ""); languageContext.getX4ODebugWriter().getContentWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(phase,e); throw new X4OPhaseException(phase,e);
} }
@ -920,13 +920,13 @@ public class X4OPhaseLanguageRead {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value); //atts.addAttribute ("", key, "", "", value);
//atts.addAttribute ("", "verbose", "", "", "true"); //atts.addAttribute ("", "verbose", "", "", "true");
languageContext.getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts); languageContext.getX4ODebugWriter().getContentWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts);
startedPrefix.clear(); startedPrefix.clear();
printXML(languageContext.getRootElement()); printXML(languageContext.getRootElement());
for (String prefix:startedPrefix) { 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); languageContext.getX4ODebugWriter().debugLanguageContext(languageContext);
} catch (SAXException e) { } catch (SAXException e) {
throw new X4OPhaseException(this,e); throw new X4OPhaseException(this,e);
@ -951,15 +951,13 @@ public class X4OPhaseLanguageRead {
if (element==null) { if (element==null) {
throw new SAXException("Can't print debug xml of null element."); 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)) { if (element.getElementType().equals(Element.ElementType.comment)) {
char[] msg = ((String)element.getElementObject()).toCharArray(); handler.comment((String)element.getElementObject());
handler.comment(msg,0,msg.length);
return; return;
} }
if (element.getElementType().equals(Element.ElementType.characters)) { if (element.getElementType().equals(Element.ElementType.characters)) {
char[] msg = ((String)element.getElementObject()).toCharArray(); handler.characters((String)element.getElementObject());
handler.characters(msg,0,msg.length);
return; return;
} }
if (element.getElementClass()==null) { if (element.getElementClass()==null) {

View file

@ -42,7 +42,7 @@ import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException; import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.element.ElementObjectPropertyValueException; import org.x4o.xml.element.ElementObjectPropertyValueException;
import org.x4o.xml.io.XMLConstants; 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.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty; 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(); writer.startDocument();
Map<String,String> prefixes = new HashMap<String,String>(); Map<String,String> prefixes = new HashMap<String,String>();
@ -273,7 +273,7 @@ public class X4OPhaseLanguageWrite {
return result; 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(); AttributesImpl atts = new AttributesImpl();
if (isRoot && schemaUriPrint) { if (isRoot && schemaUriPrint) {

View file

@ -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&lt;test/&gt;"));
}
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\"?>&lt;test/&gt; &amp; &apos;foobar&apos; is &quote;quoted&quote;!"));
}
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=\"&lt;test/&gt; &amp; &apos;foobar&apos; is &quote;quoted&quote;!\"/>"));
}
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"));
}
}

View file

@ -26,7 +26,7 @@ import java.io.StringWriter;
import org.x4o.xml.element.AbstractElement; import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException; import org.x4o.xml.element.ElementException;
import org.x4o.xml.io.sax.XMLWriter; import org.x4o.xml.io.sax.ContentWriterXml;
/** /**
* InlinePropertiesElement to test * InlinePropertiesElement to test
@ -44,7 +44,7 @@ public class InlinePropertiesElement extends AbstractElement {
@Override @Override
public void doElementStart() throws ElementException { public void doElementStart() throws ElementException {
StringWriter xmlString = new StringWriter(); StringWriter xmlString = new StringWriter();
XMLWriter writer = new XMLWriter(xmlString); ContentWriterXml writer = new ContentWriterXml(xmlString);
setElementObject(writer); setElementObject(writer);
} }

View file

@ -0,0 +1,449 @@
/*
* 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.eld.doc;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.x4o.xml.io.sax.ContentWriterHtml;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* ContentWriterHtml Writes eld/java documentation in html.
*
* @author Willem Cazander
* @version 1.0 Apr 30, 2013
*/
public class ContentWriterDoc extends ContentWriterHtml {
private boolean isAltRow = true;
public ContentWriterDoc(Writer out,String encoding,String charNewLine,String charTab) {
super(out,encoding,charNewLine,charTab);
}
public void docCommentGenerated() throws SAXException {
comment("Generated by "+ContentWriterDoc.class.getSimpleName()+" on "+new Date());
}
public void docHtmlStart(NavBarConfig conf,String title,List<String> keywords) throws SAXException {
printDocType(DocType.HTML_4_TRANSITIONAL);
comment("NewPage");
printHtmlStart("en");
// ====== Write head
printTagStart(Tag.head);
docCommentGenerated();
printHeadMetaContentType();
printHeadTitle(title);
printHeadMetaDate();
for (String keyword:keywords) {
printHeadMeta("keywords",keyword);
}
printHeadLinkCss(conf.pathPrefix+"resources/stylesheet.css");
printTagEnd(Tag.head);
// ======= Write body
printTagStart(Tag.body);
StringBuffer script = new StringBuffer();
script.append("\n");
script.append("\tif (location.href.indexOf('is-external=true') == -1) {\n");
script.append("\t\tparent.document.title=\"");script.append(title);script.append("\";\n");
script.append("\t}\n");
printScriptInline(script.toString());
printScriptNoDiv();
docNavBar(conf,true);
}
public void docHtmlEnd(NavBarConfig conf,String copyright) throws SAXException {
docNavBar(conf,false);
printTagStart(Tag.p,"legalCopy");
printTagStart(Tag.small);
charactersRaw(copyright);
printTagEnd(Tag.small);
printTagEnd(Tag.p);
if (conf.statsJS!=null) {
printScriptInline(conf.statsJS);
}
printTagEnd(Tag.body);
printHtmlEnd();
}
class NavBarConfig {
String navSelected = null;
List<String> navList = new ArrayList<String>(10);
Map<String,String> navLinks = new HashMap<String,String>(10);
Map<String,String> navNames = new HashMap<String,String>(10);
String pathPrefix;
String prev;
String next;
String frame;
String aboutLanguage;
String statsJS;
boolean linkDetails = false;
boolean linkFields = false;
boolean linkConstructors = false;
boolean linkMethods = false;
String linkFieldName = "Field";
String linkConstructorName = "Constr";
String linkMethodName = "Method";
String noFrameAllName;
String noFrameAllLink;
String noFrameAllTopJS =
"\nallClassesLink = document.getElementById(\"allclasses_navbar_top\");\n"+
"if(window==top) {\n\tallClassesLink.style.display = \"block\";\n} else {\n\tallClassesLink.style.display = \"none\";\n}\n";
String noFrameAllBottomJS =
"\nallClassesLink = document.getElementById(\"allclasses_navbar_bottom\");\n"+
"if(window==top) {\n\tallClassesLink.style.display = \"block\";\n} else {\n\tallClassesLink.style.display = \"none\";\n}\n";
public NavBarConfig() {}
public NavBarConfig(String pathPrefix,String prev,String next,String frame,String aboutLanguage) {
this.pathPrefix=pathPrefix;
this.prev=prev;
this.next=next;
this.frame=frame;
this.aboutLanguage=aboutLanguage;
}
public void addNavItem(String id,String navLink,String navName) {
navList.add(id);
if (navLink!=null) {
navLinks.put(id, navLink);
}
navNames.put(id, navName);
}
}
private void docNavBar(NavBarConfig conf,boolean isTop) throws SAXException {
String pathPrefix = conf.pathPrefix;
String barComment = "TOP";
String barCssDiv = "topNav";
String barId = "navbar_top";
if (isTop==false) {
barComment = "BOTTOM";
barCssDiv = "bottomNav";
barId = "navbar_bottom";
}
comment("========= START OF "+barComment+" NAVBAR =======");
printTagStart(Tag.div,barCssDiv);
printHrefNamed(barId); // Print named link navigation
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "href", "", "", "#skip-"+barId);
atts.addAttribute ("", "title", "", "", "Skip navigation links");
startElement("", "a", "", atts);
endElement("", "a", "");
printHrefNamed(barId+"_firstrow");
atts = new AttributesImpl();// Print nav bar
atts.addAttribute ("", "class", "", "", "navList");
atts.addAttribute ("", "title", "", "", "Navigation");
startElement("", "ul", "", atts);
for (String navKey:conf.navList) {
String navName = conf.navNames.get(navKey);
String navLink = conf.navLinks.get(navKey);
String selectedCss = null;
if (navKey.equals(conf.navSelected)) {
selectedCss = "navBarCell1Rev";
}
if (navLink==null) {
printTagText(Tag.li, navName, selectedCss);
} else {
docNavBarListItemHref(pathPrefix+navLink,navName,selectedCss);
}
}
endElement("", "ul", "");
printTagStart(Tag.div,"aboutLanguage"); // Print about language
printTagStart(Tag.em);
printTagStart(Tag.strong);charactersRaw(conf.aboutLanguage);printTagEnd(Tag.strong);
printTagEnd(Tag.em);
printTagEnd(Tag.div);
printTagEnd(Tag.div); // end barCssDiv
printTagStart(Tag.div,"subNav");
printTagStart(Tag.ul,"navList");
if (conf.prev==null) {
printTagText(Tag.li, "Prev");
} else {
docNavBarListItemHref(pathPrefix+conf.prev,"Prev",null,"strong",null);
}
if (conf.next==null) {
printTagText(Tag.li, "Next");
} else {
docNavBarListItemHref(pathPrefix+conf.next,"Next",null,"strong",null);
}
printTagEnd(Tag.ul);
if (conf.frame!=null) {
printTagStart(Tag.ul,"navList");
printTagStart(Tag.li);
printHrefTarget(pathPrefix+"index.html?"+conf.frame, "Frames", "_top");
printTagEnd(Tag.li);
printTagStart(Tag.li);
printHrefTarget(pathPrefix+conf.frame, "No Frames", "_top");
printTagEnd(Tag.li);
printTagEnd(Tag.ul);
}
if (conf.noFrameAllName!=null && conf.noFrameAllLink!=null) {
printTagStart(Tag.ul,"navList","allclasses_"+barId);
docNavBarListItemHref(pathPrefix+conf.noFrameAllLink,conf.noFrameAllName,null,null,null);
printTagEnd(Tag.ul);
printTagStart(Tag.div);
if (isTop) {
printScriptInline(conf.noFrameAllTopJS);
} else {
printScriptInline(conf.noFrameAllBottomJS);
}
printTagEnd(Tag.div);
}
String tabSpace = "&nbsp;|&nbsp;";
boolean printLink = conf.linkConstructors || conf.linkFields || conf.linkMethods;
if (printLink) {
printTagStart(Tag.div);
printTagStart(Tag.ul,"subNavList");
printTagStart(Tag.li);charactersRaw("Summary:&nbsp;");printTagEnd(Tag.li);
//printTagText(Tag.li,"Nested | "); // TODO: Nested
if (conf.linkFields) {
docNavBarListItemHref("#field_summary",conf.linkFieldName,null,null,tabSpace);
} else {
printTagText(Tag.li,conf.linkFieldName);charactersRaw(tabSpace);
}
if (conf.linkConstructors) {
docNavBarListItemHref("#constructor_summary",conf.linkConstructorName,null,null,tabSpace);
} else {
printTagText(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace);
}
if (conf.linkMethods) {
docNavBarListItemHref("#method_summary",conf.linkMethodName,null);
} else {
printTagText(Tag.li,conf.linkMethodName);
}
printTagEnd(Tag.ul);
if (conf.linkDetails){
printTagStart(Tag.ul,"subNavList");
printTagStart(Tag.li);charactersRaw("Detail:&nbsp;");printTagEnd(Tag.li);
//printTagText(Tag.li,"Nested | ");
if (conf.linkFields) {
docNavBarListItemHref("#field_detail",conf.linkFieldName,null,null,tabSpace);
} else {
printTagText(Tag.li,conf.linkFieldName);charactersRaw(tabSpace);
}
if (conf.linkConstructors) {
docNavBarListItemHref("#constructor_detail",conf.linkConstructorName,null,null,tabSpace);
} else {
printTagText(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace);
}
if (conf.linkMethods) {
docNavBarListItemHref("#method_detail",conf.linkMethodName,null);
} else {
printTagText(Tag.li,conf.linkMethodName);
}
printTagEnd(Tag.ul);
}
printTagEnd(Tag.div);
}
printHrefNamed("skip-"+barId);
printTagEnd(Tag.div);
comment("========= END OF "+barComment+" NAVBAR =======");
}
private void docNavBarListItemHref(String href,String title,String cssClass) throws SAXException {
docNavBarListItemHref(href, title, cssClass, null, null);
}
private void docNavBarListItemHref(String href,String title,String cssClass,String spanCss,String linkSpace) throws SAXException {
printTagStart(Tag.li,cssClass);
printHref(href,title,title,spanCss);
charactersRaw(linkSpace);
printTagEnd(Tag.li);
}
public void docPagePackageTitle(String title,String summary) throws SAXException {
printTagStart(Tag.div,"header");
printTagText(Tag.h1, title,"title");
printTagStart(Tag.div,"docSummary");
printTagText(Tag.div, summary,"block");
printTagEnd(Tag.div);
printTagStart(Tag.p);
charactersRaw("See:&nbsp;");
printHref("#package_description", "Description");
printTagEnd(Tag.p);
printTagEnd(Tag.div);
}
public void docPagePackageDescription(String title,String summary,String description) throws SAXException {
printHrefNamed("package_description");
printTagText(Tag.h2, title);
printTagText(Tag.div, summary,"block");
characters(description);
}
public void docPageClassStart(String title,String subTitle) throws SAXException {
comment("======== START OF CLASS DATA ========");
printTagStart(Tag.div,"header");
if (subTitle!=null) {
printTagStart(Tag.div,"subTitle");
characters(subTitle);
printTagEnd(Tag.div);
}
printTagText(Tag.h2, title, "title");
printTagEnd(Tag.div);
}
public void docPageClassEnd() throws SAXException {
comment("======== END OF CLASS DATA ========");
}
public void docPageContentStart() throws SAXException {
printTagStart(Tag.div,"contentContainer");
}
public void docPageContentEnd() throws SAXException {
printTagEnd(Tag.div);
}
public void docPageBlockStart(String title,String namedLink,String comment) throws SAXException {
if (comment!=null) {
comment(comment);
}
docPageBlockStart();
printHrefNamed(namedLink);
printTagText(Tag.h3, title);
}
public void docPageBlockStart() throws SAXException {
printTagStart(Tag.ul,"blockList");
printTagStart(Tag.li,"blockList");
}
public void docPageBlockEnd() throws SAXException {
printTagEnd(Tag.li);
printTagEnd(Tag.ul);
}
public void docPageBlockNext() throws SAXException {
printTagEnd(Tag.li);
printTagStart(Tag.li,"blockList");
}
public void docTableStart(String tableTitle,String tableDescription) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", "packageSummary");
atts.addAttribute ("", "border", "", "", "0");
atts.addAttribute ("", "cellpadding", "", "", "3");
atts.addAttribute ("", "cellspacing", "", "", "0");
if (tableDescription!=null) {
atts.addAttribute ("", "summary", "", "", tableDescription);
}
startElement("", "table", "", atts);
printTagStart(Tag.caption);
printTagStart(Tag.span);characters(tableTitle);printTagEnd(Tag.span);
printTagStart(Tag.span,"tabEnd");charactersRaw("&nbsp;");printTagEnd(Tag.span);
printTagEnd(Tag.caption);
}
public void docTableEnd() throws SAXException {
printTagEnd(Tag.table);
isAltRow = true;
}
public void docTableHeader(String titleFirst,String titleLast) throws SAXException {
printTagStart(Tag.tr);
AttributesImpl atts = new AttributesImpl();
if (titleLast==null) {
atts.addAttribute ("", "class", "", "", "colOne");
} else {
atts.addAttribute ("", "class", "", "", "colFirst");
}
atts.addAttribute ("", "scope", "", "", "col");
startElement("", "th", "", atts);
characters(titleFirst);
endElement("", "th", "");
if (titleLast==null) {
printTagEnd(Tag.tr);
return;
}
atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", "colLast");
atts.addAttribute ("", "scope", "", "", "col");
startElement("", "th", "", atts);
characters(titleLast);
printTagEnd(Tag.th);
printTagEnd(Tag.tr);
}
public void docTableRow(String dataFirst,String dataLast) throws SAXException {
docTableRow(dataFirst,dataLast,null);
}
public void docTableRow(String dataFirst,String dataLast,String dataBlock) throws SAXException {
docTableRowHref(null,dataFirst,dataLast,dataBlock);
}
public void docTableRowHref(String dataFirstHref,String dataFirst,String dataLast,String dataBlock) throws SAXException {
if (isAltRow) {
printTagStart(Tag.tr,"altColor");
} else {
printTagStart(Tag.tr,"rowColor");
}
isAltRow = !isAltRow;
if (dataLast==null) {
printTagStart(Tag.td,"colOne");
} else {
printTagStart(Tag.td,"colFirst");
}
printTagStart(Tag.code);
if (dataFirstHref==null) {
characters(dataFirst);
} else {
printHref(dataFirstHref, dataFirst, dataFirst);
}
printTagEnd(Tag.code);
printTagEnd(Tag.td);
if (dataLast==null) {
printTagEnd(Tag.tr);
return;
}
printTagStart(Tag.td,"colLast");
printTagStart(Tag.code);characters(dataLast);printTagEnd(Tag.code);
if (dataBlock!=null) {
printTagStart(Tag.div,"block");characters(dataBlock);printTagEnd(Tag.div);
}
printTagEnd(Tag.td);
printTagEnd(Tag.tr);
}
}

View file

@ -34,6 +34,7 @@ import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext; import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.lang.X4OLanguageModule; import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageContext; import org.x4o.xml.lang.X4OLanguageContext;
import org.xml.sax.SAXException;
/** /**
* EldDocGenerator writes documentation. * EldDocGenerator writes documentation.
@ -61,51 +62,60 @@ public class EldDocGenerator {
public void writeDoc(File basePath) throws ElementException { public void writeDoc(File basePath) throws ElementException {
EldDocHtmlWriter writer = new EldDocHtmlWriter(); EldDocHtmlWriter writer = new EldDocHtmlWriter();
try { try {
writer.writeTheme(basePath);
writer.writeIndex(basePath, context); writer.writeIndex(basePath, context);
writer.writeStylesheet(basePath); writer.writeIndexAll(basePath, context);
writer.writeOverviewModule(basePath, context); writer.writeDocHelp(basePath, context);
writer.writeOverviewNamespace(basePath, context); writer.writeAllElementsFrame(basePath, context, true);
writer.writeAllElementsFrame(basePath, context, false);
writer.writeOverviewFrame(basePath, context);
writer.writeOverviewLanguage(basePath, context);
writer.writeOverviewTree(basePath, context); writer.writeOverviewTree(basePath, context);
for (X4OLanguageModule mod:context.getLanguage().getLanguageModules()) { for (X4OLanguageModule mod:context.getLanguage().getLanguageModules()) {
writer.writeOverviewModule(basePath, mod); writer.writeOverviewModule(basePath, mod, context);
for (ElementBindingHandler bind:mod.getElementBindingHandlers()) { for (ElementBindingHandler bind:mod.getElementBindingHandlers()) {
writer.writeBindingHandler(basePath,bind,mod); writer.writeBindingHandler(basePath,bind,mod,context);
} }
for (ElementAttributeHandler attr:mod.getElementAttributeHandlers()) { for (ElementAttributeHandler attr:mod.getElementAttributeHandlers()) {
writer.writeAttributeHandler(basePath,attr,mod); writer.writeAttributeHandler(basePath,attr,mod,context);
} }
for (ElementConfigurator conf:mod.getElementConfiguratorGlobals()) { for (ElementConfigurator conf:mod.getElementConfiguratorGlobals()) {
writer.writeElementConfigurator(basePath,conf,mod); writer.writeElementConfigurator(basePath,conf,mod,context);
} }
for (ElementInterface iface:mod.getElementInterfaces()) { for (ElementInterface iface:mod.getElementInterfaces()) {
writer.writeElementInterface(basePath,iface,mod); writer.writeElementInterface(basePath,iface,mod,context);
for (ElementBindingHandler bind:iface.getElementBindingHandlers()) { for (ElementBindingHandler bind:iface.getElementBindingHandlers()) {
writer.writeBindingHandler(basePath,bind,mod,iface); writer.writeBindingHandler(basePath,bind,mod,iface,context);
} }
//for (ElementAttributeHandler attr:iface.getElementClassAttributes()) { //for (ElementAttributeHandler attr:iface.getElementClassAttributes()) {
// writer.writeAttributeHandler(basePath,attr,mod,true); // writer.writeAttributeHandler(basePath,attr,mod,true);
//} //}
for (ElementConfigurator conf:iface.getElementConfigurators()) { for (ElementConfigurator conf:iface.getElementConfigurators()) {
writer.writeElementConfigurator(basePath,conf,mod,iface); writer.writeElementConfigurator(basePath,conf,mod,iface,context);
} }
} }
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) { for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
writer.writeOverviewElement(basePath, ns,mod);
writer.writeOverviewElement(basePath,ns,mod,context);
writer.writeNamespaceElementsFrame(basePath,ns,mod,context);
for (ElementClass ec:ns.getElementClasses()) { for (ElementClass ec:ns.getElementClasses()) {
writer.writeElement(basePath, ec, ns, mod,context); writer.writeElement(basePath, ec, ns, mod,context);
for (ElementConfigurator conf:ec.getElementConfigurators()) { for (ElementConfigurator conf:ec.getElementConfigurators()) {
writer.writeElementConfigurator(basePath,conf,mod,ns,ec); writer.writeElementConfigurator(basePath,conf,mod,ns,ec,context);
} }
} }
} }
} }
} catch (SAXException e) {
throw new ElementException(e);
} catch (IOException e) { } catch (IOException e) {
throw new ElementException(e); throw new ElementException(e);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,447 @@
/* Javadoc JDK7 like style sheet */
body {
background-color:#ffffff;
color:#353833;
font-family:Arial, Helvetica, sans-serif;
font-size:76%;
margin:0px;
}
a:link, a:visited {
text-decoration:none;
color:#4c6b87;
}
a:hover, a:focus {
text-decoration:none;
color:#bb7a2a;
}
a:active {
text-decoration:none;
color:#4c6b87;
}
a[name] {
color:#353833;
}
a[name]:hover {
text-decoration:none;
color:#353833;
}
pre {
font-size:1.3em;
}
h1 {
font-size:1.8em;
}
h2 {
font-size:1.5em;
}
h3 {
font-size:1.4em;
}
h4 {
font-size:1.3em;
}
h5 {
font-size:1.2em;
}
h6 {
font-size:1.1em;
}
ul {
list-style-type:disc;
}
code, tt {
font-size:1.2em;
}
dt code {
font-size:1.2em;
}
table tr td dt code {
font-size:1.2em;
vertical-align:top;
}
sup {
font-size:0.6em;
}
.clear {
clear:both;
height:0px;
overflow:hidden;
}
.aboutLanguage {
float:right;
padding:0px 21px;
font-size:0.8em;
z-index:200;
margin-top:-7px;
}
.legalCopy {
margin-left:.5em;
}
.bar a, .bar a:link, .bar a:visited, .bar a:active {
color:#FFFFFF;
text-decoration:none;
}
.bar a:hover, .bar a:focus {
color:#bb7a2a;
}
.tab {
background-color:#0066FF;
background-image:url(titlebar.png);
background-position:left top;
background-repeat:no-repeat;
color:#ffffff;
padding:8px;
width:5em;
font-weight:bold;
}
.bar {
background-image:url(background.png);
background-repeat:repeat-x;
color:#FFFFFF;
padding:.8em .5em .4em .8em;
height:auto;/*height:1.8em;*/
font-size:1em;
margin:0px;
}
.topNav {
background-image:url(background.png);
background-repeat:repeat-x;
color:#FFFFFF;
float:left;
padding:0px;
width:100%;
clear:right;
height:2.8em;
padding-top:10px;
overflow:hidden;
}
.bottomNav {
margin-top:10px;
background-image:url(background.png);
background-repeat:repeat-x;
color:#FFFFFF;
float:left;
padding:0px;
width:100%;
clear:right;
height:2.8em;
padding-top:10px;
overflow:hidden;
}
.subNav {
background-color:#dee3e9;
border-bottom:1px solid #9eadc0;
float:left;
width:100%;
overflow:hidden;
}
.subNav div {
clear:left;
float:left;
padding:0 0 5px 6px;
}
ul.navList, ul.subNavList {
float:left;
margin:0px 25px 0px 0px;
padding:0px;
}
ul.navList li{
list-style:none;
float:left;
padding:3px 6px;
}
ul.subNavList li{
list-style:none;
float:left;
font-size:90%;
}
.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
color:#FFFFFF;
text-decoration:none;
}
.topNav a:hover, .bottomNav a:hover {
text-decoration:none;
color:#bb7a2a;
}
.navBarCell1Rev {
background-image:url(tab.png);
background-color:#a88834;
color:#FFFFFF;
margin: auto 5px;
border:1px solid #c9aa44;
}
.header, .footer {
clear:both;
margin:0 20px;
padding:5px 0px 0px 0px;
}
.indexHeader {
margin:10px;
position:relative;
}
.indexHeader h1 {
font-size:1.3em;
}
.title {
color:#2c4557;
margin:10px 0px;
}
.subTitle {
margin:5px 0px 0px 0px;
}
.header ul {
margin:0px 0px 25px 0px;
padding:0px;
}
.footer ul {
margin:20px 0px 5px 0px;
}
.header ul li, .footer ul li {
list-style:none;
font-size:1.2em;
}
div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
background-color:#dee3e9;
border-top:1px solid #9eadc0;
border-bottom:1px solid #9eadc0;
margin:0px 0px 6px -8px;
padding:2px 5px;
}
ul.blockList ul.blockList ul.blockList li.blockList h3 {
background-color:#dee3e9;
border-top:1px solid #9eadc0;
border-bottom:1px solid #9eadc0;
margin:0px 0px 6px -8px;
padding:2px 5px;
}
ul.blockList ul.blockList li.blockList h3 {
padding:0px;
margin:15px 0px;
}
ul.blockList li.blockList h2 {
padding:0px 0px 20px 0px;
}
.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
clear:both;
padding:10px 20px;
position:relative;
}
.indexContainer {
margin:10px;
position:relative;
font-size:1.0em;
}
.indexContainer h2 {
font-size:1.1em;
padding:0px 0px 3px 0px;
}
.indexContainer ul {
margin:0px;
padding:0px;
}
.indexContainer ul li {
list-style:none;
}
.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
font-size:1.1em;
font-weight:bold;
margin:10px 0 0 0;
color:#4E4E4E;
}
.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
margin:10px 0px 10px 20px;
}
.serializedFormContainer dl.nameValue dt {
margin-left:1px;
font-size:1.1em;
display:inline;
font-weight:bold;
}
.serializedFormContainer dl.nameValue dd {
margin:0px 0px 0px 1px;
font-size:1.1em;
display:inline;
}
ul.horizontal li {
display:inline;
font-size:0.9em;
}
ul.inheritance {
margin:0px;
padding:0px;
}
ul.inheritance li {
display:inline;
list-style:none;
}
ul.inheritance li ul.inheritance {
margin-left:15px;
padding-left:15px;
padding-top:1px;
}
ul.blockList, ul.blockListLast {
margin:10px 0px 10px 0px;
padding:0px;
}
ul.blockList li.blockList, ul.blockListLast li.blockList {
list-style:none;
margin-bottom:25px;
}
ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
padding:0px 20px 5px 10px;
border:1px solid #9eadc0;
background-color:#f9f9f9;
}
ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
padding:0px 0px 5px 8px;
background-color:#ffffff;
border:1px solid #9eadc0;
border-top:none;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
margin-left:0px;
padding-left:0px;
padding-bottom:15px;
border:none;
border-bottom:1px solid #9eadc0;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
list-style:none;
border-bottom:none;
padding-bottom:0px;
}
table tr td dl, table tr td dl dt, table tr td dl dd {
margin-top:0px;
margin-bottom:1px;
}
.contentContainer table, .classUseContainer table, .constantValuesContainer table {
border-bottom:1px solid #9eadc0;
width:100%;
}
.contentContainer ul li table, .classUseContainer ul li table, .constantValuesContainer ul li table {
width:100%;
}
.contentContainer .description table, .contentContainer .details table {
border-bottom:none;
}
.contentContainer ul li table th.colOne, .contentContainer ul li table th.colFirst, .contentContainer ul li table th.colLast, .classUseContainer ul li table th, .constantValuesContainer ul li table th, .contentContainer ul li table td.colOne, .contentContainer ul li table td.colFirst, .contentContainer ul li table td.colLast, .classUseContainer ul li table td, .constantValuesContainer ul li table td{
vertical-align:top;
padding-right:20px;
}
.contentContainer ul li table th.colLast, .classUseContainer ul li table th.colLast,.constantValuesContainer ul li table th.colLast,
.contentContainer ul li table td.colLast, .classUseContainer ul li table td.colLast,.constantValuesContainer ul li table td.colLast,
.contentContainer ul li table th.colOne, .classUseContainer ul li table th.colOne,
.contentContainer ul li table td.colOne, .classUseContainer ul li table td.colOne {
padding-right:3px;
}
.overviewSummary caption, .packageSummary caption, .contentContainer ul.blockList li.blockList caption, .summary caption, .classUseContainer caption, .constantValuesContainer caption {
position:relative;
text-align:left;
background-repeat:no-repeat;
color:#FFFFFF;
font-weight:bold;
clear:none;
overflow:hidden;
padding:0px;
margin:0px;
}
caption a:link, caption a:hover, caption a:active, caption a:visited {
color:#FFFFFF;
}
.overviewSummary caption span, .packageSummary caption span, .contentContainer ul.blockList li.blockList caption span, .summary caption span, .classUseContainer caption span, .constantValuesContainer caption span {
white-space:nowrap;
padding-top:8px;
padding-left:8px;
display:block;
float:left;
background-image:url(titlebar.png);
height:18px;
}
.overviewSummary .tabEnd, .packageSummary .tabEnd, .contentContainer ul.blockList li.blockList .tabEnd, .summary .tabEnd, .classUseContainer .tabEnd, .constantValuesContainer .tabEnd {
width:10px;
background-image:url(titlebar_end.png);
background-repeat:no-repeat;
background-position:top right;
position:relative;
float:left;
}
ul.blockList ul.blockList li.blockList table {
margin:0px 0px 12px 0px;
width:100%;
}
.tableSubHeadingColor {
background-color: #EEEEFF;
}
.altColor {
background-color:#eeeeef;
}
.rowColor {
background-color:#ffffff;
}
.overviewSummary td, .packageSummary td, .contentContainer ul.blockList li.blockList td, .summary td, .classUseContainer td, .constantValuesContainer td {
text-align:left;
padding:3px 3px 3px 7px;
}
th.colFirst, th.colLast, th.colOne, .constantValuesContainer th {
background:#dee3e9;
border-top:1px solid #9eadc0;
border-bottom:1px solid #9eadc0;
text-align:left;
padding:3px 3px 3px 7px;
}
td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
font-weight:bold;
}
td.colFirst, th.colFirst {
border-left:1px solid #9eadc0;
white-space:nowrap;
}
td.colLast, th.colLast {
border-right:1px solid #9eadc0;
}
td.colOne, th.colOne {
border-right:1px solid #9eadc0;
border-left:1px solid #9eadc0;
}
table.overviewSummary {
padding:0px;
margin-left:0px;
}
table.overviewSummary td.colFirst, table.overviewSummary th.colFirst,
table.overviewSummary td.colOne, table.overviewSummary th.colOne {
width:25%;
vertical-align:middle;
}
table.packageSummary td.colFirst, table.overviewSummary th.colFirst {
width:25%;
vertical-align:middle;
}
/*
Content styles
*/
.description pre {
margin-top:0px;
}
.deprecatedContent {
margin:0px;
padding:10px 0px;
}
.docSummary {
padding:0px;
}
.sourceLineNo {
color:green;
padding:0px 30px 0px 0px;
}
h1.hidden {
visibility:hidden;
overflow:hidden;
font-size:0.9em;
}
.block {
display:block;
margin:3px 0px 0px 0px;
}
.strong {
font-weight:bold;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B