summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/xml/libxmlj
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/xml/libxmlj')
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java117
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeCDATASection.java57
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java119
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeComment.java57
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMException.java98
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMStringList.java84
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java562
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java326
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilderFactory.java118
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentFragment.java57
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java98
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java184
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java104
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntityReference.java57
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java92
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java501
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNodeList.java66
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java80
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java79
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java132
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeTypeInfo.java65
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathExpression.java86
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java64
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNodeList.java73
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java134
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/GnomeLocator.java99
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParser.java105
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParserFactory.java92
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/GnomeXMLReader.java1065
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/Namespaces.java122
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/StringArrayAttributes.java170
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/sax/XMLName.java92
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/transform/ErrorListenerErrorHandler.java111
-rwxr-xr-xlibjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformer.java572
-rwxr-xr-xlibjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java349
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/transform/URIResolverEntityResolver.java87
-rwxr-xr-xlibjava/classpath/gnu/xml/libxmlj/transform/package.html14
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/util/EmptyNodeList.java62
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/util/NamedInputStream.java99
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/util/StandaloneDocumentType.java294
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/util/StandaloneLocator.java89
-rw-r--r--libjava/classpath/gnu/xml/libxmlj/util/XMLJ.java280
42 files changed, 7112 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java
new file mode 100644
index 000000000..da9c62c9d
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java
@@ -0,0 +1,117 @@
+/* GnomeAttr.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * A DOM attribute node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeAttr
+ extends GnomeNode
+ implements Attr
+{
+
+ GnomeAttr(Object id)
+ {
+ super(id);
+ }
+
+ public String getName()
+ {
+ return getNodeName();
+ }
+
+ public native boolean getSpecified();
+
+ public native String getValue();
+
+ public native void setValue(String value)
+ throws DOMException;
+
+ public Node getParentNode()
+ {
+ return null;
+ }
+
+ public Element getOwnerElement()
+ {
+ return (Element) super.getParentNode();
+ }
+
+ // DOM Level 3 methods
+
+ public TypeInfo getSchemaTypeInfo()
+ {
+ return new GnomeTypeInfo(id);
+ }
+
+ public boolean isId()
+ {
+ if (xmljIsId())
+ {
+ return true;
+ }
+ GnomeElement element = (GnomeElement) getOwnerElement();
+ return (element != null &&
+ element.userIdAttrs != null &&
+ element.userIdAttrs.contains(this));
+ }
+
+ private native boolean xmljIsId();
+
+ public String toString()
+ {
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
+ buffer.append("[name=");
+ buffer.append(getName());
+ buffer.append(",value=");
+ buffer.append(getValue());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCDATASection.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCDATASection.java
new file mode 100644
index 000000000..3e408e653
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCDATASection.java
@@ -0,0 +1,57 @@
+/* GnomeCDATASection.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.CDATASection;
+
+/**
+ * A DOM CDATA section node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeCDATASection
+ extends GnomeText
+ implements CDATASection
+{
+
+ GnomeCDATASection(Object id)
+ {
+ super(id);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java
new file mode 100644
index 000000000..3f3d6ecb5
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java
@@ -0,0 +1,119 @@
+/* GnomeCharacterData.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.DOMException;
+
+/**
+ * A DOM character data node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+abstract class GnomeCharacterData
+ extends GnomeNode
+ implements CharacterData
+{
+
+ GnomeCharacterData(Object id)
+ {
+ super(id);
+ }
+
+ public String getData()
+ throws DOMException
+ {
+ return getNodeValue();
+ }
+
+ public void setData(String data)
+ throws DOMException
+ {
+ setNodeValue(data);
+ }
+
+ public int getLength()
+ {
+ return getData().length();
+ }
+
+ public String substringData(int offset, int count)
+ throws DOMException
+ {
+ return getData().substring(offset, offset + count);
+ }
+
+ public void appendData(String arg)
+ throws DOMException
+ {
+ setData(getData() + arg);
+ }
+
+ public void insertData(int offset, String arg)
+ throws DOMException
+ {
+ String data = getData();
+ setData(data.substring(0, offset) + arg + data.substring(offset));
+ }
+
+ public void deleteData(int offset, int count)
+ throws DOMException
+ {
+ String data = getData();
+ setData(data.substring(0, offset) + data.substring(offset + count));
+ }
+
+ public void replaceData(int offset, int count, String arg)
+ {
+ String data = getData();
+ setData(data.substring(0, offset) + arg +
+ data.substring(offset + count));
+ }
+
+ public String toString()
+ {
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
+ buffer.append("[data=");
+ buffer.append(getData());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeComment.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeComment.java
new file mode 100644
index 000000000..b6985c4a4
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeComment.java
@@ -0,0 +1,57 @@
+/* GnomeComment.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.Comment;
+
+/**
+ * A DOM comment node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeComment
+ extends GnomeCharacterData
+ implements Comment
+{
+
+ GnomeComment(Object id)
+ {
+ super(id);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMException.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMException.java
new file mode 100644
index 000000000..a1af82335
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMException.java
@@ -0,0 +1,98 @@
+/* GnomeDOMException.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.DOMException;
+
+class GnomeDOMException
+ extends DOMException
+{
+
+ GnomeDOMException(short code, String message)
+ {
+ super(code, createMessage(code, message));
+ }
+
+ private static String createMessage(int code, String message)
+ {
+ if (message != null)
+ {
+ return message;
+ }
+ switch (code)
+ {
+ case INDEX_SIZE_ERR:
+ return "INDEX_SIZE_ERR";
+ case DOMSTRING_SIZE_ERR:
+ return "DOMSTRING_SIZE_ERR";
+ case HIERARCHY_REQUEST_ERR:
+ return "HIERARCHY_REQUEST_ERR";
+ case WRONG_DOCUMENT_ERR:
+ return "WRONG_DOCUMENT_ERR";
+ case INVALID_CHARACTER_ERR:
+ return "INVALID_CHARACTER_ERR";
+ case NO_DATA_ALLOWED_ERR:
+ return "NO_DATA_ALLOWED_ERR";
+ case NO_MODIFICATION_ALLOWED_ERR:
+ return "NO_MODIFICATION_ALLOWED_ERR";
+ case NOT_FOUND_ERR:
+ return "NOT_FOUND_ERR";
+ case NOT_SUPPORTED_ERR:
+ return "NOT_SUPPORTED_ERR";
+ case INUSE_ATTRIBUTE_ERR:
+ return "INUSE_ATTRIBUTE_ERR";
+ case INVALID_STATE_ERR:
+ return "INVALID_STATE_ERR";
+ case SYNTAX_ERR:
+ return "SYNTAX_ERR";
+ case INVALID_MODIFICATION_ERR:
+ return "INVALID_MODIFICATION_ERR";
+ case NAMESPACE_ERR:
+ return "NAMESPACE_ERR";
+ case INVALID_ACCESS_ERR:
+ return "INVALID_ACCESS_ERR";
+ case VALIDATION_ERR:
+ return "VALIDATION_ERR";
+ case TYPE_MISMATCH_ERR:
+ return "TYPE_MISMATCH_ERR";
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMStringList.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMStringList.java
new file mode 100644
index 000000000..c415ec782
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMStringList.java
@@ -0,0 +1,84 @@
+/* GnomeDOMStringList.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.DOMStringList;
+
+/**
+ * Implementation of a string list using an array of strings.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeDOMStringList
+ implements DOMStringList
+{
+
+ final String[] values;
+
+ GnomeDOMStringList(String[] values)
+ {
+ this.values = values;
+ }
+
+ public int getLength()
+ {
+ return values.length;
+ }
+
+ public String item(int index)
+ {
+ if (index < 0 || index >= values.length)
+ {
+ return null;
+ }
+ return values[index];
+ }
+
+ public boolean contains(String value)
+ {
+ for (int i = 0; i < values.length; i++)
+ {
+ if (values[i].equalsIgnoreCase(value))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java
new file mode 100644
index 000000000..0d1b487d8
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java
@@ -0,0 +1,562 @@
+/* GnomeDocument.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+import gnu.xml.dom.DomNodeIterator;
+
+import java.util.Iterator;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.DOMStringList;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.w3c.dom.UserDataHandler;
+import org.w3c.dom.traversal.DocumentTraversal;
+import org.w3c.dom.traversal.NodeFilter;
+import org.w3c.dom.traversal.NodeIterator;
+import org.w3c.dom.traversal.TreeWalker;
+import org.w3c.dom.xpath.XPathEvaluator;
+import org.w3c.dom.xpath.XPathException;
+import org.w3c.dom.xpath.XPathExpression;
+import org.w3c.dom.xpath.XPathNSResolver;
+
+/**
+ * A DOM document node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeDocument
+ extends GnomeNode
+ implements Document, DOMConfiguration, XPathEvaluator, DocumentTraversal
+{
+
+ DOMImplementation dom;
+
+ /**
+ * Not currently used.
+ */
+ boolean strictErrorChecking;
+
+ /* DOMConfiguration */
+ boolean canonicalForm = false;
+ boolean cdataSections = true;
+ boolean checkCharacterNormalization = false;
+ boolean comments = true;
+ boolean datatypeNormalization = false;
+ boolean elementContentWhitespace = true;
+ boolean entities = true;
+ DOMErrorHandler errorHandler;
+ boolean namespaces = true;
+ boolean namespaceDeclarations = true;
+ boolean normalizeCharacters = false;
+ boolean splitCdataSections = true;
+ boolean validate = false;
+ boolean validateIfSchema = false;
+ boolean wellFormed = true;
+
+ GnomeDocument(Object id)
+ {
+ super(id);
+ strictErrorChecking = true;
+ }
+
+ protected void finalize()
+ {
+ free(id);
+ }
+
+ private native void free(Object id);
+
+ public native DocumentType getDoctype();
+
+ public DOMImplementation getImplementation()
+ {
+ return dom;
+ }
+
+ public native Element getDocumentElement();
+
+ public Element createElement(String tagName)
+ throws DOMException
+ {
+ return createElementNS(null, tagName);
+ }
+
+ public native DocumentType createDocumentType(String name, String publicId,
+ String systemId);
+
+ public native DocumentFragment createDocumentFragment();
+
+ public native Text createTextNode(String data);
+
+ public native Comment createComment(String data);
+
+ public native CDATASection createCDATASection(String data)
+ throws DOMException;
+
+ public native ProcessingInstruction createProcessingInstruction(String target,
+ String data)
+ throws DOMException;
+
+ public Attr createAttribute(String name)
+ throws DOMException
+ {
+ return createAttributeNS(null, name);
+ }
+
+ public native EntityReference createEntityReference(String name)
+ throws DOMException;
+
+ public native NodeList getElementsByTagName(String tagName);
+
+ public Node importNode(Node importedNode, boolean deep)
+ throws DOMException
+ {
+ Node ret = xmljImportNode(importedNode, deep);
+ if (importedNode instanceof GnomeNode)
+ {
+ ((GnomeNode) importedNode)
+ .notifyUserDataHandlers(UserDataHandler.NODE_IMPORTED,
+ importedNode, ret);
+ }
+ return ret;
+ }
+
+ private native Node xmljImportNode(Node importedNode, boolean deep)
+ throws DOMException;
+
+ public native Element createElementNS(String namespaceURI, String
+ qualifiedName)
+ throws DOMException;
+
+ public native Attr createAttributeNS(String namespaceURI, String
+ qualifiedName)
+ throws DOMException;
+
+ public native NodeList getElementsByTagNameNS(String namespaceURI,
+ String localName);
+
+ public Element getElementById(String elementId)
+ {
+ Element element = xmljGetElementById(elementId);
+ if (element == null)
+ {
+ TreeWalker walker = createTreeWalker(this, NodeFilter.SHOW_ELEMENT,
+ null, false);
+ for (Node node = walker.nextNode(); node != null;
+ node = walker.nextNode())
+ {
+ GnomeElement e = (GnomeElement) node;
+ if (e.userIdAttrs != null)
+ {
+ for (Iterator i = e.userIdAttrs.iterator(); i.hasNext(); )
+ {
+ Attr attr = (Attr) i.next();
+ if (attr.getNodeValue().equals(elementId))
+ {
+ return e;
+ }
+ }
+ }
+ }
+ }
+ return element;
+ }
+
+ private native Element xmljGetElementById(String elementId);
+
+ // DOM Level 3 methods
+
+ public native String getInputEncoding();
+
+ public native String getXmlEncoding();
+
+ public native boolean getXmlStandalone();
+
+ public native void setXmlStandalone(boolean xmlStandalone);
+
+ public native String getXmlVersion();
+
+ public native void setXmlVersion(String xmlVersion);
+
+ public boolean getStrictErrorChecking()
+ {
+ return strictErrorChecking;
+ }
+
+ public void setStrictErrorChecking(boolean strictErrorChecking)
+ {
+ this.strictErrorChecking = strictErrorChecking;
+ }
+
+ public native String getDocumentURI();
+
+ public native void setDocumentURI(String documentURI);
+
+ public Node adoptNode(Node source)
+ throws DOMException
+ {
+ if (source == null || !(source instanceof GnomeNode))
+ {
+ return null;
+ }
+ Node ret = xmljAdoptNode(source);
+ if (source instanceof GnomeNode)
+ {
+ ((GnomeNode) source).
+ notifyUserDataHandlers(UserDataHandler.NODE_ADOPTED,
+ source, ret);
+ }
+ return ret;
+ }
+
+ private native Node xmljAdoptNode(Node source)
+ throws DOMException;
+
+ public DOMConfiguration getDomConfig()
+ {
+ return this;
+ }
+
+ public void normalizeDocument()
+ {
+ normalize();
+ }
+
+ public native Node renameNode(Node n, String namespaceURI,
+ String qualifiedName);
+
+ // -- DOMConfiguration methods --
+
+ public void setParameter(String name, Object value)
+ throws DOMException
+ {
+ name = name.toLowerCase();
+ if ("canonical-form".equals(name))
+ {
+ /* optional
+ canonicalForm = getBooleanValue(value);*/
+ }
+ else if ("cdata-sections".equals(name))
+ {
+ cdataSections = getBooleanValue(value);
+ }
+ else if ("check-character-normalization".equals(name))
+ {
+ /* optional
+ checkCharacterNormalization = getBooleanValue(value);*/
+ }
+ else if ("comments".equals(name))
+ {
+ comments = getBooleanValue(value);
+ }
+ else if ("datatype-normalization".equals(name))
+ {
+ /* optional
+ datatypeNormalization = getBooleanValue(value);*/
+ }
+ else if ("element-content-whitespace".equals(name))
+ {
+ /* optional
+ elementContentWhitespace = getBooleanValue(value);*/
+ }
+ else if ("entities".equals(name))
+ {
+ entities = getBooleanValue(value);
+ }
+ else if ("error-handler".equals(name))
+ {
+ errorHandler = (DOMErrorHandler) value;
+ }
+ else if ("infoset".equals(name))
+ {
+ if (getBooleanValue(value))
+ {
+ validateIfSchema = false;
+ entities = false;
+ datatypeNormalization = false;
+ cdataSections = false;
+ namespaceDeclarations = true;
+ wellFormed = true;
+ elementContentWhitespace = true;
+ comments = true;
+ namespaces = true;
+ }
+ }
+ else if ("namespaces".equals(name))
+ {
+ /* optional
+ namespaces = getBooleanValue(value);*/
+ }
+ else if ("namespace-declarations".equals(name))
+ {
+ namespaceDeclarations = getBooleanValue(value);
+ }
+ else if ("normalize-characters".equals(name))
+ {
+ /* optional
+ normalizeCharacters = getBooleanValue(value);*/
+ }
+ else if ("split-cdata-sections".equals(name))
+ {
+ splitCdataSections = getBooleanValue(value);
+ }
+ else if ("validate".equals(name))
+ {
+ /* optional
+ validate = getBooleanValue(value);*/
+ }
+ else if ("validate-if-schema".equals(name))
+ {
+ /* optional
+ validateIfSchema = getBooleanValue(value);*/
+ }
+ else if ("well-formed".equals(name))
+ {
+ /* optional
+ wellFormed = getBooleanValue(value);*/
+ }
+ else
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, name);
+ }
+ }
+
+ public Object getParameter(String name)
+ throws DOMException
+ {
+ name = name.toLowerCase();
+ if ("canonical-form".equals(name))
+ {
+ return Boolean.valueOf(canonicalForm);
+ }
+ else if ("cdata-sections".equals(name))
+ {
+ return Boolean.valueOf(cdataSections);
+ }
+ else if ("check-character-normalization".equals(name))
+ {
+ return Boolean.valueOf(checkCharacterNormalization);
+ }
+ else if ("comments".equals(name))
+ {
+ return Boolean.valueOf(comments);
+ }
+ else if ("datatype-normalization".equals(name))
+ {
+ return Boolean.valueOf(datatypeNormalization);
+ }
+ else if ("element-content-whitespace".equals(name))
+ {
+ return Boolean.valueOf(elementContentWhitespace);
+ }
+ else if ("entities".equals(name))
+ {
+ return Boolean.valueOf(entities);
+ }
+ else if ("error-handler".equals(name))
+ {
+ return errorHandler;
+ }
+ else if ("infoset".equals(name))
+ {
+ return Boolean.valueOf(!validateIfSchema &&
+ !entities &&
+ !datatypeNormalization &&
+ !cdataSections &&
+ namespaceDeclarations &&
+ wellFormed &&
+ elementContentWhitespace &&
+ comments &&
+ namespaces);
+ }
+ else if ("namespaces".equals(name))
+ {
+ return Boolean.valueOf(namespaces);
+ }
+ else if ("namespace-declarations".equals(name))
+ {
+ return Boolean.valueOf(namespaceDeclarations);
+ }
+ else if ("normalize-characters".equals(name))
+ {
+ return Boolean.valueOf(normalizeCharacters);
+ }
+ else if ("split-cdata-sections".equals(name))
+ {
+ return Boolean.valueOf(splitCdataSections);
+ }
+ else if ("validate".equals(name))
+ {
+ return Boolean.valueOf(validate);
+ }
+ else if ("validate-if-schema".equals(name))
+ {
+ return Boolean.valueOf(validateIfSchema);
+ }
+ else if ("well-formed".equals(name))
+ {
+ return Boolean.valueOf(wellFormed);
+ }
+ else
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, name);
+ }
+ }
+
+ public boolean canSetParameter(String name, Object value)
+ {
+ name = name.toLowerCase();
+ if ("error-handler".equals(name))
+ {
+ return (value == null || value instanceof DOMErrorHandler);
+ }
+ return ("cdata-sections".equals(name) ||
+ "comments".equals(name) ||
+ "entities".equals(name) ||
+ "namespace-declarations".equals(name) ||
+ "split-cdata-sections".equals(name));
+ }
+
+ public DOMStringList getParameterNames()
+ {
+ String[] names = new String[] {
+ "canonical-form",
+ "cdata-sections",
+ "check-character-normalization",
+ "comments",
+ "datatype-normalization",
+ "element-content-whitespace",
+ "entities",
+ "error-handler",
+ "infoset",
+ "namespaces",
+ "namespace-declarations",
+ "normalize-characters",
+ "split-cdata-sections",
+ "validate",
+ "validate-if-schema",
+ "well-formed"
+ };
+ return new GnomeDOMStringList(names);
+ }
+
+ private boolean getBooleanValue(Object value)
+ {
+ if (value instanceof Boolean)
+ {
+ return ((Boolean) value).booleanValue();
+ }
+ else if (value instanceof String)
+ {
+ return Boolean.valueOf ((String) value).booleanValue();
+ }
+ return false;
+ }
+
+ // -- XPathEvaluator methods --
+
+ public XPathExpression createExpression(String expression,
+ XPathNSResolver resolver)
+ throws XPathException, DOMException
+ {
+ return new GnomeXPathExpression(this, expression, resolver);
+ }
+
+ public XPathNSResolver createNSResolver(Node nodeResolver)
+ {
+ return new GnomeXPathNSResolver(nodeResolver);
+ }
+
+ public native Object evaluate(String expression,
+ Node contextNode,
+ XPathNSResolver resolver,
+ short type,
+ Object result)
+ throws XPathException, DOMException;
+
+ // -- DocumentTraversal methods --
+
+ public NodeIterator createNodeIterator(Node root,
+ int whatToShow,
+ NodeFilter filter,
+ boolean entityReferenceExpansion)
+ throws DOMException
+ {
+ return new DomNodeIterator(root, whatToShow, filter,
+ entityReferenceExpansion, false);
+ }
+
+ public TreeWalker createTreeWalker(Node root,
+ int whatToShow,
+ NodeFilter filter,
+ boolean entityReferenceExpansion)
+ throws DOMException
+ {
+ return new DomNodeIterator(root, whatToShow, filter,
+ entityReferenceExpansion, true);
+ }
+
+ // -- Debugging --
+
+ public String toString()
+ {
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
+ buffer.append("[version=");
+ buffer.append(getXmlVersion());
+ buffer.append(",standalone=");
+ buffer.append(getXmlStandalone());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java
new file mode 100644
index 000000000..6dea87226
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java
@@ -0,0 +1,326 @@
+/* GnomeDocumentBuilder.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import javax.xml.parsers.DocumentBuilder;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.DOMImplementation;
+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.SAXParseException;
+
+import gnu.xml.libxmlj.util.NamedInputStream;
+import gnu.xml.libxmlj.util.StandaloneDocumentType;
+import gnu.xml.libxmlj.util.StandaloneLocator;
+import gnu.xml.libxmlj.util.XMLJ;
+
+/**
+ * A JAXP DOM implementation that uses Gnome libxml2 as the underlying
+ * parser and node representation.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeDocumentBuilder
+ extends DocumentBuilder
+ implements DOMImplementation
+{
+
+ static
+ {
+ XMLJ.init();
+ }
+
+ // -- DocumentBuilder --
+
+ private boolean validate;
+ private boolean coalesce;
+ private boolean expandEntities;
+ private EntityResolver entityResolver;
+ private ErrorHandler errorHandler;
+ private boolean seenFatalError;
+
+ /**
+ * Constructs a new validating document builder.
+ */
+ public GnomeDocumentBuilder()
+ {
+ this(true, false, false);
+ }
+
+ /**
+ * Constructs a new document builder.
+ * @param validate whether to validate during parsing
+ * @param coalesce whether to merge CDATA as text nodes
+ * @param expandEntities whether to expand entity references
+ */
+ public GnomeDocumentBuilder(boolean validate,
+ boolean coalesce,
+ boolean expandEntities)
+ {
+ this.validate = validate;
+ this.coalesce = coalesce;
+ this.expandEntities = expandEntities;
+ }
+
+ public DOMImplementation getDOMImplementation()
+ {
+ return this;
+ }
+
+ public boolean isNamespaceAware()
+ {
+ return true;
+ }
+
+ public boolean isValidating()
+ {
+ return validate;
+ }
+
+ public Document newDocument()
+ {
+ return createDocument(null, null, null);
+ }
+
+ public Document parse(InputSource input)
+ throws SAXException, IOException
+ {
+ NamedInputStream in = XMLJ.getInputStream(input);
+ byte[] detectBuffer = in.getDetectBuffer();
+ String publicId = input.getPublicId();
+ String systemId = input.getSystemId();
+ String base = XMLJ.getBaseURI(systemId);
+ // Handle zero-length document
+ if (detectBuffer == null)
+ {
+ throw new SAXParseException("No document element", publicId,
+ systemId, 0, 0);
+ }
+ seenFatalError = false;
+ return parseStream(in,
+ detectBuffer,
+ publicId,
+ systemId,
+ base,
+ validate,
+ coalesce,
+ expandEntities,
+ true, //entityResolver != null,
+ errorHandler != null);
+ }
+
+ private native Document parseStream(InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean validate,
+ boolean coalesce,
+ boolean expandEntities,
+ boolean entityResolver,
+ boolean errorHandler);
+
+ public void setEntityResolver(EntityResolver resolver)
+ {
+ entityResolver = resolver;
+ }
+
+ public void setErrorHandler(ErrorHandler handler)
+ {
+ errorHandler = handler;
+ }
+
+ // -- DOMImplementation --
+
+ public boolean hasFeature(String name, String version)
+ {
+ if (name.length() == 0)
+ {
+ return false;
+ }
+ name = name.toLowerCase();
+ if (name.charAt(0) == '+')
+ {
+ name = name.substring(1);
+ }
+
+ if ("xml".equals(name) || "core".equals(name))
+ {
+ return (version == null ||
+ "".equals(version) ||
+ "1.0".equals(version) ||
+ "2.0".equals(version) ||
+ "3.0".equals(version));
+
+ }
+ else if ("ls".equals(name) || "ls-async".equals(name))
+ {
+ // TODO
+ /*
+ return (version == null ||
+ "".equals(version) ||
+ "3.0".equals(version));
+ */
+ return false;
+ }
+ else if ("traversal".equals(name))
+ {
+ return (version == null ||
+ "".equals(version) ||
+ "2.0".equals(version));
+ }
+ else if ("xpath".equals(name))
+ {
+ return (version == null ||
+ "".equals(version) ||
+ "3.0".equals(version));
+ }
+ return false;
+ }
+
+ // DOM Level 3
+
+ public Object getFeature(String feature, String version)
+ {
+ if (hasFeature(feature, version))
+ {
+ return this;
+ }
+ return null;
+ }
+
+ public native Document createDocument(String namespaceURI,
+ String qualifiedName,
+ DocumentType doctype);
+
+ public DocumentType createDocumentType(String qualifiedName,
+ String publicId,
+ String systemId)
+ {
+ return new StandaloneDocumentType(qualifiedName, publicId, systemId);
+ }
+
+ // Callback hooks from JNI
+
+ private void setDocumentLocator(Object ctx, Object loc)
+ {
+ // ignore
+ }
+
+ private InputStream resolveEntity(String publicId, String systemId,
+ String base)
+ throws SAXException, IOException
+ {
+ String url = XMLJ.getAbsoluteURI(base, systemId);
+ InputStream in = null;
+ if (entityResolver != null)
+ {
+ InputSource source = entityResolver.resolveEntity(publicId, url);
+ if (source != null)
+ {
+ in = XMLJ.getInputStream(source);
+ }
+ }
+ if (in == null)
+ {
+ in = XMLJ.getInputStream(new URL(url));
+ }
+ return in;
+ }
+
+ private void warning(String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws SAXException
+ {
+ if (!seenFatalError && errorHandler != null)
+ {
+ Locator l = new StandaloneLocator(lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorHandler.warning(new SAXParseException(message, l));
+ }
+ }
+
+ private void error(String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws SAXException
+ {
+ if (!seenFatalError && errorHandler != null)
+ {
+ Locator l = new StandaloneLocator(lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorHandler.error(new SAXParseException(message, l));
+ }
+ }
+
+ private void fatalError(String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws SAXException
+ {
+ if (!seenFatalError && errorHandler != null)
+ {
+ seenFatalError = true;
+ Locator l = new StandaloneLocator(lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorHandler.fatalError(new SAXParseException(message, l));
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilderFactory.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilderFactory.java
new file mode 100644
index 000000000..448e12351
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilderFactory.java
@@ -0,0 +1,118 @@
+/* GnomeDocumentBuilderFactory.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Factory for JAXP document builders using the libxml2 implementation.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeDocumentBuilderFactory
+ extends DocumentBuilderFactory
+{
+
+ private boolean secureProcessing;
+
+ public GnomeDocumentBuilderFactory ()
+ {
+ setNamespaceAware (true);
+ }
+
+ public Object getAttribute (String name)
+ {
+ // TODO
+ return null;
+ }
+
+ public DocumentBuilder newDocumentBuilder ()
+ throws ParserConfigurationException
+ {
+ /*
+ if (!isNamespaceAware ())
+ {
+ String msg = "Parser must be namespace-aware";
+ throw new ParserConfigurationException (msg);
+ }
+ if (isIgnoringComments ())
+ {
+ String msg = "Ignoring comments not supported";
+ throw new ParserConfigurationException (msg);
+ }
+ if (isIgnoringElementContentWhitespace ())
+ {
+ String msg = "Ignoring element content whitespace not supported";
+ throw new ParserConfigurationException (msg);
+ }
+ */
+ return new GnomeDocumentBuilder (isValidating (),
+ isCoalescing (),
+ isExpandEntityReferences ());
+ }
+
+ public void setAttribute (String name, Object value)
+ {
+ // TODO
+ }
+
+ public void setFeature(String name, boolean value)
+ throws ParserConfigurationException
+ {
+ if (name == null)
+ throw new NullPointerException();
+ if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
+ {
+ secureProcessing = true;
+ return;
+ }
+ throw new ParserConfigurationException(name);
+ }
+
+ public boolean getFeature(String name)
+ throws ParserConfigurationException
+ {
+ if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(name))
+ return secureProcessing;
+ throw new ParserConfigurationException(name);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentFragment.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentFragment.java
new file mode 100644
index 000000000..3623eb6cf
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentFragment.java
@@ -0,0 +1,57 @@
+/* GnomeDocumentFragment.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.DocumentFragment;
+
+/**
+ * A DOM document fragment node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeDocumentFragment
+extends GnomeNode
+implements DocumentFragment
+{
+
+ GnomeDocumentFragment (Object id)
+ {
+ super (id);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java
new file mode 100644
index 000000000..7649b7339
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java
@@ -0,0 +1,98 @@
+/* GnomeDocumentType.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ * A DOM document type node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeDocumentType
+extends GnomeNode
+implements DocumentType
+{
+
+ GnomeDocumentType (Object id)
+ {
+ super (id);
+ }
+
+ public String getName ()
+ {
+ return getNodeName ();
+ }
+
+ public NamedNodeMap getEntities ()
+ {
+ return new GnomeNamedNodeMap (id, 1);
+ }
+
+ public NamedNodeMap getNotations ()
+ {
+ return new GnomeNamedNodeMap (id, 2);
+ }
+
+ public native String getPublicId ();
+
+ public native String getSystemId ();
+
+ public native String getInternalSubset ();
+
+ public String toString ()
+ {
+ String publicId = getPublicId ();
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
+ buffer.append ("[");
+ if (publicId != null)
+ {
+ buffer.append ("publicId=");
+ buffer.append (publicId);
+ buffer.append (",");
+ }
+ buffer.append ("systemId=");
+ buffer.append (getSystemId ());
+ buffer.append ("]");
+ return buffer.toString ();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java
new file mode 100644
index 000000000..19889d663
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java
@@ -0,0 +1,184 @@
+/* GnomeElement.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.TypeInfo;
+
+/**
+ * A DOM element node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeElement
+ extends GnomeNode
+ implements Element
+{
+
+ /**
+ * User-defined ID attributes.
+ */
+ Set userIdAttrs;
+
+ GnomeElement(Object id)
+ {
+ super(id);
+ }
+
+ public String getTagName()
+ {
+ return getNodeName();
+ }
+
+ public native String getAttribute(String name);
+
+ public native void setAttribute(String name, String value)
+ throws DOMException;
+
+ public void removeAttribute(String name)
+ throws DOMException
+ {
+ Attr attr = getAttributeNode(name);
+ if (attr != null)
+ {
+ removeAttributeNode(attr);
+ }
+ }
+
+ public native Attr getAttributeNode(String name);
+
+ public native Attr setAttributeNode(Attr newAttr)
+ throws DOMException;
+
+ public native Attr removeAttributeNode(Attr oldAttr)
+ throws DOMException;
+
+ public native NodeList getElementsByTagName(String name);
+
+ public native String getAttributeNS(String namespaceURI, String localName);
+
+ public native void setAttributeNS(String namespaceURI, String
+ qualifiedName, String value)
+ throws DOMException;
+
+ public void removeAttributeNS(String namespaceURI, String localName)
+ throws DOMException
+ {
+ Attr attr = getAttributeNodeNS(namespaceURI, localName);
+ if (attr != null)
+ {
+ removeAttributeNode(attr);
+ }
+ }
+
+ public native Attr getAttributeNodeNS(String namespaceURI,
+ String localName);
+
+ public native Attr setAttributeNodeNS(Attr newAttr)
+ throws DOMException;
+
+ public native NodeList getElementsByTagNameNS(String namespaceURI,
+ String localName);
+
+ public native boolean hasAttribute(String name);
+
+ public native boolean hasAttributeNS(String namespaceURI,
+ String localName);
+
+ // DOM Level 3 methods
+
+ public TypeInfo getSchemaTypeInfo()
+ {
+ return new GnomeTypeInfo(id);
+ }
+
+ public void setIdAttribute(String name, boolean isId)
+ {
+ Attr attr = getAttributeNode(name);
+ setIdAttributeNode(attr, isId);
+ }
+
+ public void setIdAttributeNode(Attr attr, boolean isId)
+ {
+ if (attr == null)// FIXME || !attr.getOwnerElement().equals(this))
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
+ }
+ if (isId)
+ {
+ if (userIdAttrs == null)
+ {
+ userIdAttrs = new HashSet();
+ }
+ userIdAttrs.add(attr);
+ }
+ else if (userIdAttrs != null)
+ {
+ userIdAttrs.remove(attr);
+ if (userIdAttrs.isEmpty())
+ {
+ userIdAttrs = null;
+ }
+ }
+ }
+
+ public void setIdAttributeNS(String namespaceURI, String localName,
+ boolean isId)
+ {
+ Attr attr = getAttributeNodeNS(namespaceURI, localName);
+ setIdAttributeNode(attr, isId);
+ }
+
+ public String toString()
+ {
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
+ buffer.append("[tagName=");
+ buffer.append(getTagName());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java
new file mode 100644
index 000000000..a05217473
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java
@@ -0,0 +1,104 @@
+/* GnomeEntity.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.Entity;
+
+/**
+ * A DOM entity node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeEntity
+extends GnomeNode
+implements Entity
+{
+
+ GnomeEntity (Object id)
+ {
+ super (id);
+ }
+
+ public native String getPublicId ();
+
+ public native String getSystemId ();
+
+ public native String getNotationName ();
+
+ // DOM Level 3 methods
+
+ public String getInputEncoding ()
+ {
+ // TODO
+ return null;
+ }
+
+ public String getXmlEncoding ()
+ {
+ // TODO
+ return null;
+ }
+
+ public String getXmlVersion ()
+ {
+ // TODO
+ return null;
+ }
+
+ public String toString ()
+ {
+ String publicId = getPublicId ();
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
+ buffer.append ("[");
+ if (publicId != null)
+ {
+ buffer.append ("publicId=");
+ buffer.append (publicId);
+ buffer.append (",");
+ }
+ buffer.append ("systemId=");
+ buffer.append (getSystemId ());
+ buffer.append (",notationName=");
+ buffer.append (getNotationName ());
+ buffer.append ("]");
+ return buffer.toString ();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntityReference.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntityReference.java
new file mode 100644
index 000000000..aa2fcf1e5
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntityReference.java
@@ -0,0 +1,57 @@
+/* GnomeEntityReference.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.EntityReference;
+
+/**
+ * A DOM entity reference node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeEntityReference
+extends GnomeNode
+implements EntityReference
+{
+
+ GnomeEntityReference (Object id)
+ {
+ super (id);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java
new file mode 100644
index 000000000..b8df4fede
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java
@@ -0,0 +1,92 @@
+/* GnomeNamedNodeMap.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * A DOM named node map implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeNamedNodeMap
+implements NamedNodeMap
+{
+
+ /**
+ * The node id.
+ */
+ private final Object id;
+
+ /**
+ * The map type.
+ * 0=attributes
+ * 1=entities
+ * 2=notations
+ */
+ private final int type;
+
+ GnomeNamedNodeMap (Object id, int type)
+ {
+ this.id = id;
+ this.type = type;
+ }
+
+ public native Node getNamedItem (String name);
+
+ public native Node setNamedItem (Node arg)
+ throws DOMException;
+
+ public native Node removeNamedItem (String name)
+ throws DOMException;
+
+ public native Node item (int index);
+
+ public native int getLength ();
+
+ public native Node getNamedItemNS (String namespaceURI, String localName);
+
+ public native Node setNamedItemNS (Node arg)
+ throws DOMException;
+
+ public native Node removeNamedItemNS (String namespaceURI,
+ String localName);
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java
new file mode 100644
index 000000000..5874916e5
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java
@@ -0,0 +1,501 @@
+/* GnomeNode.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.w3c.dom.UserDataHandler;
+
+import gnu.xml.libxmlj.util.StandaloneDocumentType;
+
+/**
+ * A DOM node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeNode
+ implements Node, Comparable
+{
+
+ /**
+ * Maps document pointers to a map of node pointers to node instances.
+ */
+ static Map instances;
+
+ /**
+ * Retrieves the node instance for the specified node pointer.
+ * This creates a new instance and adds it to the cache if required.
+ * @param doc the document pointer
+ * @param node the node pointer
+ * @param type the node type
+ */
+ static GnomeNode newInstance(final Object doc, final Object node,
+ final int type)
+ {
+ if (doc == null)
+ {
+ throw new NullPointerException("doc");
+ }
+ if (node == null)
+ {
+ throw new NullPointerException("node");
+ }
+ if (instances == null)
+ {
+ instances = new HashMap();
+ }
+ Map docNodes = (Map) instances.get(doc);
+ if (docNodes == null)
+ {
+ docNodes = new HashMap(1024); // TODO review optimal initial capacity
+ instances.put(doc, docNodes);
+ }
+ GnomeNode nodeInstance = (GnomeNode) docNodes.get(node);
+ if (nodeInstance != null)
+ {
+ return nodeInstance; // Return cached version
+ }
+ switch (type)
+ {
+ case ELEMENT_NODE:
+ nodeInstance = new GnomeElement(node);
+ break;
+ case ATTRIBUTE_NODE:
+ nodeInstance = new GnomeAttr(node);
+ break;
+ case TEXT_NODE:
+ nodeInstance = new GnomeText(node);
+ break;
+ case CDATA_SECTION_NODE:
+ nodeInstance = new GnomeCDATASection(node);
+ break;
+ case ENTITY_REFERENCE_NODE:
+ nodeInstance = new GnomeEntityReference(node);
+ break;
+ case ENTITY_NODE:
+ nodeInstance = new GnomeEntity(node);
+ break;
+ case PROCESSING_INSTRUCTION_NODE:
+ nodeInstance = new GnomeProcessingInstruction(node);
+ break;
+ case COMMENT_NODE:
+ nodeInstance = new GnomeComment(node);
+ break;
+ case DOCUMENT_NODE:
+ nodeInstance = new GnomeDocument(node);
+ break;
+ case DOCUMENT_TYPE_NODE:
+ nodeInstance = new GnomeDocumentType(node);
+ break;
+ case DOCUMENT_FRAGMENT_NODE:
+ nodeInstance = new GnomeDocumentFragment(node);
+ break;
+ case NOTATION_NODE:
+ nodeInstance = new GnomeNotation(node);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown node type: " + type);
+ }
+ docNodes.put(node, nodeInstance);
+ return nodeInstance;
+ }
+
+ /**
+ * Frees the specified document.
+ * This removes all its nodes from the cache.
+ */
+ static void freeDocument(final Object doc)
+ {
+ if (instances == null || doc == null)
+ {
+ return;
+ }
+ instances.remove(doc);
+ //System.out.println("Freed "+instances.remove(doc));
+ }
+
+ /**
+ * xmlNodePtr
+ */
+ final Object id;
+
+ Map userData;
+ Map userDataHandlers;
+
+ GnomeNode(final Object id)
+ {
+ this.id = id;
+ }
+
+ public native String getNodeName();
+
+ public native String getNodeValue()
+ throws DOMException;
+
+ public native void setNodeValue(String nodeValue)
+ throws DOMException;
+
+ public native short getNodeType();
+
+ public native Node getParentNode();
+
+ public NodeList getChildNodes()
+ {
+ return new GnomeNodeList(id);
+ }
+
+ public native Node getFirstChild();
+
+ public native Node getLastChild();
+
+ public native Node getPreviousSibling();
+
+ public native Node getNextSibling();
+
+ public NamedNodeMap getAttributes()
+ {
+ return new GnomeNamedNodeMap(id, 0);
+ }
+
+ public native Document getOwnerDocument();
+
+ public Node insertBefore(Node newChild, Node refChild)
+ throws DOMException
+ {
+ if (newChild instanceof StandaloneDocumentType)
+ {
+ DocumentType dt = (DocumentType) newChild;
+ newChild = ((GnomeDocument) getOwnerDocument())
+ .createDocumentType(dt.getName(), dt.getPublicId(),
+ dt.getSystemId());
+ }
+ if (newChild == null)
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
+ }
+ if (!(newChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.WRONG_DOCUMENT_ERR, null);
+ }
+ if (refChild == null || !(refChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
+ }
+ return xmljInsertBefore(newChild, refChild);
+ }
+
+ private native Node xmljInsertBefore(Node newChild, Node refChild)
+ throws DOMException;
+
+ public Node replaceChild(Node newChild, Node oldChild)
+ throws DOMException
+ {
+ if (newChild instanceof StandaloneDocumentType)
+ {
+ DocumentType dt = (DocumentType) newChild;
+ newChild = ((GnomeDocument) getOwnerDocument())
+ .createDocumentType(dt.getName(), dt.getPublicId(),
+ dt.getSystemId());
+ }
+ if (newChild == null)
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
+ }
+ if (!(newChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.WRONG_DOCUMENT_ERR, newChild.toString());
+ }
+ if (oldChild == null || !(oldChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
+ }
+ return xmljReplaceChild(newChild, oldChild);
+ }
+
+ private native Node xmljReplaceChild(Node newChild, Node oldChild)
+ throws DOMException;
+
+ public Node removeChild(Node oldChild)
+ throws DOMException
+ {
+ if (!(oldChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.WRONG_DOCUMENT_ERR, null);
+ }
+ return xmljRemoveChild(oldChild);
+ }
+
+ private native Node xmljRemoveChild(Node oldChild)
+ throws DOMException;
+
+ public Node appendChild(Node newChild)
+ throws DOMException
+ {
+ if (newChild instanceof StandaloneDocumentType)
+ {
+ DocumentType dt = (DocumentType) newChild;
+ newChild = ((GnomeDocument) getOwnerDocument())
+ .createDocumentType(dt.getName(), dt.getPublicId(),
+ dt.getSystemId());
+ }
+ if (!(newChild instanceof GnomeNode))
+ {
+ throw new GnomeDOMException(DOMException.WRONG_DOCUMENT_ERR, null);
+ }
+ return xmljAppendChild(newChild);
+ }
+
+ private native Node xmljAppendChild(Node newChild)
+ throws DOMException;
+
+ public native boolean hasChildNodes();
+
+ public Node cloneNode(boolean deep)
+ {
+ Node ret = xmljCloneNode(deep);
+ notifyUserDataHandlers(UserDataHandler.NODE_CLONED, this, ret);
+ return ret;
+ }
+
+ private native Node xmljCloneNode(boolean deep);
+
+ public native void normalize();
+
+ public boolean isSupported(String feature, String version)
+ {
+ return getOwnerDocument().getImplementation()
+ .hasFeature(feature, version);
+ }
+
+ public native String getNamespaceURI();
+
+ public native String getPrefix();
+
+ public native void setPrefix(String prefix)
+ throws DOMException;
+
+ public native String getLocalName();
+
+ public native boolean hasAttributes();
+
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
+
+ public boolean equals(Object other)
+ {
+ if (other == this)
+ {
+ return true;
+ }
+ return (other instanceof GnomeNode &&
+ ((GnomeNode) other).id == id);
+ }
+
+ // DOM Level 3 methods
+
+ public native String getBaseURI();
+
+ public short compareDocumentPosition(Node other)
+ throws DOMException
+ {
+ return (short) compareTo(other);
+ }
+
+ public final int compareTo(Object other)
+ {
+ if (other instanceof GnomeNode)
+ {
+ return xmljCompareTo(other);
+ }
+ return 0;
+ }
+
+ private native int xmljCompareTo(Object other);
+
+ public String getTextContent()
+ throws DOMException
+ {
+ switch (getNodeType())
+ {
+ case ELEMENT_NODE:
+ case ATTRIBUTE_NODE:
+ case ENTITY_NODE:
+ case ENTITY_REFERENCE_NODE:
+ case DOCUMENT_FRAGMENT_NODE:
+ CPStringBuilder buffer = new CPStringBuilder();
+ NodeList children = getChildNodes();
+ int len = children.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node child = children.item(i);
+ String textContent = child.getTextContent();
+ if (textContent != null)
+ {
+ buffer.append(textContent);
+ }
+ }
+ return buffer.toString();
+ case TEXT_NODE:
+ case CDATA_SECTION_NODE:
+ case COMMENT_NODE:
+ case PROCESSING_INSTRUCTION_NODE:
+ return getNodeValue();
+ default:
+ return null;
+ }
+ }
+
+ public void setTextContent(String textContent)
+ throws DOMException
+ {
+ switch (getNodeType())
+ {
+ case ENTITY_REFERENCE_NODE:
+ // entity references are read only
+ throw new GnomeDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ null);
+ case ELEMENT_NODE:
+ case ATTRIBUTE_NODE:
+ case ENTITY_NODE:
+ case DOCUMENT_FRAGMENT_NODE:
+ NodeList children = getChildNodes();
+ int len = children.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node child = children.item(i);
+ removeChild(child);
+ }
+ if (textContent != null)
+ {
+ Text text = getOwnerDocument().createTextNode(textContent);
+ appendChild(text);
+ }
+ break;
+ case TEXT_NODE:
+ case CDATA_SECTION_NODE:
+ case COMMENT_NODE:
+ case PROCESSING_INSTRUCTION_NODE:
+ setNodeValue(textContent);
+ break;
+ }
+ }
+
+ public boolean isSameNode(Node other)
+ {
+ return equals(other);
+ }
+
+ public native String lookupPrefix(String namespaceURI);
+
+ public native boolean isDefaultNamespace(String namespaceURI);
+
+ public native String lookupNamespaceURI(String prefix);
+
+ public native boolean isEqualNode(Node arg);
+
+ public Object getFeature(String feature, String version)
+ {
+ return getOwnerDocument().getImplementation()
+ .getFeature(feature, version);
+ }
+
+ public Object setUserData(String key, Object data, UserDataHandler handler)
+ {
+ // TODO handler
+ if (userData == null)
+ {
+ userData = new HashMap();
+ }
+ if (handler != null)
+ {
+ if (userDataHandlers == null)
+ {
+ userDataHandlers = new HashMap();
+ }
+ userDataHandlers.put(key, handler);
+ }
+ return userData.put(key, data);
+ }
+
+ public Object getUserData(String key)
+ {
+ if (userData == null)
+ {
+ return null;
+ }
+ return userData.get(key);
+ }
+
+ void notifyUserDataHandlers(short op, Node src, Node dst)
+ {
+ if (userDataHandlers != null)
+ {
+ for (Iterator i = userDataHandlers.entrySet().iterator(); i.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) i.next();
+ String key = (String) entry.getKey();
+ UserDataHandler handler = (UserDataHandler) entry.getValue();
+ Object data = userData.get(key);
+ handler.handle(op, key, data, src, dst);
+ }
+ }
+ }
+
+ public String toString()
+ {
+ CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
+ buffer.append("[nodeName=");
+ buffer.append(getNodeName());
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNodeList.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNodeList.java
new file mode 100644
index 000000000..51a6d0bfa
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNodeList.java
@@ -0,0 +1,66 @@
+/* GnomeNodeList.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A DOM node list implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeNodeList
+implements NodeList
+{
+
+ /**
+ * The node id.
+ */
+ private final Object id;
+
+ GnomeNodeList (Object id)
+ {
+ this.id = id;
+ }
+
+ public native Node item (int index);
+
+ public native int getLength ();
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java
new file mode 100644
index 000000000..50e48e2a3
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java
@@ -0,0 +1,80 @@
+/* GnomeNotation.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.Notation;
+
+/**
+ * A DOM notation node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeNotation
+extends GnomeNode
+implements Notation
+{
+
+ GnomeNotation (Object id)
+ {
+ super (id);
+ }
+
+ public native String getPublicId ();
+
+ public native String getSystemId ();
+
+ public String toString ()
+ {
+ String publicId = getPublicId ();
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
+ buffer.append ("[");
+ if (publicId != null)
+ {
+ buffer.append ("publicId=");
+ buffer.append (publicId);
+ buffer.append (",");
+ }
+ buffer.append ("systemId=");
+ buffer.append (getSystemId ());
+ buffer.append ("]");
+ return buffer.toString ();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java
new file mode 100644
index 000000000..fad6e108a
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java
@@ -0,0 +1,79 @@
+/* GnomeProcessingInstruction.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.ProcessingInstruction;
+
+/**
+ * A DOM processing instruction node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeProcessingInstruction
+extends GnomeNode
+implements ProcessingInstruction
+{
+
+ GnomeProcessingInstruction (Object id)
+ {
+ super (id);
+ }
+
+ public String getTarget ()
+ {
+ return getNodeName ();
+ }
+
+ public native String getData ();
+
+ public native void setData (String data)
+ throws DOMException;
+
+ public String toString ()
+ {
+ CPStringBuilder buffer = new CPStringBuilder (getClass ().getName ());
+ buffer.append ("[data=");
+ buffer.append (getData ());
+ buffer.append ("]");
+ return buffer.toString ();
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java
new file mode 100644
index 000000000..e00be18a9
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java
@@ -0,0 +1,132 @@
+/* GnomeText.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * A DOM text node implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeText
+extends GnomeCharacterData
+implements Text
+{
+
+ GnomeText (Object id)
+ {
+ super (id);
+ }
+
+ public Text splitText (int offset)
+ throws DOMException
+ {
+ String value = getNodeValue ();
+ String part1 = value.substring (0, offset);
+ String part2 = value.substring (offset);
+ Text text = getOwnerDocument ().createTextNode (part1);
+ getParentNode ().insertBefore (text, this);
+ setNodeValue (part2);
+ return text;
+ }
+
+ // DOM Level 3
+
+ public boolean isElementContentWhitespace ()
+ {
+ return getTextContent ().trim ().length () == 0;
+ }
+
+ public String getWholeText ()
+ {
+ Node first = this;
+ Node node = getPreviousSibling ();
+ while (node != null && node instanceof Text)
+ {
+ first = node;
+ node = node.getPreviousSibling ();
+ }
+ CPStringBuilder buf = new CPStringBuilder (first.getNodeValue ());
+ node = first.getNextSibling ();
+ while (node != null && node instanceof Text)
+ {
+ buf.append (node.getNodeValue ());
+ node = node.getNextSibling ();
+ }
+ return buf.toString ();
+ }
+
+ public Text replaceWholeText (String content) throws DOMException
+ {
+ boolean isEmpty = (content == null || content.length () == 0);
+ if (!isEmpty)
+ {
+ setNodeValue (content);
+ }
+
+ Node first = this;
+ Node node = getPreviousSibling ();
+ while (node != null && node instanceof Text)
+ {
+ first = node;
+ node = node.getPreviousSibling ();
+ }
+ node = first.getNextSibling ();
+ Node parent = getParentNode ();
+ if (first != this || isEmpty)
+ {
+ parent.removeChild (first);
+ }
+ while (node != null && node instanceof Text)
+ {
+ Node tmp = node;
+ node = node.getNextSibling ();
+ if (tmp != this || isEmpty)
+ {
+ parent.removeChild (tmp);
+ }
+ }
+ return (isEmpty) ? null : this;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeTypeInfo.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeTypeInfo.java
new file mode 100644
index 000000000..5517e8a99
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeTypeInfo.java
@@ -0,0 +1,65 @@
+/* GnomeTypeInfo.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.TypeInfo;
+
+/**
+ * Provides XML Schema information about an element or attribute.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeTypeInfo implements TypeInfo
+{
+
+ final Object id;
+
+ GnomeTypeInfo(Object id)
+ {
+ this.id = id;
+ }
+
+ public native String getTypeName ();
+
+ public native String getTypeNamespace ();
+
+ public native boolean isDerivedFrom (String typeNamespaceArg,
+ String typeNameArg,
+ int derivationMethod);
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathExpression.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathExpression.java
new file mode 100644
index 000000000..52f4daa21
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathExpression.java
@@ -0,0 +1,86 @@
+/* GnomeXPathExpression.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.xpath.XPathException;
+import org.w3c.dom.xpath.XPathExpression;
+import org.w3c.dom.xpath.XPathNSResolver;
+
+/**
+ * A compiled XPath expression implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeXPathExpression
+implements XPathExpression
+{
+
+ /**
+ * xmlXPathCompExprPtr
+ */
+ final Object expr;
+
+ GnomeXPathExpression (GnomeDocument doc, String expression,
+ XPathNSResolver resolver)
+ {
+ expr = init (expression);
+ // TODO resolver
+ }
+
+ protected void finalize ()
+ {
+ free (expr);
+ }
+
+ private native Object init (String expression);
+
+ private native void free (Object expr);
+
+ public Object evaluate (Node contextNode, short type, Object result)
+ throws XPathException, DOMException
+ {
+ return doEvaluate (expr, contextNode, type, result);
+ }
+
+ private native Object doEvaluate (Object expr, Node contextNode,
+ short type, Object result)
+ throws XPathException, DOMException;
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java
new file mode 100644
index 000000000..039a79a03
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java
@@ -0,0 +1,64 @@
+/* GnomeXPathNSResolver.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.xpath.XPathNSResolver;
+
+/**
+ * XPath namespace URI resolver implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeXPathNSResolver
+ implements XPathNSResolver
+{
+
+ Node node;
+
+ GnomeXPathNSResolver(Node node)
+ {
+ this.node = node;
+ }
+
+ public String lookupNamespaceURI(String prefix)
+ {
+ return node.lookupNamespaceURI(prefix);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNodeList.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNodeList.java
new file mode 100644
index 000000000..b8d0a3d0a
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNodeList.java
@@ -0,0 +1,73 @@
+/* GnomeXPathNodeList.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A node list that uses an XPath result object.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeXPathNodeList
+implements NodeList
+{
+
+ /**
+ * xmlXPathObjectPtr
+ */
+ final Object obj;
+
+ GnomeXPathNodeList (Object obj)
+ {
+ this.obj = obj;
+ }
+
+ protected void finalize ()
+ {
+ free(obj);
+ }
+
+ private native void free (Object obj);
+
+ public native int getLength ();
+
+ public native Node item (int index);
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java
new file mode 100644
index 000000000..b2c706f65
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java
@@ -0,0 +1,134 @@
+/* GnomeXPathResult.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.dom;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.xpath.XPathException;
+import org.w3c.dom.xpath.XPathResult;
+
+/**
+ * An XPath result object implemented in libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeXPathResult
+implements XPathResult
+{
+
+ /**
+ * xmlXPathObjectPtr
+ */
+ final Object obj;
+
+ GnomeXPathResult (Object obj)
+ {
+ this.obj = obj;
+ }
+
+ protected void finalize ()
+ {
+ free (obj);
+ }
+
+ private native void free (Object obj);
+
+ public native short getResultType ();
+
+ public native double getNumberValue ()
+ throws XPathException;
+
+ public native String getStringValue ()
+ throws XPathException;
+
+ public native boolean getBooleanValue ()
+ throws XPathException;
+
+ public native Node getSingleNodeValue ()
+ throws XPathException;
+
+ public native boolean getInvalidIteratorState();
+
+ public native int getSnapshotLength ()
+ throws XPathException;
+
+ public native Node iterateNext ()
+ throws XPathException, DOMException;
+
+ public native Node snapshotItem (int index)
+ throws XPathException;
+
+ public String toString ()
+ {
+ short type = getResultType ();
+ switch (type)
+ {
+ case STRING_TYPE:
+ return getStringValue ();
+ case NUMBER_TYPE:
+ return Double.toString (getNumberValue ());
+ case BOOLEAN_TYPE:
+ return Boolean.valueOf (getBooleanValue ()).toString ();
+ case UNORDERED_NODE_SNAPSHOT_TYPE:
+ int len = getSnapshotLength ();
+ switch (len) {
+ case 0:
+ return "[no matches]";
+ case 1:
+ return getSingleNodeValue ().toString ();
+ default:
+ CPStringBuilder buffer = new CPStringBuilder ();
+ for (int i = 0; i < len; i++)
+ {
+ if (i > 0)
+ {
+ buffer.append (',');
+ }
+ buffer.append (snapshotItem (i));
+ }
+ return buffer.toString ();
+ }
+ default:
+ return getClass ().getName () + "[type=" + type + ",length=" +
+ getSnapshotLength () + ']';
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/GnomeLocator.java b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeLocator.java
new file mode 100644
index 000000000..dba0a72c0
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeLocator.java
@@ -0,0 +1,99 @@
+/* GnomeLocator.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import org.xml.sax.Locator;
+
+/**
+ * SAX Locator implementation that uses libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeLocator
+implements Locator
+{
+
+ // An xmlParserCtxtPtr
+ private final Object ctx;
+
+ // An xmlSAXLocatorPtr
+ private final Object loc;
+
+ GnomeLocator (Object ctx, Object loc)
+ {
+ this.ctx = ctx;
+ this.loc = loc;
+ if (ctx == null)
+ {
+ throw new NullPointerException ("ctx");
+ }
+ if (loc == null)
+ {
+ throw new NullPointerException ("loc");
+ }
+ }
+
+ public String getPublicId ()
+ {
+ return publicId (ctx, loc);
+ }
+
+ private native String publicId (Object ctx, Object loc);
+
+ public String getSystemId ()
+ {
+ return systemId (ctx, loc);
+ }
+
+ private native String systemId (Object ctx, Object loc);
+
+ public int getLineNumber ()
+ {
+ return lineNumber (ctx, loc);
+ }
+
+ private native int lineNumber (Object ctx, Object loc);
+
+ public int getColumnNumber ()
+ {
+ return columnNumber (ctx, loc);
+ }
+
+ private native int columnNumber (Object ctx, Object loc);
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParser.java b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParser.java
new file mode 100644
index 000000000..86d326b7c
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParser.java
@@ -0,0 +1,105 @@
+/* GnomeSAXParser.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import javax.xml.parsers.SAXParser;
+
+import org.xml.sax.Parser;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+/**
+ * JAXP SAX parser implementation that uses libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class GnomeSAXParser
+extends SAXParser
+{
+
+ private boolean namespaceAware;
+ private boolean validating;
+
+ /**
+ * Creates a new SAX parser.
+ */
+ GnomeSAXParser (boolean namespaceAware, boolean validating)
+ {
+ this.namespaceAware = namespaceAware;
+ this.validating = validating;
+ }
+
+ public Parser getParser ()
+ throws SAXException
+ {
+ throw new SAXNotSupportedException ("SAX version 1 not supported");
+ }
+
+ public XMLReader getXMLReader ()
+ throws SAXException
+ {
+ return new GnomeXMLReader (namespaceAware, validating);
+ }
+
+ public Object getProperty (String name)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ GnomeXMLReader.checkPropertyName (name);
+ throw new SAXNotSupportedException (name);
+ }
+
+ public void setProperty (String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ GnomeXMLReader.checkPropertyName (name);
+ throw new SAXNotSupportedException (name);
+ }
+
+ public boolean isNamespaceAware ()
+ {
+ return namespaceAware;
+ }
+
+ public boolean isValidating ()
+ {
+ return validating;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParserFactory.java b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParserFactory.java
new file mode 100644
index 000000000..0c2881240
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeSAXParserFactory.java
@@ -0,0 +1,92 @@
+/* GnomeSAXParserFactory.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+/**
+ * JAXP SAX parser factory implementation that uses libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeSAXParserFactory
+extends SAXParserFactory
+{
+
+ private Map features;
+
+ /**
+ * Creates a new SAX parser factory.
+ */
+ public GnomeSAXParserFactory ()
+ {
+ features = new HashMap ();
+ }
+
+ public SAXParser newSAXParser ()
+ throws ParserConfigurationException, SAXException
+ {
+ // TODO features
+ return new GnomeSAXParser (isNamespaceAware (), isValidating ());
+ }
+
+ public boolean getFeature (String name)
+ throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
+ {
+ GnomeXMLReader.checkFeatureName (name);
+ Boolean val = (Boolean) features.get (name);
+ return (val == null) ? false : val.booleanValue ();
+ }
+
+ public void setFeature (String name, boolean flag)
+ throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException
+ {
+ GnomeXMLReader.checkFeatureName (name);
+ features.put (name, flag ? Boolean.TRUE : Boolean.FALSE);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/GnomeXMLReader.java b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeXMLReader.java
new file mode 100644
index 000000000..3a34bc934
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/GnomeXMLReader.java
@@ -0,0 +1,1065 @@
+/* GnomeXMLReader.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+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 org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
+
+import gnu.xml.libxmlj.util.NamedInputStream;
+import gnu.xml.libxmlj.util.StandaloneLocator;
+import gnu.xml.libxmlj.util.XMLJ;
+
+/**
+ * A SAX2 parser that uses libxml2.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeXMLReader
+implements XMLReader
+{
+
+ static
+ {
+ XMLJ.init ();
+ }
+
+ private static final String FEATURES_PREFIX =
+ "http://xml.org/sax/features/";
+
+ private static final List RECOGNIZED_FEATURES =
+ Arrays.asList (new String[]
+ {
+ "external-general-entities",
+ "external-parameter-entities",
+ "is-standalone",
+ "lexical-handler/parameter-entities",
+ "namespaces",
+ "namespace-prefixes",
+ "resolve-dtd-uris",
+ "string-interning",
+ "use-attributes2",
+ "use-locator2",
+ "use-entity-resolver2",
+ "validation"
+ });
+
+ private static final String PROPERTIES_PREFIX =
+ "http://xml.org/sax/properties/";
+
+ private static final List RECOGNIZED_PROPERTIES =
+ Arrays.asList (new String[]
+ {
+ "declaration-handler",
+ "dom-node",
+ "lexical-handler",
+ "xml-string"
+ });
+
+ // Features
+
+ private transient boolean standalone;
+ private boolean namespaces;
+ private boolean namespacePrefixes;
+ private boolean validation;
+
+ // Callback handlers
+
+ private ContentHandler contentHandler;
+
+ private DTDHandler dtdHandler;
+
+ private EntityResolver entityResolver;
+
+ private ErrorHandler errorHandler;
+
+ private DeclHandler declarationHandler;
+
+ private LexicalHandler lexicalHandler;
+
+ private GnomeLocator locator;
+
+ // Namespace helper for handling callbacks
+ private transient Namespaces ns;
+
+ // If true, do not invoke callback methods except endDocument
+ private transient boolean seenFatalError;
+
+ private transient boolean seenStartDocument;
+
+ private transient String base;
+
+ public GnomeXMLReader ()
+ {
+ this (true, true);
+ }
+
+ public GnomeXMLReader (boolean namespaces, boolean validation)
+ {
+ this.namespaces = namespaces;
+ this.validation = validation;
+ ns = new Namespaces ();
+ }
+
+ public ContentHandler getContentHandler ()
+ {
+ return contentHandler;
+ }
+
+ public void setContentHandler (ContentHandler handler)
+ {
+ contentHandler = handler;
+ }
+
+ public DTDHandler getDTDHandler ()
+ {
+ return dtdHandler;
+ }
+
+ public void setDTDHandler (DTDHandler handler)
+ {
+ dtdHandler = handler;
+ }
+
+ public EntityResolver getEntityResolver ()
+ {
+ return entityResolver;
+ }
+
+ public void setEntityResolver (EntityResolver resolver)
+ {
+ entityResolver = resolver;
+ }
+
+ public ErrorHandler getErrorHandler ()
+ {
+ return errorHandler;
+ }
+
+ public void setErrorHandler (ErrorHandler handler)
+ {
+ errorHandler = handler;
+ }
+
+ // Features
+
+ public boolean getFeature (String name)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ checkFeatureName (name);
+ String key = name.substring (FEATURES_PREFIX.length ());
+ if ("external-general-entities".equals (key))
+ {
+ return validation; // TODO check this
+ }
+ else if ("external-parameter-entities".equals (key))
+ {
+ return validation; // TODO check this
+ }
+ else if ("is-standalone".equals (key))
+ {
+ return standalone;
+ }
+ else if ("namespaces".equals (key))
+ {
+ return namespaces;
+ }
+ else if ("namespace-prefixes".equals (key))
+ {
+ return namespacePrefixes;
+ }
+ else if ("resolve-dtd-uris".equals (key))
+ {
+ return true;
+ }
+ else if ("validation".equals (key))
+ {
+ return validation;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public void setFeature (String name, boolean value)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ checkFeatureName (name);
+ String key = name.substring (FEATURES_PREFIX.length ());
+ if ("namespaces".equals (key))
+ {
+ namespaces = value;
+ }
+ else if ("namespace-prefixes".equals (key))
+ {
+ namespacePrefixes = value;
+ }
+ else if ("validation".equals (key))
+ {
+ validation = value;
+ }
+ }
+
+ /**
+ * Check that the specified feature name is recognized.
+ */
+ static void checkFeatureName (String name)
+ throws SAXNotRecognizedException
+ {
+ if (name == null || !name.startsWith (FEATURES_PREFIX))
+ {
+ throw new SAXNotRecognizedException (name);
+ }
+ String key = name.substring (FEATURES_PREFIX.length ());
+ if (!RECOGNIZED_FEATURES.contains (key))
+ {
+ throw new SAXNotRecognizedException (name);
+ }
+ }
+
+ // Properties
+
+ public Object getProperty (String name)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ checkPropertyName (name);
+ String key = name.substring (PROPERTIES_PREFIX.length ());
+ if ("declaration-handler".equals (key))
+ {
+ return getDeclarationHandler ();
+ }
+ else if ("lexical-handler".equals (key))
+ {
+ return getLexicalHandler ();
+ }
+ else
+ {
+ throw new SAXNotSupportedException (name);
+ }
+ }
+
+ public void setProperty (String name, Object value)
+ throws SAXNotRecognizedException, SAXNotSupportedException
+ {
+ checkPropertyName (name);
+ String key = name.substring (PROPERTIES_PREFIX.length ());
+ if ("declaration-handler".equals (key))
+ {
+ setDeclarationHandler ((DeclHandler) value);
+ }
+ else if ("lexical-handler".equals (key))
+ {
+ setLexicalHandler ((LexicalHandler) value);
+ }
+ }
+
+ public DeclHandler getDeclarationHandler ()
+ {
+ return declarationHandler;
+ }
+
+ public void setDeclarationHandler (DeclHandler declarationHandler)
+ {
+ this.declarationHandler = declarationHandler;
+ }
+
+ public LexicalHandler getLexicalHandler ()
+ {
+ return lexicalHandler;
+ }
+
+ public void setLexicalHandler (LexicalHandler lexicalHandler)
+ {
+ this.lexicalHandler = lexicalHandler;
+ }
+
+ /**
+ * Check that the specified property name is recognized.
+ */
+ static void checkPropertyName (String name)
+ throws SAXNotRecognizedException
+ {
+ if (!name.startsWith (PROPERTIES_PREFIX))
+ {
+ throw new SAXNotRecognizedException (name);
+ }
+ String key = name.substring (PROPERTIES_PREFIX.length ());
+ if (!RECOGNIZED_PROPERTIES.contains (key))
+ {
+ throw new SAXNotRecognizedException (name);
+ }
+ }
+
+ // Parse
+
+ public void parse (String systemId)
+ throws IOException, SAXException
+ {
+ URL url = null;
+ try
+ {
+ url = new URL (systemId);
+ }
+ catch (MalformedURLException e)
+ {
+ File file = new File(systemId);
+ if (!file.exists ())
+ {
+ throw new FileNotFoundException (systemId);
+ }
+ String path = file.getAbsolutePath();
+ if (File.separatorChar != '/')
+ {
+ path = path.replace (File.separatorChar, '/');
+ }
+ if (!path.startsWith ("/"))
+ {
+ path = "/" + path;
+ }
+ if (!path.endsWith ("/") && file.isDirectory ())
+ {
+ path = path + "/";
+ }
+ url = new URL ("file:" + path);
+ }
+ InputSource source = new InputSource(url.toString ());
+ source.setByteStream (url.openStream ());
+ parse (source);
+ }
+
+ public synchronized void parse (InputSource input)
+ throws IOException, SAXException
+ {
+ NamedInputStream in = XMLJ.getInputStream (input);
+ byte[] detectBuffer = in.getDetectBuffer ();
+ String publicId = input.getPublicId ();
+ String systemId = input.getSystemId ();
+ base = XMLJ.getBaseURI (systemId);
+ // Reset state
+ standalone = false;
+ seenFatalError = false;
+ seenStartDocument = false;
+ if (systemId != null)
+ {
+ int lsi = systemId.lastIndexOf ('/');
+ if (lsi != -1)
+ {
+ base = systemId.substring (0, lsi + 1);
+ }
+ }
+ // Handle zero-length document
+ if (detectBuffer == null)
+ {
+ startDocument (true);
+ fatalError ("No document element", 0, 0, publicId, systemId);
+ endDocument ();
+ return;
+ }
+ // Parse
+ parseStream(in,
+ detectBuffer,
+ publicId,
+ systemId,
+ base,
+ validation,
+ contentHandler != null,
+ dtdHandler != null,
+ entityResolver != null,
+ errorHandler != null,
+ declarationHandler != null,
+ lexicalHandler != null);
+ in.close ();
+ }
+
+ native void parseStream (InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean validate,
+ boolean contentHandler,
+ boolean dtdHandler,
+ boolean entityResolver,
+ boolean errorHandler,
+ boolean declarationHandler,
+ boolean lexicalHandler)
+ throws IOException, SAXException;
+
+ String getURI (String prefix)
+ {
+ if (!namespaces)
+ {
+ return null;
+ }
+ return ns.getURI (prefix);
+ }
+
+ // Callbacks from libxmlj
+
+ private void startDTD (String name, String publicId, String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || lexicalHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ systemId = XMLJ.getAbsoluteURI (base, systemId);
+ lexicalHandler.startDTD (name, publicId, systemId);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void externalEntityDecl (String name, String publicId,
+ String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || declarationHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ systemId = XMLJ.getAbsoluteURI (base, systemId);
+ declarationHandler.externalEntityDecl (name, publicId, systemId);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void internalEntityDecl (String name, String value)
+ throws SAXException
+ {
+ if (seenFatalError || declarationHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ declarationHandler.internalEntityDecl (name, value);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private InputStream resolveEntity (String publicId, String systemId)
+ throws SAXException, IOException
+ {
+ if (entityResolver == null)
+ {
+ return null;
+ }
+ try
+ {
+ systemId = XMLJ.getAbsoluteURI (base, systemId);
+ InputSource source = entityResolver.resolveEntity (publicId, systemId);
+ return (source == null) ? null : XMLJ.getInputStream (source);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void notationDecl (String name, String publicId, String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || dtdHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ systemId = XMLJ.getAbsoluteURI (base, systemId);
+ dtdHandler.notationDecl (name, publicId, systemId);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void attributeDecl (String eName, String aName, String type,
+ String mode, String value)
+ throws SAXException
+ {
+ if (seenFatalError || declarationHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ declarationHandler.attributeDecl (eName, aName, type, mode, value);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void elementDecl (String name, String model)
+ throws SAXException
+ {
+ if (seenFatalError || declarationHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ declarationHandler.elementDecl (name, model);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void unparsedEntityDecl (String name, String publicId,
+ String systemId, String notationName)
+ throws SAXException
+ {
+ if (seenFatalError || dtdHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ systemId = XMLJ.getAbsoluteURI (base, systemId);
+ dtdHandler.unparsedEntityDecl (name, publicId, systemId,
+ notationName);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void setDocumentLocator (Object ctx, Object loc)
+ {
+ locator = new GnomeLocator (ctx, loc);
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ contentHandler.setDocumentLocator (locator);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ private void startDocument (boolean standalone)
+ throws SAXException
+ {
+ this.standalone = standalone;
+ seenStartDocument = true;
+ if (contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ contentHandler.startDocument ();
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void endDocument ()
+ throws SAXException
+ {
+ if (contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ contentHandler.endDocument();
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void startElement(String name, String[] attrs)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ XMLName xName = new XMLName (this, name);
+ if (namespaces)
+ {
+ // Handle defined namespaces
+ ns.push ();
+ int len = (attrs == null) ? 0 : attrs.length;
+ if (len > 0)
+ {
+ ArrayList filtered = new ArrayList (len);
+ for (int i = 0; i < len; i += 2)
+ {
+ String attName = attrs[i];
+ String attValue = attrs[i + 1];
+ if (attName.equals ("xmlns"))
+ {
+ startPrefixMapping ("", attValue);
+ }
+ else if (attName.startsWith ("xmlns:"))
+ {
+ startPrefixMapping (attName.substring (6), attValue);
+ }
+ else
+ {
+ filtered.add (attName);
+ filtered.add (attValue);
+ }
+ }
+ // Remove xmlns attributes
+ attrs = new String[filtered.size ()];
+ filtered.toArray (attrs);
+ }
+ }
+ // Construct attributes
+ Attributes atts = new StringArrayAttributes (this, attrs);
+ contentHandler.startElement (xName.uri, xName.localName, xName.qName,
+ atts);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void endElement (String name)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ XMLName xName = new XMLName (this, name);
+ String uri = (xName.uri == null) ? "" : xName.uri;
+ contentHandler.endElement (uri, xName.localName, xName.qName);
+ // Handle undefining namespaces
+ if (namespaces)
+ {
+ for (Iterator i = ns.currentPrefixes (); i.hasNext (); )
+ {
+ endPrefixMapping ((String) i.next ());
+ }
+ ns.pop (); // releases current depth
+ }
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void startPrefixMapping (String prefix, String uri)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ ns.define (prefix, uri);
+ contentHandler.startPrefixMapping (prefix, uri);
+ }
+
+ private void endPrefixMapping (String prefix)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ contentHandler.endPrefixMapping (prefix);
+ }
+
+ private void characters (String text)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null || text == null)
+ {
+ return;
+ }
+ try
+ {
+ char[] ch = text.toCharArray ();
+ contentHandler.characters (ch, 0, ch.length);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void ignorableWhitespace (String text)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null || text == null)
+ {
+ return;
+ }
+ try
+ {
+ char[] ch = text.toCharArray ();
+ contentHandler.ignorableWhitespace (ch, 0, ch.length);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void processingInstruction (String target, String data)
+ throws SAXException
+ {
+ if (seenFatalError || contentHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ if (data == null)
+ {
+ data = "";
+ }
+ contentHandler.processingInstruction (target, data);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void comment (String text)
+ throws SAXException
+ {
+ if (seenFatalError || lexicalHandler == null || text == null)
+ {
+ return;
+ }
+ try
+ {
+ char[] ch = text.toCharArray ();
+ lexicalHandler.comment (ch, 0, ch.length);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void cdataBlock (String text)
+ throws SAXException
+ {
+ if (seenFatalError || text == null)
+ {
+ return;
+ }
+ try
+ {
+ if (lexicalHandler == null)
+ {
+ characters(text);
+ }
+ else
+ {
+ lexicalHandler.startCDATA();
+ characters(text);
+ lexicalHandler.endCDATA();
+ }
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void warning (String message,
+ int lineNumber, int columnNumber,
+ String publicId, String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || errorHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ Locator l = new StandaloneLocator (lineNumber, columnNumber,
+ publicId, systemId);
+ errorHandler.warning (new SAXParseException (message, l));
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void error (String message,
+ int lineNumber, int columnNumber,
+ String publicId, String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || errorHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ Locator l = new StandaloneLocator (lineNumber, columnNumber,
+ publicId, systemId);
+ errorHandler.error (new SAXParseException (message, l));
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+ private void fatalError (String message,
+ int lineNumber, int columnNumber,
+ String publicId, String systemId)
+ throws SAXException
+ {
+ if (seenFatalError || errorHandler == null)
+ {
+ return;
+ }
+ try
+ {
+ if (!seenStartDocument)
+ {
+ startDocument (false);
+ }
+ seenFatalError = true;
+ Locator l = new StandaloneLocator (lineNumber, columnNumber,
+ publicId, systemId);
+ errorHandler.fatalError (new SAXParseException (message, l));
+ }
+ catch (Exception e)
+ {
+ if (e instanceof SAXException)
+ {
+ throw (SAXException) e;
+ }
+ else
+ {
+ throw new SAXException (e);
+ }
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/Namespaces.java b/libjava/classpath/gnu/xml/libxmlj/sax/Namespaces.java
new file mode 100644
index 000000000..473d02028
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/Namespaces.java
@@ -0,0 +1,122 @@
+/* Namespaces.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * Helper class for managing namespaces.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class Namespaces
+{
+
+ ArrayList stack = new ArrayList ();
+
+ /**
+ * Increments the tree depth.
+ * This allocates a new potential namespace entry.
+ */
+ void push ()
+ {
+ stack.add (null);
+ }
+
+ /**
+ * Decrements the tree depth.
+ * This removes namespaces defined at the extremity.
+ */
+ void pop ()
+ {
+ stack.remove (stack.size() - 1);
+ }
+
+ /**
+ * Searches for the namespace URI corresponding to the specified prefix.
+ */
+ String getURI (String prefix)
+ {
+ for (int i = stack.size () - 1; i >= 0; i--)
+ {
+ HashMap ns = (HashMap) stack.get (i);
+ if (ns != null && ns.containsKey (prefix))
+ {
+ String ret = (String) ns.get (prefix);
+ return (ret == null) ? "" : ret;
+ }
+ }
+ return "";
+ }
+
+ /**
+ * Defines the specified prefix-URI mapping at the current depth in the
+ * tree.
+ */
+ void define (String prefix, String uri)
+ {
+ int index = stack.size () - 1;
+ HashMap ns = (HashMap) stack.get (index);
+ if (ns == null)
+ {
+ ns = new HashMap ();
+ stack.set (index, ns);
+ }
+ ns.put (prefix, uri);
+ }
+
+ /**
+ * Returns an iterator over the prefixes defined at the current depth.
+ */
+ Iterator currentPrefixes ()
+ {
+ HashMap ns = (HashMap) stack.get (stack.size () - 1);
+ if (ns == null)
+ {
+ return Collections.EMPTY_LIST.iterator ();
+ }
+ else
+ {
+ return ns.keySet ().iterator ();
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/StringArrayAttributes.java b/libjava/classpath/gnu/xml/libxmlj/sax/StringArrayAttributes.java
new file mode 100644
index 000000000..f5a753c56
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/StringArrayAttributes.java
@@ -0,0 +1,170 @@
+/* StringArrayAttributes.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+import org.xml.sax.Attributes;
+
+/**
+ * An implementation of Attributes that reads values from an array of
+ * strings, supplied by libxml2.
+ * Each pair of elements in the array represents a key followed by a value.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class StringArrayAttributes
+implements Attributes
+{
+
+ private int len;
+ private XMLName[] keys;
+ private String[] values;
+
+ StringArrayAttributes (GnomeXMLReader parser, String[] pairs)
+ {
+ len = (pairs == null) ? 0 : pairs.length / 2;
+ keys = new XMLName[len];
+ values = new String[len];
+ for (int i = 0; i < len; i++)
+ {
+ int pairIndex = i * 2;
+ keys[i] = new XMLName (parser, pairs[pairIndex]);
+ values[i] = pairs[pairIndex + 1];
+ }
+ }
+
+ public int getLength ()
+ {
+ return len;
+ }
+
+ public String getURI (int index)
+ {
+ if (index < 0 || index >= len)
+ {
+ return null;
+ }
+ return keys[index].uri;
+ }
+
+ public String getLocalName (int index)
+ {
+ if (index < 0 || index >= len)
+ {
+ return null;
+ }
+ return keys[index].localName;
+ }
+
+ public String getQName (int index)
+ {
+ if (index < 0 || index >= len)
+ {
+ return null;
+ }
+ return keys[index].qName;
+ }
+
+ public String getType (int index)
+ {
+ if (index < 0 || index >= len)
+ {
+ return null;
+ }
+ // TODO can we get this information from libxml2?
+ return "CDATA";
+ }
+
+ public String getValue (int index)
+ {
+ if (index < 0 || index >= len)
+ {
+ return null;
+ }
+ return values[index];
+ }
+
+ public int getIndex (String uri, String localName)
+ {
+ for (int i = 0; i < len; i++)
+ {
+ XMLName key = keys[i];
+ if (key.localName.equals (localName))
+ {
+ if ((key.uri == null && uri == null) ||
+ (key.uri != null && key.uri.equals(uri)))
+ {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public int getIndex (String qName)
+ {
+ for (int i = 0; i < len; i++)
+ {
+ if (keys[i].qName.equals (qName))
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public String getType (String uri, String localName)
+ {
+ return getType (getIndex (uri, localName));
+ }
+
+ public String getType (String qName)
+ {
+ return getType (getIndex (qName));
+ }
+
+ public String getValue (String uri, String localName)
+ {
+ return getValue (getIndex (uri, localName));
+ }
+
+ public String getValue (String qName)
+ {
+ return getValue (getIndex (qName));
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/sax/XMLName.java b/libjava/classpath/gnu/xml/libxmlj/sax/XMLName.java
new file mode 100644
index 000000000..b9bdf9159
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/sax/XMLName.java
@@ -0,0 +1,92 @@
+/* XMLName.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.sax;
+
+/**
+ * Structure containing the components of an XML element/attribute name.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class XMLName
+{
+
+ private static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
+
+ final String uri;
+ final String localName;
+ final String qName;
+ final String prefix;
+
+ XMLName (GnomeXMLReader parser, String qName)
+ {
+ this.qName = qName;
+ int ci = qName.lastIndexOf (':');
+ if (ci < 1)
+ {
+ localName = qName;
+ prefix = null;
+ uri = "";
+ }
+ else
+ {
+ localName = qName.substring (ci + 1);
+ prefix = qName.substring (0, ci);
+ if ("xml".equals (prefix))
+ {
+ if ("lang".equals (localName) || "space".equals (localName))
+ {
+ uri = XML_URI;
+ }
+ else
+ {
+ uri = parser.getURI (prefix);
+ }
+ }
+ else
+ {
+ uri = parser.getURI (prefix);
+ }
+ }
+ }
+
+ public String toString ()
+ {
+ return qName;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/transform/ErrorListenerErrorHandler.java b/libjava/classpath/gnu/xml/libxmlj/transform/ErrorListenerErrorHandler.java
new file mode 100644
index 000000000..398a0ba2e
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/transform/ErrorListenerErrorHandler.java
@@ -0,0 +1,111 @@
+/* ErrorListenerErrorHandler.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.transform;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.TransformerException;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Provides a SAX ErrorHandler interface to an ErrorListener.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class ErrorListenerErrorHandler
+implements ErrorHandler
+{
+
+ private ErrorListener listener;
+
+ ErrorListenerErrorHandler (ErrorListener listener)
+ {
+ this.listener = listener;
+ }
+
+ public void warning (SAXParseException e)
+ throws SAXException
+ {
+ try
+ {
+ listener.warning (new TransformerException (e));
+ }
+ catch (TransformerException te)
+ {
+ throw getSAXException (te);
+ }
+ }
+
+ public void error (SAXParseException e)
+ throws SAXException
+ {
+ try
+ {
+ listener.error (new TransformerException (e));
+ }
+ catch (TransformerException te)
+ {
+ throw getSAXException (te);
+ }
+ }
+
+ public void fatalError (SAXParseException e)
+ throws SAXException
+ {
+ try
+ {
+ listener.fatalError (new TransformerException (e));
+ }
+ catch (TransformerException te)
+ {
+ throw getSAXException (te);
+ }
+ }
+
+ private SAXException getSAXException (TransformerException e)
+ {
+ Throwable cause = e.getCause ();
+ if (cause instanceof SAXException)
+ {
+ return (SAXException) cause;
+ }
+ return new SAXException (e);
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformer.java b/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformer.java
new file mode 100755
index 000000000..5f31cb898
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformer.java
@@ -0,0 +1,572 @@
+/* GnomeTransformer.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.transform;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.net.URL;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Source;
+import javax.xml.transform.SourceLocator;
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+
+import gnu.xml.libxmlj.dom.GnomeDocument;
+import gnu.xml.libxmlj.sax.GnomeXMLReader;
+import gnu.xml.libxmlj.util.NamedInputStream;
+import gnu.xml.libxmlj.util.StandaloneLocator;
+import gnu.xml.libxmlj.util.XMLJ;
+
+/**
+ * An implementation of {@link javax.xml.transform.Transformer} which
+ * performs XSLT transformation using <code>libxslt</code>.
+ *
+ * @author Julian Scheid
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeTransformer
+ extends Transformer
+ implements Templates
+{
+
+ /**
+ * The parameters added by the user via {@link setParameter()}.
+ */
+ private Map parameters;
+
+ /**
+ * The output properties set by the user.
+ */
+ private Properties outputProperties;
+
+ /**
+ * The URI resolver to use during transformation.
+ */
+ private URIResolver resolver;
+
+ /**
+ * The error listener for transformation errors.
+ */
+ private ErrorListener errorListener;
+
+ /**
+ * Handle to the source stylesheet.
+ * This is a native pointer of type xsltStylesheetPtr.
+ */
+ private Object stylesheet;
+
+ /**
+ * Constructor.
+ * @param source the XSLT stylesheet document source
+ * @param resolver the resolver to use during transformation
+ * @param errorListener the error listener for transformation errors
+ */
+ GnomeTransformer (Source source,
+ URIResolver resolver,
+ ErrorListener errorListener)
+ throws TransformerConfigurationException
+ {
+ this.resolver = resolver;
+ this.errorListener = errorListener;
+ parameters = new HashMap ();
+ outputProperties = new Properties ();
+
+ if (source == null)
+ {
+ stylesheet = newStylesheet ();
+ }
+ else if (source instanceof StreamSource)
+ {
+ try
+ {
+ StreamSource ss = (StreamSource) source;
+ NamedInputStream in = XMLJ.getInputStream (ss);
+ String systemId = ss.getSystemId ();
+ String publicId = ss.getPublicId ();
+ String base = XMLJ.getBaseURI (systemId);
+ byte[] detectBuffer = in.getDetectBuffer ();
+ if (detectBuffer == null)
+ {
+ String msg = "No document element";
+ throw new TransformerConfigurationException (msg);
+ }
+ stylesheet = newStylesheetFromStream (in, detectBuffer, publicId,
+ systemId, base,
+ (resolver != null),
+ (errorListener != null));
+ }
+ catch (IOException e)
+ {
+ throw new TransformerConfigurationException (e);
+ }
+ }
+ else if (source instanceof DOMSource)
+ {
+ DOMSource ds = (DOMSource) source;
+ Node node = ds.getNode ();
+ if (!(node instanceof GnomeDocument))
+ {
+ String msg = "Node is not a GnomeDocument";
+ throw new TransformerConfigurationException (msg);
+ }
+ GnomeDocument doc = (GnomeDocument) node;
+ stylesheet = newStylesheetFromDoc (doc);
+ }
+ else
+ {
+ String msg = "Source type not supported (" + source + ")";
+ throw new TransformerConfigurationException (msg);
+ }
+ }
+
+ /**
+ * Copy constructor.
+ */
+ private GnomeTransformer (Object stylesheet,
+ URIResolver resolver,
+ ErrorListener errorListener,
+ Map parameters,
+ Properties outputProperties)
+ {
+ this.stylesheet = stylesheet;
+ this.resolver = resolver;
+ this.errorListener = errorListener;
+ this.parameters = parameters;
+ this.outputProperties = outputProperties;
+ }
+
+ private native Object newStylesheet ()
+ throws TransformerConfigurationException;
+
+ private native Object newStylesheetFromStream (InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean entityResolver,
+ boolean errorHandler)
+ throws TransformerConfigurationException;
+
+ private native Object newStylesheetFromDoc (GnomeDocument doc)
+ throws TransformerConfigurationException;
+
+ //--- Implementation of javax.xml.transform.Transformer follows.
+
+ // Set, get and clear the parameters to use on transformation
+
+ public synchronized void setParameter (String parameter, Object value)
+ {
+ parameters.put (parameter, value);
+ }
+
+ public synchronized Object getParameter (String name)
+ {
+ return parameters.get (name);
+ }
+
+ public synchronized void clearParameters ()
+ {
+ parameters.clear ();
+ }
+
+ // Set and get the ErrorListener to use on transformation
+
+ public void setErrorListener (ErrorListener listener)
+ {
+ this.errorListener = listener;
+ }
+
+ public ErrorListener getErrorListener ()
+ {
+ return errorListener;
+ }
+
+ // Set and get the URIResolver to use on transformation
+
+ public void setURIResolver (URIResolver resolver)
+ {
+ this.resolver = resolver;
+ }
+
+ public URIResolver getURIResolver ()
+ {
+ return resolver;
+ }
+
+ // Set the output properties to use on transformation; get default
+ // output properties and output properties specified in the
+ // stylesheet or by the user.
+
+ public void setOutputProperties (Properties outputProperties)
+ {
+ // Note: defensive copying
+ this.outputProperties = new Properties (outputProperties);
+ }
+
+ public void setOutputProperty (String name, String value)
+ {
+ outputProperties.setProperty (name, value);
+ }
+
+ public Properties getOutputProperties ()
+ {
+ // Note: defensive copying
+ return new Properties (this.outputProperties);
+ }
+
+ public String getOutputProperty (String name)
+ {
+ return outputProperties.getProperty (name);
+ }
+
+ // -- Templates --
+
+ public Transformer newTransformer ()
+ {
+ return new GnomeTransformer (stylesheet, resolver, errorListener,
+ new HashMap (parameters),
+ new Properties (outputProperties));
+ }
+
+ // -- transform --
+
+ /**
+ * Transforms the given source and writes the result to the
+ * given target.
+ */
+ public void transform (Source source, Result result)
+ throws TransformerException
+ {
+ if (source instanceof StreamSource)
+ {
+ try
+ {
+ StreamSource ss = (StreamSource) source;
+ NamedInputStream in = XMLJ.getInputStream (ss);
+ String publicId = ss.getPublicId ();
+ String systemId = ss.getSystemId ();
+ String base = XMLJ.getBaseURI (systemId);
+ byte[] detectBuffer = in.getDetectBuffer ();
+ if (detectBuffer == null)
+ {
+ throw new TransformerException ("No document element");
+ }
+ if (result instanceof StreamResult)
+ {
+ OutputStream out = XMLJ.getOutputStream ((StreamResult) result);
+ transformStreamToStream (in, detectBuffer, publicId, systemId,
+ base, (resolver != null),
+ (errorListener != null), out);
+ }
+ else if (result instanceof DOMResult)
+ {
+ DOMResult dr = (DOMResult) result;
+ GnomeDocument ret =
+ transformStreamToDoc (in, detectBuffer, publicId, systemId,
+ base, (resolver != null),
+ (errorListener != null));
+ dr.setNode (ret);
+ dr.setSystemId (null);
+ }
+ else if (result instanceof SAXResult)
+ {
+ SAXResult sr = (SAXResult) result;
+ transformStreamToSAX (in, detectBuffer, publicId, systemId,
+ base, (resolver != null),
+ (errorListener != null),
+ getSAXContext (sr));
+ }
+ else
+ {
+ String msg = "Result type not supported (" + result + ")";
+ throw new TransformerConfigurationException (msg);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new TransformerException (e);
+ }
+ }
+ else if (source instanceof DOMSource)
+ {
+ DOMSource ds = (DOMSource) source;
+ Node node = ds.getNode ();
+ if (!(node instanceof GnomeDocument))
+ {
+ String msg = "Node is not a GnomeDocument (" + node + ")";
+ throw new TransformerException (msg);
+ }
+ GnomeDocument doc = (GnomeDocument) node;
+ if (result instanceof StreamResult)
+ {
+ try
+ {
+ OutputStream out = XMLJ.getOutputStream ((StreamResult) result);
+ transformDocToStream (doc, out);
+ }
+ catch (IOException e)
+ {
+ throw new TransformerException (e);
+ }
+ }
+ else if (result instanceof DOMResult)
+ {
+ DOMResult dr = (DOMResult) result;
+ GnomeDocument ret = transformDocToDoc (doc);
+ dr.setNode (ret);
+ dr.setSystemId (null);
+ }
+ else if (result instanceof SAXResult)
+ {
+ SAXResult sr = (SAXResult) result;
+ transformDocToSAX (doc, getSAXContext (sr));
+ }
+ else
+ {
+ String msg = "Result type not supported";
+ throw new TransformerConfigurationException (msg);
+ }
+ }
+ else
+ {
+ String msg = "Source type not supported";
+ throw new TransformerConfigurationException (msg);
+ }
+ }
+
+ private GnomeXMLReader getSAXContext (SAXResult result)
+ {
+ GnomeXMLReader ctx = new GnomeXMLReader ();
+ ctx.setContentHandler (result.getHandler ());
+ ctx.setLexicalHandler (result.getLexicalHandler ());
+ if (errorListener != null)
+ {
+ ErrorHandler errorHandler =
+ new ErrorListenerErrorHandler (errorListener);
+ ctx.setErrorHandler (errorHandler);
+ }
+ if (resolver != null)
+ {
+ EntityResolver entityResolver =
+ new URIResolverEntityResolver (resolver);
+ ctx.setEntityResolver (entityResolver);
+ }
+ return ctx;
+ }
+
+ private native void transformStreamToStream (InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean entityResolver,
+ boolean errorHandler,
+ OutputStream out)
+ throws TransformerException;
+
+ private native GnomeDocument transformStreamToDoc (InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean entityResolver,
+ boolean errorHandler)
+ throws TransformerException;
+
+ private native void transformStreamToSAX (InputStream in,
+ byte[] detectBuffer,
+ String publicId,
+ String systemId,
+ String base,
+ boolean entityResolver,
+ boolean errorHandler,
+ GnomeXMLReader out)
+ throws TransformerException;
+
+ private native void transformDocToStream (GnomeDocument in,
+ OutputStream out)
+ throws TransformerException;
+
+ private native GnomeDocument transformDocToDoc (GnomeDocument in)
+ throws TransformerException;
+
+ private native void transformDocToSAX (GnomeDocument in,
+ GnomeXMLReader out)
+ throws TransformerException;
+
+ /*
+ * Retrieve parameters as a string array.
+ * This is a convenience method called from native code.
+ */
+ private String[] getParameterArray ()
+ {
+ String[] parameterArray = new String[parameters.size () * 2];
+ int index = 0;
+ for (Iterator it = parameters.keySet ().iterator ();
+ it.hasNext ();
+ ++index)
+ {
+ String parameterKey = (String) it.next ();
+ String parameterValue = (String) parameters.get (parameterKey);
+ parameterArray[index * 2 + 0] = parameterKey;
+ parameterArray[index * 2 + 1] =
+ "'" + ((parameterValue != null) ? parameterValue : "") + "'";
+ // FIXME encode parameter value correctly for XPath
+ }
+ return parameterArray;
+ }
+
+ // -- Free xsltStylesheet handle --
+
+ public void finalize ()
+ {
+ if (stylesheet != null)
+ {
+ free ();
+ stylesheet = null;
+ }
+ }
+
+ private native void free ();
+
+ // -- Callbacks --
+
+ private InputStream resolveEntity (String publicId, String systemId)
+ throws TransformerException
+ {
+ if (resolver != null)
+ {
+ systemId = resolver.resolve (null, systemId).getSystemId ();
+ }
+ if (systemId == null)
+ {
+ return null;
+ }
+ try
+ {
+ URL url = new URL (systemId);
+ return XMLJ.getInputStream (url);
+ }
+ catch (IOException e)
+ {
+ throw new TransformerException (e);
+ }
+ }
+
+ private void setDocumentLocator (Object ctx, Object loc)
+ {
+ }
+
+ private void warning (String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws TransformerException
+ {
+ if (errorListener == null)
+ {
+ return;
+ }
+ SourceLocator l = new StandaloneLocator (lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorListener.warning (new TransformerException (message, l));
+ }
+
+ private void error (String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws TransformerException
+ {
+ if (errorListener == null)
+ {
+ return;
+ }
+ SourceLocator l = new StandaloneLocator (lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorListener.error (new TransformerException (message, l));
+ }
+
+ private void fatalError (String message,
+ int lineNumber,
+ int columnNumber,
+ String publicId,
+ String systemId)
+ throws TransformerException
+ {
+ if (errorListener == null)
+ {
+ return;
+ }
+ SourceLocator l = new StandaloneLocator (lineNumber,
+ columnNumber,
+ publicId,
+ systemId);
+ errorListener.fatalError (new TransformerException (message, l));
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java b/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java
new file mode 100755
index 000000000..4a0100a21
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java
@@ -0,0 +1,349 @@
+/* GnomeTransformerFactory.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.transform;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.URIResolver;
+
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+import gnu.xml.libxmlj.util.XMLJ;
+
+/**
+ * An implementation of <code>TransformerFactory</code> producing
+ * <code>Transformer</code> objects which use <code>libxslt</code>
+ * for transformation.
+ *
+ * @author Julian Scheid
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public class GnomeTransformerFactory
+ extends TransformerFactory
+{
+
+ static
+ {
+ XMLJ.init ();
+ }
+
+ /**
+ * URIResolver set by user, or default implementation.
+ */
+ private URIResolver uriResolver;
+
+ /**
+ * ErrorListener set by user, or default implementation.
+ */
+ private ErrorListener errorListener;
+
+ /**
+ * Attributes set by user.
+ */
+ private Map attributes = new HashMap ();
+
+ //--- Implementation of javax.xml.transform.TransformerFactory
+ //--- follows.
+
+ // -- begin getAssociatedStylesheet implementation --
+
+ /**
+ * Returns the stylesheet associated with the specified XML source, or
+ * <code>null</code> if no associated stylesheet could be found.
+ */
+ public Source getAssociatedStylesheet(Source source, String media,
+ String title, String charset)
+ throws TransformerConfigurationException
+ {
+ String href= null;
+ String base = source.getSystemId();
+ if (source instanceof DOMSource)
+ {
+ Node node = ((DOMSource) source).getNode();
+ Document doc = (node.getNodeType() == Node.DOCUMENT_NODE) ?
+ (Document) node : node.getOwnerDocument();
+ if (base == null)
+ {
+ base = doc.getDocumentURI();
+ }
+ for (node = doc.getFirstChild(); node != null;
+ node = node.getNextSibling())
+ {
+ if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE &&
+ "xml-stylesheet".equals(node.getNodeName()))
+ {
+ String data = node.getNodeValue();
+ if (media != null &&
+ !media.equals(parseParameter(data, "type")))
+ {
+ continue;
+ }
+ if (title != null &&
+ !title.equals(parseParameter(data, "title")))
+ {
+ continue;
+ }
+ href = parseParameter(data, "href");
+ }
+ }
+ }
+ else
+ {
+ InputSource input;
+ XMLReader parser = null;
+ try
+ {
+ if (source instanceof SAXSource)
+ {
+ SAXSource sax = (SAXSource) source;
+ input = sax.getInputSource();
+ parser = sax.getXMLReader();
+ }
+ else
+ {
+ StreamSource stream = (StreamSource) source;
+ InputStream in = stream.getInputStream();
+ input = new InputSource(in);
+ }
+ input.setSystemId(base);
+ if (parser == null)
+ {
+ parser = createXMLReader();
+ }
+ AssociatedStylesheetHandler ash =
+ new AssociatedStylesheetHandler();
+ ash.media = media;
+ ash.title = title;
+ parser.setContentHandler(ash);
+ parser.parse(input);
+ href = ash.href;
+ }
+ catch (SAXException e)
+ {
+ throw new TransformerConfigurationException(e);
+ }
+ catch (IOException e)
+ {
+ throw new TransformerConfigurationException(e);
+ }
+ }
+ if (href == null)
+ {
+ return null;
+ }
+ if (base != null)
+ {
+ base = XMLJ.getBaseURI(base);
+ }
+ href = XMLJ.getAbsoluteURI(base, href);
+ return new StreamSource(href);
+ }
+
+ private XMLReader createXMLReader()
+ throws TransformerConfigurationException
+ {
+ try
+ {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ SAXParser parser = factory.newSAXParser();
+ return parser.getXMLReader();
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new TransformerConfigurationException(e);
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new TransformerConfigurationException(e);
+ }
+ catch (SAXException e)
+ {
+ throw new TransformerConfigurationException(e);
+ }
+ }
+
+ class AssociatedStylesheetHandler
+ extends DefaultHandler
+ {
+
+ String media;
+ String title;
+ String href;
+
+ public void processingInstruction(String target, String data)
+ throws SAXException
+ {
+ if ("xml-stylesheet".equals(target))
+ {
+ if (media != null && !media.equals(parseParameter(data, "type")))
+ {
+ return;
+ }
+ if (title != null && !title.equals(parseParameter(data, "title")))
+ {
+ return;
+ }
+ href = parseParameter(data, "href");
+ }
+ }
+
+ }
+
+ String parseParameter(String data, String name)
+ {
+ int start = data.indexOf(name + "=");
+ if (start != -1)
+ {
+ start += name.length() + 2;
+ char delim = data.charAt(start - 1);
+ int end = data.indexOf(delim, start);
+ if (end != -1)
+ {
+ return data.substring(start, end);
+ }
+ }
+ return null;
+ }
+
+ // -- end getAssociatedStylesheet implementation --
+
+ public synchronized void setAttribute (String name, Object value)
+ {
+ this.attributes.put (name, value);
+ }
+
+ public synchronized Object getAttribute (String name)
+ {
+ return attributes.get (name);
+ }
+
+ public void setErrorListener (ErrorListener errorListener)
+ {
+ this.errorListener = errorListener;
+ }
+
+ public ErrorListener getErrorListener ()
+ {
+ return errorListener;
+ }
+
+ public void setURIResolver (URIResolver uriResolver)
+ {
+ this.uriResolver = uriResolver;
+ }
+
+ public URIResolver getURIResolver ()
+ {
+ return uriResolver;
+ }
+
+ public boolean getFeature (String name)
+ {
+ return (StreamSource.FEATURE.equals (name) ||
+ StreamResult.FEATURE.equals (name) ||
+ DOMSource.FEATURE.equals (name) ||
+ DOMResult.FEATURE.equals (name));
+ }
+
+ public void setFeature(String name, boolean value)
+ throws TransformerConfigurationException
+ {
+ throw new TransformerConfigurationException(name);
+ }
+
+ /**
+ * Returns a new instance of class {@link Transformer} for a
+ * null souce.
+ */
+ public Transformer newTransformer ()
+ throws TransformerConfigurationException
+ {
+ return newTransformer (null);
+ }
+
+ /**
+ * Returns a new instance of class {@link Transformer} for
+ * the given souce.
+ */
+ public Transformer newTransformer (Source source)
+ throws TransformerConfigurationException
+ {
+ return new GnomeTransformer (source, uriResolver, errorListener);
+ }
+
+ /**
+ * Returns a new instance of class {@link Templates} for
+ * the given souce.
+ */
+ public Templates newTemplates (Source source)
+ throws TransformerConfigurationException
+ {
+ return new GnomeTransformer (source, uriResolver, errorListener);
+ }
+
+ /**
+ * Perform native cleanup.
+ */
+ public static native void freeLibxsltGlobal ();
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/transform/URIResolverEntityResolver.java b/libjava/classpath/gnu/xml/libxmlj/transform/URIResolverEntityResolver.java
new file mode 100644
index 000000000..0ce71d0ef
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/transform/URIResolverEntityResolver.java
@@ -0,0 +1,87 @@
+/* URIResolverEntityResolver.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.transform;
+
+import java.io.IOException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Provides an EntityResolver interface to a URIResolver.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class URIResolverEntityResolver
+implements EntityResolver
+{
+
+ private URIResolver resolver;
+
+ URIResolverEntityResolver (URIResolver resolver)
+ {
+ this.resolver = resolver;
+ }
+
+ public InputSource resolveEntity (String publicId, String systemId)
+ throws SAXException, IOException
+ {
+ try
+ {
+ return SAXSource.sourceToInputSource (resolver.resolve (systemId,
+ null));
+ }
+ catch (TransformerException e)
+ {
+ Throwable cause = e.getCause ();
+ if (cause instanceof SAXException)
+ {
+ throw (SAXException) cause;
+ }
+ else if (cause instanceof IOException)
+ {
+ throw (IOException) cause;
+ }
+ throw new SAXException (e);
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/transform/package.html b/libjava/classpath/gnu/xml/libxmlj/transform/package.html
new file mode 100755
index 000000000..dac1027ff
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/transform/package.html
@@ -0,0 +1,14 @@
+<body>
+<p>
+ A JAXP-compliant wrapper for the XSLT C library for Gnome, also
+ known as libxslt. Allows to use libxslt via the Java API for XML
+ processing.
+</p>
+
+<p>
+ <b>Usage:</b>
+ <li>Set the system property <code>javax.xml.transform.TransformerFactory</code>
+ to <code>gnu.xml.libxmlj.GnomeTransformerFactory</code>.</li>
+ </ul>
+</p>
+</body>
diff --git a/libjava/classpath/gnu/xml/libxmlj/util/EmptyNodeList.java b/libjava/classpath/gnu/xml/libxmlj/util/EmptyNodeList.java
new file mode 100644
index 000000000..60019ddd4
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/util/EmptyNodeList.java
@@ -0,0 +1,62 @@
+/* EmptyNodeList.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.util;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * An empty node list.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+class EmptyNodeList
+implements NodeList
+{
+
+ public Node item (int index)
+ {
+ return null;
+ }
+
+ public int getLength ()
+ {
+ return 0;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/util/NamedInputStream.java b/libjava/classpath/gnu/xml/libxmlj/util/NamedInputStream.java
new file mode 100644
index 000000000..01b3af90d
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/util/NamedInputStream.java
@@ -0,0 +1,99 @@
+/* NamedInputStream.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.util;
+
+import java.io.FilterInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.PushbackInputStream;
+
+/**
+ * An input stream associated with an XML system ID.
+ * It can report the system ID and the first few bytes of the stream
+ * in order to detect the character encoding of the stream.
+ *
+ * @author <a href='dog@gnu.org'>Chris Burdess</a>
+ */
+public class NamedInputStream
+extends FilterInputStream
+{
+
+ private static int DETECT_BUFFER_SIZE = 50;
+
+ private String name;
+
+ NamedInputStream (String name, InputStream in, int size)
+ {
+ super (new PushbackInputStream (in, size));
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the stream (the XML system ID).
+ */
+ public String getName ()
+ {
+ return name;
+ }
+
+ /**
+ * Returns the first few bytes of the stream for character encoding
+ * purposes. The entire stream can thereafter be read normally from the
+ * beginning. This method is only valid if no bytes have yet been read
+ * from the stream.
+ */
+ public byte[] getDetectBuffer ()
+ throws IOException
+ {
+ PushbackInputStream p = (PushbackInputStream) in;
+ byte[] buffer = new byte[DETECT_BUFFER_SIZE];
+ int len = p.read (buffer);
+ if (len < 0)
+ {
+ return null;
+ }
+ else
+ {
+ p.unread (buffer, 0, len);
+ byte[] ret = new byte[len];
+ System.arraycopy (buffer, 0, ret, 0, len);
+ return ret;
+ }
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/util/StandaloneDocumentType.java b/libjava/classpath/gnu/xml/libxmlj/util/StandaloneDocumentType.java
new file mode 100644
index 000000000..5c3316611
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/util/StandaloneDocumentType.java
@@ -0,0 +1,294 @@
+/* StandaloneDocumentType.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.util;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.UserDataHandler;
+
+/**
+ * A "standalone" document type, i.e. one that isn't attached to a document
+ * node.
+ * This can be used to create new documents.
+ */
+public final class StandaloneDocumentType
+implements DocumentType
+{
+
+ private final String name;
+ private final String publicId;
+ private final String systemId;
+
+ public StandaloneDocumentType (String name, String publicId, String systemId)
+ {
+ this.name = name;
+ this.publicId = publicId;
+ this.systemId = systemId;
+ }
+
+ public String getName ()
+ {
+ return name;
+ }
+
+ public NamedNodeMap getEntities ()
+ {
+ // TODO
+ return null;
+ }
+
+ public NamedNodeMap getNotations ()
+ {
+ // TODO
+ return null;
+ }
+
+ public String getPublicId ()
+ {
+ return publicId;
+ }
+
+ public String getSystemId ()
+ {
+ return systemId;
+ }
+
+ public String getInternalSubset ()
+ {
+ return null;
+ }
+
+ // -- Node --
+
+ public String getNodeName ()
+ {
+ return getName ();
+ }
+
+ public String getNodeValue ()
+ throws DOMException
+ {
+ return null;
+ }
+
+ public void setNodeValue (String nodeValue)
+ throws DOMException
+ {
+ }
+
+ public short getNodeType ()
+ {
+ return DOCUMENT_TYPE_NODE;
+ }
+
+ public Node getParentNode ()
+ {
+ return null;
+ }
+
+ public NodeList getChildNodes ()
+ {
+ return new EmptyNodeList ();
+ }
+
+ public Node getFirstChild ()
+ {
+ return null;
+ }
+
+ public Node getLastChild ()
+ {
+ return null;
+ }
+
+ public Node getPreviousSibling ()
+ {
+ return null;
+ }
+
+ public Node getNextSibling ()
+ {
+ return null;
+ }
+
+ public NamedNodeMap getAttributes ()
+ {
+ return null;
+ }
+
+ public Document getOwnerDocument ()
+ {
+ return null;
+ }
+
+ public Node insertBefore (Node newChild, Node refChild)
+ throws DOMException
+ {
+ throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public Node replaceChild (Node newChild, Node oldChild)
+ throws DOMException
+ {
+ throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public Node removeChild (Node oldChild)
+ throws DOMException
+ {
+ throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public Node appendChild (Node oldChild)
+ throws DOMException
+ {
+ throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public boolean hasChildNodes ()
+ {
+ return false;
+ }
+
+ public Node cloneNode (boolean deep)
+ {
+ return new StandaloneDocumentType (name, publicId, systemId);
+ }
+
+ public void normalize ()
+ {
+ }
+
+ public boolean isSupported (String feature, String version)
+ {
+ return false;
+ }
+
+ public String getNamespaceURI ()
+ {
+ return null;
+ }
+
+ public String getPrefix ()
+ {
+ return null;
+ }
+
+ public void setPrefix (String prefix)
+ {
+ throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public String getLocalName ()
+ {
+ return getName ();
+ }
+
+ public boolean hasAttributes ()
+ {
+ return false;
+ }
+
+ // DOM Level 3
+
+ public String getBaseURI ()
+ {
+ return null;
+ }
+
+ public short compareDocumentPosition (Node node)
+ {
+ return -1;
+ }
+
+ public String getTextContent ()
+ {
+ return null;
+ }
+
+ public void setTextContent (String content)
+ {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, null);
+ }
+
+ public boolean isSameNode (Node other)
+ {
+ return equals (other);
+ }
+
+ public String lookupPrefix (String namespace)
+ {
+ return null;
+ }
+
+ public boolean isDefaultNamespace (String namespace)
+ {
+ return false;
+ }
+
+ public String lookupNamespaceURI (String prefix)
+ {
+ return null;
+ }
+
+ public boolean isEqualNode (Node other)
+ {
+ return equals (other);
+ }
+
+ public Object getFeature (String feature, String version)
+ {
+ return null;
+ }
+
+ public Object setUserData (String name, Object value,
+ UserDataHandler handler)
+ {
+ return null;
+ }
+
+ public Object getUserData (String name)
+ {
+ return null;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/util/StandaloneLocator.java b/libjava/classpath/gnu/xml/libxmlj/util/StandaloneLocator.java
new file mode 100644
index 000000000..75b40bdf1
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/util/StandaloneLocator.java
@@ -0,0 +1,89 @@
+/* StandaloneLocator.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.util;
+
+import javax.xml.transform.SourceLocator;
+import org.xml.sax.Locator;
+
+/**
+ * SAX Locator implementation that uses the specified values.
+ *
+ * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
+ */
+public final class StandaloneLocator
+implements Locator, SourceLocator
+{
+
+ private final int lineNumber;
+
+ private final int columnNumber;
+
+ private final String publicId;
+
+ private final String systemId;
+
+ public StandaloneLocator (int lineNumber, int columnNumber,
+ String publicId, String systemId)
+ {
+ this.lineNumber = lineNumber;
+ this.columnNumber = columnNumber;
+ this.publicId = publicId;
+ this.systemId = systemId;
+ }
+
+ public String getPublicId ()
+ {
+ return publicId;
+ }
+
+ public String getSystemId ()
+ {
+ return systemId;
+ }
+
+ public int getLineNumber ()
+ {
+ return lineNumber;
+ }
+
+ public int getColumnNumber ()
+ {
+ return columnNumber;
+ }
+
+}
diff --git a/libjava/classpath/gnu/xml/libxmlj/util/XMLJ.java b/libjava/classpath/gnu/xml/libxmlj/util/XMLJ.java
new file mode 100644
index 000000000..8d954d0be
--- /dev/null
+++ b/libjava/classpath/gnu/xml/libxmlj/util/XMLJ.java
@@ -0,0 +1,280 @@
+/* XMLJ.java -
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.xml.libxmlj.util;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.xml.sax.InputSource;
+
+import gnu.xml.libxmlj.transform.GnomeTransformerFactory;
+
+import gnu.xml.dom.ls.ReaderInputStream;
+import gnu.xml.dom.ls.WriterOutputStream;
+
+/**
+ * Utility functions for libxmlj.
+ */
+public final class XMLJ
+{
+
+ static class XMLJShutdownHook
+ implements Runnable
+ {
+
+ public void run ()
+ {
+ // Make sure finalizers are run
+ System.gc ();
+ Runtime.getRuntime ().runFinalization ();
+
+ // Perform global cleanup on the native level
+ GnomeTransformerFactory.freeLibxsltGlobal ();
+ }
+
+ }
+
+ private static boolean initialised = false;
+
+ public static void init ()
+ {
+ if (!initialised)
+ {
+ System.loadLibrary ("xmlj");
+
+ XMLJShutdownHook hook = new XMLJShutdownHook ();
+ Runtime.getRuntime ().addShutdownHook (new Thread (hook));
+ }
+ initialised = true;
+ }
+
+ private static final int LOOKAHEAD = 50;
+
+ /**
+ * Returns an input stream for the specified input source.
+ * This returns a pushback stream that libxmlj can use to detect the
+ * character encoding of the stream.
+ */
+ public static NamedInputStream getInputStream (InputSource input)
+ throws IOException
+ {
+ InputStream in = input.getByteStream ();
+ String systemId = input.getSystemId ();
+ if (in == null)
+ {
+ Reader r = input.getCharacterStream();
+ if (r != null)
+ in = new ReaderInputStream(r);
+ }
+ if (in == null)
+ {
+ in = getInputStream(systemId);
+ }
+ return new NamedInputStream (systemId, in, LOOKAHEAD);
+ }
+
+ /**
+ * Returns an input stream for the specified transformer source.
+ * This returns a pushback stream that libxmlj can use to detect the
+ * character encoding of the stream.
+ */
+ public static NamedInputStream getInputStream (Source source)
+ throws IOException
+ {
+ if (source instanceof SAXSource)
+ {
+ return getInputStream (((SAXSource) source).getInputSource ());
+ }
+ InputStream in = null;
+ String systemId = source.getSystemId ();
+ if (source instanceof StreamSource)
+ {
+ in = ((StreamSource) source).getInputStream ();
+ }
+ if (in == null)
+ {
+ in = getInputStream(systemId);
+ }
+ return new NamedInputStream (systemId, in, LOOKAHEAD);
+ }
+
+ private static InputStream getInputStream(String systemId)
+ throws IOException
+ {
+ if (systemId == null)
+ {
+ throw new IOException("no system ID");
+ }
+ try
+ {
+ return new URL(systemId).openStream();
+ }
+ catch (MalformedURLException e)
+ {
+ return new FileInputStream(systemId);
+ }
+ }
+
+ /**
+ * Returns an input stream for the specified URL.
+ * This returns a pushback stream that libxmlj can use to detect the
+ * character encoding of the stream.
+ */
+ public static NamedInputStream getInputStream (URL url)
+ throws IOException
+ {
+ return new NamedInputStream (url.toString (), url.openStream(),
+ LOOKAHEAD);
+ }
+
+ /**
+ * Convenience method for xmljDocLoader
+ */
+ static NamedInputStream xmljGetInputStream(String base, String url)
+ throws IOException
+ {
+ try
+ {
+ if (base != null)
+ {
+ url = new URL(new URL(base), url).toString();
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ }
+ InputStream in = getInputStream(url);
+ return new NamedInputStream(url, in, LOOKAHEAD);
+ }
+
+ /**
+ * Returns an output stream for the specified transformer result.
+ */
+ public static OutputStream getOutputStream (Result result)
+ throws IOException
+ {
+ OutputStream out = null;
+ if (result instanceof StreamResult)
+ {
+ out = ((StreamResult) result).getOutputStream ();
+ }
+ if (out == null)
+ {
+ Writer w = ((StreamResult) result).getWriter ();
+ if (w != null)
+ out = new WriterOutputStream (w);
+ }
+ if (out == null)
+ {
+ String systemId = result.getSystemId ();
+ if (systemId == null)
+ {
+ throw new IOException ("no system ID");
+ }
+ try
+ {
+ URL url = new URL (systemId);
+ URLConnection connection = url.openConnection ();
+ connection.setDoOutput (true);
+ out = connection.getOutputStream ();
+ }
+ catch (MalformedURLException e)
+ {
+ out = new FileOutputStream (systemId);
+ }
+ }
+
+ return out;
+ }
+
+ /**
+ * Returns the absolute form of the specified URI.
+ * If the URI is already absolute, returns it as-is.
+ * Otherwise returns a new URI relative to the given base URI.
+ */
+ public static String getAbsoluteURI (String base, String uri)
+ {
+ if (uri != null &&
+ base != null &&
+ (uri.length() > 0) &&
+ (uri.indexOf(':') == -1) &&
+ (uri.charAt(0) != '/'))
+ {
+ // URI is relative
+ if (base.charAt(base.length() - 1) != '/')
+ {
+ int i = base.lastIndexOf('/');
+ base = base.substring(0, i + 1);
+ }
+ return base + uri;
+ }
+ else
+ {
+ // URI is absolute or no base specified
+ return uri;
+ }
+ }
+
+ public static String getBaseURI(String uri)
+ {
+ if (uri != null)
+ {
+ int si = uri.lastIndexOf('/');
+ if (si != -1)
+ {
+ uri = uri.substring(0, si + 1);
+ }
+ }
+ return uri;
+ }
+
+}