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:55 UTC

[03/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/internal/stream/XMLStreamWriterImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java
new file mode 100644
index 0000000..4305189
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java
@@ -0,0 +1,939 @@
+/*
+ * 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.internal.stream;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+import javolution.io.UTF8StreamWriter;
+import javolution.lang.Realtime;
+import javolution.text.CharArray;
+import javolution.text.TextBuilder;
+import javolution.xml.stream.XMLOutputFactory;
+import javolution.xml.stream.XMLStreamException;
+import javolution.xml.stream.XMLStreamWriter;
+
+/**
+ * <p> This class represents an implementation of {@link XMLStreamWriter}.</p>
+ *     
+ * <p> The <code>writeCharacters</code> methods will escape &amp; , &lt; and 
+ *     &gt;. For attribute values, the <code>writeAttribute</code> methods will
+ *     escape the above characters plus &quot; and control characters.</p>
+ *     
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, September 4, 2006
+ */
+@Realtime
+public final class XMLStreamWriterImpl implements XMLStreamWriter {
+
+    /** 
+     * Holds the length of intermediate buffer.
+     */
+    private static final int BUFFER_LENGTH = 2048;
+
+    /** 
+     * Holds the current nesting level.
+     */
+    private int _nesting = 0;
+
+    /** 
+     * Holds the element qualified name (indexed per nesting level)
+     */
+    private TextBuilder[] _qNames = new TextBuilder[16];
+
+    /** 
+     * Indicates if the current element is open.
+     */
+    private boolean _isElementOpen;
+
+    /** 
+     * Indicates if the current element is an empty element.
+     */
+    private boolean _isEmptyElement;
+
+    /** 
+     * Holds intermediate buffer.
+     */
+    private final char[] _buffer = new char[BUFFER_LENGTH];
+
+    /** 
+     * Holds the namespace stack.
+     */
+    private final NamespacesImpl _namespaces = new NamespacesImpl();
+
+    /** 
+     * Holds the buffer current index.
+     */
+    private int _index;
+
+    /** 
+     * Holds repairing namespace property.
+     */
+    private boolean _isRepairingNamespaces;
+
+    /** 
+     * Holds repairing prefix property.
+     */
+    private String _repairingPrefix = "ns";
+
+    /** 
+     * Holds indentation property.
+     */
+    private String _indentation;
+
+    /**
+     * Holds line separator property.
+     */
+    private String _lineSeparator = "\n";
+
+    /** 
+     * Holds current indentation level.
+     */
+    private int _indentationLevel;
+
+    /** 
+     * Holds automatic empty elements  property.
+     */
+    private boolean _automaticEmptyElements;
+
+    /** 
+     * Holds no empty element tag property.
+     */
+    private boolean _noEmptyElementTag;
+
+    /** 
+     * Holds counter for automatic namespace generation.
+     */
+    private int _autoNSCount;
+
+    /** 
+     * Indicates if the current object written is an attribute value.
+     */
+    private boolean _isAttributeValue;
+
+    ////////////////////////
+    // Temporary Settings //
+    ////////////////////////
+
+    /** 
+     * Holds the writer destination (<code>null</code> when unused).
+     */
+    private Writer _writer;
+
+    /** 
+     * Holds the encoding  (<code>null</code> if N/A).
+     */
+    private String _encoding;
+
+    /**
+     * Holds the default writer for output streams.
+     */
+    private final UTF8StreamWriter _utf8StreamWriter = new UTF8StreamWriter();
+
+    /**
+     * Holds the factory (if any) 
+     */
+    private final XMLOutputFactoryImpl _factory;
+
+    /** 
+     * Default constructor.
+     */
+    public XMLStreamWriterImpl() {
+        this(null);
+    }
+
+    /** 
+     * Factory-based constructor.
+     */
+    XMLStreamWriterImpl(XMLOutputFactoryImpl factory) {
+        _factory = factory;
+        for (int i = 0; i < _qNames.length;) {
+            _qNames[i++] = new TextBuilder();
+        }
+    }
+
+    /**
+     * Sets the output stream destination for this XML stream writer 
+     * (UTF-8 encoding).
+     *
+     * @param out the output source with utf-8 encoding.
+     */
+    public void setOutput(OutputStream out) throws XMLStreamException {
+        _utf8StreamWriter.setOutput(out);
+        _encoding = "UTF-8";
+        setOutput(_utf8StreamWriter);
+    }
+
+    /**
+     * Sets the output stream destination and encoding for this XML stream 
+     * writer.
+     *
+     * @param out the output source.
+     * @param encoding the associated encoding.
+     * @throws XMLStreamException if the specified encoding is not supported.
+     */
+    public void setOutput(OutputStream out, String encoding)
+            throws XMLStreamException {
+        if (encoding.equals("UTF-8") || encoding.equals("utf-8")
+                || encoding.equals("ASCII")) {
+            setOutput(out); // Default encoding.
+        } else {
+            try {
+                _encoding = encoding;
+                setOutput(new OutputStreamWriter(out, encoding));
+            } catch (UnsupportedEncodingException e) {
+                throw new XMLStreamException(e);
+            }
+        }
+    }
+
+    /**
+     * Sets the writer output destination for this XML stream writer. 
+     *
+     * @param  writer the output destination writer.
+     * @see    javolution.io.UTF8StreamWriter
+     * @see    javolution.io.UTF8ByteBufferWriter
+     * @see    javolution.io.AppendableWriter
+     */
+    public void setOutput(Writer writer) throws XMLStreamException {
+        if (_writer != null)
+            throw new IllegalStateException("Writer not closed or reset");
+        _writer = writer;
+    }
+
+    /** 
+     * Requires this writer to create a new prefix when a namespace has none
+     * (default <code>false</code>).
+     * 
+     * @param isRepairingNamespaces <code>true</code> if namespaces 
+     *        are repaired; <code>false</code> otherwise.
+     */
+    public void setRepairingNamespaces(boolean isRepairingNamespaces) {
+        _isRepairingNamespaces = isRepairingNamespaces;
+    }
+
+    /** 
+     * Specifies the prefix to be append 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
+     * (default <code>"ns"</code>).
+     * 
+     * @param repairingPrefix the prefix root.
+     */
+    public void setRepairingPrefix(String repairingPrefix) {
+        _repairingPrefix = repairingPrefix;
+    }
+
+    /** 
+     * Specifies the indentation string; non-null indentation 
+     * forces the writer to write elements into separate lines
+     * (default <code>null</code>).
+     * 
+     * @param indentation the indentation string.
+     */
+    public void setIndentation(String indentation) {
+        _indentation = indentation;
+    }
+
+    /**
+     * Specifies the line separator (default <code>"\n"</code>).
+     *
+     * @param lineSeparator the line separator string.
+     */
+    public void setLineSeparator(String lineSeparator) {
+        _lineSeparator = lineSeparator;
+    }
+
+    /** 
+     * Requires this writer to automatically output empty elements when a 
+     * start element is immediately followed by matching end element
+     * (default <code>false</code>).
+     * 
+     * @param automaticEmptyElements <code>true</code> if start element 
+     *        immediately followed by end element results in an empty element
+     *        beign written; <code>false</code> otherwise.
+     */
+    public void setAutomaticEmptyElements(boolean automaticEmptyElements) {
+        _automaticEmptyElements = automaticEmptyElements;
+    }
+
+    /** 
+     * Prevent this writer from using empty element tags
+     * (default <code>false</code>).
+     * 
+     * @param noEmptyElementTag <code>true</code> if empty element tags 
+     *        are replaced by start/end elements with no content;
+     *        <code>false</code> otherwise.
+     */
+    public void setNoEmptyElementTag(boolean noEmptyElementTag) {
+        _noEmptyElementTag = noEmptyElementTag;
+    }
+
+    // Implements reusable.
+    public void reset() {
+        _automaticEmptyElements = false;
+        _autoNSCount = 0;
+        _encoding = null;
+        _indentation = null;
+        _indentationLevel = 0;
+        _index = 0;
+        _isAttributeValue = false;
+        _isElementOpen = false;
+        _isEmptyElement = false;
+        _isRepairingNamespaces = false;
+        _namespaces.reset();
+        _nesting = 0;
+        _noEmptyElementTag = false;
+        _repairingPrefix = "ns";
+        _utf8StreamWriter.reset();
+        _writer = null;
+
+        if (_factory != null)
+            _factory.recycle(this);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartElement(CharSequence localName)
+            throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        writeNewElement(null, localName, null);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartElement(CharSequence namespaceURI,
+            CharSequence localName) throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        if (namespaceURI == null)
+            throw new XMLStreamException("Namespace URI cannot be null");
+        writeNewElement(null, localName, namespaceURI);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartElement(CharSequence prefix, CharSequence localName,
+            CharSequence namespaceURI) throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        if (namespaceURI == null)
+            throw new XMLStreamException("Namespace URI cannot be null");
+        if (prefix == null)
+            throw new XMLStreamException("Prefix cannot be null");
+        writeNewElement(prefix, localName, namespaceURI);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEmptyElement(CharSequence localName)
+            throws XMLStreamException {
+        writeStartElement(localName);
+        _isEmptyElement = true;
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEmptyElement(CharSequence namespaceURI,
+            CharSequence localName) throws XMLStreamException {
+        writeStartElement(namespaceURI, localName);
+        _isEmptyElement = true;
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEmptyElement(CharSequence prefix, CharSequence localName,
+            CharSequence namespaceURI) throws XMLStreamException {
+        writeStartElement(prefix, localName, namespaceURI);
+        _isEmptyElement = true;
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEndElement() throws XMLStreamException {
+        if (_isElementOpen) { // Empty element.
+            if (_isEmptyElement) { // Closes the empty element tag.
+                closeOpenTag();
+            } else { // Start element open.
+                if (_automaticEmptyElements) { // Do as if empty element written. 		    
+                    _isEmptyElement = true;
+                    closeOpenTag();
+                    return;
+                } else { // Closes the start element tag.
+                    closeOpenTag();
+                }
+            }
+        }
+        if ((_indentation != null) && (_indentationLevel != _nesting - 1)) {
+            // Do not indent if no change in indentation level
+            // to avoid interfering with text only elements.
+            writeNoEscape(_lineSeparator);
+            for (int i = 1; i < _nesting; i++) {
+                writeNoEscape(_indentation);
+            }
+        }
+
+        write('<');
+        write('/');
+        writeNoEscape(_qNames[_nesting--]);
+        write('>');
+        _namespaces.pop();
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEndDocument() throws XMLStreamException {
+        if (_isElementOpen)
+            closeOpenTag();
+        while (_nesting > 0) { // Implicits closing of all elements.
+            writeEndElement();
+        }
+        flush(); // Not mandatory but safer.
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void close() throws XMLStreamException {
+        if (_writer != null) {
+            if (_nesting != 0) { // Closes all elements.
+                writeEndDocument();
+            }
+            flush();
+        }
+        reset(); // Explicit reset.
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void flush() throws XMLStreamException {
+        flushBuffer();
+        try {
+            _writer.flush();
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeAttribute(CharSequence localName, CharSequence value)
+            throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        if (value == null)
+            throw new XMLStreamException("Value cannot be null");
+        writeAttributeOrNamespace(null, null, localName, value);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeAttribute(CharSequence namespaceURI,
+            CharSequence localName, CharSequence value)
+            throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        if (value == null)
+            throw new XMLStreamException("Value cannot be null");
+        if (namespaceURI == null)
+            throw new XMLStreamException("Namespace URI cannot be null");
+        writeAttributeOrNamespace(null, namespaceURI, localName, value);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeAttribute(CharSequence prefix, CharSequence namespaceURI,
+            CharSequence localName, CharSequence value)
+            throws XMLStreamException {
+        if (localName == null)
+            throw new XMLStreamException("Local name cannot be null");
+        if (value == null)
+            throw new XMLStreamException("Value cannot be null");
+        if (namespaceURI == null)
+            throw new XMLStreamException("Namespace URI cannot be null");
+        if (prefix == null)
+            throw new XMLStreamException("Prefix cannot be null");
+        writeAttributeOrNamespace(prefix, namespaceURI, localName, value);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeNamespace(CharSequence prefix, CharSequence namespaceURI)
+            throws XMLStreamException {
+        if ((prefix == null) || (prefix.length() == 0)
+                || _namespaces._xmlns.equals(prefix)) {
+            prefix = _namespaces._defaultNsPrefix;
+        }
+        if (!_isElementOpen) // Check now as the actual writting is queued.
+            throw new IllegalStateException("No open start element");
+        _namespaces.setPrefix(prefix,
+                (namespaceURI == null) ? _namespaces._nullNsURI : namespaceURI,
+                true);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeDefaultNamespace(CharSequence namespaceURI)
+            throws XMLStreamException {
+        writeNamespace(_namespaces._defaultNsPrefix, namespaceURI);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeComment(CharSequence data) throws XMLStreamException {
+        if (_isElementOpen)
+            closeOpenTag();
+        writeNoEscape("<!--");
+        if (data != null) { // null values allowed.
+            writeNoEscape(data);
+        }
+        writeNoEscape("-->");
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeProcessingInstruction(CharSequence target)
+            throws XMLStreamException {
+        writeProcessingInstruction(target, _noChar);
+    }
+
+    private final CharArray _noChar = new CharArray("");
+
+    // Implements XMLStreamWriter interface.
+    public void writeProcessingInstruction(CharSequence target,
+            CharSequence data) throws XMLStreamException {
+        if (target == null)
+            throw new XMLStreamException("Target cannot be null");
+        if (data == null)
+            throw new XMLStreamException("Data cannot be null");
+        if (_isElementOpen)
+            closeOpenTag();
+        writeNoEscape("<?");
+        writeNoEscape(target);
+        write(' ');
+        writeNoEscape(data);
+        writeNoEscape(" ?>");
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeCData(CharSequence data) throws XMLStreamException {
+        if (data == null)
+            throw new XMLStreamException("Data cannot be null");
+        if (_isElementOpen)
+            closeOpenTag();
+        writeNoEscape("<![CDATA[");
+        writeNoEscape(data);
+        writeNoEscape("]]>");
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeDTD(CharSequence dtd) throws XMLStreamException {
+        if (dtd == null)
+            throw new XMLStreamException("DTD cannot be null");
+        if (_nesting > 0)
+            throw new XMLStreamException(
+                    "DOCTYPE declaration (DTD) when not in document root (prolog)");
+        writeNoEscape(dtd);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeEntityRef(CharSequence name) throws XMLStreamException {
+        write('&');
+        writeNoEscape(name);
+        write(';');
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartDocument() throws XMLStreamException {
+        writeStartDocument(null, null);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartDocument(CharSequence version)
+            throws XMLStreamException {
+        writeStartDocument(null, version);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeStartDocument(CharSequence encoding, CharSequence version)
+            throws XMLStreamException {
+        if (_nesting > 0)
+            throw new XMLStreamException("Not in document root");
+        writeNoEscape("<?xml version=\"");
+        if (version != null) {
+            writeNoEscape(version);
+            write('"');
+        } else { // Default to 1.0
+            writeNoEscape("1.0\"");
+        }
+        if (encoding != null) {
+            writeNoEscape(" encoding=\"");
+            writeNoEscape(encoding);
+            write('"');
+        } else if (_encoding != null) { // Use init encoding (if any).
+            writeNoEscape(" encoding=\"");
+            writeNoEscape(_encoding);
+            write('"');
+        }
+        writeNoEscape(" ?>");
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeCharacters(CharSequence text) throws XMLStreamException {
+        if (_isElementOpen)
+            closeOpenTag();
+        if (text == null)
+            return;
+        writeEscape(text);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void writeCharacters(char[] text, int start, int length)
+            throws XMLStreamException {
+        _tmpCharArray.setArray(text, start, length);
+        writeCharacters(_tmpCharArray);
+    }
+
+    private final CharArray _tmpCharArray = new CharArray();
+
+    // Implements XMLStreamWriter interface.
+    public CharSequence getPrefix(CharSequence uri) throws XMLStreamException {
+        return _namespaces.getPrefix(uri);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void setPrefix(CharSequence prefix, CharSequence uri)
+            throws XMLStreamException {
+        _namespaces.setPrefix(prefix, (uri == null) ? _namespaces._nullNsURI
+                : uri, false);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public void setDefaultNamespace(CharSequence uri) throws XMLStreamException {
+        setPrefix(_namespaces._defaultNsPrefix, uri);
+    }
+
+    // Implements XMLStreamWriter interface.
+    public Object getProperty(String name) throws IllegalArgumentException {
+        if (name.equals(XMLOutputFactory.IS_REPAIRING_NAMESPACES)) {
+            return new Boolean(_isRepairingNamespaces);
+        } else if (name.equals(XMLOutputFactory.REPAIRING_PREFIX)) {
+            return _repairingPrefix;
+        } else if (name.equals(XMLOutputFactory.AUTOMATIC_EMPTY_ELEMENTS)) {
+            return new Boolean(_automaticEmptyElements);
+        } else if (name.equals(XMLOutputFactory.NO_EMPTY_ELEMENT_TAG)) {
+            return new Boolean(_noEmptyElementTag);
+        } else if (name.equals(XMLOutputFactory.INDENTATION)) {
+            return _indentation;
+        } else if (name.equals(XMLOutputFactory.LINE_SEPARATOR)) {
+            return _lineSeparator;
+        } else {
+            throw new IllegalArgumentException("Property: " + name
+                    + " not supported");
+        }
+    }
+
+    // Writes a new start or empty element.
+    private void writeNewElement(CharSequence prefix, CharSequence localName,
+            CharSequence namespaceURI) throws XMLStreamException {
+
+        // Close any open element and gets ready to write a new one.
+        if (_isElementOpen)
+            closeOpenTag();
+        if (_indentation != null) {
+            writeNoEscape(_lineSeparator);
+            _indentationLevel = _nesting;
+            for (int i = 0; i < _indentationLevel; i++) {
+                writeNoEscape(_indentation);
+            }
+        }
+        write('<');
+        _isElementOpen = true;
+
+        // Enters a new local scope.
+        if (++_nesting >= _qNames.length)
+            resizeElemStack();
+        _namespaces.push();
+
+        // Constructs qName.
+        TextBuilder qName = _qNames[_nesting].clear();
+
+        // Writes prefix if any.
+        if ((namespaceURI != null)
+                && (!_namespaces._defaultNamespace.equals(namespaceURI))) {
+            if (_isRepairingNamespaces) { // Repairs prefix.
+                prefix = getRepairedPrefix(prefix, namespaceURI);
+            } else if (prefix == null) { // Retrieves prefix.
+                prefix = getPrefix(namespaceURI);
+                if (prefix == null)
+                    throw new XMLStreamException("URI: " + namespaceURI
+                            + " not bound and repairing namespaces disabled");
+            }
+            if (prefix.length() > 0) {
+                qName.append(prefix);
+                qName.append(':');
+            }
+        }
+        qName.append(localName);
+        writeNoEscape(qName);
+    }
+
+    // Writes a new attribute.
+    private void writeAttributeOrNamespace(CharSequence prefix,
+            CharSequence namespaceURI, CharSequence localName,
+            CharSequence value) throws XMLStreamException {
+        if (!_isElementOpen)
+            throw new IllegalStateException("No open start element");
+        write(' ');
+
+        // Writes prefix if any.
+        if ((namespaceURI != null)
+                && (!_namespaces._defaultNamespace.equals(namespaceURI))) {
+            if (_isRepairingNamespaces) { // Repairs prefix if current prefix is not correct.
+                prefix = getRepairedPrefix(prefix, namespaceURI);
+            } else if (prefix == null) {
+                prefix = getPrefix(namespaceURI);
+                if (prefix == null)
+                    throw new XMLStreamException("URI: " + namespaceURI
+                            + " not bound and repairing namespaces disabled");
+            }
+            if (prefix.length() > 0) {
+                writeNoEscape(prefix);
+                write(':');
+            }
+        }
+
+        writeNoEscape(localName);
+        write('=');
+        write('"');
+        _isAttributeValue = true;
+        writeEscape(value);
+        _isAttributeValue = false;
+        write('"');
+    }
+
+    // Closes the current element (scope if empty element).
+    private void closeOpenTag() throws XMLStreamException {
+
+        // Writes namespaces now.
+        writeNamespaces();
+
+        // Closes the tag.
+        _isElementOpen = false;
+        if (_isEmptyElement) {
+            if (_noEmptyElementTag) {
+                write('<');
+                write('/');
+                writeNoEscape(_qNames[_nesting]);
+                write('>');
+            } else { // Use empty element tag.
+                write('/');
+                write('>');
+            }
+            _nesting--;
+            _namespaces.pop();
+            _isEmptyElement = false;
+        } else {
+            write('>');
+        }
+    }
+
+    // Writes all namespaces, these include namespaces set but 
+    // not written in outer scope.
+    private void writeNamespaces() throws XMLStreamException {
+        int i0 = (_nesting > 1) ? _namespaces._namespacesCount[_nesting - 2]
+                : NamespacesImpl.NBR_PREDEFINED_NAMESPACES;
+        int i1 = _namespaces._namespacesCount[_nesting - 1];
+        int i2 = _namespaces._namespacesCount[_nesting];
+        for (int i = i0; i < i2; i++) {
+            if (((_isRepairingNamespaces && (i < i1) && !_namespaces._prefixesWritten[i]))
+                    || ((i >= i1) && _namespaces._prefixesWritten[i])) { // Write namespace.
+
+                // In repairing mode, removes redondancy.
+                if (_isRepairingNamespaces) {
+                    CharArray prefix = _namespaces.getPrefix(
+                            _namespaces._namespaces[i], i);
+                    if (_namespaces._prefixes[i].equals(prefix))
+                        continue; // Not necessary.
+                } // Direct mode, just write them as requested (no check).
+
+                // Writes namespace.
+                if (_namespaces._prefixes[i].length() == 0) { // Default namespace.
+                    writeAttributeOrNamespace(null, null, _namespaces._xmlns,
+                            _namespaces._namespaces[i]);
+                } else {
+                    writeAttributeOrNamespace(_namespaces._xmlns,
+                            _namespaces._xmlnsURI, _namespaces._prefixes[i],
+                            _namespaces._namespaces[i]);
+                }
+            }
+        }
+    }
+
+    // Returns the prefix for the specified namespace.
+    private CharSequence getRepairedPrefix(CharSequence prefix,
+            CharSequence namespaceURI) throws XMLStreamException {
+        CharArray prefixForURI = _namespaces.getPrefix(namespaceURI);
+        if ((prefixForURI != null)
+                && ((prefix == null) || prefixForURI.equals(prefix)))
+            return prefixForURI; // No repair needed.
+        if ((prefix == null) || (prefix.length() == 0)) { // Creates new prefix.
+            prefix = _autoPrefix.clear().append(_repairingPrefix)
+                    .append(_autoNSCount++);
+        }
+        _namespaces.setPrefix(prefix, namespaceURI, true); // Map to namespace URI.
+        return prefix;
+    }
+
+    private final TextBuilder _autoPrefix = new TextBuilder();
+
+    // Resizes element stack  (same memory area as the writer).
+    private void resizeElemStack() {
+        final int oldLength = _qNames.length;
+        final int newLength = oldLength * 2;
+
+        // Resizes elements qNames stack.
+        TextBuilder[] tmp = new TextBuilder[newLength];
+        System.arraycopy(_qNames, 0, tmp, 0, oldLength);
+        _qNames = tmp;
+        for (int i = oldLength; i < newLength; i++) {
+            _qNames[i] = new TextBuilder();
+        }
+    }
+
+    // Writes methods.
+    //
+
+    private final void writeNoEscape(String str) throws XMLStreamException {
+        write(str, 0, str.length(), false);
+    }
+
+    private final void writeNoEscape(TextBuilder tb) throws XMLStreamException {
+        write(tb, 0, tb.length(), false);
+    }
+
+    private final void writeNoEscape(CharSequence csq)
+            throws XMLStreamException {
+        write(csq, 0, csq.length(), false);
+    }
+
+    private final void writeEscape(CharSequence csq) throws XMLStreamException {
+        write(csq, 0, csq.length(), true);
+    }
+
+    private final void write(Object csq, int start, int length,
+            boolean escapeMarkup) throws XMLStreamException {
+        if (_index + length <= BUFFER_LENGTH) { // Enough buffer space.
+            if (csq instanceof String) {
+                ((String) csq).getChars(start, start + length, _buffer, _index);
+            } else if (csq instanceof javolution.text.Text) {
+                ((javolution.text.Text) csq).getChars(start, start + length,
+                        _buffer, _index);
+            } else if (csq instanceof javolution.text.TextBuilder) {
+                ((javolution.text.TextBuilder) csq).getChars(start, start
+                        + length, _buffer, _index);
+            } else if (csq instanceof javolution.text.CharArray) {
+                ((javolution.text.CharArray) csq).getChars(start, start
+                        + length, _buffer, _index);
+            } else {
+                getChars((CharSequence) csq, start, start + length, _buffer,
+                        _index);
+            }
+            if (escapeMarkup) {
+                int end = _index + length;
+                for (int i = _index; i < end; i++) {
+                    char c = _buffer[i];
+                    if ((c >= '?') || !isEscaped(c))
+                        continue;
+                    // Found character to escape.
+                    _index = i;
+                    flushBuffer();
+                    writeDirectEscapedCharacters(_buffer, i, end);
+                    return; // Done (buffer is empty).
+                }
+            }
+            _index += length;
+
+        } else { // Not enough remaining space.
+            if (length <= BUFFER_LENGTH) { // Enough space if buffer emptied.
+                flushBuffer();
+                write(csq, start, length, escapeMarkup);
+            } else {
+                int half = length >> 1;
+                write(csq, start, half, escapeMarkup);
+                write(csq, start + half, length - half, escapeMarkup);
+            }
+        }
+    }
+
+    private static void getChars(CharSequence csq, int start, int end,
+            char dest[], int destPos) {
+        for (int i = start, j = destPos; i < end;) {
+            dest[j++] = csq.charAt(i++);
+        }
+    }
+
+    // The buffer must have been flushed prior to calling this method.
+    private final void writeDirectEscapedCharacters(char[] chars, int start,
+            int end) throws XMLStreamException {
+        try {
+            int blockStart = start;
+            for (int i = start; i < end;) {
+                char c = chars[i++];
+                if ((c >= '?') || !isEscaped(c))
+                    continue;
+                // Flush already read characters (excluding escaped one).
+                int blockLength = i - blockStart - 1;
+                if (blockLength > 0) {
+                    _writer.write(_buffer, blockStart, blockLength);
+                }
+                blockStart = i;
+                switch (c) {
+                    case '<':
+                        _writer.write("&lt;");
+                        break;
+                    case '>':
+                        _writer.write("&gt;");
+                        break;
+                    case '\'':
+                        _writer.write("&apos;");
+                        break;
+                    case '"':
+                        _writer.write("&quot;");
+                        break;
+                    case '&':
+                        _writer.write("&amp;");
+                        break;
+                    default:
+                        _writer.write("&#");
+                        _writer.write((char) ('0' + c / 10));
+                        _writer.write((char) ('0' + c % 10));
+                        _writer.write(';');
+                }
+            }
+            // Flush the current block.
+            int blockLength = end - blockStart;
+            if (blockLength > 0) {
+                _writer.write(_buffer, blockStart, blockLength);
+            }
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    private boolean isEscaped(char c) {
+        return ((c < ' ') && _isAttributeValue)
+                || (c == '"' && _isAttributeValue) || (c == '<') || (c == '>')
+                || (c == '&');
+    }
+
+    private final void write(char c) throws XMLStreamException {
+        if (_index == BUFFER_LENGTH) {
+            flushBuffer();
+        }
+        _buffer[_index++] = c;
+    }
+
+    private void flushBuffer() throws XMLStreamException {
+        try {
+            _writer.write(_buffer, 0, _index);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        } finally {
+            _index = 0;
+        }
+    }
+
+}
\ 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/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java
new file mode 100644
index 0000000..32c5661
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java
@@ -0,0 +1,346 @@
+/**
+<p>Support for the encoding of objects, and the objects reachable from them,
+   into <code>XML</code>; and the complementary reconstruction of the
+   object graph from <code>XML</code>. 
+</p>
+<p><i> This page has been translated into 
+<a href="http://www.webhostinghub.com/support/es/misc/paquete-javolutionxml">Spanish</a>
+language by Maria Ramos  from <a href="http://www.webhostinghub.com/support/edu">
+Webhostinghub.com/support/edu</a>.</i></p>
+
+<h2><a name="OVERVIEW">XML marshalling/unmarshalling facility:</a></h2>
+
+
+<IMG alt="XML Data Binding" src="doc-files/xmlDataBinding.png">
+
+<p> Key Advantages:<ul>
+    <li> Real-time characteristics with no adverse effect on memory footprint or 
+ garbage collection (e.g. it can be used for time critical communications).
+ {@link javolution.xml.XMLFormat XMLFormat} is basically a "smart" 
+ wrapper around our real-time StAX-like
+ {@link javolution.xml.stream.XMLStreamReader XMLStreamReader} and 
+ {@link javolution.xml.stream.XMLStreamWriter XMLStreamWriter}.</li>
+    <li> Works directly with your existing Java classes, no need to create new classes
+ or customize your implementation in any way.</li>
+    <li> The XML representation can be high level and impervious to obfuscation
+ or changes to your implementation.</li>
+    <li> Performance on a par or better than default Java<sup>TM</sup> Serialization/Deserialization 
+ (See <a href="https://bindmark.dev.java.net/">bindmark</a> for performance comparison).</li>
+    <li> Small footprint, runs on any platform including Android.</li>
+    <li> The XML mapping can be defined for a top class (or interface) and is automatically 
+ inherited by all sub-classes (or all implementing classes).</li>
+    <li> Supports object references (to avoid expanding objects already serialized).</li>
+    </ul>
+</p>
+
+<p> The default XML format for a class is typically defined using 
+    the {@link javolution.xml.DefaultXMLFormat} annotation tag. 
+[code]
+@DefaultXMLFormat(Graphic.XML.class)     
+public abstract class Graphic implements XMLSerializable {
+    private boolean isVisible;
+    private Paint paint; // null if none.
+    private Stroke stroke; // null if none.
+    private Transform transform; // null if none.
+   
+    // Default XML format with name associations (members identified by an unique name).
+    // See XMLFormat for examples of positional associations.
+    public static class XML extends XMLFormat {
+        public void write(Graphic g, OutputElement xml) throws XMLStreamException {
+            xml.setAttribute("isVisible", g.isVisible); 
+            xml.add(g.paint, "Paint");
+            xml.add(g.stroke, "Stroke");
+            xml.add(g.transform, "Transform");
+        }
+        public void read(InputElement xml, Graphic g) throws XMLStreamException {
+            g.isVisible = xml.getAttribute("isVisible", true);
+            g.paint = xml.get("Paint");
+            g.stroke = xml.get("Stroke");
+            g.transform = xml.get("Transform");
+        }
+    };
+}[/code]
+    Sub-classes may override the inherited XML format:
+[code]
+@DefaultXMLFormat(Area.XML.class)     
+public class Area extends Graphic {
+    private Shape geometry;  
+
+    // Adds geometry to format.
+    public static class XML extends XMLFormat<Area> {
+        XMLFormat graphicXML = new Graphic.XML();
+        public void write(Area area, OutputElement xml) throws XMLStreamException {
+            graphicXML.write(area, xml); // Calls parent write.
+            xml.add(area.geometry, "Geometry");
+        }
+        public void read(InputElement xml, Area area) throws XMLStreamException {
+            graphicXML.read(xml, area); // Calls parent read.
+            area.geometry = xml.get("Geometry");
+        }
+    };
+}[/code]
+    
+The following writes a graphic area to a file, then reads it:
+
+[code]    
+// Creates some useful aliases for class names.
+XMLBinding binding = new XMLBinding();
+binding.setAlias(Color.class, "Color");
+binding.setAlias(Polygon.class, "Polygon");
+binding.setClassAttribute("type"); // Use "type" instead of "class" for class attribute.
+    
+// Writes the area to a file.
+XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream("C:/area.xml"));
+writer.setBinding(binding); // Optional.
+writer.setIndentation("\t"); // Optional (use tabulation for indentation).
+writer.write(area, "Area", Area.class);
+writer.close(); 
+
+// Reads the area back
+XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream("C:/area.xml"));
+reader.setBinding(binding);
+Area a = reader.read("Area", Area.class);
+reader.close();
+[/code]
+ 
+     Here is an example of valid XML representation for an area:
+
+[code]
+<Area isVisible="true">
+    <Paint type="Color" rgb="#F3EBC6" />
+    <Geometry type="Polygon">
+        <Vertex x="123" y="-34" />
+        <Vertex x="-43" y="-34" />
+        <Vertex x="-12" y="123" />
+    </Geometry>
+</Area>[/code]
+   
+</p>
+<p> The following table illustrates the variety of XML representations supported 
+    (Foo class with a single String member named text):
+    <center>
+      <table cellpadding="2" cellspacing="2" border="1" style="text-align: left"><tbody>
+      <tr>
+        <td style="vertical-align: top; text-align: center;"><span style="font-weight: bold;">XML FORMAT</span></td>
+        <td style="vertical-align: top; text-align: center;"><span style="font-weight: bold;">XML DATA</span></td>
+      </tr>
+      <tr>
+<td>[code]
+XMLFormat<Foo> XML = new XMLFormat<Foo>() {
+    public void write(Foo foo, OutputElement xml) throws XMLStreamException {
+         xml.setAttribute("text", foo.text); 
+    }
+    public void read(InputElement xml, Foo foo) throws XMLStreamException {
+         foo.text = xml.getAttribute("text", "");
+    }
+};[/code]</td>
+<td><pre>
+ <b>&lt;!-- Member as attribute --&gt;</b>
+ &lt;Foo text="This is a text"/&gt;
+</pre></td>
+      </tr>
+      
+      <tr>
+<td>
+[code]
+XMLFormat<Foo> XML = new XMLFormat<Foo>() {
+    public void write(Foo foo, OutputElement xml) throws XMLStreamException {
+        xml.add(foo.text); 
+    }
+    public void read(InputElement xml, Foo foo) throws XMLStreamException {
+        foo.text = xml.getNext();
+    }
+};[/code]</td>
+<td><pre>
+ <b>&lt;!-- Member as anonymous nested element --&gt;</b>
+ &lt;Foo&gt;
+     &lt;java.lang.String value="This is a text"/&gt;
+ &lt;/Foo&gt;
+</pre></td>
+      </tr>
+
+      <tr>
+<td>
+[code]
+XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
+    public void write(Foo foo, OutputElement xml) throws XMLStreamException {
+        xml.addText(foo.text); // or xml.getStreamWriter().writeCDATA(foo.text) to use CDATA block. 
+    }
+    public void read(InputElement xml, Foo foo) throws XMLStreamException {
+        foo.text = xml.getText().toString(); // Content of a text-only element.
+    }
+};[/code]</td>
+<td><pre>
+ <b>&lt;!-- Member as Character Data --&gt;</b>
+ &lt;Foo&gt;This is a text&lt;/Foo&gt;
+</pre></td>
+      </tr>
+
+      <tr>
+<td>
+[code]
+XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
+    public void write(Foo foo, OutputElement xml) throws XMLStreamException {
+        xml.add(foo.text, "Text"); 
+    }
+    public void read(InputElement xml, Foo foo) throws XMLStreamException {
+        foo.text = xml.get("Text");
+    }
+};[/code]</td>
+<td><pre>
+ <b>&lt;!-- Member as named element of unknown type  --&gt;</b>
+ &lt;Foo&gt;
+     &lt;Text class="java.lang.String" value="This is a text"/&gt;
+ &lt;/Foo&gt;
+</pre></td>
+      </tr>
+
+      <tr>
+<td><pre>
+[code]
+XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
+    public void write(Foo foo, OutputElement xml) throws XMLStreamException {
+        xml.add(foo.text, "Text", String.class); 
+    }
+    public void read(InputElement xml, Foo foo) throws XMLStreamException {
+        foo.text = xml.get("Text", String.class);
+    }
+};[/code]</td>
+<td><pre>
+ <b>&lt;!-- Member as named element of actual type known --&gt;</b>
+ &lt;Foo&gt;
+     &lt;Text value="This is a text"/&gt;
+ &lt;/Foo&gt;
+</pre></td>
+      </tr>
+      </tbody></table>
+    </center>
+</p>
+
+<p> XML format do not have to use the classes
+    public no-arg constructors, instances can be created using factory methods, 
+    private constructors (with constructor parameters set from the XML element)
+    or even retrieved from a collection 
+    (if the object is shared or unique). For example:
+[code]
+@DefaultXMLFormat(Point.XML.class)     
+public final class Point implements XMLSerializable { 
+    private int x;
+    private int y;
+    private Point() {}; // No-arg constructor not visible.
+    public static Point valueOf(int x, int y) { ... }
+    public static class XML = new XMLFormat<Point>() {
+        public boolean isReferencable() {
+            return false; // Always manipulated by value.
+        }
+        public Point newInstance(Class<Point> cls, InputElement xml) throws XMLStreamException {
+             return Point.valueOf(xml.getAttribute("x", 0), xml.getAttribute("y", 0)); 
+        }
+        public void write(Point point, OutputElement xml) throws XMLStreamException {
+             xml.setAttribute("x", point.x);
+             xml.setAttribute("y", point.y);
+        }
+        public void read(InputElement xml, Point point) throws XMLStreamException {
+            // Do nothing immutable.
+        }
+    };
+}[/code]
+</p>
+
+<p> Document cross-references are supported, including circular references. 
+    Let's take for example:
+[code]
+@DefaultXMLFormat(xml=Polygon.XML.class)     
+public class Polygon implements Shape, XMLSerializable { 
+    private Point[] vertices;
+    public static class XML extends XMLFormat<Polygon> {
+         public void write(Polygon polygon, OutputElement xml) throws XMLStreamException {
+             xml.setAttibutes("count", vertices.length);
+             for (Point p : vertices) {
+                 xml.add(p, "Vertex", Point.class);
+             }
+         }
+         public void read(InputElement xml, Polygon polygon) throws XMLStreamException {
+             int count = xml.getAttributes("count", 0);
+             polygon.vertices = new Point[count];
+             for (int i=0; i < count; i++) {
+                 vertices[i] = xml.get("Vertex", Point.class);
+             }
+        }
+    };
+}
+Polygon[] polygons = new Polygon[] {p1, p2, p1};
+...
+TextBuilder xml = TextBuilder.newInstance();
+AppendableWriter out = new AppendableWriter().setOutput(xml)
+XMLObjectWriter writer = XMLObjectWriter.newInstance(out);
+writer.setXMLReferenceResolver(new XMLReferenceResolver()); // Enables cross-references.
+writer.write(polygons, "Polygons", Polygon[].class); 
+writer.close();
+System.out.println(xml);
+[/code]
+    Prints the following (noticed that the first polygon and last one are being shared).
+[code]
+<Polygons length="3">
+   <Polygon id="0" count="3">
+      <Vertex x="123" y="-34" />  
+      <Vertex x="-43" y="-34" />
+      <Vertex x="-12" y="123" />
+   </Polygon>
+   <Polygon id="1" count="3">
+      <Vertex x="-43" y="-34" />
+      <Vertex x="123" y="-34" />
+      <Vertex x="-12" y="123" />
+   </Polygon>
+   <Polygon ref="0"/>
+      </Polygons>[/code] 
+</p>
+
+<B>ALGORITHMS:</B>
+
+<p> Our {@link javolution.xml.XMLObjectReader XMLObjectReader}/{@link javolution.xml.XMLObjectWriter XMLObjectWriter} 
+    are in fact simple wrappers around our <b>J</b>avolution high-performance StAX-like
+    {@link javolution.xml.stream.XMLStreamReader XMLStreamReader} and 
+    {@link javolution.xml.stream.XMLStreamWriter XMLStreamWriter} classes. 
+    The logic of these wrappers is described below:
+<pre>
+
+OutputElement.add(object, name, uri, class):
+
+1. if (object == null) return
+
+2. getStreamWriter().writeStartElement(uri, name)
+
+3. isReference = referenceResolver.writeReference(object, this)
+   
+4. if (!isReference) binding.getFormat(class).write(object, this)
+
+5. getStreamWriter().writeEndElement()
+
+6. end
+
+
+InputElement.get(name, uri, class):
+
+1. if (!getStreamReader().getLocalName().equals(name) ||
+!getStreamReader().getNamespaceURI().equals(uri)) return null
+
+2. object = referenceResolver.readReference(inputElement)
+   
+3. if (object != null) Goto 8 // Found reference
+
+4. format = binding.getFormat(class)
+
+5. object = format.newInstance(class, inputElement)
+
+6. referenceResolver.createReference(object, inputElement) // Done before parsing to support circular references.
+
+7. format.read(inputElement, object)
+
+8. getStreamReader().nextTag()
+
+9. end
+</pre></p>
+ */
+package javolution.xml;
+

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e43574ef/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
new file mode 100644
index 0000000..9192ffc
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
@@ -0,0 +1,178 @@
+/*
+ * 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.lang.CharSequence;
+
+import javolution.text.CharArray;
+
+/**
+ * <p> This interface represents a list of XML attributes.</p>
+ * 
+ * <p> It is a more efficient version of <code>org.xml.sax.Attributes</code>
+ *     with  {@link CharArray CharArray}/{@link CharSequence CharSequence} 
+ *     instead of the <code>String</code> to avoid forcing dynamic object 
+ *     allocations.</p>
+ *
+ * @author  <a href="mailto:sax@megginson.com">David Megginson</a>
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, June 16, 2006
+ */
+public interface Attributes {
+
+    /**
+     * Returns the number of attributes in this list of attributes.
+     *
+     * @return the number of attributes.
+     */
+    int getLength();
+
+    /**
+     * Looks up an attribute's Namespace URI by index.
+     *
+     * @param  index the attribute index (zero-based).
+     * @return the Namespace URI, or an empty character sequence if none is
+     *         available, or <code>null</code> if the index is out of range.
+     * @see    #getLength
+     */
+    CharArray getURI(int index);
+
+    /**
+     * Looks up an attribute's local name by index.
+     *
+     * @param  index the attribute index (zero-based).
+     * @return the local name, or an empty character sequence if Namespace
+     *         processing is  not being performed, or <code>null</code> if
+     *         the index is out of range.
+     * @see    #getLength
+     */
+    CharArray getLocalName(int index);
+
+    /**
+     * Looks up an attribute's XML 1.0 qualified name by index.
+     *
+     * @param  index the attribute index (zero-based).
+     * @return the XML 1.0 qualified name, or an empty character sequence if
+     *         none is available, or <code>null</code> if the index is out
+     *         of range.
+     * @see    #getLength
+     */
+    CharArray getQName(int index);
+
+    /**
+     * Looks up an attribute's type by index.
+     *
+     * <p> The attribute type is one of the strings "CDATA", "ID",
+     *    "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
+     *    or "NOTATION" (always in upper case).</p>
+     *
+     * <p> If the parser has not read a declaration for the attribute,
+     *     or if the parser does not report attribute types, then it must
+     *     return the value "CDATA" as stated in the XML 1.0 Recommentation
+     *     (clause 3.3.3, "Attribute-TextBuilder Normalization").</p>
+     *
+     * <p> For an enumerated attribute that is not a notation, the
+     *     parser will report the type as "NMTOKEN".</p>
+     *
+     * @param  index the attribute index (zero-based).
+     * @return the attribute's type as a string, or null if the
+     *         index is out of range.
+     * @see    #getLength
+     */
+    CharArray getType(int index);
+
+    /**
+     * Looks up an attribute's value by index.
+     *
+     * <p> If the attribute value is a list of tokens (IDREFS,
+     *     ENTITIES, or NMTOKENS), the tokens will be concatenated
+     *     into a single string with each token separated by a
+     *     single space.</p>
+     *
+     * @param  index the attribute index (zero-based).
+     * @return the attribute's value as a character sequence,
+     *         <code>null</code> if the index is out of range.
+     * @see    #getLength
+     */
+    CharArray getValue(int index);
+
+    /**
+     * Looks up the index of an attribute by namespace name (convenience 
+     * method).
+     * This method returns the index of the attribute whose uri/localName 
+     * have the same character content as the specified uri/localName.
+     *
+     * @param  uri the Namespace URI, or an empty character sequence if
+     *         the name has no Namespace URI.
+     * @param  localName the attribute's local name.
+     * @return the index of the attribute, or <code>-1</code> if it does not
+     *         appear in the list.
+     */
+    int getIndex(CharSequence uri, CharSequence localName);
+
+    /**
+     * Looks up the index of an attribute by XML 1.0 qualified name 
+     * (convenience method). This method returns the index of the attribute 
+     * whose name has the same character content as the specified qName.
+     *
+     * @param  qName the qualified (prefixed) name.
+     * @return the index of the attribute, or <code>-1</code> if it does not
+     *         appear in the list.
+     */
+    int getIndex(CharSequence qName);
+
+    /**
+     * Looks up an attribute's type by Namespace name (convenience method).
+     * This method returns the type of the attribute whose uri/localName 
+     * have the same character content as the specified uri/localName.
+     *
+     * @param  uri the Namespace URI, or an empty string if the
+     *         name has no Namespace URI.
+     * @param  localName the local name of the attribute.
+     * @return the attribute type as a string, or null if the attribute is not
+     *         in the list or if Namespace processing is not being performed.
+     */
+    CharArray getType(CharSequence uri, CharSequence localName);
+
+    /**
+     * Looks up an attribute's type by XML 1.0 qualified name.
+     * This method returns the type of the attribute whose qName 
+     * has the same character content as the specified qName.
+     *
+     * @param  qName The XML 1.0 qualified name.
+     * @return the attribute type as a string, or null if the attribute is not
+     *         in the list or if qualified names are not available.
+     */
+    CharArray getType(CharSequence qName);
+
+    /**
+     * Looks up an attribute's value by Namespace name (convenience method).
+     * This method returns the value of the attribute whose uri/localName 
+     * have the same character content as the specified uri/localName.
+     *
+     * @param  uri the Namespace URI, or the empty string if the name has no 
+     *         Namespace URI.
+     * @param  localName the local name of the attribute.
+     * @return the attribute value as a character sequence, or <code>null</code>
+     *         if the attribute is not in the list.
+     */
+    CharArray getValue(CharSequence uri, CharSequence localName);
+
+    /**
+     * Looks up an attribute's value by XML 1.0 qualified name (convenience 
+     * method). This method returns the value of the attribute whose qName 
+     * has the same character content as the specified qName.
+     *
+     * @param  qName The XML 1.0 qualified name.
+     * @return the attribute value as a character sequence, or <code>null</code>
+     *         if the attribute is not in the list or if qualified names
+     *         are not available.
+     */
+    CharArray getValue(CharSequence qName);
+}
\ 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/ContentHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java
new file mode 100644
index 0000000..3c38511
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java
@@ -0,0 +1,144 @@
+/*
+ * 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 javolution.text.CharArray;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ * <p> Receives notification of the logical content of a document.</p>
+ * 
+ * <p> It is a more efficient version of <code>org.xml.sax.ContentHandler</code>
+ *     with  {@link CharArray CharArray}/{@link CharSequence CharSequence} 
+ *     instead of the <code>String</code> to avoid forcing dynamic object 
+ *     allocations.</p>
+ *
+ * @author  <a href="mailto:sax@megginson.com">David Megginson</a>
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 4.0, June 16, 2006
+ */
+public interface ContentHandler {
+
+    /**
+     * Receives an object for locating the origin of SAX document events.
+     *
+     * @param  locator the document locator.
+     */
+    void setDocumentLocator(Locator locator);
+
+    /**
+     * Receives notification of the beginning of a document.
+     *
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void startDocument() throws SAXException;
+
+    /**
+     * Receives notification of the end of a document.
+     *
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void endDocument() throws SAXException;
+
+    /**
+     * Begins the scope of a prefix-URI Namespace mapping.
+     *
+     * @param  prefix the Namespace prefix being declared.
+     * @param  uri the namespace URI the prefix is mapped to.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void startPrefixMapping(CharArray prefix, CharArray uri)
+            throws SAXException;
+
+    /**
+     * Ends the scope of a prefix-URI mapping.
+     *
+     * @param  prefix the prefix that was being mapping.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void endPrefixMapping(CharArray prefix) throws SAXException;
+
+    /**
+     * Receives notification of the beginning of an element.
+     *
+     * @param  uri the namespace URI, or an empty character sequence if the
+     *         element has no Namespace URI or if namespace processing is not
+     *         being performed.
+     * @param  localName the local name (without prefix), or an empty character
+     *         sequence if namespace processing is not being performed.
+     * @param  qName the qualified name (with prefix), or an empty character
+     *         sequence if qualified names are not available.
+     * @param  atts the attributes attached to the element.  If there are no
+     *         attributes, it shall be an empty {@link Attributes} object.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void startElement(CharArray uri, CharArray localName, CharArray qName,
+            Attributes atts) throws SAXException;
+
+    /**
+     * Receives notification of the end of an element.
+     *
+     * @param  uri the namespace URI, or an empty character sequence if the
+     *         element has no Namespace URI or if namespace processing is not
+     *         being performed.
+     * @param  localName the local name (without prefix), or an empty character
+     *         sequence if namespace processing is not being performed.
+     * @param  qName the qualified XML 1.0 name (with prefix), or an empty
+     *         character sequence if qualified names are not available.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void endElement(CharArray uri, CharArray localName, CharArray qName)
+            throws SAXException;
+
+    /**
+     * Receives notification of character data.
+     *
+     * @param  ch the characters from the XML document.
+     * @param  start the start position in the array.
+     * @param  length the number of characters to read from the array.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void characters(char ch[], int start, int length) throws SAXException;
+
+    /**
+     * Receives notification of ignorable whitespace in element content.
+     *
+     * @param  ch the characters from the XML document.
+     * @param  start the start position in the array.
+     * @param  length the number of characters to read from the array.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void ignorableWhitespace(char ch[], int start, int length)
+            throws SAXException;
+
+    /**
+     * Receives notification of a processing instruction.
+     *
+     * @param  target the processing instruction target.
+     * @param  data the processing instruction data, or null if
+     *         none was supplied.  The data does not include any
+     *         whitespace separating it from the target.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void processingInstruction(CharArray target, CharArray data)
+            throws SAXException;
+
+    /**
+     * Receives notification of a skipped entity.
+     *
+     * @param name the name of the skipped entity.  If it is a
+     *        parameter entity, the name will begin with '%', and if
+     *        it is the external DTD subset, it will be the character sequence
+     *        "[dtd]".
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    void skippedEntity(CharArray name) throws SAXException;
+
+}
\ 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/DefaultHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java
new file mode 100644
index 0000000..325e832
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java
@@ -0,0 +1,116 @@
+/*
+ * 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 javolution.text.CharArray;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Default base class for real-time handling of XML events.
+ *
+ * @author  <a href="mailto:sax@megginson.com">David Megginson</a>
+ * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
+ * @version 3.1, March 11, 2005
+ */
+public class DefaultHandler implements ContentHandler, ErrorHandler {
+
+    /**
+     * Receives notification of a warning. The default behaviour is to take no
+     * action.
+     *
+     * @param  e the warning information encapsulated in a SAX parse exception.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    public void warning(SAXParseException e) throws SAXException {}
+
+    /**
+     * Receives notification of recoverable parser error. The default behaviour
+     * is to take no action.
+     *
+     * @param  e the error information encapsulated in a SAX parse exception.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    public void error(SAXParseException e) throws SAXException {}
+
+    /**
+     * Reports a fatal XML parsing error. The default behaviour is to throw
+     * the specified exception.
+     *
+     * @param  e the error information encapsulated in a SAX parse exception.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    public void fatalError(SAXParseException e) throws SAXException {
+        throw e;
+    }
+
+    // Implements ContentHandler
+    public void setDocumentLocator(Locator locator) {}
+
+    // Implements ContentHandler
+    public void startDocument() throws SAXException {}
+
+    // Implements ContentHandler
+    public void endDocument() throws SAXException {}
+
+    // Implements ContentHandler
+    public void startPrefixMapping(CharArray prefix, CharArray uri)
+            throws SAXException {}
+
+    // Implements ContentHandler
+    public void endPrefixMapping(CharArray prefix) throws SAXException {}
+
+    // Implements ContentHandler
+    public void startElement(CharArray namespaceURI, CharArray localName,
+            CharArray qName, Attributes atts) throws SAXException {}
+
+    // Implements ContentHandler
+    public void endElement(CharArray namespaceURI, CharArray localName,
+            CharArray qName) throws SAXException {}
+
+    // Implements ContentHandler
+    public void characters(char ch[], int start, int length)
+            throws SAXException {}
+
+    // Implements ContentHandler
+    public void ignorableWhitespace(char ch[], int start, int length)
+            throws SAXException {}
+
+    // Implements ContentHandler
+    public void processingInstruction(CharArray target, CharArray data)
+            throws SAXException {}
+
+    // Implements ContentHandler
+    public void skippedEntity(CharArray name) throws SAXException {}
+
+    /**
+     * <p> Generates compile-time error if <code>startElement</code> is not
+     *     correctly overriden.  This method generates a compile-error
+     *     <code>"final method cannot be overridden"</code> if
+     *     <code>org.xml.sax.Attributes</code> is used instead of
+     *     <code>javolution.xml.sax.Attributes</code> (common mistake).</p>
+     * @param  uri the namespace URI, or an empty character sequence if the
+     *         element has no Namespace URI or if namespace processing is not
+     *         being performed.
+     * @param  localName the local name (without prefix), or an empty character
+     *         sequence if namespace processing is not being performed.
+     * @param  qName the qualified name (with prefix), or an empty character
+     *         sequence if qualified names are not available.
+     * @param  atts the attributes attached to the element.  If there are no
+     *         attributes, it shall be an empty {@link Attributes} object.
+     * @throws org.xml.sax.SAXException any SAX exception.
+     */
+    protected final void startElement(CharArray uri, CharArray localName,
+            CharArray qName, org.xml.sax.Attributes atts) throws SAXException {
+        throw new UnsupportedOperationException();
+    }
+
+}
\ 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/SAX2ReaderImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java
new file mode 100644
index 0000000..3b51cd9
--- /dev/null
+++ b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java
@@ -0,0 +1,386 @@
+/*
+ * 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 javolution.text.CharArray;
+import javolution.text.Text;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+import java.lang.CharSequence;
+
+/**
+ * <p> This class provides a SAX2-compliant parser wrapping a
+ *     {@link javolution.xml.sax.XMLReaderImpl}. This parser allocates 
+ *     <code>java.lang.String</code> instances while parsing in accordance 
+ *     with the SAX2 specification. For faster performance (2-5x), the use of 
+ *     the SAX2-like {@link javolution.xml.sax.XMLReaderImpl 
+ *     XMLSaxParserImpl} or better{@link javolution.xml.stream.XMLStreamReader 
+ *     XMLStreamReader} is recommended.</p>
+ *
+ * @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 final class SAX2ReaderImpl implements XMLReader {
+
+    /**
+     * Holds the SAX2 default handler instance.
+     */
+    private static Sax2DefaultHandler DEFAULT_HANDLER = new Sax2DefaultHandler();
+
+    /**
+     * Holds the real-time parser instance associated to this SAX2 parser.
+     */
+    private final XMLReaderImpl _parser = new XMLReaderImpl();
+
+    /**
+     * Holds the content handler proxy.
+     */
+    private final Proxy _proxy = new Proxy();
+
+    /**
+     * Default constructor.
+     */
+    public SAX2ReaderImpl() {}
+
+    // Implements org.xml.sax.XMLReader interface.
+    public boolean getFeature(String name) throws SAXNotRecognizedException,
+            SAXNotSupportedException {
+        return _parser.getFeature(name);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setFeature(String name, boolean value)
+            throws SAXNotRecognizedException, SAXNotSupportedException {
+        _parser.setFeature(name, value);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public Object getProperty(String name) throws SAXNotRecognizedException,
+            SAXNotSupportedException {
+        return _parser.getProperty(name);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setProperty(String name, Object value)
+            throws SAXNotRecognizedException, SAXNotSupportedException {
+        _parser.setProperty(name, value);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setEntityResolver(EntityResolver resolver) {
+        _parser.setEntityResolver(resolver);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public EntityResolver getEntityResolver() {
+        return _parser.getEntityResolver();
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setDTDHandler(DTDHandler handler) {
+        _parser.setDTDHandler(handler);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public DTDHandler getDTDHandler() {
+        return _parser.getDTDHandler();
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setContentHandler(ContentHandler handler) {
+        if (handler != null) {
+            _proxy._sax2Handler = handler;
+            _parser.setContentHandler(_proxy);
+        } else {
+            throw new NullPointerException();
+        }
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public ContentHandler getContentHandler() {
+        return (_proxy._sax2Handler == DEFAULT_HANDLER) ? null
+                : _proxy._sax2Handler;
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void setErrorHandler(ErrorHandler handler) {
+        _parser.setErrorHandler(handler);
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public ErrorHandler getErrorHandler() {
+        return _parser.getErrorHandler();
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void parse(InputSource input) throws IOException, SAXException {
+        try {
+            _parser.parse(input);
+        } finally {
+            _parser.reset();
+        }
+    }
+
+    // Implements org.xml.sax.XMLReader interface.
+    public void parse(String systemId) throws IOException, SAXException {
+        try {
+            _parser.parse(systemId);
+        } finally {
+            _parser.reset();
+        }
+    }
+
+    // Implements Reusable interface.
+    public void reset() {
+        _parser.reset();
+    }
+
+    /**
+     * This class defines the proxy for content handler and attributes.
+     */
+    private static final class Proxy implements
+            javolution.xml.sax.ContentHandler, Attributes {
+
+        /**
+         * Holds the SAX2 content handler to which SAX2 events are forwarded.
+         */
+        private ContentHandler _sax2Handler = DEFAULT_HANDLER;
+
+        /**
+         * Holds the real-time attributes implementation from which attributes
+         * values are read.
+         */
+        private javolution.xml.sax.Attributes _attributes;
+
+        /**
+         * Default constructor.
+         */
+        public Proxy() {}
+
+        // Implements ContentHandler
+        public void setDocumentLocator(Locator locator) {
+            _sax2Handler.setDocumentLocator(locator);
+        }
+
+        // Implements ContentHandler
+        public void startDocument() throws SAXException {
+            _sax2Handler.startDocument();
+        }
+
+        // Implements ContentHandler
+        public void endDocument() throws SAXException {
+            _sax2Handler.endDocument();
+            _sax2Handler = DEFAULT_HANDLER;
+        }
+
+        // Implements ContentHandler
+        public void startPrefixMapping(CharArray prefix, CharArray uri)
+                throws SAXException {
+            _sax2Handler.startPrefixMapping(prefix.toString(), uri.toString());
+        }
+
+        // Implements ContentHandler
+        public void endPrefixMapping(CharArray prefix) throws SAXException {
+            _sax2Handler.endPrefixMapping(prefix.toString());
+        }
+
+        // Implements ContentHandler
+        public void startElement(CharArray namespaceURI, CharArray localName,
+                CharArray qName, javolution.xml.sax.Attributes atts)
+                throws SAXException {
+            _attributes = atts;
+            _sax2Handler.startElement(namespaceURI.toString(),
+                    localName.toString(), qName.toString(), this);
+        }
+
+        // Implements ContentHandler
+        public void endElement(CharArray namespaceURI, CharArray localName,
+                CharArray qName) throws SAXException {
+            _sax2Handler.endElement(namespaceURI.toString(),
+                    localName.toString(), qName.toString());
+        }
+
+        // Implements ContentHandler
+        public void characters(char ch[], int start, int length)
+                throws SAXException {
+            _sax2Handler.characters(ch, start, length);
+        }
+
+        // Implements ContentHandler
+        public void ignorableWhitespace(char ch[], int start, int length)
+                throws SAXException {
+            _sax2Handler.ignorableWhitespace(ch, start, length);
+        }
+
+        // Implements ContentHandler
+        public void processingInstruction(CharArray target, CharArray data)
+                throws SAXException {
+            _sax2Handler.processingInstruction(target.toString(),
+                    data.toString());
+        }
+
+        // Implements ContentHandler
+        public void skippedEntity(CharArray name) throws SAXException {
+            _sax2Handler.skippedEntity(name.toString());
+        }
+
+        // Implements Attributes
+        public int getLength() {
+            return (_attributes != null ? _attributes.getLength() : 0);
+        }
+
+        // Implements Attributes
+        public String getURI(int index) {
+            CharSequence chars = (_attributes != null ? _attributes
+                    .getURI(index) : null);
+            return (chars != null ? chars.toString() : "");
+        }
+
+        // Implements Attributes
+        public String getLocalName(int index) {
+            CharSequence chars = (_attributes != null ? _attributes
+                    .getLocalName(index) : null);
+            return (chars != null ? chars.toString() : "");
+        }
+
+        // Implements Attributes
+        public String getQName(int index) {
+            CharSequence chars = (_attributes != null ? _attributes
+                    .getQName(index) : null);
+            return (chars != null ? chars.toString() : "");
+        }
+
+        // Implements Attributes
+        public String getType(int index) {
+            return (_attributes != null ? _attributes.getType(index).toString()
+                    : null);
+        }
+
+        // Implements Attributes
+        public String getValue(int index) {
+            CharSequence chars = (_attributes != null ? _attributes
+                    .getValue(index) : null);
+            return (chars != null ? chars.toString() : null);
+        }
+
+        // Implements Attributes
+        public int getIndex(String uri, String localName) {
+            return (uri != null && localName != null && _attributes != null ? _attributes
+                    .getIndex(toCharSequence(uri), toCharSequence(localName))
+                    : -1);
+        }
+
+        // Implements Attributes
+        public int getIndex(String qName) {
+            return (qName != null && _attributes != null ? _attributes
+                    .getIndex(toCharSequence(qName)) : -1);
+        }
+
+        // Implements Attributes
+        public String getType(String uri, String localName) {
+            return (uri != null && localName != null && _attributes != null ? _attributes
+                    .getType(toCharSequence(uri), toCharSequence(localName))
+                    .toString() : null);
+        }
+
+        // Implements Attributes
+        public String getType(String qName) {
+            return (qName != null && _attributes != null ? _attributes.getType(
+                    toCharSequence(qName)).toString() : null);
+        }
+
+        // Implements Attributes
+        public String getValue(String uri, String localName) {
+            return (uri != null
+                    && localName != null
+                    && _attributes != null
+                    && _attributes.getValue(toCharSequence(uri),
+                            toCharSequence(localName)) != null ? _attributes
+                    .getValue(toCharSequence(uri), toCharSequence(localName))
+                    .toString() : null);
+        }
+
+        // Implements Attributes
+        public String getValue(String qName) {
+            return (qName != null && _attributes != null ? _attributes
+                    .getValue(toCharSequence(qName)).toString() : null);
+        }
+    }
+
+    private static final class Sax2DefaultHandler implements EntityResolver,
+            DTDHandler, ContentHandler, ErrorHandler {
+
+        public InputSource resolveEntity(String publicId, String systemId)
+                throws SAXException, IOException {
+            return null;
+        }
+
+        public void notationDecl(String name, String publicId, String systemId)
+                throws SAXException {}
+
+        public void unparsedEntityDecl(String name, String publicId,
+                String systemId, String notationName) throws SAXException {}
+
+        public void setDocumentLocator(Locator locator) {}
+
+        public void startDocument() throws SAXException {}
+
+        public void endDocument() throws SAXException {}
+
+        public void startPrefixMapping(String prefix, String uri)
+                throws SAXException {}
+
+        public void endPrefixMapping(String prefix) throws SAXException {}
+
+        public void startElement(String uri, String localName, String qName,
+                Attributes atts) throws SAXException {}
+
+        public void endElement(String uri, String localName, String qName)
+                throws SAXException {}
+
+        public void characters(char[] ch, int start, int length)
+                throws SAXException {}
+
+        public void ignorableWhitespace(char[] ch, int start, int length)
+                throws SAXException {}
+
+        public void processingInstruction(String target, String data)
+                throws SAXException {}
+
+        public void skippedEntity(String name) throws SAXException {}
+
+        public void warning(SAXParseException exception) throws SAXException {}
+
+        public void error(SAXParseException exception) throws SAXException {}
+
+        public void fatalError(SAXParseException exception) throws SAXException {
+            throw exception;
+        }
+    }
+
+    private static CharSequence toCharSequence(Object obj) {
+        return obj instanceof CharSequence ? (CharSequence) obj : Text
+                .valueOf(obj);
+    }
+
+}
\ No newline at end of file