summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Burdess <dog@bluezoo.org>2006-01-07 15:57:44 +0000
committerChris Burdess <dog@bluezoo.org>2006-01-07 15:57:44 +0000
commit72eb4f5ccb8a6626e3ce9051543539bb1a9b8fe3 (patch)
tree1236565604cfbb2ba0701f17faafb891f8f8ef59
parentfa7301f01e8fcb385858bed6edda6caa8dff5845 (diff)
downloadclasspath-72eb4f5ccb8a6626e3ce9051543539bb1a9b8fe3.tar.gz
2006-01-07 Chris Burdess <dog@gnu.org>
* gnu/xml/stream/BufferedReader.java: Removed commented out code. * gnu/xml/stream/XIncludeFilter.java: Correct XML Base behaviour. * gnu/xml/stream/XMLParser.java: Make additional StAX properties available; correct handling of unparsed entity references; absolutize all base URIs; remove commented out code.
-rw-r--r--ChangeLog8
-rw-r--r--gnu/xml/stream/BufferedReader.java10
-rw-r--r--gnu/xml/stream/XIncludeFilter.java11
-rw-r--r--gnu/xml/stream/XMLParser.java83
4 files changed, 59 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index 2820a016d..404ef6fa7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2006-01-07 Chris Burdess <dog@gnu.org>
+ * gnu/xml/stream/BufferedReader.java: Removed commented out code.
+ * gnu/xml/stream/XIncludeFilter.java: Correct XML Base behaviour.
+ * gnu/xml/stream/XMLParser.java: Make additional StAX properties
+ available; correct handling of unparsed entity references;
+ absolutize all base URIs; remove commented out code.
+
+2006-01-07 Chris Burdess <dog@gnu.org>
+
* gnu/xml/stream/SAXParser.java,
gnu/xml/stream/XMLParser.java: Add SAX property to return base
URI of the current event.
diff --git a/gnu/xml/stream/BufferedReader.java b/gnu/xml/stream/BufferedReader.java
index f598ae230..f8287e823 100644
--- a/gnu/xml/stream/BufferedReader.java
+++ b/gnu/xml/stream/BufferedReader.java
@@ -84,7 +84,6 @@ class BufferedReader
{
marklimit = readlimit;
markpos = pos;
- //System.out.println("--mark@"+Integer.toHexString(pos)+":"+marklimit);
}
public boolean markSupported()
@@ -97,7 +96,6 @@ class BufferedReader
{
if (pos >= count && !refill())
return -1;
- //System.out.println("--read1@"+Integer.toHexString(pos)+":"+new String(buf, pos, 1));
return (int) buf[pos++];
}
@@ -121,7 +119,6 @@ class BufferedReader
int ret = Math.min(count - pos, len);
System.arraycopy(buf, pos, b, off, ret);
- //System.out.println("--read2@"+Integer.toHexString(pos)+":"+new String(b, off, ret)+" ("+ret+")");
pos += ret;
off += ret;
len -= ret;
@@ -130,7 +127,6 @@ class BufferedReader
{
int remain = Math.min(count - pos, len);
System.arraycopy(buf, pos, b, off, remain);
- //System.out.println("--read3@"+Integer.toHexString(pos)+":"+new String(b, off, remain));
pos += remain;
off += remain;
len -= remain;
@@ -146,7 +142,6 @@ class BufferedReader
if (markpos == -1)
throw new IOException(buf == null ? "Stream closed." : "Invalid mark.");
pos = markpos;
- //System.out.println("--reset@"+Integer.toHexString(pos));
}
public long skip(long n)
@@ -154,7 +149,6 @@ class BufferedReader
{
if (buf == null)
throw new IOException("Stream closed.");
- //System.out.println("--skip:"+n);
final long origN = n;
while (n > 0L)
{
@@ -173,13 +167,11 @@ class BufferedReader
if (buf == null)
throw new IOException("Stream closed.");
- //System.out.println("--refill:pos="+Integer.toHexString(pos)+" count="+Integer.toHexString(count));
int markcount = count - markpos;
if (markpos == -1 || markcount >= marklimit)
{
markpos = -1;
pos = count = 0;
- //System.out.println("--refill1@"+Integer.toHexString(pos));
}
else
{
@@ -193,14 +185,12 @@ class BufferedReader
count = markcount;
pos -= markpos;
markpos = 0;
- //System.out.println("--refill2@"+Integer.toHexString(pos)+":"+Integer.toHexString(count));
}
int numread = in.read(buf, count, bufferSize);
if (numread <= 0)
return false;
- //System.out.println("--refill3("+Integer.toHexString(numread)+"):"+new String(buf, count, numread));
count += numread;
return true;
}
diff --git a/gnu/xml/stream/XIncludeFilter.java b/gnu/xml/stream/XIncludeFilter.java
index be3640d7c..e151ac69d 100644
--- a/gnu/xml/stream/XIncludeFilter.java
+++ b/gnu/xml/stream/XIncludeFilter.java
@@ -672,6 +672,12 @@ class XIncludeFilter
}
return space;
}
+
+ String getBaseURI()
+ {
+ String base = (String) getParent().getProperty("gnu.xml.stream.baseURI");
+ return (base == null) ? systemId : base;
+ }
boolean includeResource(String href, String parse, String xpointer,
String encoding, String accept,
@@ -682,10 +688,11 @@ class XIncludeFilter
{
if (xpointer != null)
throw new XMLStreamException("xpointer attribute not yet supported");
+ String base = getBaseURI();
if (href == null || "".equals(href))
- href = systemId;
+ href = base;
else
- href = XMLParser.absolutize(systemId, href);
+ href = XMLParser.absolutize(base, href);
if (parse == null || "xml".equals(parse))
{
seen.clear();
diff --git a/gnu/xml/stream/XMLParser.java b/gnu/xml/stream/XMLParser.java
index 89204566e..7505e6e60 100644
--- a/gnu/xml/stream/XMLParser.java
+++ b/gnu/xml/stream/XMLParser.java
@@ -89,6 +89,18 @@ import gnu.java.net.CRLFInputStream;
/**
* An XML parser.
+ * This parser supports the following additional StAX properties:
+ * <table>
+ * <tr><td>gnu.xml.stream.stringInterning</td>
+ * <td>Boolean</td>
+ * <td>Indicates whether markup strings will be interned</td></tr>
+ * <tr><td>gnu.xml.stream.xmlBase</td>
+ * <td>Boolean</td>
+ * <td>Indicates whether XML Base processing will be performed</td></tr>
+ * <tr><td>gnu.xml.stream.baseURI</td>
+ * <td>String</td>
+ * <td>Returns the base URI of the current event</td></tr>
+ * </table>
*
* @see http://www.w3.org/TR/REC-xml/
* @see http://www.w3.org/TR/xml11/
@@ -803,7 +815,12 @@ public class XMLParser
return resolver;
if (XMLInputFactory.SUPPORT_DTD.equals(name))
return supportDTD ? Boolean.TRUE : Boolean.FALSE;
- // TODO stringInterning
+ if ("gnu.xml.stream.stringInterning".equals(name))
+ return stringInterning ? Boolean.TRUE : Boolean.FALSE;
+ if ("gnu.xml.stream.xmlBase".equals(name))
+ return baseAware ? Boolean.TRUE : Boolean.FALSE;
+ if ("gnu.xml.stream.baseURI".equals(name))
+ return getXMLBase();
return null;
}
@@ -1053,7 +1070,7 @@ public class XMLParser
{
event = readCharData(text);
}
- else if (replaceERefs)
+ else if (replaceERefs && !isUnparsedEntity(ref))
{
expandEntity(ref, false); //report start-entity
event = next();
@@ -1471,17 +1488,7 @@ public class XMLParser
if (!externalEntities)
return;
InputStream in = null;
- String base = getXMLBase();
- String url = absolutize(base, ids.systemId);
- // Unparsed entity?
- boolean unparsedEntity = false;
- if (ids.notationName != null)
- {
- ExternalIds notation = doctype.getNotation(ids.notationName);
- if (notation == null)
- error("reference to undeclared notation", ids.notationName);
- unparsedEntity = true;
- }
+ String url = absolutize(input.systemId, ids.systemId);
// Check for recursion
for (Iterator i = inputStack.iterator(); i.hasNext(); )
{
@@ -1505,18 +1512,11 @@ public class XMLParser
if (in == null)
error("unable to resolve external entity",
(ids.systemId != null) ? ids.systemId : ids.publicId);
- if (unparsedEntity)
- {
- // TODO read unparsed entity into buf
- }
- else
- {
- pushInput(new Input(in, null, ids.publicId, url, name, null, report));
- input.init();
- if (tryRead(TEST_XML_DECL))
- readTextDecl();
- input.finalizeEncoding();
- }
+ pushInput(new Input(in, null, ids.publicId, url, name, null, report));
+ input.init();
+ if (tryRead(TEST_XML_DECL))
+ readTextDecl();
+ input.finalizeEncoding();
}
/**
@@ -2535,7 +2535,6 @@ public class XMLParser
private int readStartElement()
throws IOException, XMLStreamException
{
- //System.err.println("readStartElement");
// Read element name
String elementName = readNmtoken(true);
attrs.clear();
@@ -2627,8 +2626,9 @@ public class XMLParser
}
if (baseAware)
{
- String base = getAttributeValue(XMLConstants.XML_NS_URI, "base");
- bases.addFirst(base);
+ String uri = getAttributeValue(XMLConstants.XML_NS_URI, "base");
+ String base = getXMLBase();
+ bases.addFirst(absolutize(base, uri));
}
if (namespaceAware)
{
@@ -2693,7 +2693,6 @@ public class XMLParser
private void readAttribute(String elementName)
throws IOException, XMLStreamException
{
- //System.err.println("readAttribute");
// Read attribute name
String attributeName = readNmtoken(true);
String type = getAttributeType(elementName, attributeName);
@@ -2853,7 +2852,6 @@ public class XMLParser
private void readEndElement()
throws IOException, XMLStreamException
{
- //System.err.println("readEndElement");
// pop element off stack
String expected = (String) stack.removeLast();
require(expected);
@@ -3034,10 +3032,6 @@ public class XMLParser
buf.append(text);
else
{
- //if (replaceERefs)
- // expandEntity(entityName, false); //report start-entity
- //else
- // reset(); // report reference
pushInput("", "&" + entityName + ";", false);
done = true;
break;
@@ -3138,6 +3132,20 @@ public class XMLParser
}
/**
+ * Indicates whether the specified entity is unparsed.
+ */
+ private boolean isUnparsedEntity(String name)
+ {
+ if (doctype != null)
+ {
+ Object value = doctype.getEntity(name);
+ if (value != null && value instanceof ExternalIds)
+ return ((ExternalIds) value).notationName != null;
+ }
+ return false;
+ }
+
+ /**
* Read an equals sign.
*/
private void readEq()
@@ -3244,8 +3252,6 @@ public class XMLParser
else
{
reset();
- //if (replaceERefs || (flags & LIT_NORMALIZE) > 0)
- // {
String entityName = readNmtoken(true);
require(';');
String text =
@@ -3257,7 +3263,6 @@ public class XMLParser
(flags & LIT_ATTRIBUTE) != 0);
entities = true;
continue;
- // }
}
}
break;
@@ -4948,8 +4953,6 @@ public class XMLParser
{
offset++;
int ret = (unicodeReader != null) ? unicodeReader.read() : in.read();
- //if (ret != -1)
- // System.out.println(" read1:"+((char) ret));
if (ret == 0x0d || (xml11 && (ret == 0x85 || ret == 0x2028)))
{
// Normalize CR etc to LF
@@ -4990,7 +4993,6 @@ public class XMLParser
if (ret != -1)
{
// Locator handling
- //System.out.println(" read:"+new String(b, off, ret));
for (int i = 0; i < ret; i++)
{
int c = b[off + i];
@@ -5015,7 +5017,6 @@ public class XMLParser
void reset()
throws IOException
{
- //System.out.println(" reset");
if (unicodeReader != null)
unicodeReader.reset();
else