You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/09/06 14:26:54 UTC
[02/18] temporarily added a patched version of javolution with fast
collections, because the released version has several bugs (see
https://java.net/jira/browse/JAVOLUTION-106 and
https://java.net/jira/browse/JAVOLUTION-105)
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
new file mode 100644
index 0000000..31cf51b
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
@@ -0,0 +1,346 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.sax;
+
+import java.io.IOException;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+/**
+ * SAX2-like interface for reading an XML document using callbacks.
+ *
+ * @author David Megginson
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, June 16, 2005
+ * @see <a href="http://www.saxproject.org"> SAX -- Simple API for XML</a>
+ */
+public interface XMLReader {
+
+ /**
+ * Look up the value of a feature flag.
+ *
+ * <p>The feature name is any fully-qualified URI. It is
+ * possible for an XMLReader to recognize a feature name but
+ * temporarily be unable to return its value.
+ * Some feature values may be available only in specific
+ * contexts, such as before, during, or after a parse.
+ * Also, some feature values may not be programmatically accessible.
+ * (In the case of an adapter for SAX1 {@link org.xml.sax.Parser}, there
+ * is no implementation-independent way to expose whether the underlying
+ * parser is performing validation, expanding external entities,
+ * and so forth.) </p>
+ *
+ * <p>All XMLReaders are required to recognize the
+ * http://xml.org/sax/features/namespaces and the
+ * http://xml.org/sax/features/namespace-prefixes feature names.</p>
+ *
+ * <p>Typical usage is something like this:</p>
+ *
+ * <pre>
+ * XMLReader r = new MySAXDriver();
+ *
+ * // try to activate validation
+ * try {
+ * r.setFeature("http://xml.org/sax/features/validation", true);
+ * } catch (SAXException e) {
+ * System.err.println("Cannot activate validation.");
+ * }
+ *
+ * // register event handlers
+ * r.setContentHandler(new MyContentHandler());
+ * r.setErrorHandler(new MyErrorHandler());
+ *
+ * // parse the first document
+ * try {
+ * r.parse("http://www.foo.com/mydoc.xml");
+ * } catch (IOException e) {
+ * System.err.println("I/O exception reading XML document");
+ * } catch (SAXException e) {
+ * System.err.println("XML exception reading document.");
+ * }
+ * </pre>
+ *
+ * <p>Implementors are free (and encouraged) to invent their own features,
+ * using names built on their own URIs.</p>
+ *
+ * @param name The feature name, which is a fully-qualified URI.
+ * @return The current value of the feature (true or false).
+ * @exception org.xml.sax.SAXNotRecognizedException If the feature
+ * value can't be assigned or retrieved.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the feature name but
+ * cannot determine its value at this time.
+ * @see #setFeature
+ */
+ public boolean getFeature(String name) throws SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+ /**
+ * Set the value of a feature flag.
+ *
+ * <p>The feature name is any fully-qualified URI. It is
+ * possible for an XMLReader to expose a feature value but
+ * to be unable to change the current value.
+ * Some feature values may be immutable or mutable only
+ * in specific contexts, such as before, during, or after
+ * a parse.</p>
+ *
+ * <p>All XMLReaders are required to support setting
+ * http://xml.org/sax/features/namespaces to true and
+ * http://xml.org/sax/features/namespace-prefixes to false.</p>
+ *
+ * @param name The feature name, which is a fully-qualified URI.
+ * @param value The requested value of the feature (true or false).
+ * @exception org.xml.sax.SAXNotRecognizedException If the feature
+ * value can't be assigned or retrieved.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the feature name but
+ * cannot set the requested value.
+ * @see #getFeature
+ */
+ public void setFeature(String name, boolean value)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+ /**
+ * Look up the value of a property.
+ *
+ * <p>The property name is any fully-qualified URI. It is
+ * possible for an XMLReader to recognize a property name but
+ * temporarily be unable to return its value.
+ * Some property values may be available only in specific
+ * contexts, such as before, during, or after a parse.</p>
+ *
+ * <p>XMLReaders are not required to recognize any specific
+ * property names, though an initial core set is documented for
+ * SAX2.</p>
+ *
+ * <p>Implementors are free (and encouraged) to invent their own properties,
+ * using names built on their own URIs.</p>
+ *
+ * @param name The property name, which is a fully-qualified URI.
+ * @return The current value of the property.
+ * @exception org.xml.sax.SAXNotRecognizedException If the property
+ * value can't be assigned or retrieved.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the property name but
+ * cannot determine its value at this time.
+ * @see #setProperty
+ */
+ public Object getProperty(String name) throws SAXNotRecognizedException,
+ SAXNotSupportedException;
+
+ /**
+ * Set the value of a property.
+ *
+ * <p>The property name is any fully-qualified URI. It is
+ * possible for an XMLReader to recognize a property name but
+ * to be unable to change the current value.
+ * Some property values may be immutable or mutable only
+ * in specific contexts, such as before, during, or after
+ * a parse.</p>
+ *
+ * <p>XMLReaders are not required to recognize setting
+ * any specific property names, though a core set is defined by
+ * SAX2.</p>
+ *
+ * <p>This method is also the standard mechanism for setting
+ * extended handlers.</p>
+ *
+ * @param name The property name, which is a fully-qualified URI.
+ * @param value The requested value for the property.
+ * @exception org.xml.sax.SAXNotRecognizedException If the property
+ * value can't be assigned or retrieved.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the property name but
+ * cannot set the requested value.
+ */
+ public void setProperty(String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException;
+
+ ////////////////////////////////////////////////////////////////////
+ // Event handlers.
+ ////////////////////////////////////////////////////////////////////
+
+ /**
+ * Allow an application to register an entity resolver.
+ *
+ * <p>If the application does not register an entity resolver,
+ * the XMLReader will perform its own default resolution.</p>
+ *
+ * <p>Applications may register a new or different resolver in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * resolver immediately.</p>
+ *
+ * @param resolver The entity resolver.
+ * @see #getEntityResolver
+ */
+ public void setEntityResolver(EntityResolver resolver);
+
+ /**
+ * Return the current entity resolver.
+ *
+ * @return The current entity resolver, or null if none
+ * has been registered.
+ * @see #setEntityResolver
+ */
+ public EntityResolver getEntityResolver();
+
+ /**
+ * Allow an application to register a DTD event handler.
+ *
+ * <p>If the application does not register a DTD handler, all DTD
+ * events reported by the SAX parser will be silently ignored.</p>
+ *
+ * <p>Applications may register a new or different handler in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * handler immediately.</p>
+ *
+ * @param handler The DTD handler.
+ * @see #getDTDHandler
+ */
+ public void setDTDHandler(DTDHandler handler);
+
+ /**
+ * Return the current DTD handler.
+ *
+ * @return The current DTD handler, or null if none
+ * has been registered.
+ * @see #setDTDHandler
+ */
+ public DTDHandler getDTDHandler();
+
+ /**
+ * Allow an application to register a content event handler.
+ *
+ * <p>If the application does not register a content handler, all
+ * content events reported by the SAX parser will be silently
+ * ignored.</p>
+ *
+ * <p>Applications may register a new or different handler in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * handler immediately.</p>
+ *
+ * @param handler The content handler.
+ * @see #getContentHandler
+ */
+ public void setContentHandler(ContentHandler handler);
+
+ /**
+ * Return the current content handler.
+ *
+ * @return The current content handler, or null if none
+ * has been registered.
+ * @see #setContentHandler
+ */
+ public ContentHandler getContentHandler();
+
+ /**
+ * Allow an application to register an error event handler.
+ *
+ * <p>If the application does not register an error handler, all
+ * error events reported by the SAX parser will be silently
+ * ignored; however, normal processing may not continue. It is
+ * highly recommended that all SAX applications implement an
+ * error handler to avoid unexpected bugs.</p>
+ *
+ * <p>Applications may register a new or different handler in the
+ * middle of a parse, and the SAX parser must begin using the new
+ * handler immediately.</p>
+ *
+ * @param handler The error handler.
+ * @see #getErrorHandler
+ */
+ public void setErrorHandler(ErrorHandler handler);
+
+ /**
+ * Return the current error handler.
+ *
+ * @return The current error handler, or null if none
+ * has been registered.
+ * @see #setErrorHandler
+ */
+ public ErrorHandler getErrorHandler();
+
+ ////////////////////////////////////////////////////////////////////
+ // Parsing.
+ ////////////////////////////////////////////////////////////////////
+
+ /**
+ * Parse an XML document.
+ *
+ * <p>The application can use this method to instruct the XML
+ * reader to begin parsing an XML document from any valid input
+ * source (a character stream, a byte stream, or a URI).</p>
+ *
+ * <p>Applications may not invoke this method while a parse is in
+ * progress (they should create a new XMLReader instead for each
+ * nested XML document). Once a parse is complete, an
+ * application may reuse the same XMLReader object, possibly with a
+ * different input source.
+ * Configuration of the XMLReader object (such as handler bindings and
+ * values established for feature flags and properties) is unchanged
+ * by completion of a parse, unless the definition of that aspect of
+ * the configuration explicitly specifies other behavior.
+ * (For example, feature flags or properties exposing
+ * characteristics of the document being parsed.)
+ * </p>
+ *
+ * <p>During the parse, the XMLReader will provide information
+ * about the XML document through the registered event
+ * handlers.</p>
+ *
+ * <p>This method is synchronous: it will not return until parsing
+ * has ended. If a client application wants to terminate
+ * parsing early, it should throw an exception.</p>
+ *
+ * @param input The input source for the top-level of the
+ * XML document.
+ * @exception org.xml.sax.SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception j2me.io.IOException An IO exception from the parser,
+ * possibly from a byte stream or character stream
+ * supplied by the application.
+ * @see org.xml.sax.InputSource
+ * @see #setEntityResolver
+ * @see #setDTDHandler
+ * @see #setContentHandler
+ * @see #setErrorHandler
+ */
+ public void parse(InputSource input) throws IOException, SAXException;
+
+ /**
+ * Parse an XML document from a system identifier (URI).
+ *
+ * <p>This method is a shortcut for the common case of reading a
+ * document from a system identifier. It is the exact
+ * equivalent of the following:</p>
+ *
+ * <pre>
+ * parse(new InputSource(systemId));
+ * </pre>
+ *
+ * <p>If the system identifier is a URL, it must be fully resolved
+ * by the application before it is passed to the parser.</p>
+ *
+ * @param systemId The system identifier (URI).
+ * @exception org.xml.sax.SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception j2me.io.IOException An IO exception from the parser,
+ * possibly from a byte stream or character stream
+ * supplied by the application.
+ * @see #parse(org.xml.sax.InputSource)
+ */
+ public void parse(String systemId) throws IOException, SAXException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
new file mode 100644
index 0000000..12cdf26
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
@@ -0,0 +1,363 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.sax;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import javolution.text.CharArray;
+import javolution.xml.internal.stream.XMLStreamReaderImpl;
+import javolution.xml.stream.XMLStreamConstants;
+import javolution.xml.stream.XMLStreamException;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+/**
+ * <p> This class provides a real-time SAX2-like XML parser; this parser is
+ * <i>extremely</i> fast and <b>does not create temporary objects</b>
+ * (no garbage generated and no GC interruption).</p>
+ *
+ * <p> The parser is implemented as a SAX2 wrapper around
+ * {@link XMLStreamReaderImpl} and share the same characteristics.</p>
+ *
+ * <p><i> Note: This parser is a <b>SAX2-like</b> parser with the
+ * <code>java.lang.String</code> type replaced by
+ * {@link CharArray}/{@link CharSequence} in the {@link ContentHandler},
+ * {@link Attributes} interfaces and {@link DefaultHandler} base class.
+ * If a standard SAX2 or JAXP parser is required, you may consider using
+ * the wrapping class {@link SAX2ReaderImpl}. Fast but not as fast as
+ * <code>java.lang.String</code> instances are dynamically allocated
+ * while parsing.</i></p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, June 16, 2006
+ */
+public class XMLReaderImpl implements XMLReader {
+
+ /**
+ * Holds the default handler instance.
+ */
+ private static DefaultHandler DEFAULT_HANDLER = new DefaultHandler();
+
+ /**
+ * Holds the content handler.
+ */
+ private ContentHandler _contentHandler;
+
+ /**
+ * Holds the error handler.
+ */
+ private ErrorHandler _errorHandler;
+
+ /**
+ * Holds reusable StAX reader.
+ */
+ private final XMLStreamReaderImpl _xmlReader = new XMLStreamReaderImpl();
+
+ /**
+ * Default constructor.
+ */
+ public XMLReaderImpl() {
+ // Sets default handlers.
+ setContentHandler(DEFAULT_HANDLER);
+ setErrorHandler(DEFAULT_HANDLER);
+ }
+
+ /**
+ * Parses an XML document from the specified input stream
+ * (encoding retrieved from input source and the XML prolog if any).
+ *
+ * @param in the input stream with unknown encoding.
+ * @throws org.xml.sax.SAXException any SAX exception, possibly
+ * wrapping another exception.
+ * @throws IOException an IO exception from the parser,
+ * possibly from a byte stream or character stream
+ * supplied by the application.
+ */
+ public void parse(InputStream in) throws IOException, SAXException {
+ try {
+ _xmlReader.setInput(in);
+ parseAll();
+ } catch (XMLStreamException e) {
+ if (e.getNestedException() instanceof IOException)
+ throw (IOException) e.getNestedException();
+ throw new SAXException(e.getMessage());
+ } finally {
+ _xmlReader.reset();
+ }
+ }
+
+ /**
+ * Parses an XML document from the specified input stream and encoding.
+ *
+ * @param in the input stream.
+ * @param encoding the input stream encoding.
+ * @throws org.xml.sax.SAXException any SAX exception, possibly
+ * wrapping another exception.
+ * @throws IOException an IO exception from the parser,
+ * possibly from a byte stream or character stream
+ * supplied by the application.
+ */
+ public void parse(InputStream in, String encoding) throws IOException,
+ SAXException {
+ try {
+ _xmlReader.setInput(in, encoding);
+ parseAll();
+ } catch (XMLStreamException e) {
+ if (e.getNestedException() instanceof IOException)
+ throw (IOException) e.getNestedException();
+ throw new SAXException(e.getMessage());
+ } finally {
+ _xmlReader.reset();
+ }
+ }
+
+ /**
+ * Parses an XML document using the specified reader.
+ *
+ * @param reader the document reader.
+ * @throws SAXException any SAX exception, possibly wrapping another
+ * exception.
+ * @throws IOException an IO exception from the parser, possibly from
+ * a byte stream or character stream supplied by the application.
+ * @see javolution.io.UTF8StreamReader
+ * @see javolution.io.UTF8ByteBufferReader
+ * @see javolution.io.CharSequenceReader
+ */
+ public void parse(Reader reader) throws IOException, SAXException {
+ try {
+ _xmlReader.setInput(reader);
+ parseAll();
+ } catch (XMLStreamException e) {
+ if (e.getNestedException() instanceof IOException)
+ throw (IOException) e.getNestedException();
+ throw new SAXException(e.getMessage());
+ } finally {
+ _xmlReader.reset();
+ }
+ }
+
+ // Implements XMLReader interface.
+ public void parse(InputSource input) throws IOException, SAXException {
+ Reader reader = input.getCharacterStream();
+ if (reader != null) {
+ parse(reader);
+ } else {
+ InputStream inStream = input.getByteStream();
+ if (inStream != null) {
+ parse(inStream, input.getEncoding());
+ } else {
+ parse(input.getSystemId());
+ }
+ }
+ }
+
+ // Implements XMLReader interface.
+ public void parse(String systemId) throws IOException, SAXException {
+ InputStream inStream;
+ try {
+ URL url = new URL(systemId);
+ inStream = url.openStream();
+ } catch (Exception urlException) { // Try as filename.
+ try {
+ inStream = new FileInputStream(systemId);
+ } catch (Exception fileException) {
+ throw new UnsupportedOperationException("Cannot parse "
+ + systemId);
+ }
+ }
+ parse(inStream);
+ }
+
+ // Implements XMLReader interface.
+ public void setContentHandler(ContentHandler handler) {
+ if (handler != null) {
+ _contentHandler = handler;
+ } else {
+ throw new NullPointerException();
+ }
+ }
+
+ // Implements XMLReader interface.
+ public ContentHandler getContentHandler() {
+ return (_contentHandler == DEFAULT_HANDLER) ? null : _contentHandler;
+ }
+
+ // Implements XMLReader interface.
+ public void setErrorHandler(ErrorHandler handler) {
+ if (handler != null) {
+ _errorHandler = handler;
+ } else {
+ throw new NullPointerException();
+ }
+ }
+
+ // Implements XMLReader interface.
+ public ErrorHandler getErrorHandler() {
+ return (_errorHandler == DEFAULT_HANDLER) ? null : _errorHandler;
+ }
+
+ // Implements XMLReader interface.
+ public boolean getFeature(String name) throws SAXNotRecognizedException,
+ SAXNotSupportedException {
+ if (name.equals("http://xml.org/sax/features/namespaces")) {
+ return true;
+ } else if (name
+ .equals("http://xml.org/sax/features/namespace-prefixes")) {
+ return true;
+ } else {
+ throw new SAXNotRecognizedException("Feature " + name
+ + " not recognized");
+ }
+ }
+
+ public void setFeature(String name, boolean value)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
+ if (name.equals("http://xml.org/sax/features/namespaces")
+ || name.equals("http://xml.org/sax/features/namespace-prefixes")) {
+ return; // Ignores, these features are always set.
+ } else {
+ throw new SAXNotRecognizedException("Feature " + name
+ + " not recognized");
+ }
+ }
+
+ public Object getProperty(String name) throws SAXNotRecognizedException,
+ SAXNotSupportedException {
+ throw new SAXNotRecognizedException("Property " + name
+ + " not recognized");
+ }
+
+ public void setProperty(String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException {
+ throw new SAXNotRecognizedException("Property " + name
+ + " not recognized");
+ }
+
+ public void setEntityResolver(EntityResolver resolver) {
+ _entityResolver = resolver;
+ }
+
+ private EntityResolver _entityResolver;
+
+ public EntityResolver getEntityResolver() {
+ return _entityResolver;
+ }
+
+ public void setDTDHandler(DTDHandler handler) {
+ _dtdHandler = handler;
+ }
+
+ private DTDHandler _dtdHandler;
+
+ public DTDHandler getDTDHandler() {
+ return _dtdHandler;
+ }
+
+ // Implements Reusable.
+ public void reset() {
+ setContentHandler(DEFAULT_HANDLER);
+ setErrorHandler(DEFAULT_HANDLER);
+ _xmlReader.reset();
+ }
+
+ /**
+ * Parses the whole document using the real-time pull parser.
+ *
+ * @throws SAXException any SAX exception, possibly wrapping another
+ * exception.
+ * @throws IOException an IO exception from the parser, possibly from
+ * a byte stream or character stream supplied by the application.
+ */
+ private void parseAll() throws XMLStreamException, SAXException {
+ int eventType = _xmlReader.getEventType();
+ if (eventType != XMLStreamConstants.START_DOCUMENT)
+ throw new SAXException("Currently parsing");
+ _contentHandler.startDocument();
+
+ boolean doContinue = true;
+ while (doContinue) {
+ CharArray uri, localName, qName, prefix, text;
+ switch (_xmlReader.next()) {
+ case XMLStreamConstants.START_ELEMENT:
+
+ // Start prefix mapping.
+ for (int i = 0, count = _xmlReader.getNamespaceCount(); i < count; i++) {
+ prefix = _xmlReader.getNamespacePrefix(i);
+ prefix = (prefix == null) ? NO_CHAR : prefix; // Default namespace is ""
+ uri = _xmlReader.getNamespaceURI(i);
+ _contentHandler.startPrefixMapping(prefix, uri);
+ }
+
+ // Start element.
+ uri = _xmlReader.getNamespaceURI();
+ uri = (uri == null) ? NO_CHAR : uri;
+ localName = _xmlReader.getLocalName();
+ qName = _xmlReader.getQName();
+ _contentHandler.startElement(uri, localName, qName,
+ _xmlReader.getAttributes());
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+
+ // End element.
+ uri = _xmlReader.getNamespaceURI();
+ uri = (uri == null) ? NO_CHAR : uri;
+ localName = _xmlReader.getLocalName();
+ qName = _xmlReader.getQName();
+ _contentHandler.endElement(uri, localName, qName);
+
+ // End prefix mapping.
+ for (int i = 0, count = _xmlReader.getNamespaceCount(); i < count; i++) {
+ prefix = _xmlReader.getNamespacePrefix(i);
+ prefix = (prefix == null) ? NO_CHAR : prefix; // Default namespace is ""
+ _contentHandler.endPrefixMapping(prefix);
+ }
+ break;
+
+ case XMLStreamConstants.CDATA:
+ case XMLStreamConstants.CHARACTERS:
+ text = _xmlReader.getText();
+ _contentHandler.characters(text.array(), text.offset(),
+ text.length());
+ break;
+
+ case XMLStreamConstants.SPACE:
+ text = _xmlReader.getText();
+ _contentHandler.ignorableWhitespace(text.array(),
+ text.offset(), text.length());
+ break;
+
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ _contentHandler.processingInstruction(
+ _xmlReader.getPITarget(), _xmlReader.getPIData());
+ break;
+
+ case XMLStreamConstants.COMMENT:
+ // Ignores.
+ break;
+
+ case XMLStreamConstants.END_DOCUMENT:
+ doContinue = false;
+ _xmlReader.close();
+ break;
+
+ }
+ }
+ }
+
+ private static final CharArray NO_CHAR = new CharArray("");
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
new file mode 100644
index 0000000..b418101
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
@@ -0,0 +1,8 @@
+/**
+<p> {@link javolution.xml.sax.SAX2ReaderImpl SAX2} and high-performance
+ {@link javolution.xml.sax.XMLReaderImpl SAX2-Like} parsers. The later
+ being several times faster than conventional SAX2 parsers (by avoiding
+ <code>String</code> allocations while parsing).</p>
+ */
+package javolution.xml.sax;
+
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
new file mode 100644
index 0000000..c89a30f
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
@@ -0,0 +1,56 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+/**
+ * Provides information on the location of an event.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 3.8, May 22, 2006
+ */
+public interface Location {
+
+ /**
+ * Return the line number where the current event ends,
+ * returns -1 if none is available.
+ * @return the current line number
+ */
+ int getLineNumber();
+
+ /**
+ * Return the column number where the current event ends,
+ * returns -1 if none is available.
+ * @return the current column number
+ */
+ int getColumnNumber();
+
+ /**
+ * Return the byte or character offset into the input source this location
+ * is pointing to. If the input source is a file or a byte stream then
+ * this is the byte offset into that stream, but if the input source is
+ * a character media then the offset is the character offset.
+ * Returns -1 if there is no offset available.
+ *
+ * @return the current offset
+ */
+ int getCharacterOffset();
+
+ /**
+ * Returns the public ID of the XML
+ *
+ * @return the public ID, or null if not available
+ */
+ public String getPublicId();
+
+ /**
+ * Returns the system ID of the XML
+ * @return the system ID, or null if not available
+ */
+ public String getSystemId();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
new file mode 100644
index 0000000..040e8f5
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
@@ -0,0 +1,55 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+import java.util.Iterator;
+import javolution.text.CharArray;
+
+/**
+ * This interface represents the XML namespace context stack while parsing.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, September 12, 2006
+ */
+public interface NamespaceContext {
+
+ /**
+ * Returns the namespace URI bound to a prefix in the current scope
+ * or <code>null</code> if the prefix is unbound.
+ *
+ * @param prefix prefix to look up
+ * @return the namespace URI.
+ * @throws IllegalArgumentException if <code>prefix</code> is
+ * <code>null</code>
+ */
+ CharArray getNamespaceURI(CharSequence prefix);
+
+ /**
+ * Returns the prefix bound to the namespace URI in the current scope
+ * or <code>null</code> if the namespace URI is unbound.
+ *
+ * @param namespaceURI URI of the namespace to lookup.
+ * @return the prefix bound to the namespace URI.
+ * @throws IllegalArgumentException if <code>namespaceURI</code> is
+ * <code>null</code>
+ */
+ CharArray getPrefix(CharSequence namespaceURI);
+
+ /**
+ * Returns all prefixes bound to a namespace URI in the current scope
+ * (including predefined prefixes).
+ *
+ * @param namespaceURI URI of Namespace to lookup
+ * @return an <code>Iterator</code> over {@link CharArray} prefixes.
+ * @throws IllegalArgumentException if <code>namespaceURI</code> is
+ * <code>null</code>
+ */
+ Iterator<CharArray> getPrefixes(CharSequence namespaceURI);
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
new file mode 100644
index 0000000..0ffd10c
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
@@ -0,0 +1,150 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import javolution.lang.Parallelizable;
+
+/**
+ * <p> The OSGi factory service to create {@link XMLStreamReader} instances.
+ * For each bundle, a distinct factory instance is returned and can be
+ * individually configured (if not enough the factory can be
+ * {@link #clone cloned}).
+ * [code]
+ * import javolution.xml.stream.*;
+ * public class Activator implements BundleActivator {
+ * public void start(BundleContext bc) throws Exception {
+ *
+ * // Configures factory.
+ * ServiceTracker<XMLInputFactory, XMLInputFactory> tracker
+ * = new ServiceTracker<>(bc, XMLInputFactory.class, null);
+ * tracker.open();
+ * tracker.getService().setProperty(IS_COALESCING, true);
+ *
+ * // Instantiates a reader.
+ * String xml = "<test>This is a test</test>";
+ * CharSequenceReader in = new CharSequenceReader().setInput(xml);
+ * XMLStreamReader reader = tracker.getService().createXMLStreamReader(in);
+ *
+ * // Parses XML.
+ * while (reader.hasNext()) {
+ * int eventType = reader.next();
+ * if (eventType == XMLStreamConstants.CHARACTERS) {
+ * System.out.println(reader.getText());
+ * }
+ * }
+ *
+ * // Closes the reader which may be recycled back to the factory.
+ * reader.close();
+ * }
+ * }[/code]</p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+@Parallelizable(comment="Factory configuration should be performed sequentially.")
+public interface XMLInputFactory extends Cloneable {
+
+ /**
+ * The property that requires the parser to coalesce adjacent character data
+ * sections.
+ */
+ public static final String IS_COALESCING = "javolution.xml.stream.isCoalescing";
+
+ /**
+ * The property that requires the parser to validate the input data.
+ */
+ public static final String IS_VALIDATING = "javolution.xml.stream.isValidating";
+
+ /**
+ * Property used to specify additional entities to be recognized by the
+ * readers (type: <code>java.util.Map</code>, default: <code>null</code>).
+ * For example:[code]
+ * FastMap<String, String> HTML_ENTITIES = new FastMap<String, String>();
+ * HTML_ENTITIES.put("nbsp", " ");
+ * HTML_ENTITIES.put("copy", "©");
+ * HTML_ENTITIES.put("eacute", "é");
+ * ...
+ * XMLInputFactory factory = factoryRef.getService();
+ * factory.setProperty(ENTITIES, HTML_ENTITIES);
+ * [/code]
+ */
+ public static final String ENTITIES = "javolution.xml.stream.entities";
+
+ /**
+ * Returns a XML stream reader for the specified I/O reader.
+ *
+ * @param reader the XML data to read from.
+ * @throws XMLStreamException
+ */
+ XMLStreamReader createXMLStreamReader(Reader reader)
+ throws XMLStreamException;
+
+ /**
+ * Returns a XML stream reader for the specified input stream
+ * (encoding autodetected).
+ *
+ * @param stream the input stream to read from.
+ * @return a xml stream reader possibly recycled.
+ * @throws XMLStreamException
+ */
+ XMLStreamReader createXMLStreamReader(InputStream stream)
+ throws XMLStreamException;
+
+ /**
+ * Returns a XML stream reader for the specified input stream using the
+ * specified encoding.
+ *
+ * @param stream the input stream to read from.
+ * @param encoding the character encoding of the stream.
+ * @return a xml stream reader possibly recycled.
+ * @throws XMLStreamException
+ */
+ XMLStreamReader createXMLStreamReader(InputStream stream,
+ String encoding) throws XMLStreamException;
+
+ /**
+ * Allows the user to set specific feature/property on the underlying
+ * implementation. The underlying implementation is not required to support
+ * every setting of every property in the specification and may use
+ * <code>IllegalArgumentException</code> to signal that an unsupported
+ * property may not be set with the specified value.
+ *
+ * @param name the name of the property.
+ * @param value the value of the property
+ * @throws IllegalArgumentException if the property is not supported.
+ */
+ void setProperty(String name, Object value) throws IllegalArgumentException;
+
+ /**
+ * Gets the value of a feature/property from the underlying implementation.
+ *
+ * @param name the name of the property (may not be null).
+ * @return the value of the property.
+ * @throws IllegalArgumentException if the property is not supported.
+ */
+ Object getProperty(String name) throws IllegalArgumentException;
+
+ /**
+ * Queries the set of properties that this factory supports.
+ *
+ * @param name the name of the property.
+ * @return <code>true</code> if the property is supported;
+ * <code>false</code> otherwise.
+ */
+ boolean isPropertySupported(String name);
+
+ /**
+ * Returns a clone of this factory which can be independently configured.
+ */
+ XMLInputFactory clone();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
new file mode 100644
index 0000000..8f93138
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
@@ -0,0 +1,169 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+import java.io.OutputStream;
+import java.io.Writer;
+
+import javolution.lang.Parallelizable;
+
+/**
+ * <p> The OSGi factory service to create {@link XMLStreamWriter} instances.
+ * For each bundle, a distinct factory instance is returned and can be
+ * individually configured (if not enough the factory can be
+ * {@link #clone cloned}).
+ * [code]
+ * import javolution.xml.stream.*;
+ * public class Activator implements BundleActivator {
+ * public void start(BundleContext bc) throws Exception {
+ *
+ * // Configures factory.
+ * ServiceTracker<XMLOutputFactory, XMLOutputFactory> tracker
+ * = new ServiceTracker<>(bc, XMLOutputFactory.class, null);
+ * tracker.open();
+ * tracker.getService().setProperty(XMLOutputFactory.INDENTATION, "/t"); // Use tab for indentations.
+ *
+ * // Instantiates a new writer.
+ * TextBuilder xml = new TextBuilder();
+ * AppendableWriter out = new AppendableWriter(xml);
+ * XMLStreamWriter writer = tracker.getService().createXMLStreamWriter(out);
+ *
+ * // Formats to XML.
+ * writer.writeStartDocument("1.0");
+ * writer.writeCharacters("\n");
+ * writer.writeStartElement("ns1", "sample", "http://www.e.com/ns1");
+ * writer.writeNamespace("ns1", "http://www.e.com/ns1");
+ * writer.writeEndElement();
+ * writer.writeEndDocument();
+ *
+ * // Closes the writer which may be recycled back to the factory.
+ * writer.close();
+ *
+ * // Displays the formatted output.
+ * System.out.println(xml);
+ * }
+ * [/code]</p>
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+@Parallelizable(comment="Factory configuration should be performed sequentially.")
+public interface XMLOutputFactory extends Cloneable {
+
+ /**
+ * Property used to set prefix defaulting on the output side
+ * (type: <code>Boolean</code>, default: <code>FALSE</code>).
+ */
+ public static final String IS_REPAIRING_NAMESPACES = "javolution.xml.stream.isRepairingNamespaces";
+
+ /**
+ * Property used to specify the prefix to be appended by a trailing
+ * part (a sequence number) in order to make it unique to be usable as
+ * a temporary non-colliding prefix when repairing namespaces
+ * (type: <code>String</code>, default: <code>"ns"</code>).
+ */
+ public final static String REPAIRING_PREFIX = "javolution.xml.stream.repairingPrefix";
+
+ /**
+ * Property used to specify an indentation string; non-null indentation
+ * forces the writer to write elements into separate lines
+ * (type: <code>String</code>, default: <code>null</code>).
+ */
+ public static final String INDENTATION = "javolution.xml.stream.indentation";
+
+ /**
+ * Property used to specify the new line characters
+ * (type: <code>String</code>, default: <code>"\n"</code>).
+ */
+ public static final String LINE_SEPARATOR = "javolution.xml.stream.lineSeparator";
+
+ /**
+ * Property indicating if the stream writers are allowed to automatically
+ * output empty elements when a start element is immediately followed by
+ * matching end element
+ * (type: <code>Boolean</code>, default: <code>FALSE</code>).
+ */
+ public final static String AUTOMATIC_EMPTY_ELEMENTS = "javolution.xml.stream.automaticEmptyElements";
+
+ /**
+ * Property indicating if the stream writers are not allowed to use
+ * empty element tags
+ * (type: <code>Boolean</code>, default: <code>FALSE</code>).
+ * When set, this property forces the use of start/end element tag
+ * (e.g. i.e. "<empty />" replaced by "<empty></empty>"),
+ * This property takes precedence over {@link #AUTOMATIC_EMPTY_ELEMENTS}.
+ */
+ public final static String NO_EMPTY_ELEMENT_TAG = "javolution.xml.stream.noEmptyElementTag";
+
+ /**
+ * Returns a XML stream writer to the specified i/o writer.
+ *
+ * @param writer the writer to write to.
+ * @return a xml stream writer possibly recycled.
+ * @throws XMLStreamException
+ */
+ XMLStreamWriter createXMLStreamWriter(Writer writer)
+ throws XMLStreamException;
+
+ /**
+ * Returns a XML stream writer to the specified output stream (UTF-8
+ * encoding).
+ *
+ * @param stream the stream to write to.
+ * @return a xml stream writer possibly recycled.
+ * @throws XMLStreamException
+ */
+ XMLStreamWriter createXMLStreamWriter(OutputStream stream)
+ throws XMLStreamException;
+
+ /**
+ * Returns a XML stream writer to the specified output stream using the
+ * specified encoding.
+ *
+ * @param stream the stream to write to.
+ * @param encoding the encoding to use.
+ * @return a xml stream writer possibly recycled.
+ * @throws XMLStreamException
+ */
+ XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding)
+ throws XMLStreamException;
+
+ /**
+ * Allows the user to set specific features/properties on the underlying
+ * implementation.
+ *
+ * @param name the name of the property.
+ * @param value the value of the property.
+ * @throws IllegalArgumentException if the property is not supported.
+ */
+ void setProperty(String name, Object value) throws IllegalArgumentException;
+
+ /**
+ * Gets a feature/property on the underlying implementation.
+ *
+ * @param name the name of the property
+ * @return the value of the property
+ * @throws IllegalArgumentException if the property is not supported.
+ */
+ Object getProperty(String name) throws IllegalArgumentException;
+
+ /**
+ * Queries the set of properties that this factory supports.
+ *
+ * @param name the name of the property (may not be null).
+ * @return <code>true</code> if the property is supported;
+ * <code>false</code> otherwise.
+ */
+ boolean isPropertySupported(String name);
+
+ /**
+ * Returns a clone of this factory which can be independently configured.
+ */
+ XMLOutputFactory clone();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
new file mode 100644
index 0000000..aef6e60
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
@@ -0,0 +1,98 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+/**
+ * This interface declares the constants used in this API. Numbers in the range
+ * 0 to 256 are reserved for the specification, user defined events must use
+ * event codes outside that range.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, June 16, 2006
+ */
+public interface XMLStreamConstants {
+
+ /**
+ * Indicates an event is a start element.
+ */
+ public static final int START_ELEMENT = 1;
+
+ /**
+ * Indicates an event is an end element.
+ */
+ public static final int END_ELEMENT = 2;
+
+ /**
+ * Indicates an event is a processing instruction.
+ */
+ public static final int PROCESSING_INSTRUCTION = 3;
+
+ /**
+ * Indicates an event is characters.
+ */
+ public static final int CHARACTERS = 4;
+
+ /**
+ * Indicates an event is a comment.
+ */
+ public static final int COMMENT = 5;
+
+ /**
+ * The characters are white space (see [XML], 2.10 "White Space Handling").
+ * Events are only reported as SPACE if they are ignorable white space.
+ * Otherwise they are reported as CHARACTERS.
+ */
+ public static final int SPACE = 6;
+
+ /**
+ * Indicates an event is a start document.
+ */
+ public static final int START_DOCUMENT = 7;
+
+ /**
+ * Indicates an event is an end document.
+ */
+ public static final int END_DOCUMENT = 8;
+
+ /**
+ * Indicates an event is an entity reference.
+ */
+ public static final int ENTITY_REFERENCE = 9;
+
+ /**
+ * Indicates an event is an attribute.
+ */
+ public static final int ATTRIBUTE = 10;
+
+ /**
+ * Indicates an event is a DTD.
+ */
+ public static final int DTD = 11;
+
+ /**
+ * Indicates an event is a CDATA section.
+ */
+ public static final int CDATA = 12;
+
+ /**
+ * Indicates the event is a namespace declaration.
+ */
+ public static final int NAMESPACE = 13;
+
+ /**
+ * Indicates a Notation.
+ */
+ public static final int NOTATION_DECLARATION = 14;
+
+ /**
+ * Indicates a Entity Declaration.
+ */
+ public static final int ENTITY_DECLARATION = 15;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
new file mode 100644
index 0000000..fd449b6
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
@@ -0,0 +1,128 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+/**
+ * This class represents the base exception for unexpected processing errors.
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 3.8, May 22, 2006
+ */
+public class XMLStreamException extends Exception {
+
+ /**
+ * Holds the nested exception if any.
+ */
+ private Throwable _nested;
+
+ /**
+ * Holds the location.
+ */
+ private Location _location;
+
+ /**
+ * Default constructor
+ */
+ public XMLStreamException() {
+ super();
+ }
+
+ /**
+ * Constructs an exception with the assocated message.
+ *
+ * @param msg the message to report.
+ */
+ public XMLStreamException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs an exception with the assocated nested exception.
+ *
+ * @param nested the nested exception.
+ */
+ public XMLStreamException(Throwable nested) {
+ _nested = nested;
+ }
+
+ /**
+ * Constructs an exception with the assocated message and exception.
+ *
+ * @param msg the message to report.
+ * @param nested the nested exception.
+ */
+ public XMLStreamException(String msg, Throwable nested) {
+ super(msg);
+ _nested = nested;
+ }
+
+ /**
+ * Constructs an exception with the assocated message, exception and
+ * location.
+ *
+ * @param msg the message to report.
+ * @param location the location.
+ * @param nested the nested exception.
+ */
+ public XMLStreamException(String msg, Location location, Throwable nested) {
+ super(msg);
+ _nested = nested;
+ _location = location;
+ }
+
+ /**
+ * Constructs an exception with the assocated message, exception and
+ * location.
+ *
+ * @param msg the message to report
+ * @param location the location of the error
+ */
+ public XMLStreamException(String msg, Location location) {
+ super(msg);
+ _location = location;
+ }
+
+ /**
+ * Returns the nested exception.
+ *
+ * @return the nested exception
+ */
+ public Throwable getNestedException() {
+ return _nested;
+ }
+
+ /**
+ * Returns the location of the exception.
+ *
+ * @return the location of the exception or <code>null</code>
+ * if none is available
+ */
+ public Location getLocation() {
+ return _location;
+ }
+
+ /**
+ * Returns the textual representation of this exception.
+ *
+ * @return the string representation of the exception.
+ */
+ public String toString() {
+ String msg = super.toString();
+ if (_location != null) {
+ msg += " (at line " + _location.getLineNumber() + ", column "
+ + _location.getColumnNumber() + ")";
+ }
+ if (_nested != null) {
+ msg += " caused by " + _nested.toString();
+ }
+ return msg;
+ }
+
+ private static final long serialVersionUID = 1L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
new file mode 100644
index 0000000..fd407d6
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
@@ -0,0 +1,604 @@
+/*
+ * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
+ * Copyright (C) 2012 - Javolution (http://javolution.org/)
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software is
+ * freely granted, provided that this notice is preserved.
+ */
+package javolution.xml.stream;
+
+import java.util.NoSuchElementException;
+
+import javolution.text.CharArray;
+
+/**
+ * <p> This interface is similar to
+ * <code>javax.xml.stream.XMLStreamReader</code>; but it does not forces
+ * dynamic allocation when parsing (its methods returns
+ * {@link CharArray CharArray} instances instead of {@link String}).</p>
+ *
+ * <p> Except for the speed (faster) and its real-time characteristics
+ * the usage/behavior is about the same as its StAX counterpart.</p>
+ *
+ * <p> The {@link CharArray CharArray} instances returned by this reader
+ * supports fast primitive conversions as illustrated below.
+ * [code]
+ * // Creates a new reader (potentially recycled).
+ * XMLInputFactory factory = OSGiServices.getXMLInputFactory();
+ * XMLStreamReader reader = factory.createXMLStreamReader(inputStream);
+ *
+ * while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
+ * switch (reader.next()) {
+ * case XMLStreamConstants.START_ELEMENT:
+ * if (reader.getLocalName().equals("Time")) {
+ * // Reads primitive types (int) attributes directly (no memory allocation).
+ * time.hour = reader.getAttributeValue(null, "hour").toInt();
+ * time.minute = reader.getAttributeValue(null, "minute").toInt();
+ * time.second = reader.getAttributeValue(null, "second").toInt();
+ * }
+ * ...
+ * break;
+ * }
+ * }
+ * reader.close(); // Close the reader (does not close underlying input stream).
+ * [/code]
+ *
+ * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 6.0 December 12, 2012
+ */
+public interface XMLStreamReader extends XMLStreamConstants {
+
+ /**
+ * Gets the value of a feature/property from the underlying implementation
+ *
+ * @param name the name of the property.
+ * @return the value of the property.
+ */
+ Object getProperty(String name) throws IllegalArgumentException;
+
+ /**
+ * Gets next parsing event - contiguous character data is returned into a
+ * single chunk.
+ *
+ * By default entity references must be expanded and reported transparently
+ * to the application. An exception will be thrown if an entity reference
+ * cannot be expanded. If element content is empty (i.e. content is "") then
+ * no CHARACTERS event will be reported.
+ *
+ * <p>
+ * Given the following XML:<br>
+ * <foo><!--description-->content
+ * text<![CDATA[<greeting>Hello</greeting>]]>other content</foo><br>
+ * The behavior of calling next() when being on foo will be:<br>
+ * 1- the comment (COMMENT)<br>
+ * 2- then the characters section (CHARACTERS)<br>
+ * 3- then the CDATA section (another CHARACTERS)<br>
+ * 4- then the next characters section (another CHARACTERS)<br>
+ * 5- then the END_ELEMENT<br>
+ *
+ * <p>
+ * <b>NOTE:</b> empty element (such as <tag/>) will be reported with two
+ * separate events: START_ELEMENT, END_ELEMENT - This preserves parsing
+ * equivalency of empty element to <tag></tag>.
+ *
+ * This method will throw an IllegalStateException if it is called after
+ * hasNext() returns false.
+ *
+ * @return the integer code corresponding to the current parse event
+ * @throws NoSuchElementException if this is called when hasNext()
+ * returns false
+ * @throws XMLStreamException if there is an error processing the
+ * underlying XML source
+ */
+ int next() throws XMLStreamException;
+
+ /**
+ * Tests if the current event is of the given type and if the namespace and
+ * name match the current namespace and name of the current event. If the
+ * namespaceURI is null it is not checked for equality, if the localName is
+ * null it is not checked for equality.
+ *
+ * @param type the event type.
+ * @param namespaceURI the uri of the event, may be null.
+ * @param localName the localName of the event, may be null.
+ * @throws XMLStreamException if the required values are not matched.
+ */
+ void require(int type, CharSequence namespaceURI,
+ CharSequence localName) throws XMLStreamException;
+
+ /**
+ * Reads the content of a text-only element, an exception is thrown if this
+ * is not a text-only element. Regardless of the value of
+ * javax.xml.stream.isCoalescing this method always returns coalesced
+ * content. <br />
+ * Precondition: the current event is START_ELEMENT. <br />
+ * Postcondition: the current event is the corresponding END_ELEMENT.
+ *
+ * <br />
+ * The method does the following (implementations are free to optimized but
+ * must do equivalent processing):
+ *
+ * <pre>
+ * if (getEventType() != XMLStreamConstants.START_ELEMENT) {
+ * throw new XMLStreamException(
+ * "parser must be on START_ELEMENT to read next text", getLocation());
+ * }
+ * int eventType = next();
+ * StringBuffer content = new StringBuffer();
+ * while (eventType != XMLStreamConstants.END_ELEMENT) {
+ * if (eventType == XMLStreamConstants.CHARACTERS
+ * || eventType == XMLStreamConstants.CDATA
+ * || eventType == XMLStreamConstants.SPACE
+ * || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
+ * buf.append(getText());
+ * } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+ * || eventType == XMLStreamConstants.COMMENT) {
+ * // skipping
+ * } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
+ * throw new XMLStreamException(
+ * "unexpected end of document when reading element text content",
+ * this);
+ * } else if (eventType == XMLStreamConstants.START_ELEMENT) {
+ * throw new XMLStreamException(
+ * "element text content may not contain START_ELEMENT",
+ * getLocation());
+ * } else {
+ * throw new XMLStreamException("Unexpected event type " + eventType,
+ * getLocation());
+ * }
+ * eventType = next();
+ * }
+ * return buf.toString();
+ * </pre>
+ *
+ * @throws XMLStreamException if the current event is not a START_ELEMENT
+ * or if a non text element is encountered.
+ */
+ CharArray getElementText() throws XMLStreamException;
+
+ /**
+ * Skips any white space (isWhiteSpace() returns true), COMMENT, or
+ * PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached.
+ * If other than white space characters, COMMENT, PROCESSING_INSTRUCTION,
+ * START_ELEMENT, END_ELEMENT are encountered, an exception is thrown. This
+ * method should be used when processing element-only content seperated by
+ * white space.
+ *
+ * <br />
+ * Precondition: none <br />
+ * Postcondition: the current event is START_ELEMENT or END_ELEMENT and
+ * cursor may have moved over any whitespace event.
+ *
+ * <br />
+ * Essentially it does the following (implementations are free to optimized
+ * but must do equivalent processing):
+ *
+ * <pre>
+ * int eventType = next();
+ * while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
+ * || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
+ * // skip whitespace
+ * || eventType == XMLStreamConstants.SPACE
+ * || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+ * || eventType == XMLStreamConstants.COMMENT
+ * ) {
+ * eventType = next();
+ * }
+ * if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
+ * throw new String XMLStreamException("expected start or end tag", getLocation());
+ * }
+ * return eventType;
+ * </pre>
+ *
+ * @return the event type of the element read (START_ELEMENT or END_ELEMENT)
+ * @throws XMLStreamException if the current event is not white space,
+ * PROCESSING_INSTRUCTION, START_ELEMENT or END_ELEMENT
+ * @throws NoSuchElementException if this is called when hasNext()
+ * returns false
+ */
+ int nextTag() throws XMLStreamException;
+
+ /**
+ * Returns true if there are more parsing events and false if there are no
+ * more events. This method will return false if the current state of the
+ * XMLStreamReader is END_DOCUMENT.
+ *
+ * @return true if there are more events, false otherwise.
+ * @throws XMLStreamException if there is a fatal error detecting the next
+ * state.
+ */
+ boolean hasNext() throws XMLStreamException;
+
+ /**
+ * Frees any resources associated with this Reader. This method does not
+ * close the underlying input source.
+ *
+ * @throws XMLStreamException if there are errors freeing associated
+ * resources
+ */
+ void close() throws XMLStreamException;
+
+ /**
+ * Returns the uri for the given prefix. The uri returned depends on the
+ * current state of the processor.
+ *
+ * <p>
+ * <strong>NOTE:</strong>The 'xml' prefix is bound as defined in <a
+ * href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
+ * specification to "http://www.w3.org/XML/1998/namespace".
+ *
+ * <p>
+ * <strong>NOTE:</strong> The 'xmlns' prefix must be resolved to following
+ * namespace <a
+ * href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a>
+ *
+ * @param prefix the prefix to lookup.
+ * @return the uri bound to the given prefix or <code>null</code> if it is
+ * not bound
+ */
+ CharArray getNamespaceURI(CharSequence prefix);
+
+ /**
+ * Indicates if the cursor points to a start tag.
+ *
+ * @return <code>true</code> if the cursor points to a start tag;
+ * <code>false</code> otherwise.
+ */
+ boolean isStartElement();
+
+ /**
+ * Indicates if the cursor points to an end tag.
+ *
+ * @return <code>true</code> if the cursor points to a end tag;
+ * <code>false</code> otherwise.
+ */
+ boolean isEndElement();
+
+ /**
+ * Indicates if the cursor points to character data.
+ *
+ * @return <code>true</code> if the cursor points to character data;
+ * <code>false</code> otherwise.
+ */
+ boolean isCharacters();
+
+ /**
+ * Indicates if the cursor points to character data that consists
+ * of all whitespace.
+ *
+ * @return <code>true</code> if the cursor points to whitespaces;
+ * <code>false</code> otherwise.
+ */
+ boolean isWhiteSpace();
+
+ /**
+ * Returns the normalized attribute value of the attribute with the
+ * namespace and localName.
+ *
+ * @param namespaceURI the namespace of the attribute or <code>null</code>.
+ * @param localName the local name of the attribute.
+ * @return returns the value of the attribute or <code>null</code>.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributeValue(CharSequence namespaceURI,
+ CharSequence localName);
+
+ /**
+ * Returns the count of attributes on this START_ELEMENT, this method is
+ * only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace
+ * definitions. Attribute indices are zero-based.
+ *
+ * @return returns the number of attributes.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ int getAttributeCount();
+
+ /**
+ * Returns the namespace of the attribute at the provided index
+ *
+ * @param index the position of the attribute.
+ * @return the namespace URI or <code>null</code> if no prefix.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributeNamespace(int index);
+
+ /**
+ * Returns the localName of the attribute at the provided index.
+ *
+ * @param index the position of the attribute.
+ * @return the localName of the attribute.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributeLocalName(int index);
+
+ /**
+ * Returns the prefix of this attribute at the provided index
+ *
+ * @param index the position of the attribute.
+ * @return the prefix of the attribute or <code>null</code> if no prefix.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributePrefix(int index);
+
+ /**
+ * Returns the XML type of the attribute at the provided index.
+ *
+ * @param index the position of the attribute
+ * @return the XML type of the attribute.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributeType(int index);
+
+ /**
+ * Returns the value of the attribute at the index.
+ *
+ * @param index the position of the attribute.
+ * @return the attribute value.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ CharArray getAttributeValue(int index);
+
+ /**
+ * Indicates if this attribute was created by default.
+ *
+ * @param index the position of the attribute.
+ * @return <code>true</code> if this is a default attribute;
+ * <code>false</code> otherwise.
+ * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
+ */
+ boolean isAttributeSpecified(int index);
+
+ /**
+ * Returns the count of namespaces declared on this START_ELEMENT or
+ * END_ELEMENT. This method is only valid on a START_ELEMENT, END_ELEMENT or
+ * NAMESPACE. On an END_ELEMENT the count is of the namespaces that are
+ * about to go out of scope. This is the equivalent of the information
+ * reported by SAX callback for an end element event.
+ *
+ * @return returns the number of namespace declarations on this specific
+ * element.
+ * @throws IllegalStateException if not a START_ELEMENT or END_ELEMENT.
+ */
+ int getNamespaceCount();
+
+ /**
+ * Returns the prefix for the namespace declared at the index.
+ *
+ * @param index the position of the namespace declaration.
+ * @return returns the namespace prefix or <code>null</code> if no prefix.
+ * @throws IllegalStateException if this is not a START_ELEMENT,
+ * END_ELEMENT or NAMESPACE.
+ */
+ CharArray getNamespacePrefix(int index);
+
+ /**
+ * Returns the URI for the namespace declared at the index.
+ *
+ * @param index the position of the namespace declaration.
+ * @return returns the namespace uri or <code>null</code> if no prefix.
+ * @throws IllegalStateException if this is not a START_ELEMENT,
+ * END_ELEMENT or NAMESPACE.
+ */
+ CharArray getNamespaceURI(int index);
+
+ /**
+ * Returns a read only namespace context for the current position.
+ *
+ * @return return a namespace context
+ */
+ NamespaceContext getNamespaceContext();
+
+ /**
+ * Returns an integer code that indicates the type of the event the cursor
+ * is pointing to.
+ *
+ * @return the event type.
+ */
+ int getEventType();
+
+ /**
+ * Returns the current value of the parse event as a string, this returns
+ * the string value of a CHARACTERS event, returns the value of a COMMENT,
+ * the replacement value for an ENTITY_REFERENCE, the string value of a
+ * CDATA section, the string value for a SPACE event, or the String value of
+ * the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved,
+ * any character data will be reported as CHARACTERS events.
+ *
+ * @return the current text or <code>null</code>
+ * @throws IllegalStateException if this state is not a valid text state.
+ */
+ CharArray getText();
+
+ /**
+ * Returns an array which contains the characters from this event. This
+ * array should be treated as read-only and transient. I.e. the array will
+ * contain the text characters until the XMLStreamReader moves on to the
+ * next event. Attempts to hold onto the character array beyond that time or
+ * modify the contents of the array are breaches of the contract for this
+ * interface.
+ *
+ * @return the current text or an empty array.
+ * @throws IllegalStateException if this state is not a valid text state.
+ */
+ char[] getTextCharacters();
+
+ /**
+ * Gets the the text associated with a CHARACTERS, SPACE or CDATA event.
+ * Text starting a "sourceStart" is copied into "target" starting at
+ * "targetStart". Up to "length" characters are copied. The number of
+ * characters actually copied is returned.
+ *
+ * The "sourceStart" argument must be greater or equal to 0 and less than or
+ * equal to the number of characters associated with the event. Usually, one
+ * requests text starting at a "sourceStart" of 0. If the number of
+ * characters actually copied is less than the "length", then there is no
+ * more text. Otherwise, subsequent calls need to be made until all text has
+ * been retrieved. For example:
+ *
+ * <code>
+ * int length = 1024;
+ * char[] myBuffer = new char[ length ];
+ *
+ * for ( int sourceStart = 0 ; ; sourceStart += length )
+ * {
+ * int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length );
+ *
+ * if (nCopied < length)
+ * break;
+ * }
+ * </code> XMLStreamException may be thrown
+ * if there are any XML errors in the underlying source. The "targetStart"
+ * argument must be greater than or equal to 0 and less than the length of
+ * "target", Length must be greater than 0 and "targetStart + length" must
+ * be less than or equal to length of "target".
+ *
+ * @param sourceStart the index of te first character in the source array
+ * to copy
+ * @param target the destination array
+ * @param targetStart the start offset in the target array
+ * @param length the number of characters to copy
+ * @return the number of characters actually copied
+ * @throws XMLStreamException if the XML source is not well-formed.
+ * @throws IndexOutOfBoundsException
+ * if targetStart < 0 or > than the length of target
+ * @throws IndexOutOfBoundsException
+ * if length < 0 or targetStart + length > length of target
+ * @throws UnsupportedOperationException if this method is not supported.
+ */
+ int getTextCharacters(int sourceStart, char[] target,
+ int targetStart, int length) throws XMLStreamException;
+
+ /**
+ * Returns the offset into the text character array where the first
+ * character (of this text event) is stored.
+ *
+ * @throws IllegalStateException if this state is not a valid text state.
+ */
+ int getTextStart();
+
+ /**
+ * Returns the length of the sequence of characters for this Text event
+ * within the text character array.
+ *
+ * @throws IllegalStateException if this state is not a valid text state.
+ */
+ int getTextLength();
+
+ /**
+ * Returns the input encoding if known or <code>null</code> if unknown.
+ *
+ * @return the encoding of this instance or null.
+ */
+ String getEncoding();
+
+ /**
+ * Indicates if the current event has text. The following
+ * events have text: CHARACTERS, DTD ,ENTITY_REFERENCE, COMMENT, SPACE.
+ *
+ * @return <code>true</code> if the current event as text;
+ * <code>false</code> otherwise.
+ */
+ boolean hasText();
+
+ /**
+ * Return the current location of the processor. If the Location is unknown
+ * the processor should return an implementation of Location that returns -1
+ * for the location and null for the publicId and systemId. The location
+ * information is only valid until next() is called.
+ *
+ * @return the current location.
+ */
+ Location getLocation();
+
+ /**
+ * Returns the (local) name of the current event. For START_ELEMENT or
+ * END_ELEMENT returns the (local) name of the current element. For
+ * ENTITY_REFERENCE it returns entity name. The current event must be
+ * START_ELEMENT or END_ELEMENT, or ENTITY_REFERENCE.
+ *
+ * @return the localName.
+ * @throws IllegalStateException if this not a START_ELEMENT, END_ELEMENT
+ * or ENTITY_REFERENCE
+ */
+ CharArray getLocalName();
+
+ /**
+ * Indicates if the current event has a name (is a START_ELEMENT or
+ * END_ELEMENT).
+ *
+ * @return <code>true</code> if the current event has a name;
+ * <code>false</code> otherwise.
+ */
+ boolean hasName();
+
+ /**
+ * If the current event is a START_ELEMENT or END_ELEMENT this method
+ * returns the URI of the current element (URI mapping to the prefix
+ * element/attribute has; or if no prefix <code>null</code>).
+ *
+ * @return the URI bound to this elements prefix or <code>null</code>.
+ * @throws IllegalStateException if not a START_ELEMENT, END_ELEMENT
+ * or ATTRIBUTE.
+ */
+ CharArray getNamespaceURI();
+
+ /**
+ * Returns the prefix of the current event or null if the event does not
+ * have a prefix.
+ *
+ * @return the prefix or <code>null</code>
+ * @throws IllegalStateException if not a START_ELEMENT or END_ELEMENT.
+ */
+ CharArray getPrefix();
+
+ /**
+ * Gets the xml version declared on the xml declaration.
+ *
+ * @return the XML version or <code>null</code>
+ */
+ CharArray getVersion();
+
+ /**
+ * Gets the standalone declaration from the xml declaration.
+ *
+ * @return <code>true</code> if this is standalone;
+ * <code>false</code> otherwise.
+ */
+ boolean isStandalone();
+
+ /**
+ * Checks if standalone was set in the document.
+ *
+ * @return <code>true</code> if standalone was set;
+ * <code>false</code> otherwise.
+ */
+ boolean standaloneSet();
+
+ /**
+ * Returns the character encoding declared on the xml declaration.
+ *
+ * @return the encoding declared in the document or <code>null</code>
+ */
+ CharArray getCharacterEncodingScheme();
+
+ /**
+ * Returns the target of a processing instruction.
+ *
+ * @return the target.
+ * @throws IllegalStateException if the current event is not a
+ * {@link XMLStreamConstants#PROCESSING_INSTRUCTION}
+ */
+ CharArray getPITarget();
+
+ /**
+ * Get the data section of a processing instruction.
+ *
+ * @return the data (if processing instruction has any) or
+ * <code>null</code> if the processing instruction only has target.
+ * @throws IllegalStateException if the current event is not a
+ * {@link XMLStreamConstants#PROCESSING_INSTRUCTION}
+ */
+ CharArray getPIData();
+
+}