Created sax content writers and created generic api doc model for
documentation. Improved writer support with attribute write order and new-lining after long attribute values.
This commit is contained in:
parent
92644fd148
commit
8d71b63a6f
82 changed files with 5637 additions and 2620 deletions
|
|
@ -24,13 +24,14 @@ package org.x4o.xml.eld.xsd;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXsd;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
|
|
@ -70,9 +71,9 @@ public class EldXsdXmlGenerator {
|
|||
if (basePath==null) {
|
||||
throw new ElementException("Can't write schema to null output path.");
|
||||
}
|
||||
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
|
||||
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE; }
|
||||
if (charTab==null) { charTab = XMLConstants.CHAR_TAB; }
|
||||
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
|
||||
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE+""; }
|
||||
if (charTab==null) { charTab = XMLConstants.CHAR_TAB+""; }
|
||||
try {
|
||||
|
||||
|
||||
|
|
@ -82,24 +83,26 @@ public class EldXsdXmlGenerator {
|
|||
throw new NullPointerException("Could not find namespace: "+namespace);
|
||||
}
|
||||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
|
||||
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
|
||||
try {
|
||||
ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
|
||||
ContentWriterXsd out = new ContentWriterXsd(wr,encoding,charNew,charTab);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
wr.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (X4OLanguageModule mod:language.getLanguageModules()) {
|
||||
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
|
||||
checkNamespace(ns);
|
||||
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
|
||||
File outputFile = new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource());
|
||||
Writer wr = new OutputStreamWriter(new FileOutputStream(outputFile), encoding);
|
||||
try {
|
||||
ContentWriterXml out = new ContentWriterXml(fio,encoding,charNew,charTab);
|
||||
ContentWriterXsd out = new ContentWriterXsd(wr,encoding,charNew,charTab);
|
||||
generateSchema(ns.getUri(), out);
|
||||
} finally {
|
||||
fio.close();
|
||||
wr.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +112,7 @@ public class EldXsdXmlGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateSchema(String namespaceUri,ContentWriter xmlWriter) throws SAXException {
|
||||
public void generateSchema(String namespaceUri,ContentWriterXsd xmlWriter) throws SAXException {
|
||||
|
||||
ElementNamespaceContext ns = language.findElementNamespaceContext(namespaceUri);
|
||||
if (ns==null) {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import org.x4o.xml.element.ElementInterface;
|
|||
import org.x4o.xml.element.ElementMetaBase;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXsd;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguage;
|
||||
import org.xml.sax.SAXException;
|
||||
|
|
@ -57,14 +57,14 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
public class EldXsdXmlWriter {
|
||||
|
||||
|
||||
static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
|
||||
static public final String SCHEMA_URI = XMLConstants.XML_SCHEMA_NS_URI;
|
||||
|
||||
protected X4OLanguage language = null;
|
||||
protected ContentWriter xmlWriter = null;
|
||||
protected ContentWriterXsd xmlWriter = null;
|
||||
protected String writeNamespace = null;
|
||||
protected Map<String, String> namespaces = null;
|
||||
|
||||
public EldXsdXmlWriter(ContentWriter xmlWriter,X4OLanguage language) {
|
||||
public EldXsdXmlWriter(ContentWriterXsd xmlWriter,X4OLanguage language) {
|
||||
this.xmlWriter=xmlWriter;
|
||||
this.language=language;
|
||||
this.namespaces=new HashMap<String,String>(10);
|
||||
|
|
@ -150,9 +150,9 @@ public class EldXsdXmlWriter {
|
|||
public void startSchema(ElementNamespaceContext ns) throws SAXException {
|
||||
|
||||
xmlWriter.startDocument();
|
||||
writeIgnorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
writeComment(COMMENT_SEPERATOR);
|
||||
writeIgnorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.comment(COMMENT_SEPERATOR);
|
||||
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
|
||||
// this is a mess;
|
||||
String desc = "Automatic generated schema for language: "+language.getLanguageName();
|
||||
|
|
@ -167,10 +167,10 @@ public class EldXsdXmlWriter {
|
|||
}
|
||||
b.append(COMMENT_TEXT);
|
||||
b.append(" ");
|
||||
writeComment(b.toString());
|
||||
writeIgnorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
writeComment(COMMENT_SEPERATOR);
|
||||
writeIgnorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.comment(b.toString());
|
||||
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.comment(COMMENT_SEPERATOR);
|
||||
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
|
||||
X4OLanguageModule module = null;
|
||||
for (X4OLanguageModule elm:language.getLanguageModules()) {
|
||||
|
|
@ -190,7 +190,7 @@ public class EldXsdXmlWriter {
|
|||
b.append("\n\tUri schema:\t"); b.append(ns.getSchemaUri());
|
||||
b.append("\n\tCreated on:\t\t"); b.append(new Date());
|
||||
b.append("\n");
|
||||
writeComment(b.toString());
|
||||
xmlWriter.comment(b.toString());
|
||||
|
||||
|
||||
xmlWriter.startPrefixMapping("", SCHEMA_URI);
|
||||
|
|
@ -222,7 +222,7 @@ public class EldXsdXmlWriter {
|
|||
|
||||
public void endSchema() throws SAXException {
|
||||
xmlWriter.endElement (SCHEMA_URI, "schema" , "");
|
||||
writeIgnorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.ignorableWhitespace(XMLConstants.CHAR_NEWLINE);
|
||||
xmlWriter.endDocument();
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ public class EldXsdXmlWriter {
|
|||
|
||||
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
|
||||
// oke, reverse this if and rm whitespace.
|
||||
writeIgnorableWhitespace(" ");
|
||||
xmlWriter.ignorableWhitespace(' ');
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -447,32 +447,8 @@ public class EldXsdXmlWriter {
|
|||
atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "xml:lang", "", "", "en");
|
||||
xmlWriter.startElement(SCHEMA_URI, "documentation", "", atts);
|
||||
writeCharacters(base.getDescription());
|
||||
xmlWriter.characters(base.getDescription());
|
||||
xmlWriter.endElement(SCHEMA_URI, "documentation", "");
|
||||
xmlWriter.endElement(SCHEMA_URI, "annotation", "");
|
||||
}
|
||||
|
||||
private void writeCharacters(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
char[] msg = text.toCharArray();
|
||||
xmlWriter.characters(msg,0,msg.length);
|
||||
}
|
||||
|
||||
private void writeComment(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
char[] msg = text.toCharArray();
|
||||
xmlWriter.comment(msg,0,msg.length);
|
||||
}
|
||||
|
||||
private void writeIgnorableWhitespace(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
char[] msg = text.toCharArray();
|
||||
xmlWriter.ignorableWhitespace(msg,0,msg.length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import org.x4o.xml.lang.X4OLanguageContext;
|
|||
* from the attibutes or parent (object)element.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 01/02/2005
|
||||
* @version 1.0 Feb 01, 2005
|
||||
*/
|
||||
public interface Element {
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ public interface Element {
|
|||
* @throws ElementException Can be thrown when structure is not correct.
|
||||
*/
|
||||
void doElementStart() throws ElementException;
|
||||
|
||||
|
||||
/**
|
||||
* This method is fired only once in the run phase.
|
||||
* @throws ElementException Can be thrown when structure is not correct.
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.X4ODebugWriter;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriter;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXml;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageContextLocal;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
|
|
|||
|
|
@ -139,12 +139,12 @@ public final class XMLConstants {
|
|||
/**
|
||||
* Tab char
|
||||
*/
|
||||
public static final String CHAR_TAB = "\t";
|
||||
public static final char CHAR_TAB = '\t';
|
||||
|
||||
/**
|
||||
* Newline char
|
||||
*/
|
||||
public static final String CHAR_NEWLINE = "\n";
|
||||
public static final char CHAR_NEWLINE = '\n';
|
||||
|
||||
|
||||
|
||||
|
|
@ -220,6 +220,16 @@ public final class XMLConstants {
|
|||
return false;
|
||||
}
|
||||
|
||||
static public boolean isCharString(String value) {
|
||||
for (int i=0;i<value.length();i++) {
|
||||
char c = value.charAt(i);
|
||||
if (isNameChar(c)==false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static public boolean isNameString(String value) {
|
||||
for (int i=0;i<value.length();i++) {
|
||||
char c = value.charAt(i);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.x4o.xml.element.Element.ElementType;
|
|||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
|
||||
import org.x4o.xml.io.sax.ext.AttributeMap;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
import org.xml.sax.Attributes;
|
||||
|
|
@ -46,7 +47,7 @@ import java.util.logging.Logger;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
*/
|
||||
public class X4OTagHandler extends DefaultHandler2 {
|
||||
public class X4OContentHandler extends DefaultHandler2 {
|
||||
|
||||
/** The logger to log to */
|
||||
private Logger logger = null;
|
||||
|
|
@ -71,8 +72,8 @@ public class X4OTagHandler extends DefaultHandler2 {
|
|||
* Creates an X4OTagHandler
|
||||
* which can receice sax xml events and converts them into the Element* interfaces events.
|
||||
*/
|
||||
public X4OTagHandler(X4OLanguageContext elementLanguage) {
|
||||
logger = Logger.getLogger(X4OTagHandler.class.getName());
|
||||
public X4OContentHandler(X4OLanguageContext elementLanguage) {
|
||||
logger = Logger.getLogger(X4OContentHandler.class.getName());
|
||||
loggerFinest = logger.isLoggable(Level.FINEST);
|
||||
elementStack = new Stack<Element>();
|
||||
this.elementLanguage = elementLanguage;
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* 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.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* X4OContentParser Runs the SAX parser with the X4OContentHandler.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 20, 2005
|
||||
*/
|
||||
public class X4OContentParser {
|
||||
|
||||
public void parse(X4OLanguageContext languageContext) throws SAXException, IOException {
|
||||
|
||||
// If xsd caching is needed this should be the way
|
||||
//XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
|
||||
//config.setProperty("http://apache.org/xml/properties/internal/grammar-pool",myFullGrammarPool);
|
||||
//SAXParser parser = new SAXParser(config);
|
||||
|
||||
// Create Sax parser with x4o tag handler
|
||||
X4OContentHandler xth = new X4OContentHandler(languageContext);
|
||||
XMLReader saxParser = XMLReaderFactory.createXMLReader();
|
||||
saxParser.setErrorHandler(new X4OErrorHandler(languageContext));
|
||||
saxParser.setEntityResolver(new X4OEntityResolver(languageContext));
|
||||
saxParser.setContentHandler(xth);
|
||||
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
|
||||
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
|
||||
|
||||
// Set properties and optional
|
||||
Map<String,Object> saxParserProperties = languageContext.getLanguage().getLanguageConfiguration().getSAXParserProperties(languageContext);
|
||||
for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object value= entry.getValue();
|
||||
saxParser.setProperty(name, value);
|
||||
debugMessage("Set SAX property: "+name+" to: "+value,languageContext);
|
||||
}
|
||||
Map<String,Object> saxParserPropertiesOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserPropertiesOptional(languageContext);
|
||||
for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object value= entry.getValue();
|
||||
try {
|
||||
saxParser.setProperty(name, value);
|
||||
debugMessage("Set SAX optional property: "+name+" to: "+value,languageContext);
|
||||
} catch (SAXException e) {
|
||||
debugMessage("Could not set optional SAX property: "+name+" to: "+value+" error: "+e.getMessage(),languageContext);
|
||||
}
|
||||
}
|
||||
|
||||
// Set sax features and optional
|
||||
Map<String, Boolean> features = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeatures(languageContext);
|
||||
for (String key:features.keySet()) {
|
||||
Boolean value=features.get(key);
|
||||
saxParser.setFeature(key, value);
|
||||
debugMessage("Set SAX feature: "+key+" to: "+value,languageContext);
|
||||
}
|
||||
Map<String, Boolean> featuresOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesOptional(languageContext);
|
||||
for (String key:featuresOptional.keySet()) {
|
||||
Boolean value=featuresOptional.get(key);
|
||||
try {
|
||||
saxParser.setFeature(key, value);
|
||||
debugMessage("Set SAX optional feature: "+key+" to: "+value,languageContext);
|
||||
} catch (SAXException e) {
|
||||
debugMessage("Could not set optional SAX feature: "+key+" to: "+value+" error: "+e.getMessage(),languageContext);
|
||||
}
|
||||
}
|
||||
|
||||
// check for required features
|
||||
List<String> requiredFeatures = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesRequired(languageContext);
|
||||
for (String requiredFeature:requiredFeatures) {
|
||||
debugMessage("Checking required SAX feature: "+requiredFeature,languageContext);
|
||||
if (saxParser.getFeature(requiredFeature)==false) {
|
||||
throw new IllegalStateException("Missing required feature: "+requiredFeature);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally start parsing the xml input stream
|
||||
Object requestInputSource = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SOURCE);
|
||||
InputSource input = null;
|
||||
InputStream inputStream = null;
|
||||
if (requestInputSource instanceof InputSource) {
|
||||
input = (InputSource)requestInputSource;
|
||||
} else {
|
||||
inputStream = (InputStream)languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_STREAM);
|
||||
input = new InputSource(inputStream);
|
||||
}
|
||||
|
||||
Object requestInputEncoding = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_ENCODING);
|
||||
if (requestInputEncoding!=null && requestInputEncoding instanceof String) {
|
||||
input.setEncoding(requestInputEncoding.toString());
|
||||
}
|
||||
Object requestSystemId = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SYSTEM_ID);
|
||||
if (requestSystemId!=null && requestSystemId instanceof String) {
|
||||
input.setSystemId(requestSystemId.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
saxParser.parse(input);
|
||||
} finally {
|
||||
if (inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void debugMessage(String message,X4OLanguageContext languageContext) throws SAXException {
|
||||
if (languageContext.hasX4ODebugWriter()) {
|
||||
try {
|
||||
languageContext.getX4ODebugWriter().debugPhaseMessage(message, X4OContentParser.class);
|
||||
} catch (ElementException ee) {
|
||||
throw new SAXException(ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ import org.x4o.xml.element.ElementException;
|
|||
import org.x4o.xml.element.ElementInterface;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriter;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageConfiguration;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter {
|
||||
|
||||
public AbstractContentWriter(Writer out, String encoding,String charNewLine, String charTab) {
|
||||
super(out, encoding, charNewLine, charTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and end then element.
|
||||
* @see org.x4o.xml.io.sax.ext.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,12 +20,9 @@
|
|||
* 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;
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -36,19 +33,20 @@ import java.util.Stack;
|
|||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
* AbstractContentWriterHandler writes SAX content handler events as XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 17, 2005
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public class ContentWriterXml implements ContentWriter {
|
||||
public class AbstractContentWriterHandler implements ContentHandler {
|
||||
|
||||
public final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
protected final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
protected String encoding = null;
|
||||
private String charNewline = null;
|
||||
private String charTab = null;
|
||||
|
|
@ -59,14 +57,13 @@ public class ContentWriterXml implements ContentWriter {
|
|||
private StringBuffer startElement = null;
|
||||
private boolean printReturn = false;
|
||||
private String lastElement = null;
|
||||
private boolean printCDATA = false;
|
||||
private Stack<String> elements = null;
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
public AbstractContentWriterHandler(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
if (out==null) {
|
||||
throw new NullPointerException("Can't write on null writer.");
|
||||
}
|
||||
|
|
@ -74,10 +71,10 @@ public class ContentWriterXml implements ContentWriter {
|
|||
encoding = XMLConstants.XML_DEFAULT_ENCODING;
|
||||
}
|
||||
if (charNewLine==null) {
|
||||
charNewLine = XMLConstants.CHAR_NEWLINE;
|
||||
charNewLine = XMLConstants.CHAR_NEWLINE+"";
|
||||
}
|
||||
if (charTab==null) {
|
||||
charTab = XMLConstants.CHAR_TAB;
|
||||
charTab = XMLConstants.CHAR_TAB+"";
|
||||
}
|
||||
this.out = out;
|
||||
this.encoding = encoding;
|
||||
|
|
@ -87,52 +84,6 @@ public class ContentWriterXml implements ContentWriter {
|
|||
printedMappings = new ArrayList<String>(15);
|
||||
elements = new Stack<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out,String encoding) {
|
||||
this(out,encoding,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out) {
|
||||
this(out,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @param encoding The OutputStream encoding.
|
||||
* @param charNewLine The newline char.
|
||||
* @param charTab The tab char.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out,String encoding,String charNewLine,String charTab) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding,charNewLine,charTab);
|
||||
}
|
||||
|
||||
// TODO: check location of this. (add to api?)
|
||||
public void closeWriter() throws IOException {
|
||||
|
|
@ -168,15 +119,6 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The xml namespace uri.
|
||||
* @param localName The local name of the xml tag.
|
||||
|
|
@ -186,7 +128,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
*/
|
||||
public void startElement(String uri, String localName, String name,Attributes atts) throws SAXException {
|
||||
if (localName==null) {
|
||||
localName = "null"; // mmm rm ?
|
||||
throw new SAXException("LocalName may not be null.");
|
||||
}
|
||||
if (XMLConstants.isNameString(localName)==false) {
|
||||
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
|
||||
|
|
@ -282,10 +224,15 @@ public class ContentWriterXml implements ContentWriter {
|
|||
String attributeName = XMLConstants.escapeAttributeName(atts.getLocalName(i));
|
||||
String attributeValue = atts.getValue(i);
|
||||
if (attributeValue==null) {
|
||||
attributeValue = "null";
|
||||
attributeValue = "null"; // TODO: Add null value key to config.
|
||||
}
|
||||
String attributeValueSafe = XMLConstants.escapeAttributeValue(attributeValue);
|
||||
boolean printNewLine = attributeValueSafe.length()>80; // TODO add config
|
||||
if (i==0) {
|
||||
startElement.append(' ');
|
||||
} else if (!printNewLine) {
|
||||
startElement.append(' ');
|
||||
}
|
||||
startElement.append(' ');
|
||||
|
||||
if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
|
||||
startElement.append(attributeName);
|
||||
} else {
|
||||
|
|
@ -293,10 +240,15 @@ public class ContentWriterXml implements ContentWriter {
|
|||
startElement.append(XMLConstants.XMLNS_ASSIGN);
|
||||
startElement.append(attributeName);
|
||||
}
|
||||
|
||||
startElement.append("=\"");
|
||||
startElement.append(XMLConstants.escapeAttributeValue(attributeValue));
|
||||
startElement.append(attributeValueSafe);
|
||||
startElement.append('"');
|
||||
if (printNewLine) {
|
||||
startElement.append(XMLConstants.CHAR_NEWLINE);
|
||||
for (int ii = 0; ii < indent+1; ii++) {
|
||||
startElement.append(charTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,7 +334,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints xml characters.
|
||||
* Prints xml characters and uses characters(java.lang.String) method.
|
||||
*
|
||||
* @param ch Character buffer.
|
||||
* @param start The start index of the chars in the ch buffer.
|
||||
|
|
@ -395,20 +347,18 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#characters(java.lang.String)
|
||||
* Escape and prints xml characters.
|
||||
* @see org.x4o.xml.io.sax.ext.ContentWriter#characters(java.lang.String)
|
||||
*/
|
||||
public void characters(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
return;
|
||||
}
|
||||
autoCloseStartElement();
|
||||
checkPrintedReturn(text);
|
||||
if (printCDATA) {
|
||||
text = XMLConstants.escapeCharactersCdata(text,"","");
|
||||
} else {
|
||||
text = XMLConstants.escapeCharacters(text);
|
||||
}
|
||||
write(text);
|
||||
charactersRaw(XMLConstants.escapeCharacters(text));
|
||||
}
|
||||
|
||||
public void characters(char c) throws SAXException {
|
||||
characters(new char[]{c},0,1);
|
||||
}
|
||||
|
||||
// move or remove ?
|
||||
|
|
@ -435,7 +385,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||
* @see org.x4o.xml.io.sax.ext.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||
*/
|
||||
public void ignorableWhitespace(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
|
|
@ -444,6 +394,10 @@ public class ContentWriterXml implements ContentWriter {
|
|||
autoCloseStartElement();
|
||||
write(text); // TODO: check chars
|
||||
}
|
||||
|
||||
public void ignorableWhitespace(char c) throws SAXException {
|
||||
ignorableWhitespace(new char[]{c},0,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints xml instructions.
|
||||
|
|
@ -453,14 +407,26 @@ public class ContentWriterXml implements ContentWriter {
|
|||
* @param data The data.
|
||||
*/
|
||||
public void processingInstruction(String target, String data) throws SAXException {
|
||||
String targetLow = target.toLowerCase();
|
||||
if (targetLow.startsWith(XMLConstants.XML)) {
|
||||
throw new SAXException("Processing instruction may not start with xml.");
|
||||
}
|
||||
if (XMLConstants.isNameString(target)==false) {
|
||||
throw new SAXException("Processing instruction target is invalid name; '"+target+"'");
|
||||
}
|
||||
if (XMLConstants.isCharString(data)==false) {
|
||||
throw new SAXException("Processing instruction data is invalid char; '"+data+"'");
|
||||
}
|
||||
autoCloseStartElement();
|
||||
write(charNewline);
|
||||
writeIndent();
|
||||
write(XMLConstants.PROCESS_START);
|
||||
write(target);
|
||||
write(' ');
|
||||
write(data);
|
||||
write(XMLConstants.PROCESS_END);
|
||||
write(charNewline);
|
||||
writeFlush();
|
||||
printReturn = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -496,7 +462,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ContentWriter#comment(java.lang.String)
|
||||
* @see org.x4o.xml.io.sax.ext.ContentWriter#comment(java.lang.String)
|
||||
*/
|
||||
public void comment(String text) throws SAXException {
|
||||
if (text==null) {
|
||||
|
|
@ -514,65 +480,8 @@ public class ContentWriterXml implements ContentWriter {
|
|||
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) {
|
||||
if (value.indexOf(XMLConstants.CHAR_NEWLINE)>0) {
|
||||
printReturn = true;
|
||||
} else {
|
||||
printReturn = false;
|
||||
|
|
@ -583,7 +492,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
* Auto close the start element if working in printing event.
|
||||
* @throws IOException When prints gives exception.
|
||||
*/
|
||||
private void autoCloseStartElement() throws SAXException {
|
||||
protected void autoCloseStartElement() throws SAXException {
|
||||
if (startElement==null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -601,7 +510,7 @@ public class ContentWriterXml implements ContentWriter {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeFlush() throws SAXException {
|
||||
protected void writeFlush() throws SAXException {
|
||||
try {
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
|
||||
/**
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler {
|
||||
|
||||
protected boolean printCDATA = false;
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public AbstractContentWriterLexical(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out, encoding, charNewLine, charTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
||||
*/
|
||||
public void startCDATA() throws SAXException {
|
||||
autoCloseStartElement();
|
||||
charactersRaw(XMLConstants.CDATA_START);
|
||||
printCDATA = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
||||
*/
|
||||
public void endCDATA() throws SAXException {
|
||||
charactersRaw(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 {
|
||||
charactersRaw(XMLConstants.XML_DOCTYPE);
|
||||
charactersRaw(" ");
|
||||
charactersRaw(name);
|
||||
if (publicId!=null) {
|
||||
charactersRaw(" ");
|
||||
charactersRaw(publicId);
|
||||
}
|
||||
if (systemId!=null) {
|
||||
charactersRaw(" \"");
|
||||
charactersRaw(systemId);
|
||||
charactersRaw("\"");
|
||||
}
|
||||
charactersRaw(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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ext.AbstractContentWriterHandler#characters(char[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
characters(new String(ch, start, length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.io.sax.ext.AbstractContentWriterHandler#characters(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void characters(String text) throws SAXException {
|
||||
if (printCDATA) {
|
||||
charactersRaw(XMLConstants.escapeCharactersCdata(text,"",""));
|
||||
} else {
|
||||
super.characters(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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;
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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;
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
|
@ -49,6 +49,10 @@ public interface ContentWriter extends ContentHandler,LexicalHandler {
|
|||
void comment(String text) throws SAXException;
|
||||
|
||||
void ignorableWhitespace(String text) throws SAXException;
|
||||
|
||||
void ignorableWhitespace(char c) throws SAXException;
|
||||
|
||||
void characters(String text) throws SAXException;
|
||||
|
||||
void characters(char c) throws SAXException;
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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;
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
/**
|
||||
* ContentWriterConfig Defines config options for ContentWriter.
|
||||
|
|
@ -20,12 +20,11 @@
|
|||
* 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;
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
|
@ -35,7 +34,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 30, 2013
|
||||
*/
|
||||
public class ContentWriterHtml extends ContentWriterXml {
|
||||
public class ContentWriterHtml extends ContentWriterXmlTag<ContentWriterHtml.Tag> {
|
||||
|
||||
public ContentWriterHtml(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out,encoding,charNewLine,charTab);
|
||||
|
|
@ -63,7 +62,7 @@ public class ContentWriterHtml extends ContentWriterXml {
|
|||
}
|
||||
|
||||
public void printHeadTitle(String title) throws SAXException {
|
||||
printTagText("title",title);
|
||||
printTagCharacters(Tag.title,title);
|
||||
}
|
||||
|
||||
public void printHeadMetaContentType() throws SAXException {
|
||||
|
|
@ -156,24 +155,13 @@ public class ContentWriterHtml extends ContentWriterXml {
|
|||
}
|
||||
printTagEnd(Tag.a);
|
||||
}
|
||||
|
||||
|
||||
private void printTagText(String tag,String text) throws SAXException {
|
||||
startElement ("", tag, "", EMPTY_ATTRIBUTES);
|
||||
characters(text);
|
||||
endElement ("",tag , "");
|
||||
public void printTagCharacters(Tag tag,String text,String tagClass) throws SAXException {
|
||||
printTagCharacters(tag,text,tagClass,null);
|
||||
}
|
||||
|
||||
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);
|
||||
public void printTagCharacters(Tag tag,String text,String tagClass,String tagId) throws SAXException {
|
||||
printTagStart(tag,tagClass,tagId,null);
|
||||
if (text==null) {
|
||||
text = " ";
|
||||
}
|
||||
|
|
@ -181,21 +169,21 @@ public class ContentWriterHtml extends ContentWriterXml {
|
|||
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);
|
||||
printTagStart(tag,tagClass,null,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,String tagClass,String tagId) throws SAXException {
|
||||
printTagStart(tag,tagClass,tagId,null);
|
||||
public void printTagStart(Tag tag,Enum<?> tagClassEnum) throws SAXException {
|
||||
printTagStart(tag,tagClassEnum,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,Enum<?> tagClassEnum,String tagId) throws SAXException {
|
||||
printTagStart(tag,tagClassEnum,tagId,null);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,Enum<?> tagClassEnum,String tagId,String typeId) throws SAXException {
|
||||
printTagStart(tag,tagClassEnum.name(),tagId,typeId);
|
||||
}
|
||||
|
||||
public void printTagStart(Tag tag,String tagClass,String tagId,String typeId) throws SAXException {
|
||||
|
|
@ -212,14 +200,6 @@ public class ContentWriterHtml extends ContentWriterXml {
|
|||
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 */
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* ContentWriterTag writes enum tags as xml.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public interface ContentWriterTag<T extends Enum<?>> extends ContentWriter {
|
||||
|
||||
String getTagNamespaceUri();
|
||||
|
||||
void printTagStartEnd(T tag) throws SAXException;
|
||||
|
||||
void printTagStartEnd(T tag,Attributes atts) throws SAXException;
|
||||
|
||||
void printTagStart(T tag) throws SAXException;
|
||||
|
||||
void printTagStart(T tag,Attributes atts) throws SAXException;
|
||||
|
||||
void printTagEnd(T tag) throws SAXException;
|
||||
|
||||
void printTagCharacters(T tag,String text) throws SAXException;
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
|
||||
/**
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 17, 2005
|
||||
*/
|
||||
public class ContentWriterXml extends AbstractContentWriter {
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out, encoding, charNewLine, charTab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out,String encoding) {
|
||||
this(out,encoding,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the Writer interface.
|
||||
* @param out The writer to print the xml to.
|
||||
*/
|
||||
public ContentWriterXml(Writer out) {
|
||||
this(out,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates XmlWriter which prints to the OutputStream interface.
|
||||
* @param out The OutputStream to write to.
|
||||
* @param encoding The OutputStream encoding.
|
||||
* @param charNewLine The newline char.
|
||||
* @param charTab The tab char.
|
||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||
*/
|
||||
public ContentWriterXml(OutputStream out,String encoding,String charNewLine,String charTab) throws UnsupportedEncodingException {
|
||||
this(new OutputStreamWriter(out, encoding),encoding,charNewLine,charTab);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* ContentWriterXml writes SAX content handler events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public class ContentWriterXmlTag<T extends Enum<?>> extends ContentWriterXml implements ContentWriterTag<T> {
|
||||
|
||||
public ContentWriterXmlTag(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out, encoding, charNewLine, charTab);
|
||||
}
|
||||
|
||||
public String getTagNamespaceUri() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void printTagStartEnd(T tag,Attributes atts) throws SAXException {
|
||||
printTagStart(tag,atts);
|
||||
printTagEnd(tag);
|
||||
}
|
||||
|
||||
public void printTagStartEnd(T tag) throws SAXException {
|
||||
printTagStart(tag);
|
||||
printTagEnd(tag);
|
||||
}
|
||||
|
||||
public void printTagStart(T tag) throws SAXException {
|
||||
printTagStart(tag,EMPTY_ATTRIBUTES);
|
||||
}
|
||||
|
||||
public void printTagStart(T tag,Attributes atts) throws SAXException {
|
||||
startElement (getTagNamespaceUri(), tag.name(), "", atts);
|
||||
}
|
||||
|
||||
public void printTagEnd(T tag) throws SAXException {
|
||||
endElement (getTagNamespaceUri(),tag.name() , "");
|
||||
}
|
||||
|
||||
public void printTagCharacters(T tag,String text) throws SAXException {
|
||||
printTagStart(tag);
|
||||
if (text==null) {
|
||||
text = " ";
|
||||
}
|
||||
characters(text);
|
||||
printTagEnd(tag);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2013, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.xml.io.sax.ext;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* ContentWriterXsd writes XSD events as SAX events to XML.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 3, 2013
|
||||
*/
|
||||
public class ContentWriterXsd extends ContentWriterXmlTag<ContentWriterXsd.Tag> {
|
||||
|
||||
public ContentWriterXsd(Writer out,String encoding,String charNewLine,String charTab) {
|
||||
super(out,encoding,charNewLine,charTab);
|
||||
}
|
||||
|
||||
public String getTagNamespaceUri() {
|
||||
return XMLConstants.XML_SCHEMA_NS_URI;
|
||||
}
|
||||
|
||||
public void printXsdImport(String namespace,String schemaLocation) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "namespace", "", "", namespace);
|
||||
atts.addAttribute ("", "schemaLocation", "", "", schemaLocation);
|
||||
startElement (getTagNamespaceUri(), "import", "", atts);
|
||||
endElement (getTagNamespaceUri(), "import", ""); // import is keyword
|
||||
}
|
||||
|
||||
public void printXsdDocumentation(String description) throws SAXException {
|
||||
if (description==null) {
|
||||
return;
|
||||
}
|
||||
printTagStart(Tag.annotation);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "xml:lang", "", "", "en");
|
||||
printTagStart(Tag.documentation,atts);
|
||||
characters(description);
|
||||
printTagEnd(Tag.documentation);
|
||||
printTagEnd(Tag.annotation);
|
||||
}
|
||||
|
||||
public void printXsdElementAttribute(String name,String type,String description) throws SAXException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "name", "", "", name);
|
||||
atts.addAttribute ("", "type", "", "", type);
|
||||
printTagStart(Tag.attribute,atts);
|
||||
printXsdDocumentation(description);
|
||||
printTagEnd(Tag.attribute);
|
||||
}
|
||||
|
||||
public enum Tag {
|
||||
all,annotation,any,anyAttribute,appinfo,attribute,attributeGroup,
|
||||
choise,complexContent,complexType,documentation,element,extension,
|
||||
field,group,/*_import,*/include,key,keyref,list,notation,
|
||||
redefine,restriction,schema,selector,sequence,
|
||||
simpleContent,simpleType,unoin,unique
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
package org.x4o.xml.lang.phase;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -45,21 +44,16 @@ import org.x4o.xml.element.ElementConfiguratorGlobal;
|
|||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.element.ElementInterface;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.sax.ContentWriter;
|
||||
import org.x4o.xml.io.sax.X4OContentParser;
|
||||
import org.x4o.xml.io.sax.X4ODebugWriter;
|
||||
import org.x4o.xml.io.sax.X4OEntityResolver;
|
||||
import org.x4o.xml.io.sax.X4OErrorHandler;
|
||||
import org.x4o.xml.io.sax.X4OTagHandler;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriter;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageClassLoader;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* Factory which can create X4OPhaseHandlers for all the predefined phases used in default x4o language parsing.
|
||||
|
|
@ -144,8 +138,6 @@ public class X4OPhaseLanguageRead {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates the startX4OPhase which is a empty meta phase.
|
||||
*/
|
||||
|
|
@ -198,94 +190,8 @@ public class X4OPhaseLanguageRead {
|
|||
}
|
||||
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
|
||||
try {
|
||||
//XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
|
||||
//config.setProperty("http://apache.org/xml/properties/internal/grammar-pool",myFullGrammarPool);
|
||||
//SAXParser parser = new SAXParser(config);
|
||||
|
||||
// Create Sax parser with x4o tag handler
|
||||
X4OTagHandler xth = new X4OTagHandler(languageContext);
|
||||
XMLReader saxParser = XMLReaderFactory.createXMLReader();
|
||||
saxParser.setErrorHandler(new X4OErrorHandler(languageContext));
|
||||
saxParser.setEntityResolver(new X4OEntityResolver(languageContext));
|
||||
saxParser.setContentHandler(xth);
|
||||
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
|
||||
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
|
||||
|
||||
// Set properties and optional
|
||||
Map<String,Object> saxParserProperties = languageContext.getLanguage().getLanguageConfiguration().getSAXParserProperties(languageContext);
|
||||
for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object value= entry.getValue();
|
||||
saxParser.setProperty(name, value);
|
||||
debugPhaseMessage("Set SAX property: "+name+" to: "+value,this,languageContext);
|
||||
}
|
||||
Map<String,Object> saxParserPropertiesOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserPropertiesOptional(languageContext);
|
||||
for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Object value= entry.getValue();
|
||||
try {
|
||||
saxParser.setProperty(name, value);
|
||||
debugPhaseMessage("Set SAX optional property: "+name+" to: "+value,this,languageContext);
|
||||
} catch (SAXException e) {
|
||||
debugPhaseMessage("Could not set optional SAX property: "+name+" to: "+value+" error: "+e.getMessage(),this,languageContext);
|
||||
}
|
||||
}
|
||||
|
||||
// Set sax features and optional
|
||||
Map<String, Boolean> features = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeatures(languageContext);
|
||||
for (String key:features.keySet()) {
|
||||
Boolean value=features.get(key);
|
||||
saxParser.setFeature(key, value);
|
||||
debugPhaseMessage("Set SAX feature: "+key+" to: "+value,this,languageContext);
|
||||
}
|
||||
Map<String, Boolean> featuresOptional = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesOptional(languageContext);
|
||||
for (String key:featuresOptional.keySet()) {
|
||||
Boolean value=featuresOptional.get(key);
|
||||
try {
|
||||
saxParser.setFeature(key, value);
|
||||
debugPhaseMessage("Set SAX optional feature: "+key+" to: "+value,this,languageContext);
|
||||
} catch (SAXException e) {
|
||||
debugPhaseMessage("Could not set optional SAX feature: "+key+" to: "+value+" error: "+e.getMessage(),this,languageContext);
|
||||
}
|
||||
}
|
||||
|
||||
// check for required features
|
||||
List<String> requiredFeatures = languageContext.getLanguage().getLanguageConfiguration().getSAXParserFeaturesRequired(languageContext);
|
||||
for (String requiredFeature:requiredFeatures) {
|
||||
debugPhaseMessage("Checking required SAX feature: "+requiredFeature,this,languageContext);
|
||||
if (saxParser.getFeature(requiredFeature)==false) {
|
||||
Exception e = new IllegalStateException("Missing required feature: "+requiredFeature);
|
||||
throw new X4OPhaseException(this,e);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally start parsing the xml input stream
|
||||
Object requestInputSource = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SOURCE);
|
||||
InputSource input = null;
|
||||
InputStream inputStream = null;
|
||||
if (requestInputSource instanceof InputSource) {
|
||||
input = (InputSource)requestInputSource;
|
||||
} else {
|
||||
inputStream = (InputStream)languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_STREAM);
|
||||
input = new InputSource(inputStream);
|
||||
}
|
||||
|
||||
Object requestInputEncoding = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_ENCODING);
|
||||
if (requestInputEncoding!=null && requestInputEncoding instanceof String) {
|
||||
input.setEncoding(requestInputEncoding.toString());
|
||||
}
|
||||
Object requestSystemId = languageContext.getLanguageProperty(X4OLanguageProperty.READER_INPUT_SYSTEM_ID);
|
||||
if (requestSystemId!=null && requestSystemId instanceof String) {
|
||||
input.setSystemId(requestSystemId.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
saxParser.parse(input);
|
||||
} finally {
|
||||
if (inputStream!=null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
X4OContentParser parser = new X4OContentParser();
|
||||
parser.parse(languageContext);
|
||||
} catch (Exception e) {
|
||||
throw new X4OPhaseException(this,e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import java.io.OutputStream;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -42,7 +44,7 @@ import org.x4o.xml.element.ElementNamespaceContext;
|
|||
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
|
||||
import org.x4o.xml.element.ElementObjectPropertyValueException;
|
||||
import org.x4o.xml.io.XMLConstants;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXml;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguageProperty;
|
||||
|
|
@ -189,8 +191,11 @@ public class X4OPhaseLanguageWrite {
|
|||
}
|
||||
public void runElementPhase(Element element) throws X4OPhaseException {
|
||||
}
|
||||
boolean schemaUriPrint;
|
||||
String schemaUriRoot;
|
||||
|
||||
private AttributeEntryComparator attributeEntryComparator = new AttributeEntryComparator();
|
||||
private boolean schemaUriPrint;
|
||||
private String schemaUriRoot;
|
||||
|
||||
public void runPhase(X4OLanguageContext languageContext) throws X4OPhaseException {
|
||||
OutputStream out = (OutputStream)languageContext.getLanguageProperty(X4OLanguageProperty.WRITER_OUTPUT_STREAM);
|
||||
try {
|
||||
|
|
@ -200,8 +205,8 @@ public class X4OPhaseLanguageWrite {
|
|||
schemaUriPrint = languageContext.getLanguagePropertyBoolean(X4OLanguageProperty.WRITER_SCHEMA_URI_PRINT);
|
||||
schemaUriRoot = languageContext.getLanguagePropertyString(X4OLanguageProperty.WRITER_SCHEMA_URI_ROOT);
|
||||
if (encoding==null) { encoding = XMLConstants.XML_DEFAULT_ENCODING; }
|
||||
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE; }
|
||||
if (charTab==null) { charTab = XMLConstants.CHAR_TAB; }
|
||||
if (charNew==null) { charNew = XMLConstants.CHAR_NEWLINE+""; }
|
||||
if (charTab==null) { charTab = XMLConstants.CHAR_TAB+""; }
|
||||
|
||||
Element root = languageContext.getRootElement();
|
||||
if (schemaUriRoot==null) {
|
||||
|
|
@ -272,15 +277,18 @@ public class X4OPhaseLanguageWrite {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void writeTree(ContentWriterXml writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
if (isRoot && schemaUriPrint) {
|
||||
String rootUri = findElementUri(element);
|
||||
writer.startPrefixMapping("xsi", XMLConstants.XML_SCHEMA_INSTANCE_NS_URI);
|
||||
atts.addAttribute ("xsi", "schemaLocation", "", "", rootUri+" "+schemaUriRoot);
|
||||
class AttributeEntry {
|
||||
String id;
|
||||
String value;
|
||||
Integer writeOrder;
|
||||
}
|
||||
class AttributeEntryComparator implements Comparator<AttributeEntry> {
|
||||
public int compare(AttributeEntry o1, AttributeEntry o2) {
|
||||
return o1.writeOrder.compareTo(o2.writeOrder);
|
||||
}
|
||||
}
|
||||
private void writeTree(ContentWriterXml writer,Element element,boolean isRoot) throws SAXException, ElementObjectPropertyValueException {
|
||||
List<AttributeEntry> attr = new ArrayList<AttributeEntry>(20);
|
||||
if (element.getElementClass().getAutoAttributes()!=null && element.getElementClass().getAutoAttributes()==false) {
|
||||
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
|
||||
if (eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
|
||||
|
|
@ -291,19 +299,29 @@ public class X4OPhaseLanguageWrite {
|
|||
if (value==null) {
|
||||
continue;
|
||||
}
|
||||
atts.addAttribute ("", eca.getId(), "", "", ""+value);
|
||||
AttributeEntry e = new AttributeEntry();
|
||||
e.id = eca.getId();
|
||||
e.value = ""+value;
|
||||
e.writeOrder = calcOrderNumber(e.id,eca.getWriteOrder());
|
||||
attr.add(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
for (String p:getProperties(element.getElementObject().getClass())) {
|
||||
|
||||
Integer writeOrder = null;
|
||||
ElementClassAttribute eca = element.getElementClass().getElementClassAttributeByName(p);
|
||||
if (eca!=null) {
|
||||
writeOrder = eca.getWriteOrder();
|
||||
}
|
||||
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()) {
|
||||
continue;
|
||||
}
|
||||
boolean writeValue = true;
|
||||
for (ElementInterface ei:element.getLanguageContext().getLanguage().findElementInterfaces(element.getElementObject().getClass())) {
|
||||
eca = ei.getElementClassAttributeByName(p);
|
||||
if (eca!=null && writeOrder==null) {
|
||||
writeOrder = eca.getWriteOrder(); // add interface but allow override local
|
||||
}
|
||||
if (eca!=null && eca.getRunBeanValue()!=null && eca.getRunBeanValue()==false) {
|
||||
writeValue = false;
|
||||
break;
|
||||
|
|
@ -321,10 +339,30 @@ public class X4OPhaseLanguageWrite {
|
|||
if (value instanceof List || value instanceof Collection) {
|
||||
continue; // TODO; filter on type of childeren
|
||||
}
|
||||
atts.addAttribute ("", p, "", "", ""+value);
|
||||
AttributeEntry e = new AttributeEntry();
|
||||
e.id = p;
|
||||
e.value = ""+value;
|
||||
e.writeOrder = calcOrderNumber(e.id,writeOrder);
|
||||
attr.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Create atts to write and append schema first.
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
if (isRoot && schemaUriPrint) {
|
||||
String rootUri = findElementUri(element);
|
||||
writer.startPrefixMapping("xsi", XMLConstants.XML_SCHEMA_INSTANCE_NS_URI);
|
||||
atts.addAttribute ("xsi", "schemaLocation", "", "", rootUri+" "+schemaUriRoot);
|
||||
}
|
||||
|
||||
// Sort attributes in natural order of localName and add to attributes
|
||||
Collections.sort(attr, attributeEntryComparator);
|
||||
for (int i=0;i<attr.size();i++) {
|
||||
AttributeEntry a = attr.get(i);
|
||||
atts.addAttribute ("", a.id, "", "", a.value);
|
||||
}
|
||||
|
||||
// Write Element tree recursive.
|
||||
String elementUri = findElementUri(element);
|
||||
writer.startElement(elementUri, element.getElementClass().getId(), "", atts);
|
||||
for (Element e:element.getChilderen()) {
|
||||
|
|
@ -333,6 +371,30 @@ public class X4OPhaseLanguageWrite {
|
|||
writer.endElement(elementUri, element.getElementClass().getId(), "");
|
||||
}
|
||||
|
||||
// TODO: move to defaults layer so visible in docs.
|
||||
private Integer calcOrderNumber(String name,Integer orderNumberOverride) {
|
||||
if (orderNumberOverride!=null) {
|
||||
return orderNumberOverride;
|
||||
}
|
||||
if (name==null) {
|
||||
throw new NullPointerException("Can't calculate order of null name.");
|
||||
}
|
||||
int nameSize = name.length();
|
||||
if (nameSize==1) {
|
||||
return (name.charAt(0) * 1000);
|
||||
}
|
||||
if (nameSize==2) {
|
||||
return (name.charAt(0) * 1000) + (name.charAt(1) * 100);
|
||||
}
|
||||
if (nameSize==3) {
|
||||
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10);
|
||||
}
|
||||
if (nameSize>3) {
|
||||
return (name.charAt(0) * 1000) + (name.charAt(1) * 100) + (name.charAt(2) * 10) + (name.charAt(3) * 1);
|
||||
}
|
||||
throw new IllegalArgumentException("Can't calculate order of empty name.");
|
||||
}
|
||||
|
||||
private String findElementUri(Element e) {
|
||||
for (X4OLanguageModule mod:e.getLanguageContext().getLanguage().getLanguageModules()) {
|
||||
for (ElementNamespaceContext c:mod.getElementNamespaceContexts()) {
|
||||
|
|
|
|||
|
|
@ -22,25 +22,6 @@
|
|||
*/
|
||||
package org.x4o.xml.eld;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.X4ODriverManager;
|
||||
import org.x4o.xml.eld.EldDriver;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.Element.ElementType;
|
||||
import org.x4o.xml.element.ElementClass;
|
||||
import org.x4o.xml.element.ElementNamespaceContext;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.io.X4OSchemaWriter;
|
||||
import org.x4o.xml.io.X4OWriter;
|
||||
import org.x4o.xml.lang.X4OLanguageModule;
|
||||
import org.x4o.xml.lang.X4OLanguageContext;
|
||||
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
|
||||
import org.x4o.xml.test.TestDriver;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -79,17 +60,16 @@ public class EldParserTest extends TestCase {
|
|||
|
||||
public void testRunEldParserCore() throws Exception {
|
||||
|
||||
X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
|
||||
X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
//X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
//X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
//EldDriver parser = new EldDriver(true);
|
||||
reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
|
||||
//reader.setProperty(X4OLanguagePropertyKeys.PHASE_SKIP_RELEASE, true);
|
||||
try {
|
||||
X4OLanguageModule module = reader.readResource("META-INF/eld/eld-lang.eld");
|
||||
List<String> resultTags = new ArrayList<String>(50);
|
||||
for (ElementNamespaceContext ns:module.getElementNamespaceContexts()) {
|
||||
|
||||
}
|
||||
//X4OLanguageModule module = reader.readResource("META-INF/eld/eld-lang.eld");
|
||||
//List<String> resultTags = new ArrayList<String>(50);
|
||||
//for (ElementNamespaceContext ns:module.getElementNamespaceContexts()) {
|
||||
//
|
||||
//}
|
||||
/*
|
||||
for (Element e:parser.getDriver().getElementLanguage().getRootElement().getAllChilderen()) {
|
||||
//System.out.println("obj: "+e.getElementObject());
|
||||
|
|
@ -117,8 +97,8 @@ public class EldParserTest extends TestCase {
|
|||
public void testRunEldParser() throws Exception {
|
||||
//EldDriver parser = new EldDriver(false);
|
||||
//parser.parseResource("META-INF/test/test-lang.eld");
|
||||
X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
reader.readResource("META-INF/test/test-lang.eld");
|
||||
//X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
|
||||
//X4OReader<X4OLanguageModule> reader = driver.createReader();
|
||||
//reader.readResource("META-INF/test/test-lang.eld");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.test.TestDriver;
|
||||
import org.x4o.xml.test.models.TestObjectRoot;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* X4OWriterAttributeTest tests xml write attribute write order.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 19, 2013
|
||||
*/
|
||||
public class X4OWriterAttributeTest extends TestCase {
|
||||
|
||||
|
||||
private File createOutputFile() throws IOException {
|
||||
File outputFile = File.createTempFile("test-writer-attr", ".xml");
|
||||
outputFile.deleteOnExit();
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
public void testWriteAttrNatural() throws Exception {
|
||||
File outputFile = createOutputFile();
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
X4OWriter<TestObjectRoot> writer = driver.createWriter();
|
||||
|
||||
TestObjectRoot root = reader.readResource("tests/writer/test-attribute-order.xml");
|
||||
writer.writeFile(root, outputFile);
|
||||
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
|
||||
outputFile.delete();
|
||||
|
||||
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
assertTrue(text.contains("TestAttributeOrderChildNatural"+
|
||||
" aaaName=\"NAME_1\" aabName=\"NAME_2\" aacName=\"NAME_3\""+
|
||||
" abaName=\"NAME_4\" abbName=\"NAME_5\" abcName=\"NAME_6\""+
|
||||
" caaName=\"NAME_7\" cabName=\"NAME_8\" cacName=\"NAME_9\""));
|
||||
}
|
||||
|
||||
public void testWriteAttrOrdered() throws Exception {
|
||||
File outputFile = createOutputFile();
|
||||
X4ODriver<TestObjectRoot> driver = TestDriver.getInstance();
|
||||
X4OReader<TestObjectRoot> reader = driver.createReader();
|
||||
X4OWriter<TestObjectRoot> writer = driver.createWriter();
|
||||
|
||||
TestObjectRoot root = reader.readResource("tests/writer/test-attribute-order.xml");
|
||||
writer.writeFile(root, outputFile);
|
||||
String text = new Scanner( outputFile ).useDelimiter("\\A").next();
|
||||
outputFile.delete();
|
||||
|
||||
assertTrue(text.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
assertTrue(text.contains("custom-ordered-child"+
|
||||
" cacName=\"NAME_9\" cabName=\"NAME_8\" caaName=\"NAME_7\""+
|
||||
" abcName=\"NAME_6\" abbName=\"NAME_5\" abaName=\"NAME_4\""+
|
||||
" aaaName=\"NAME_1\" aabName=\"NAME_2\" aacName=\"NAME_3\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -40,10 +40,10 @@ import org.x4o.xml.test.swixml.SwingEngine;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* X4OWriterTest runs parser with debug output.
|
||||
* X4OWriterTest test xml writer output.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Aug 26, 2012
|
||||
* @version 1.0 Apr 28, 2013
|
||||
*/
|
||||
public class X4OWriterTest extends TestCase {
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ package org.x4o.xml.io.sax;
|
|||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXml;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
|
@ -292,4 +293,121 @@ public class ContentWriterXmlTest extends TestCase {
|
|||
assertTrue(e.getMessage().contains("2"));
|
||||
assertTrue(e.getMessage().contains("open"));
|
||||
}
|
||||
|
||||
public void testProcessingInstruction() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "data");
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
String output = outputWriter.toString();
|
||||
assertNull(e);
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test/>"));
|
||||
}
|
||||
|
||||
public void testProcessingInstructionInline() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "data");
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.processingInstruction("target-doc", "data-doc");
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
String output = outputWriter.toString();
|
||||
assertNull(e);
|
||||
assertNotNull(output);
|
||||
assertTrue(output.length()>0);
|
||||
assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test>\n\t<?target-doc data-doc?>\n</test>"));
|
||||
}
|
||||
|
||||
public void testProcessingInstructionTargetXmlPrefix() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("xmlPrefix", "isInvalid");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
assertNotNull(e);
|
||||
assertEquals(SAXException.class, e.getClass());
|
||||
assertTrue(e.getMessage().contains("instruction"));
|
||||
assertTrue(e.getMessage().contains("start with xml"));
|
||||
}
|
||||
|
||||
public void testProcessingInstructionTargetNoneNameChar() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("4Prefix", "isInvalid");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
assertNotNull(e);
|
||||
assertEquals(SAXException.class, e.getClass());
|
||||
assertTrue(e.getMessage().contains("instruction"));
|
||||
assertTrue(e.getMessage().contains("invalid name"));
|
||||
assertTrue(e.getMessage().contains("4Prefix"));
|
||||
}
|
||||
|
||||
public void testProcessingInstructionDataNoneChar() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "isInvalidChar="+0xD800);
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
assertNotNull(e);
|
||||
assertEquals(SAXException.class, e.getClass());
|
||||
assertTrue(e.getMessage().contains("instruction"));
|
||||
assertTrue(e.getMessage().contains("invalid char"));
|
||||
assertTrue(e.getMessage().contains("isInvalidChar=55296"));
|
||||
}
|
||||
|
||||
public void testAttributeValueLongData() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
ContentWriterXml writer = new ContentWriterXml(outputWriter);
|
||||
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
String data = "_FOR_FOO_BAR";
|
||||
String dataValue = "LOOP";
|
||||
for (int i=0;i<15;i++) {
|
||||
atts.addAttribute("", "attr"+i, "", "", dataValue+=data);
|
||||
}
|
||||
writer.startDocument();
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.startElement("", "testNode", "", new AttributesImpl());
|
||||
writer.endElement("", "testNode", "");
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
|
||||
String output = outputWriter.toString();
|
||||
assertNotNull(output);
|
||||
assertTrue(output.split("\n").length==13);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,8 @@
|
|||
*/
|
||||
package org.x4o.xml.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.x4o.xml.X4ODriver;
|
||||
import org.x4o.xml.io.X4OReader;
|
||||
import org.x4o.xml.lang.X4OLanguagePropertyKeys;
|
||||
import org.x4o.xml.test.models.TestObjectRoot;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.io.StringWriter;
|
|||
|
||||
import org.x4o.xml.element.AbstractElement;
|
||||
import org.x4o.xml.element.ElementException;
|
||||
import org.x4o.xml.io.sax.ContentWriterXml;
|
||||
import org.x4o.xml.io.sax.ext.ContentWriterXml;
|
||||
|
||||
/**
|
||||
* InlinePropertiesElement to test
|
||||
|
|
|
|||
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* 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.test.models;
|
||||
|
||||
public class TestAttributeOrderChild extends TestObjectChild {
|
||||
|
||||
private String aaaName = null;
|
||||
private String aabName = null;
|
||||
private String aacName = null;
|
||||
|
||||
private String abaName = null;
|
||||
private String abbName = null;
|
||||
private String abcName = null;
|
||||
|
||||
private String caaName = null;
|
||||
private String cabName = null;
|
||||
private String cacName = null;
|
||||
|
||||
/**
|
||||
* @return the caaName
|
||||
*/
|
||||
public String getCaaName() {
|
||||
return caaName;
|
||||
}
|
||||
/**
|
||||
* @param caaName the caaName to set
|
||||
*/
|
||||
public void setCaaName(String caaName) {
|
||||
this.caaName = caaName;
|
||||
}
|
||||
/**
|
||||
* @return the cabName
|
||||
*/
|
||||
public String getCabName() {
|
||||
return cabName;
|
||||
}
|
||||
/**
|
||||
* @param cabName the cabName to set
|
||||
*/
|
||||
public void setCabName(String cabName) {
|
||||
this.cabName = cabName;
|
||||
}
|
||||
/**
|
||||
* @return the cacName
|
||||
*/
|
||||
public String getCacName() {
|
||||
return cacName;
|
||||
}
|
||||
/**
|
||||
* @param cacName the cacName to set
|
||||
*/
|
||||
public void setCacName(String cacName) {
|
||||
this.cacName = cacName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the aaaName
|
||||
*/
|
||||
public String getAaaName() {
|
||||
return aaaName;
|
||||
}
|
||||
/**
|
||||
* @param aaaName the aaaName to set
|
||||
*/
|
||||
public void setAaaName(String aaaName) {
|
||||
this.aaaName = aaaName;
|
||||
}
|
||||
/**
|
||||
* @return the aabName
|
||||
*/
|
||||
public String getAabName() {
|
||||
return aabName;
|
||||
}
|
||||
/**
|
||||
* @param aabName the aabName to set
|
||||
*/
|
||||
public void setAabName(String aabName) {
|
||||
this.aabName = aabName;
|
||||
}
|
||||
/**
|
||||
* @return the aacName
|
||||
*/
|
||||
public String getAacName() {
|
||||
return aacName;
|
||||
}
|
||||
/**
|
||||
* @param aacName the aacName to set
|
||||
*/
|
||||
public void setAacName(String aacName) {
|
||||
this.aacName = aacName;
|
||||
}
|
||||
/**
|
||||
* @return the abaName
|
||||
*/
|
||||
public String getAbaName() {
|
||||
return abaName;
|
||||
}
|
||||
/**
|
||||
* @param abaName the abaName to set
|
||||
*/
|
||||
public void setAbaName(String abaName) {
|
||||
this.abaName = abaName;
|
||||
}
|
||||
/**
|
||||
* @return the abbName
|
||||
*/
|
||||
public String getAbbName() {
|
||||
return abbName;
|
||||
}
|
||||
/**
|
||||
* @param abbName the abbName to set
|
||||
*/
|
||||
public void setAbbName(String abbName) {
|
||||
this.abbName = abbName;
|
||||
}
|
||||
/**
|
||||
* @return the abcName
|
||||
*/
|
||||
public String getAbcName() {
|
||||
return abcName;
|
||||
}
|
||||
/**
|
||||
* @param abcName the abcName to set
|
||||
*/
|
||||
public void setAbcName(String abcName) {
|
||||
this.abcName = abcName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.test.models;
|
||||
|
||||
public class TestAttributeOrderChildNatural extends TestAttributeOrderChild {
|
||||
|
||||
}
|
||||
|
|
@ -22,8 +22,6 @@
|
|||
*/
|
||||
package org.x4o.xml.test.models;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Bean for property testing.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,41 +45,6 @@ public class SwiXmlDriver extends X4ODriver<Component> {
|
|||
public static final String[] LANGUAGE_VERSIONS = new String[]{LANGUAGE_VERSION_2,LANGUAGE_VERSION_3};
|
||||
public static final String LANGUAGE_EL_SWING_ENGINE = "swingEngine";
|
||||
|
||||
/*
|
||||
* Protected constructor for write schema api.
|
||||
* @param xmlVersion The xml version.
|
||||
|
||||
protected SwiXmlDriver(SwiXmlVersion xmlVersion) {
|
||||
|
||||
// Create language by version
|
||||
super(LANGUAGE_NAME,xmlVersion.getLanguageVersion());
|
||||
|
||||
// Sets empty namespace uri for version 2 xml documents
|
||||
if (SwiXmlVersion.VERSION_2.equals(xmlVersion)) {
|
||||
setProperty(X4OLanguagePropertyKeys.INPUT_EMPTY_NAMESPACE_URI, VERSION_2_NS_URI);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
* Creates an SwiXmlParser with an SwingEngine and a xml version.
|
||||
* @param engine The SwingEngine to parse for.
|
||||
* @param xmlVersion The xml language version to parse.
|
||||
|
||||
public SwiXmlDriver(SwingEngine engine,SwiXmlVersion xmlVersion) {
|
||||
|
||||
// Create language
|
||||
this(xmlVersion);
|
||||
|
||||
// Check engine
|
||||
if (engine==null) {
|
||||
throw new NullPointerException("Can't parse with null SwingEngine.");
|
||||
}
|
||||
|
||||
// Add engine for callback
|
||||
addELBeanInstance(SWING_ENGINE_EL_NAME,engine);
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* Helper for while parsing to get the SwingEngine.
|
||||
* @param elementLanguage The elementLanguage to get the swingEngine out.
|
||||
|
|
@ -91,7 +56,6 @@ public class SwiXmlDriver extends X4ODriver<Component> {
|
|||
return se;
|
||||
}
|
||||
|
||||
|
||||
static public SwiXmlDriver getInstance() {
|
||||
return (SwiXmlDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,13 +142,28 @@
|
|||
<eld:element tag="testObjectParent" objectClass="org.x4o.xml.test.models.TestObjectParent"/>
|
||||
<eld:element tag="testObjectChild" objectClass="org.x4o.xml.test.models.TestObjectChild"/>
|
||||
<eld:element tag="testBeanObjectChild" objectClass="org.x4o.xml.test.models.TestObjectChild">
|
||||
<!--
|
||||
<eld:element tag="testBeanObjectChild" objectClass="org.x4o.xml.models.TestObjectChild" parentNamespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject"/>
|
||||
<eld:elementClass tag="JTextArea" objectClassName="javax.swing.JTextArea"/>
|
||||
<eld:elementClassParentElementClass namespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject"/>
|
||||
<eld:elementClassParentElementClass namespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject2"/>
|
||||
-->
|
||||
<!--
|
||||
<eld:element tag="testBeanObjectChild" objectClass="org.x4o.xml.models.TestObjectChild" parentNamespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject"/>
|
||||
<eld:elementClass tag="JTextArea" objectClassName="javax.swing.JTextArea"/>
|
||||
<eld:elementClassParentElementClass namespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject"/>
|
||||
<eld:elementClassParentElementClass namespace="http://test.x4o.org/eld/iets.eld" elementTag="superObject2"/>
|
||||
-->
|
||||
</eld:element>
|
||||
|
||||
<eld:element objectClass="org.x4o.xml.test.models.TestAttributeOrderChildNatural"/>
|
||||
|
||||
<eld:element id="custom-ordered-child" objectClass="org.x4o.xml.test.models.TestAttributeOrderChild">
|
||||
<eld:attribute id="aaaName" writeOrder="5000"/>
|
||||
<eld:attribute id="aabName" writeOrder="5010"/>
|
||||
<eld:attribute id="aacName" writeOrder="5020"/>
|
||||
<eld:attribute id="abaName" writeOrder="3002"/>
|
||||
<eld:attribute id="abbName" writeOrder="3001"/>
|
||||
<eld:attribute id="abcName" writeOrder="3000"/>
|
||||
<eld:attribute id="caaName" writeOrder="1003"/>
|
||||
<eld:attribute id="cabName" writeOrder="1002"/>
|
||||
<eld:attribute id="cacName" writeOrder="1000"/>
|
||||
</eld:element>
|
||||
|
||||
|
||||
<eld:element tag="JFrame" objectClass="javax.swing.JFrame">
|
||||
<eld:elementParent tag="root" uri="http://test.x4o.org/xml/ns/test-root"/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
<root:root
|
||||
xmlns:root="http://test.x4o.org/xml/ns/test-root"
|
||||
xmlns="http://test.x4o.org/xml/ns/test-lang"
|
||||
>
|
||||
<TestAttributeOrderChildNatural
|
||||
aaaName="NAME_1"
|
||||
aabName="NAME_2"
|
||||
aacName="NAME_3"
|
||||
abaName="NAME_4"
|
||||
abbName="NAME_5"
|
||||
abcName="NAME_6"
|
||||
caaName="NAME_7"
|
||||
cabName="NAME_8"
|
||||
cacName="NAME_9"
|
||||
/>
|
||||
<custom-ordered-child
|
||||
aaaName="NAME_1"
|
||||
aabName="NAME_2"
|
||||
aacName="NAME_3"
|
||||
abaName="NAME_4"
|
||||
abbName="NAME_5"
|
||||
abcName="NAME_6"
|
||||
caaName="NAME_7"
|
||||
cabName="NAME_8"
|
||||
cacName="NAME_9"
|
||||
/>
|
||||
</root:root>
|
||||
Loading…
Add table
Add a link
Reference in a new issue