From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../classpath/gnu/xml/libxmlj/dom/GnomeAttr.java | 117 +++++ .../gnu/xml/libxmlj/dom/GnomeCDATASection.java | 57 +++ .../gnu/xml/libxmlj/dom/GnomeCharacterData.java | 119 +++++ .../gnu/xml/libxmlj/dom/GnomeComment.java | 57 +++ .../gnu/xml/libxmlj/dom/GnomeDOMException.java | 98 ++++ .../gnu/xml/libxmlj/dom/GnomeDOMStringList.java | 84 +++ .../gnu/xml/libxmlj/dom/GnomeDocument.java | 562 +++++++++++++++++++++ .../gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java | 326 ++++++++++++ .../libxmlj/dom/GnomeDocumentBuilderFactory.java | 118 +++++ .../gnu/xml/libxmlj/dom/GnomeDocumentFragment.java | 57 +++ .../gnu/xml/libxmlj/dom/GnomeDocumentType.java | 98 ++++ .../gnu/xml/libxmlj/dom/GnomeElement.java | 184 +++++++ .../classpath/gnu/xml/libxmlj/dom/GnomeEntity.java | 104 ++++ .../gnu/xml/libxmlj/dom/GnomeEntityReference.java | 57 +++ .../gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java | 92 ++++ .../classpath/gnu/xml/libxmlj/dom/GnomeNode.java | 501 ++++++++++++++++++ .../gnu/xml/libxmlj/dom/GnomeNodeList.java | 66 +++ .../gnu/xml/libxmlj/dom/GnomeNotation.java | 80 +++ .../libxmlj/dom/GnomeProcessingInstruction.java | 79 +++ .../classpath/gnu/xml/libxmlj/dom/GnomeText.java | 132 +++++ .../gnu/xml/libxmlj/dom/GnomeTypeInfo.java | 65 +++ .../gnu/xml/libxmlj/dom/GnomeXPathExpression.java | 86 ++++ .../gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java | 64 +++ .../gnu/xml/libxmlj/dom/GnomeXPathNodeList.java | 73 +++ .../gnu/xml/libxmlj/dom/GnomeXPathResult.java | 134 +++++ 25 files changed, 3410 insertions(+) create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeAttr.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeCDATASection.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeCharacterData.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeComment.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMException.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDOMStringList.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocument.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentBuilderFactory.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentFragment.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeDocumentType.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeElement.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntity.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeEntityReference.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeNamedNodeMap.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeNode.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeNodeList.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeNotation.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeProcessingInstruction.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeText.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeTypeInfo.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathExpression.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNSResolver.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathNodeList.java create mode 100644 libjava/classpath/gnu/xml/libxmlj/dom/GnomeXPathResult.java (limited to 'libjava/classpath/gnu/xml/libxmlj/dom') 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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 Chris Burdess + */ +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 () + ']'; + } + } + +} -- cgit v1.2.3