PatchSet 5575 Date: 2004/12/08 22:03:23 Author: robilad Branch: HEAD Tag: (none) Log: Resynced with GNU JAXP: various fixes for DOM and eclipse3
Members: ChangeLog:1.3121->1.3122 libraries/javalib/gnu/xml/dom/DomAttr.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomCharacterData.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomDoctype.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomDocument.java:1.9->1.10 libraries/javalib/gnu/xml/dom/DomEntity.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomEntityReference.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomExtern.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomImpl.java:1.8->1.9 libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java:1.7->1.8 libraries/javalib/gnu/xml/dom/DomNode.java:1.9->1.10 libraries/javalib/gnu/xml/dom/DomNotation.java:1.7->1.8 libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java:1.3->1.4 libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java:1.1->1.2 libraries/javalib/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java:1.6->1.7 libraries/javalib/gnu/xml/libxmlj/transform/GnomeTransformer.java:1.9->1.10 libraries/javalib/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java:1.5->1.6 libraries/javalib/gnu/xml/libxmlj/transform/TransformTest.java:1.6->1.7 libraries/javalib/gnu/xml/transform/TransformerImpl.java:1.3->1.4 libraries/javalib/gnu/xml/transform/XSLComparator.java:1.2->1.3 libraries/javalib/gnu/xml/transform/XSLURIResolver.java:1.2->1.3 libraries/javalib/gnu/xml/xpath/XPathParser.y:1.4->1.5 libraries/javalib/javax/xml/namespace/QName.java:1.5->1.6 libraries/javalib/javax/xml/transform/TransformerFactory.java:1.11->1.12 Index: kaffe/ChangeLog diff -u kaffe/ChangeLog:1.3121 kaffe/ChangeLog:1.3122 --- kaffe/ChangeLog:1.3121 Wed Dec 8 21:16:45 2004 +++ kaffe/ChangeLog Wed Dec 8 22:03:23 2004 @@ -11,6 +11,63 @@ 2004-12-08 Dalibor Topic <[EMAIL PROTECTED]> + * libraries/javalib/gnu/xml/dom/DomAttr.java, + libraries/javalib/gnu/xml/dom/DomCharacterData.java, + libraries/javalib/gnu/xml/dom/DomDoctype.java, + libraries/javalib/gnu/xml/dom/DomDocument.java, + libraries/javalib/gnu/xml/dom/DomEntity.java, + libraries/javalib/gnu/xml/dom/DomEntityReference.java, + libraries/javalib/gnu/xml/dom/DomExtern.java, + libraries/javalib/gnu/xml/dom/DomImpl.java, + libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java, + libraries/javalib/gnu/xml/dom/DomNode.java, + libraries/javalib/gnu/xml/dom/DomNotation.java, + libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java, + libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java, + libraries/javalib/gnu/xml/libxmlj/dom/GnomeDocumentBuilder.java, + libraries/javalib/gnu/xml/libxmlj/transform/GnomeTransformer.java, + libraries/javalib/gnu/xml/libxmlj/transform/GnomeTransformerFactory.java, + libraries/javalib/gnu/xml/libxmlj/transform/TransformTest.java, + libraries/javalib/gnu/xml/transform/TransformerImpl.java, + libraries/javalib/gnu/xml/transform/XSLComparator.java, + libraries/javalib/gnu/xml/transform/XSLURIResolver.java, + libraries/javalib/gnu/xml/xpath/XPathParser.y, + libraries/javalib/javax/xml/namespace/QName.java, + libraries/javalib/javax/xml/transform/TransformerFactory.java: + Resynced with GNU JAXP. + + 2004-12-07 Chris Burdess <[EMAIL PROTECTED]> + + * dom: Minor DOM Level 3 Core conformance improvements. + + 2004-12-07 Mark Wielaard <[EMAIL PROTECTED]> + + * ReaderInputStream.java: Mark and reset implementation. + + 2004-12-06 Chris Burdess <[EMAIL PROTECTED]> + + * dom: Minor DOM Level 3 Core conformance improvements. + + 2004-12-06 Mark Wielaard <[EMAIL PROTECTED]> + + * TransformerImpl.java: Use StreamResult's Writer if no byte stream + is present. + + 2004-12-05 Chris Burdess <[EMAIL PROTECTED]> + + * TransformerImpl.java,XSLURIResolver.java: Permit identity + transforms with target nodes and null system IDs. + + 2004-12-04 Dalibor Topic <[EMAIL PROTECTED]> + + * ElementAvailableFunction.java,FunctionAvailableFunction.java, + KeyFunction.java,SortKey.java,Stylesheet.java, + SystemPropertyFunction.java,TransformerImpl.java,XSLComparator.java, + NameTest.java,NamespaceTest.java,XPathParser.java,QName.java: + Corrected QName.getLocalName to getLocalPart. Fixed missing imports. + +2004-12-08 Dalibor Topic <[EMAIL PROTECTED]> + * libraries/javalib/gnu/java/net/protocol/http/HTTPURLConnection.java: Resynced with GNU Classpath. Index: kaffe/libraries/javalib/gnu/xml/dom/DomAttr.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomAttr.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomAttr.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomAttr.java:1.7 Sat Dec 4 21:12:24 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomAttr.java Wed Dec 8 22:03:29 2004 @@ -296,6 +296,14 @@ } /** + * The base URI of an Attr is always <code>null</code>. + */ + public final String getBaseURI() + { + return null; + } + + /** * Shallow clone of the attribute, breaking all ties with any * elements. */ Index: kaffe/libraries/javalib/gnu/xml/dom/DomCharacterData.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomCharacterData.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomCharacterData.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomCharacterData.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomCharacterData.java Wed Dec 8 22:03:29 2004 @@ -281,6 +281,15 @@ } } + /** + * The base URI for character data is <code>null</code>. + * @since DOM Level 3 Core + */ + public final String getBaseURI() + { + return null; + } + private void mutating(String newValue) { if (!reportMutations) Index: kaffe/libraries/javalib/gnu/xml/dom/DomDoctype.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomDoctype.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomDoctype.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomDoctype.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomDoctype.java Wed Dec 8 22:03:29 2004 @@ -281,6 +281,15 @@ { return subset; } + + /** + * The base URI of a DocumentType is always <code>null</code>. + * See the Infoset Mapping, appendix C. + */ + public final String getBaseURI() + { + return null; + } /** * Sets the internal "readonly" flag so the node and its associated @@ -414,5 +423,33 @@ // TODO notations return true; } + + /** + * Shallow clone of the doctype, except that associated + * entities and notations are (deep) cloned. + */ + public Object clone() + { + DomDoctype node = (DomDoctype) super.clone(); + + if (entities != null) + { + node.entities = new DomNamedNodeMap(node, Node.ENTITY_NODE); + for (DomNode ctx = entities.first; ctx != null; ctx = ctx.next) + { + node.entities.setNamedItem(ctx.cloneNode(true)); + } + } + if (notations != null) + { + node.notations = new DomNamedNodeMap(node, Node.NOTATION_NODE); + for (DomNode ctx = notations.first; ctx != null; ctx = ctx.next) + { + node.notations.setNamedItem(ctx.cloneNode(true)); + } + } + return node; + } + } Index: kaffe/libraries/javalib/gnu/xml/dom/DomDocument.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomDocument.java:1.9 kaffe/libraries/javalib/gnu/xml/dom/DomDocument.java:1.10 --- kaffe/libraries/javalib/gnu/xml/dom/DomDocument.java:1.9 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomDocument.java Wed Dec 8 22:03:30 2004 @@ -432,7 +432,7 @@ } break; default: - if (c != ':' && c != '_' && c < 0x02bb && c > 0x02c1 && + if (c != ':' && c != '_' && (c < 0x02bb || c > 0x02c1) && c != 0x0559 && c != 0x06e5 && c != 0x06e6) { throw new DomEx(DomEx.INVALID_CHARACTER_ERR, name, null, c); @@ -495,7 +495,7 @@ break; default: if (c != '-' && c != '.' && c != ':' && c != '_' && - c != 0x0387 && c < 0x02bb && c > 0x02c1 && + c != 0x0387 && (c < 0x02bb || c > 0x02c1) && c != 0x0559 && c != 0x06e5 && c != 0x06e6 && c != 0x00b7) { throw new DomEx(DomEx.INVALID_CHARACTER_ERR, name, null, c); @@ -836,22 +836,21 @@ */ public EntityReference createEntityReference(String name) { - DomEntityReference retval; - - if (checkingCharacters) + DomEntityReference ret = new DomEntityReference(this, name); + DocumentType doctype = getDoctype(); + if (doctype != null) { - checkName(name, "1.1".equals(version)); + DomEntity ent = (DomEntity) doctype.getEntities().getNamedItem(name); + if (ent != null) + { + for (DomNode ctx = ent.first; ctx != null; ctx = ctx.next) + { + ret.appendChild(ctx.cloneNode(true)); + } + } } - retval = new DomEntityReference(this, name); - // - // If we have such an entity, it's allowed that one arrange that - // the children of this reference be "the same as" (in an undefined - // sense of "same", clearly not identity) the children of the entity. - // That can be immediate or deferred. It's also allowed that nothing - // be done -- we take that option here. - // - retval.makeReadonly(); - return retval; + ret.makeReadonly(); + return ret; } /** @@ -1076,12 +1075,12 @@ public void setXmlVersion(String xmlVersion) { - if (version == null) + if (xmlVersion == null) { - version = "1.0"; + xmlVersion = "1.0"; } - if ("1.0".equals(version) || - "1.1".equals(version)) + if ("1.0".equals(xmlVersion) || + "1.1".equals(xmlVersion)) { version = xmlVersion; } @@ -1121,6 +1120,8 @@ public String getBaseURI() { + return getDocumentURI(); + /* Node root = getDocumentElement(); if (root != null) { @@ -1132,6 +1133,7 @@ } } return systemId; + */ } public String getDocumentURI() @@ -1181,7 +1183,10 @@ public void normalizeDocument() { + boolean save = building; + building = true; normalizeNode(this); + building = save; } void normalizeNode(DomNode node) Index: kaffe/libraries/javalib/gnu/xml/dom/DomEntity.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomEntity.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomEntity.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomEntity.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomEntity.java Wed Dec 8 22:03:30 2004 @@ -96,12 +96,12 @@ String systemId, String notation) { - super(ENTITY_NODE, owner, name, publicId, systemId); + super(ENTITY_NODE, owner, name, publicId, systemId); this.notation = notation; - // NOTE: if notation == null, this is a parsed entity - // which could reasonably be given child nodes ... - makeReadonly(); + // NOTE: if notation == null, this is a parsed entity + // which could reasonably be given child nodes ... + makeReadonly(); } /** @@ -132,5 +132,17 @@ // TODO return null; } + + /** + * The base URI of an external entity is its system ID. + * The base URI of an internal entity is the parent document's base URI. + * @since DOM Level 3 Core + */ + public String getBaseURI() + { + String systemId = getSystemId(); + return (systemId == null) ? owner.getBaseURI() : systemId; + } } + Index: kaffe/libraries/javalib/gnu/xml/dom/DomEntityReference.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomEntityReference.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomEntityReference.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomEntityReference.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomEntityReference.java Wed Dec 8 22:03:30 2004 @@ -38,6 +38,8 @@ package gnu.xml.dom; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; /** @@ -98,12 +100,32 @@ } /** - * <b>DOM L1</b> * Returns the name of the referenced entity. + * @since DOM Level 1 Core */ - final public String getNodeName() + public final String getNodeName() { return name; + } + + /** + * The base URI of an entity reference is the base URI where the entity + * declaration occurs. + * @since DOM Level 3 Core + */ + public final String getBaseURI() + { + DocumentType doctype = owner.getDoctype(); + if (doctype == null) + { + return null; + } + Entity entity = (Entity) doctype.getEntities().getNamedItem(name); + if (entity == null) + { + return null; + } + return entity.getBaseURI(); } } Index: kaffe/libraries/javalib/gnu/xml/dom/DomExtern.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomExtern.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomExtern.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomExtern.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomExtern.java Wed Dec 8 22:03:30 2004 @@ -56,9 +56,9 @@ extends DomNode { - private String name; - private String publicId; - private String systemId; + private final String name; + private final String publicId; + private final String systemId; /** * Constructs a node associated with the specified document, @@ -86,7 +86,7 @@ * <b>DOM L1</b> * Returns the SYSTEM identifier associated with this object, if any. */ - final public String getSystemId() + public final String getSystemId() { return systemId; } @@ -95,7 +95,7 @@ * <b>DOM L1</b> * Returns the PUBLIC identifier associated with this object, if any. */ - final public String getPublicId() + public final String getPublicId() { return publicId; } @@ -104,7 +104,12 @@ * <b>DOM L1</b> * Returns the object's name. */ - final public String getNodeName() + public final String getNodeName() + { + return name; + } + + public final String getLocalName() { return name; } Index: kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.8 kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.9 --- kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.8 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java Wed Dec 8 22:03:30 2004 @@ -86,6 +86,10 @@ */ public boolean hasFeature(String name, String version) { + if (name.length() == 0) + { + return false; + } name = name.toLowerCase(); if (name.charAt(0) == '+') { @@ -104,6 +108,7 @@ else if ("ls".equals(name) || "ls-async".equals(name)) { return (version == null || + "".equals(version) || "3.0".equals(version)); } else if ("events".equals(name) @@ -136,9 +141,6 @@ else if (DomNode.reportMutations && "traversal".equals(name)) { - - // Note: nyet tree walker support ... - return (version == null || "".equals(version) || "2.0".equals(version)); @@ -225,15 +227,9 @@ public Object getFeature(String feature, String version) { - feature = feature.toLowerCase(); - - // DOM Level 3 Load and Save - if ("ls".equals(feature) || "ls-async".equals(feature)) + if (hasFeature(feature, version)) { - if (version == null || "3.0".equals(version)) - { - return this; - } + return this; } return null; } Index: kaffe/libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomNamedNodeMap.java Wed Dec 8 22:03:30 2004 @@ -115,6 +115,10 @@ */ public Node getNamedItemNS(String namespaceURI, String localName) { + if ("".equals(namespaceURI)) + { + namespaceURI = null; + } for (DomNode ctx = first; ctx != null; ctx = ctx.next) { String name = ctx.getLocalName(); @@ -122,6 +126,10 @@ (localName != null && localName.equals(name))) { String uri = ctx.getNamespaceURI(); + if ("".equals(uri)) + { + uri = null; + } if ((namespaceURI == null && uri == null) || (namespaceURI != null && namespaceURI.equals(uri))) { @@ -182,7 +190,7 @@ node.depth = owner.depth + 1; } - String nodeName = ns ? null : node.getNodeName(); + String nodeName = node.getNodeName(); String localName = ns ? node.getLocalName() : null; String namespaceURI = ns ? node.getNamespaceURI() : null; if ("".equals(namespaceURI)) Index: kaffe/libraries/javalib/gnu/xml/dom/DomNode.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomNode.java:1.9 kaffe/libraries/javalib/gnu/xml/dom/DomNode.java:1.10 --- kaffe/libraries/javalib/gnu/xml/dom/DomNode.java:1.9 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomNode.java Wed Dec 8 22:03:30 2004 @@ -611,6 +611,7 @@ { DomNode child = (DomNode) newChild; DomNode ref = (DomNode) refChild; + if (child.nodeType == DOCUMENT_FRAGMENT_NODE) { // Append all nodes in the fragment to this node @@ -628,7 +629,7 @@ else { checkMisc(child); - if (ref.parent != this) + if (ref == null || ref.parent != this) { throw new DomEx(DomEx.NOT_FOUND_ERR, null, ref, 0); } @@ -719,6 +720,10 @@ { checkMisc(ctx); } + if (ref == null || ref.parent != this) + { + throw new DomEx(DomEx.NOT_FOUND_ERR, null, ref, 0); + } if (reportMutations) { @@ -778,6 +783,10 @@ else { checkMisc(child); + if (ref == null || ref.parent != this) + { + throw new DomEx(DomEx.NOT_FOUND_ERR, null, ref, 0); + } if (reportMutations) { @@ -821,7 +830,7 @@ } ref.parent = null; ref.index = 0; - ref.depth = 0; + ref.setDepth(0); ref.previous = null; ref.next = null; @@ -893,7 +902,7 @@ ctx.index = i++; } ref.parent = null; - ref.depth = 0; + ref.setDepth(0); ref.index = 0; ref.previous = null; ref.next = null; @@ -1154,6 +1163,7 @@ node.parent = null; node.depth = 0; node.index = 0; + node.length = 0; node.first = null; node.last = null; node.previous = null; @@ -1749,8 +1759,11 @@ * relevant) merge adjacent text nodes. This is done while ignoring * text which happens to use CDATA delimiters). */ - public void normalize() + public final void normalize() { + // Suspend readonly status + boolean saved = readonly; + readonly = false; for (DomNode ctx = first; ctx != null; ctx = ctx.next) { switch (ctx.nodeType) @@ -1773,10 +1786,13 @@ // Fall through case DOCUMENT_NODE: case DOCUMENT_FRAGMENT_NODE: + case ATTRIBUTE_NODE: + case ENTITY_REFERENCE_NODE: ctx.normalize(); break; } } + readonly = saved; } /** @@ -1881,7 +1897,7 @@ */ final int compareTo2(DomNode n1, DomNode n2) { - if (n1.depth == 0 || n1 == n2 || n1 == null || n2 == null) + if (n1 == n2 || n1.depth == 0 || n2.depth == 0) { return 0; } @@ -1901,7 +1917,6 @@ switch (nodeType) { case ELEMENT_NODE: - case ATTRIBUTE_NODE: case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case DOCUMENT_FRAGMENT_NODE: @@ -1922,6 +1937,8 @@ return ""; } return getNodeValue(); + case ATTRIBUTE_NODE: + return getNodeValue(); case COMMENT_NODE: case PROCESSING_INSTRUCTION_NODE: return topLevel ? getNodeValue() : ""; @@ -1990,16 +2007,35 @@ { return true; } + if (arg == null) + { + return false; + } if (nodeType != arg.getNodeType() || !equal(getNodeName(), arg.getNodeName()) || !equal(getLocalName(), arg.getLocalName()) || !equal(getNamespaceURI(), arg.getNamespaceURI()) || !equal(getPrefix(), arg.getPrefix()) || - !equal(getNodeValue(), arg.getNodeValue()) || - !equal(getChildNodes(), arg.getChildNodes())) + !equal(getNodeValue(), arg.getNodeValue())) { return false; } + // Children + Node argCtx = arg.getFirstChild(); + getFirstChild(); // because of DomAttr lazy children + for (DomNode ctx = first; ctx != null; ctx = ctx.next) + { + if (!ctx.isEqualNode(argCtx)) + { + return false; + } + argCtx = argCtx.getNextSibling(); + } + if (argCtx != null) + { + return false; + } + // TODO Attr NamedNodeMap // TODO DocumentType return true; @@ -2011,34 +2047,6 @@ (arg1 != null && arg1.equals(arg2))); } - boolean equal(NodeList arg1, NodeList arg2) - { - if (arg1 == null && arg2 == null) - { - return true; - } - if (arg1 == null || arg2 == null) - { - return false; - } - int len1 = arg1.getLength(); - int len2 = arg2.getLength(); - if (len1 != len2) - { - return false; - } - for (int i = 0; i < len1; i++) - { - Node child1 = arg1.item(i); - Node child2 = arg2.item(i); - if (!child1.isSameNode(child2)) - { - return false; - } - } - return true; - } - public Object getFeature(String feature, String version) { DOMImplementation impl = (nodeType == DOCUMENT_NODE) ? Index: kaffe/libraries/javalib/gnu/xml/dom/DomNotation.java diff -u kaffe/libraries/javalib/gnu/xml/dom/DomNotation.java:1.7 kaffe/libraries/javalib/gnu/xml/dom/DomNotation.java:1.8 --- kaffe/libraries/javalib/gnu/xml/dom/DomNotation.java:1.7 Sat Dec 4 21:12:25 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/DomNotation.java Wed Dec 8 22:03:30 2004 @@ -89,5 +89,16 @@ makeReadonly(); } + /** + * The base URI of an external entity is its system ID. + * The base URI of an internal entity is the parent document's base URI. + * @since DOM Level 3 Core + */ + public String getBaseURI() + { + String systemId = getSystemId(); + return (systemId == null) ? owner.getBaseURI() : systemId; + } + } Index: kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java diff -u kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java:1.3 kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java:1.4 --- kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java:1.3 Mon Dec 6 09:02:52 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/ls/ReaderInputStream.java Wed Dec 8 22:03:30 2004 @@ -1,6 +1,6 @@ /* * ReaderInputStream.java - * Copyright (C) 1999,2000,2001 The Free Software Foundation + * Copyright (C) 1999, 2000, 2001, 2004 The Free Software Foundation * * This file is part of GNU JAXP, a library. * @@ -46,6 +46,7 @@ * Character stream wrapper. * * @author <a href='mailto:[EMAIL PROTECTED]'>Chris Burdess</a> + * @author <a href='mailto:[EMAIL PROTECTED]'>Mark Wielaard</a> */ public class ReaderInputStream extends InputStream @@ -54,10 +55,17 @@ private Reader reader; private String encoding; + // Holds extra spillover data if necessary + private byte extra[]; + private int pos; + + private byte extra_marked[]; + private int pos_marked; + public ReaderInputStream(Reader reader) { this.reader = reader; - encoding = "UTF-8"; + this.encoding = "UTF-8"; } void setEncoding(String encoding) @@ -68,6 +76,16 @@ public int read() throws IOException { + if (extra != null) + { + int result = extra[pos]; + pos++; + if (pos >= extra.length) + { + extra = null; + } + return result; + } return reader.read(); } @@ -80,14 +98,46 @@ public int read(byte[] b, int off, int len) throws IOException { - int l = len - off; - char[] c = new char[l]; - l = reader.read(c, 0, l); + if (len == 0) + { + return 0; + } + + if (extra != null) + { + int available = extra.length - pos; + int l = available < len ? available : len; + System.arraycopy(extra, 0, b, off, l); + pos += l; + if (pos >= extra.length) + { + extra = null; + } + return l; + } + + char[] c = new char[len]; + int l = reader.read(c, 0, len); + if (l == -1) + { + return -1; + } + String s = new String(c, 0, l); byte[] d = s.getBytes(encoding); - // FIXME d.length may be > len - System.arraycopy(d, 0, b, off, d.length); - return d.length; + + int available = d.length; + int more = d.length - len; + if (more > 0) + { + extra = new byte[more]; + pos = 0; + System.arraycopy(d, len, extra, 0, more); + available -= more; + } + + System.arraycopy(d, 0, b, off, available); + return available; } public void close() @@ -103,29 +153,86 @@ public void mark(int limit) { + if (extra != null) + { + extra_marked = new byte[extra.length]; + System.arraycopy(extra, 0, extra_marked, 0, extra.length); + pos_marked = pos; + } + else + { + extra_marked = null; + } + try { + // Note that this might be a bit more than asked for. + // Because we might also have the extra_marked bytes. + // That is fine (and necessary for reset() to work). reader.mark(limit); } - catch (IOException e) + catch (IOException ioe) { - throw new RuntimeException(e.getMessage()); + throw new RuntimeException(ioe); } } public void reset() throws IOException { + extra = extra_marked; + pos = pos_marked; + extra_marked = null; + reader.reset(); } public long skip(long n) throws IOException { - return reader.skip(n); + long done = 0; + if (extra != null) + { + int available = extra.length - pos; + done = available < n ? available : n; + pos += done; + if (pos >= extra.length) + { + extra = null; + } + } + + n -= done; + if (n > 0) + { + return reader.skip(n) + done; + } + else + { + return done; + } + } + + /** + * Returns conservative number of bytes available without blocking. + * Actual number of bytes that can be read without blocking might + * be (much) bigger. + */ + public int available() + throws IOException + { + if (extra != null) + { + return pos - extra.length; + } + + return reader.ready() ? 1 : 0; } - // TODO available + public String toString() + { + return getClass().getName() + "[" + reader + ", " + encoding + "]"; + } } Index: kaffe/libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java diff -u kaffe/libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java:1.1 kaffe/libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java:1.2 --- kaffe/libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java:1.1 Sat Dec 4 21:12:26 2004 +++ kaffe/libraries/javalib/gnu/xml/dom/ls/SAXEventSink.java Wed Dec 8 22:03:30 2004 @@ -81,6 +81,7 @@ DomDocument doc; // document being constructed Node ctx; // current context (parent node) + LinkedList entityCtx; // entity context List pending; // namespace nodes waiting for a declaring element Locator locator; boolean inCDATA; @@ -354,13 +355,19 @@ public void startEntity(String name) throws SAXException { - // Get entity DocumentType doctype = doc.getDoctype(); if (doctype == null) { throw new SAXException("SAX parser error: " + "reference to entity in undeclared doctype"); } + if ("[dtd]".equals(name) || name.charAt(0) == '%') + { + // Ignore DTD and parameter entities + ctx = doctype; + return; + } + // Get entity NamedNodeMap entities = doctype.getEntities(); Entity entity = (Entity) entities.getNamedItem(name); if (entity == null) @@ -368,6 +375,18 @@ throw new SAXException("SAX parser error: " + "reference to undeclared entity: " + name); } + pushEntity(entity); + } + + public void endEntity(String name) + throws SAXException + { + if ("[dtd]".equals(name) || name.charAt(0) == '%') + { + // Ignore DTD and parameter entities + return; + } + Entity entity = popEntity(); // TODO resolve external entities to ensure that entity has content if (expandEntityReferences) { @@ -382,18 +401,24 @@ { Node entityReference = doc.createEntityReference(name); ctx.appendChild(entityReference); - // Copy entity content - for (Node child = entity.getFirstChild(); child != null; - child = child.getNextSibling()) - { - entityReference.appendChild(child.cloneNode(true)); - } } } *** Patch too long, truncated *** _______________________________________________ kaffe mailing list [EMAIL PROTECTED] http://kaffe.org/cgi-bin/mailman/listinfo/kaffe