Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r111942
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* CRLFReader.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -153,13 +153,14 @@ class CRLFReader
|
||||
throws IOException
|
||||
{
|
||||
doReset = false;
|
||||
int lm1 = len - 1;
|
||||
for (int i = off; i < len; i++)
|
||||
int end = off + len;
|
||||
int em1 = end - 1;
|
||||
for (int i = off; i < end; i++)
|
||||
{
|
||||
if (b[i] == '\r') // CR
|
||||
{
|
||||
int d;
|
||||
if (i == lm1)
|
||||
if (i == em1)
|
||||
{
|
||||
d = in.read();
|
||||
doReset = true;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/* EndEntityImpl.java --
|
||||
Copyright (C) 2005 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.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.EndEntity;
|
||||
|
||||
/**
|
||||
* An end-entity event.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
public class EndEntityImpl
|
||||
extends XMLEventImpl
|
||||
implements EndEntity
|
||||
{
|
||||
|
||||
protected final String name;
|
||||
|
||||
protected EndEntityImpl(Location location, String name)
|
||||
{
|
||||
super(location);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getEventType()
|
||||
{
|
||||
return END_ENTITY;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void writeAsEncodedUnicode(Writer writer)
|
||||
throws XMLStreamException
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* EntityReferenceImpl.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
//import javax.xml.stream.events.EntityDeclaration;
|
||||
import javax.xml.stream.events.EntityDeclaration;
|
||||
import javax.xml.stream.events.EntityReference;
|
||||
|
||||
/**
|
||||
@@ -54,26 +54,16 @@ public class EntityReferenceImpl
|
||||
implements EntityReference
|
||||
{
|
||||
|
||||
//protected final EntityDeclaration decl;
|
||||
protected final EntityDeclaration decl;
|
||||
protected final String name;
|
||||
protected final String baseUri;
|
||||
protected final String publicId;
|
||||
protected final String systemId;
|
||||
protected final String replacementText;
|
||||
|
||||
protected EntityReferenceImpl(Location location,
|
||||
//EntityDeclaration decl,
|
||||
String name,
|
||||
String baseUri, String publicId,
|
||||
String systemId, String replacementText)
|
||||
EntityDeclaration decl,
|
||||
String name)
|
||||
{
|
||||
super(location);
|
||||
//this.decl = decl;
|
||||
this.decl = decl;
|
||||
this.name = name;
|
||||
this.baseUri = baseUri;
|
||||
this.publicId = publicId;
|
||||
this.systemId = systemId;
|
||||
this.replacementText = replacementText;
|
||||
}
|
||||
|
||||
public int getEventType()
|
||||
@@ -81,36 +71,16 @@ public class EntityReferenceImpl
|
||||
return ENTITY_REFERENCE;
|
||||
}
|
||||
|
||||
/*public EntityDeclaration getDeclaration()
|
||||
public EntityDeclaration getDeclaration()
|
||||
{
|
||||
return decl;
|
||||
}*/
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getBaseUri()
|
||||
{
|
||||
return baseUri;
|
||||
}
|
||||
|
||||
public String getPublicId()
|
||||
{
|
||||
return publicId;
|
||||
}
|
||||
|
||||
public String getSystemId()
|
||||
{
|
||||
return systemId;
|
||||
}
|
||||
|
||||
public String getReplacementText()
|
||||
{
|
||||
return replacementText;
|
||||
}
|
||||
|
||||
public void writeAsEncodedUnicode(Writer writer)
|
||||
throws XMLStreamException
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* FilteredEventReader.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -56,24 +56,37 @@ class FilteredEventReader
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
throws XMLStreamException
|
||||
{
|
||||
// XXX ???
|
||||
return super.hasNext();
|
||||
}
|
||||
|
||||
public XMLEvent next()
|
||||
public XMLEvent nextEvent()
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLEvent ret;
|
||||
do
|
||||
{
|
||||
ret = super.next();
|
||||
ret = super.nextEvent();
|
||||
}
|
||||
while (!filter.accept(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Object next()
|
||||
{
|
||||
try
|
||||
{
|
||||
return nextEvent();
|
||||
}
|
||||
catch (XMLStreamException e)
|
||||
{
|
||||
RuntimeException e2 = new RuntimeException();
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
public XMLEvent peek()
|
||||
throws XMLStreamException
|
||||
{
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/* LocationImpl.java --
|
||||
Copyright (C) 2005 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.stream;
|
||||
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
/**
|
||||
* Information about the location of an XML event within the underlying
|
||||
* stream.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
public class LocationImpl
|
||||
implements Location
|
||||
{
|
||||
|
||||
protected final int offset;
|
||||
|
||||
protected final int col;
|
||||
|
||||
protected final int line;
|
||||
|
||||
protected final String systemId;
|
||||
|
||||
protected LocationImpl(int offset, int col, int line, String systemId)
|
||||
{
|
||||
this.offset = offset;
|
||||
this.col = col;
|
||||
this.line = line;
|
||||
this.systemId = systemId;
|
||||
}
|
||||
|
||||
public int getLineNumber()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
public int getColumnNumber()
|
||||
{
|
||||
return col;
|
||||
}
|
||||
|
||||
public int getCharacterOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
public String getLocationURI()
|
||||
{
|
||||
return systemId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* SAXParser.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -92,8 +92,7 @@ import org.xml.sax.ext.Locator2;
|
||||
*/
|
||||
public class SAXParser
|
||||
extends javax.xml.parsers.SAXParser
|
||||
implements XMLReader, Attributes2, Locator2, XMLReporter,
|
||||
XMLParser.XMLResolver2
|
||||
implements XMLReader, Attributes2, Locator2, XMLReporter, XMLResolver
|
||||
{
|
||||
|
||||
ContentHandler contentHandler;
|
||||
@@ -323,6 +322,7 @@ public class SAXParser
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
true,
|
||||
this,
|
||||
this);
|
||||
else
|
||||
@@ -338,6 +338,7 @@ public class SAXParser
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
true,
|
||||
this,
|
||||
this);
|
||||
}
|
||||
@@ -357,6 +358,7 @@ public class SAXParser
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
true,
|
||||
this,
|
||||
this);
|
||||
}
|
||||
@@ -486,14 +488,14 @@ public class SAXParser
|
||||
contentHandler.processingInstruction(target, data);
|
||||
}
|
||||
break;
|
||||
case XMLStreamConstants.START_ENTITY:
|
||||
case XMLParser.START_ENTITY:
|
||||
if (lexicalHandler != null)
|
||||
{
|
||||
String name = reader.getText();
|
||||
lexicalHandler.startEntity(name);
|
||||
}
|
||||
break;
|
||||
case XMLStreamConstants.END_ENTITY:
|
||||
case XMLParser.END_ENTITY:
|
||||
if (lexicalHandler != null)
|
||||
{
|
||||
String name = reader.getText();
|
||||
@@ -649,24 +651,36 @@ public class SAXParser
|
||||
lexicalHandler.endDTD();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (XMLStreamException e)
|
||||
{
|
||||
if (!startDocumentDone && contentHandler != null)
|
||||
contentHandler.startDocument();
|
||||
SAXParseException e2 = new SAXParseException(e.getMessage(), this);
|
||||
e2.initCause(e);
|
||||
if (errorHandler != null)
|
||||
errorHandler.fatalError(e2);
|
||||
if (contentHandler != null)
|
||||
contentHandler.endDocument();
|
||||
throw e2;
|
||||
}
|
||||
finally
|
||||
{
|
||||
reset();
|
||||
if (opened)
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SAXParseException e2 = new SAXParseException(e.getMessage(), this);
|
||||
e2.initCause(e);
|
||||
try
|
||||
{
|
||||
if (!startDocumentDone && contentHandler != null)
|
||||
contentHandler.startDocument();
|
||||
if (errorHandler != null)
|
||||
errorHandler.fatalError(e2);
|
||||
if (contentHandler != null)
|
||||
contentHandler.endDocument();
|
||||
}
|
||||
catch (SAXException sex)
|
||||
{
|
||||
// Ignored, we will rethrow the original exception.
|
||||
}
|
||||
reset();
|
||||
if (opened)
|
||||
in.close();
|
||||
if (e instanceof SAXException)
|
||||
throw (SAXException) e;
|
||||
if (e instanceof IOException)
|
||||
throw (IOException) e;
|
||||
else
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +699,7 @@ public class SAXParser
|
||||
int ac = reader.getAttributeCount();
|
||||
for (int i = 0; i < ac; i++)
|
||||
{
|
||||
QName aname = reader.getAttributeQName(i);
|
||||
QName aname = reader.getAttributeName(i);
|
||||
if ("space".equals(aname.getLocalPart()) &&
|
||||
XMLConstants.XML_NS_URI.equals(aname.getNamespaceURI()))
|
||||
{
|
||||
@@ -726,7 +740,7 @@ public class SAXParser
|
||||
int len = reader.getAttributeCount();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
QName q = reader.getAttributeQName(i);
|
||||
QName q = reader.getAttributeName(i);
|
||||
String localName = q.getLocalPart();
|
||||
String prefix = q.getPrefix();
|
||||
String qn = ("".equals(prefix)) ? localName : prefix + ":" + localName;
|
||||
@@ -741,7 +755,7 @@ public class SAXParser
|
||||
int len = reader.getAttributeCount();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
QName q = reader.getAttributeQName(i);
|
||||
QName q = reader.getAttributeName(i);
|
||||
String ln = q.getLocalPart();
|
||||
String u = q.getNamespaceURI();
|
||||
if (u == null && uri != null)
|
||||
@@ -761,12 +775,12 @@ public class SAXParser
|
||||
|
||||
public String getLocalName(int index)
|
||||
{
|
||||
return reader.getAttributeName(index);
|
||||
return reader.getAttributeLocalName(index);
|
||||
}
|
||||
|
||||
public String getQName(int index)
|
||||
{
|
||||
QName q = reader.getAttributeQName(index);
|
||||
QName q = reader.getAttributeName(index);
|
||||
String localName = q.getLocalPart();
|
||||
String prefix = q.getPrefix();
|
||||
return ("".equals(prefix)) ? localName : prefix + ":" + localName;
|
||||
@@ -864,13 +878,14 @@ public class SAXParser
|
||||
|
||||
public String getPublicId()
|
||||
{
|
||||
return null;
|
||||
Location l = reader.getLocation();
|
||||
return l.getPublicId();
|
||||
}
|
||||
|
||||
public String getSystemId()
|
||||
{
|
||||
Location l = reader.getLocation();
|
||||
return l.getLocationURI();
|
||||
return l.getSystemId();
|
||||
}
|
||||
|
||||
public String getEncoding()
|
||||
@@ -885,13 +900,8 @@ public class SAXParser
|
||||
|
||||
// -- XMLResolver --
|
||||
|
||||
public InputStream resolve(String uri)
|
||||
throws XMLStreamException
|
||||
{
|
||||
return resolve(null, uri);
|
||||
}
|
||||
|
||||
public InputStream resolve(String publicId, String systemId)
|
||||
public Object resolveEntity(String publicId, String systemId,
|
||||
String baseURI, String namespace)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (entityResolver != null)
|
||||
@@ -901,7 +911,16 @@ public class SAXParser
|
||||
InputSource input =
|
||||
entityResolver.resolveEntity(publicId, systemId);
|
||||
if (input != null)
|
||||
return input.getByteStream();
|
||||
{
|
||||
InputStream in = input.getByteStream();
|
||||
if (in == null)
|
||||
{
|
||||
String newSystemId = input.getSystemId();
|
||||
if (newSystemId != null && !newSystemId.equals(systemId))
|
||||
in = XMLParser.resolve(newSystemId);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
}
|
||||
catch (SAXException e)
|
||||
{
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/* StartEntityImpl.java --
|
||||
Copyright (C) 2005 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.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.StartEntity;
|
||||
|
||||
/**
|
||||
* A start-entity event.
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
public class StartEntityImpl
|
||||
extends XMLEventImpl
|
||||
implements StartEntity
|
||||
{
|
||||
|
||||
protected final String name;
|
||||
|
||||
protected StartEntityImpl(Location location, String name)
|
||||
{
|
||||
super(location);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getEventType()
|
||||
{
|
||||
return START_ENTITY;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void writeAsEncodedUnicode(Writer writer)
|
||||
throws XMLStreamException
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import java.io.Reader;
|
||||
*
|
||||
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
||||
*/
|
||||
class UnicodeReader
|
||||
public class UnicodeReader
|
||||
{
|
||||
|
||||
final Reader in;
|
||||
@@ -152,6 +152,10 @@ class UnicodeReader
|
||||
in.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified UTF-16 char array as an array of Unicode code
|
||||
* points.
|
||||
*/
|
||||
public static int[] toCodePointArray(String text)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashSet;
|
||||
@@ -121,7 +122,17 @@ class XIncludeFilter
|
||||
boolean expandERefs)
|
||||
{
|
||||
super(reader);
|
||||
this.systemId = XMLParser.absolutize(null, systemId);
|
||||
try
|
||||
{
|
||||
this.systemId = XMLParser.absolutize(null, systemId);
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
RuntimeException e2 = new RuntimeException("unsupported URL: " +
|
||||
systemId);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
this.namespaceAware = namespaceAware;
|
||||
this.validating = validating;
|
||||
this.expandERefs = expandERefs;
|
||||
@@ -137,7 +148,7 @@ class XIncludeFilter
|
||||
return super.getAttributeCount();
|
||||
}
|
||||
|
||||
public String getAttributeName(int index)
|
||||
public String getAttributeLocalName(int index)
|
||||
{
|
||||
if (current != null)
|
||||
{
|
||||
@@ -147,7 +158,7 @@ class XIncludeFilter
|
||||
Node attr = attrs.item(index);
|
||||
return attr.getLocalName();
|
||||
}
|
||||
return super.getAttributeName(index);
|
||||
return super.getAttributeLocalName(index);
|
||||
}
|
||||
|
||||
public String getAttributeNamespace(int index)
|
||||
@@ -176,7 +187,7 @@ class XIncludeFilter
|
||||
return super.getAttributePrefix(index);
|
||||
}
|
||||
|
||||
public QName getAttributeQName(int index)
|
||||
public QName getAttributeName(int index)
|
||||
{
|
||||
if (current != null)
|
||||
{
|
||||
@@ -189,7 +200,7 @@ class XIncludeFilter
|
||||
String prefix = attr.getPrefix();
|
||||
return new QName(uri, localName, prefix);
|
||||
}
|
||||
return super.getAttributeQName(index);
|
||||
return super.getAttributeName(index);
|
||||
}
|
||||
|
||||
public String getAttributeType(int index)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* XMLEventAllocatorImpl.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -116,10 +116,9 @@ public class XMLEventAllocatorImpl
|
||||
namespaces);
|
||||
case XMLStreamConstants.ENTITY_REFERENCE:
|
||||
String name = reader.getLocalName();
|
||||
//EntityDeclaration decl =
|
||||
// (EntityDeclaration) entityDeclarations.get(name);
|
||||
//return new EntityReferenceImpl(location, decl, name);
|
||||
return new EntityReferenceImpl(location, name, null, null, null, null);
|
||||
EntityDeclaration decl =
|
||||
(EntityDeclaration) entityDeclarations.get(name);
|
||||
return new EntityReferenceImpl(location, decl, name);
|
||||
case XMLStreamConstants.PROCESSING_INSTRUCTION:
|
||||
return new ProcessingInstructionImpl(location,
|
||||
reader.getPITarget(),
|
||||
@@ -132,7 +131,7 @@ public class XMLEventAllocatorImpl
|
||||
return new CharactersImpl(location, text,
|
||||
whitespace, false, ignorableWhitespace);
|
||||
case XMLStreamConstants.START_DOCUMENT:
|
||||
String systemId = location.getLocationURI();
|
||||
String systemId = location.getSystemId();
|
||||
String encoding = reader.getCharacterEncodingScheme();
|
||||
boolean encodingDeclared = encoding != null;
|
||||
if (encoding == null)
|
||||
@@ -164,7 +163,7 @@ public class XMLEventAllocatorImpl
|
||||
List attributes = new LinkedList();
|
||||
for (int i = 0; i < len; i++)
|
||||
attributes.add(new AttributeImpl(location,
|
||||
reader.getAttributeQName(i),
|
||||
reader.getAttributeName(i),
|
||||
reader.getAttributeValue(i),
|
||||
QName.valueOf(reader.getAttributeType(i)),
|
||||
reader.isAttributeSpecified(i)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* XMLEventFactoryImpl.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -233,12 +233,9 @@ public class XMLEventFactoryImpl
|
||||
}
|
||||
|
||||
public EntityReference createEntityReference(String name,
|
||||
//EntityDeclaration declaration)
|
||||
String replacementText)
|
||||
EntityDeclaration declaration)
|
||||
{
|
||||
//return new EntityReferenceImpl(location, declaration, name);
|
||||
return new EntityReferenceImpl(location, name, null, null, null,
|
||||
replacementText);
|
||||
return new EntityReferenceImpl(location, declaration, name);
|
||||
}
|
||||
|
||||
public Comment createComment(String text)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* XMLEventImpl.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -116,16 +116,6 @@ public abstract class XMLEventImpl
|
||||
return getEventType() == END_DOCUMENT;
|
||||
}
|
||||
|
||||
public boolean isStartEntity()
|
||||
{
|
||||
return getEventType() == START_ENTITY;
|
||||
}
|
||||
|
||||
public boolean isEndEntity()
|
||||
{
|
||||
return getEventType() == END_ENTITY;
|
||||
}
|
||||
|
||||
public StartElement asStartElement()
|
||||
{
|
||||
return (StartElement) this;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class XMLEventReaderImpl
|
||||
this.systemId = systemId;
|
||||
}
|
||||
|
||||
public XMLEvent next()
|
||||
public XMLEvent nextEvent()
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLEvent ret = peek();
|
||||
@@ -75,10 +75,32 @@ public class XMLEventReaderImpl
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
throws XMLStreamException
|
||||
public Object next()
|
||||
{
|
||||
return peekEvent != null || reader.hasNext();
|
||||
try
|
||||
{
|
||||
return nextEvent();
|
||||
}
|
||||
catch (XMLStreamException e)
|
||||
{
|
||||
RuntimeException e2 = new RuntimeException();
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNext()
|
||||
{
|
||||
if (peekEvent != null)
|
||||
return true;
|
||||
try
|
||||
{
|
||||
return reader.hasNext();
|
||||
}
|
||||
catch (XMLStreamException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public XMLEvent peek()
|
||||
@@ -121,5 +143,16 @@ public class XMLEventReaderImpl
|
||||
return reader.getProperty(name);
|
||||
}
|
||||
|
||||
public void close()
|
||||
throws XMLStreamException
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public class XMLEventWriterImpl
|
||||
throws XMLStreamException
|
||||
{
|
||||
while (reader.hasNext())
|
||||
add(reader.next());
|
||||
add(reader.nextEvent());
|
||||
}
|
||||
|
||||
public String getPrefix(String uri)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* XMLInputFactoryImpl.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2005,2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -89,28 +89,7 @@ public class XMLInputFactoryImpl
|
||||
public XMLStreamReader createXMLStreamReader(Reader reader)
|
||||
throws XMLStreamException
|
||||
{
|
||||
/*
|
||||
return new XMLStreamReaderImpl(reader, null, null,
|
||||
resolver, reporter,
|
||||
validating, namespaceAware,
|
||||
coalescing, replacingEntityReferences,
|
||||
externalEntities, supportDTD);
|
||||
*/
|
||||
XMLParser ret = new XMLParser(reader, null,
|
||||
validating,
|
||||
namespaceAware,
|
||||
coalescing,
|
||||
replacingEntityReferences,
|
||||
externalEntities,
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
reporter,
|
||||
resolver);
|
||||
if (xIncludeAware)
|
||||
return new XIncludeFilter(ret, null, namespaceAware, validating,
|
||||
replacingEntityReferences);
|
||||
return ret;
|
||||
return createXMLStreamReader(null, reader);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(Source source)
|
||||
@@ -118,11 +97,6 @@ public class XMLInputFactoryImpl
|
||||
{
|
||||
String systemId = source.getSystemId();
|
||||
InputStream in = getInputStream(source);
|
||||
/*return new XMLStreamReaderImpl(in, null, systemId,
|
||||
resolver, reporter,
|
||||
validating, namespaceAware,
|
||||
coalescing, replacingEntityReferences,
|
||||
externalEntities, supportDTD);*/
|
||||
XMLParser ret = new XMLParser(in, systemId,
|
||||
validating,
|
||||
namespaceAware,
|
||||
@@ -132,6 +106,7 @@ public class XMLInputFactoryImpl
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
false,
|
||||
reporter,
|
||||
resolver);
|
||||
if (xIncludeAware)
|
||||
@@ -143,26 +118,7 @@ public class XMLInputFactoryImpl
|
||||
public XMLStreamReader createXMLStreamReader(InputStream in)
|
||||
throws XMLStreamException
|
||||
{
|
||||
/*return new XMLStreamReaderImpl(in, null, null,
|
||||
resolver, reporter,
|
||||
validating, namespaceAware,
|
||||
coalescing, replacingEntityReferences,
|
||||
externalEntities, supportDTD);*/
|
||||
XMLParser ret = new XMLParser(in, null,
|
||||
validating,
|
||||
namespaceAware,
|
||||
coalescing,
|
||||
replacingEntityReferences,
|
||||
externalEntities,
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
reporter,
|
||||
resolver);
|
||||
if (xIncludeAware)
|
||||
return new XIncludeFilter(ret, null, namespaceAware, validating,
|
||||
replacingEntityReferences);
|
||||
return ret;
|
||||
return createXMLStreamReader(null, in);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(InputStream in, String encoding)
|
||||
@@ -171,6 +127,48 @@ public class XMLInputFactoryImpl
|
||||
return createXMLStreamReader(in);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(String systemId, InputStream in)
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLParser ret = new XMLParser(in, systemId,
|
||||
validating,
|
||||
namespaceAware,
|
||||
coalescing,
|
||||
replacingEntityReferences,
|
||||
externalEntities,
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
false,
|
||||
reporter,
|
||||
resolver);
|
||||
if (xIncludeAware)
|
||||
return new XIncludeFilter(ret, null, namespaceAware, validating,
|
||||
replacingEntityReferences);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(String systemId, Reader reader)
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLParser ret = new XMLParser(reader, systemId,
|
||||
validating,
|
||||
namespaceAware,
|
||||
coalescing,
|
||||
replacingEntityReferences,
|
||||
externalEntities,
|
||||
supportDTD,
|
||||
baseAware,
|
||||
stringInterning,
|
||||
false,
|
||||
reporter,
|
||||
resolver);
|
||||
if (xIncludeAware)
|
||||
return new XIncludeFilter(ret, null, namespaceAware, validating,
|
||||
replacingEntityReferences);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(Reader reader)
|
||||
throws XMLStreamException
|
||||
{
|
||||
@@ -178,6 +176,13 @@ public class XMLInputFactoryImpl
|
||||
return new XMLEventReaderImpl(sr, allocator, null);
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(String systemId, Reader reader)
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLStreamReader sr = createXMLStreamReader(systemId, reader);
|
||||
return new XMLEventReaderImpl(sr, allocator, null);
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(XMLStreamReader reader)
|
||||
throws XMLStreamException
|
||||
{
|
||||
@@ -205,6 +210,13 @@ public class XMLInputFactoryImpl
|
||||
return new XMLEventReaderImpl(sr, allocator, null);
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(String systemId, InputStream in)
|
||||
throws XMLStreamException
|
||||
{
|
||||
XMLStreamReader sr = createXMLStreamReader(systemId, in);
|
||||
return new XMLEventReaderImpl(sr, allocator, null);
|
||||
}
|
||||
|
||||
public XMLStreamReader createFilteredReader(XMLStreamReader reader,
|
||||
StreamFilter filter)
|
||||
throws XMLStreamException
|
||||
|
||||
@@ -42,6 +42,8 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
@@ -94,6 +96,22 @@ public class XMLOutputFactoryImpl
|
||||
}
|
||||
}
|
||||
|
||||
public XMLStreamWriter createXMLStreamWriter(Result result)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (result instanceof StreamResult)
|
||||
{
|
||||
StreamResult sr = (StreamResult) result;
|
||||
OutputStream out = sr.getOutputStream();
|
||||
if (out != null)
|
||||
return createXMLStreamWriter(out);
|
||||
Writer writer = sr.getWriter();
|
||||
if (writer != null)
|
||||
return createXMLStreamWriter(writer);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(OutputStream stream)
|
||||
throws XMLStreamException
|
||||
{
|
||||
@@ -116,10 +134,26 @@ public class XMLOutputFactoryImpl
|
||||
return new XMLEventWriterImpl(writer);
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(Result result)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (result instanceof StreamResult)
|
||||
{
|
||||
StreamResult sr = (StreamResult) result;
|
||||
OutputStream out = sr.getOutputStream();
|
||||
if (out != null)
|
||||
return createXMLEventWriter(out);
|
||||
Writer writer = sr.getWriter();
|
||||
if (writer != null)
|
||||
return createXMLEventWriter(writer);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (IS_PREFIX_DEFAULTING.equals(name))
|
||||
if (IS_REPAIRING_NAMESPACES.equals(name))
|
||||
prefixDefaulting = ((Boolean) value).booleanValue();
|
||||
else
|
||||
throw new IllegalArgumentException(name);
|
||||
@@ -128,14 +162,14 @@ public class XMLOutputFactoryImpl
|
||||
public Object getProperty(String name)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (IS_PREFIX_DEFAULTING.equals(name))
|
||||
if (IS_REPAIRING_NAMESPACES.equals(name))
|
||||
return new Boolean(prefixDefaulting);
|
||||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
|
||||
public boolean isPropertySupported(String name)
|
||||
{
|
||||
if (IS_PREFIX_DEFAULTING.equals(name))
|
||||
if (IS_REPAIRING_NAMESPACES.equals(name))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,6 +137,10 @@ public class XMLParser
|
||||
final static int ATTRIBUTE_DEFAULT_REQUIRED = 33;
|
||||
final static int ATTRIBUTE_DEFAULT_FIXED = 34;
|
||||
|
||||
// -- additional event types --
|
||||
final static int START_ENTITY = 50;
|
||||
final static int END_ENTITY = 51;
|
||||
|
||||
/**
|
||||
* The current input.
|
||||
*/
|
||||
@@ -317,6 +321,12 @@ public class XMLParser
|
||||
*/
|
||||
private final boolean baseAware;
|
||||
|
||||
/**
|
||||
* Whether to report extended event types (START_ENTITY and END_ENTITY)
|
||||
* in addition to the standard event types. Used by the SAX parser.
|
||||
*/
|
||||
private final boolean extendedEventTypes;
|
||||
|
||||
/**
|
||||
* The reporter to receive parsing warnings.
|
||||
*/
|
||||
@@ -389,6 +399,7 @@ public class XMLParser
|
||||
boolean supportDTD,
|
||||
boolean baseAware,
|
||||
boolean stringInterning,
|
||||
boolean extendedEventTypes,
|
||||
XMLReporter reporter,
|
||||
XMLResolver resolver)
|
||||
{
|
||||
@@ -400,6 +411,7 @@ public class XMLParser
|
||||
this.supportDTD = supportDTD;
|
||||
this.baseAware = baseAware;
|
||||
this.stringInterning = stringInterning;
|
||||
this.extendedEventTypes = extendedEventTypes;
|
||||
this.reporter = reporter;
|
||||
this.resolver = resolver;
|
||||
if (validating)
|
||||
@@ -446,6 +458,7 @@ public class XMLParser
|
||||
boolean supportDTD,
|
||||
boolean baseAware,
|
||||
boolean stringInterning,
|
||||
boolean extendedEventTypes,
|
||||
XMLReporter reporter,
|
||||
XMLResolver resolver)
|
||||
{
|
||||
@@ -457,6 +470,7 @@ public class XMLParser
|
||||
this.supportDTD = supportDTD;
|
||||
this.baseAware = baseAware;
|
||||
this.stringInterning = stringInterning;
|
||||
this.extendedEventTypes = extendedEventTypes;
|
||||
this.reporter = reporter;
|
||||
this.resolver = resolver;
|
||||
if (validating)
|
||||
@@ -561,7 +575,7 @@ public class XMLParser
|
||||
return attrs.size();
|
||||
}
|
||||
|
||||
public String getAttributeName(int index)
|
||||
public String getAttributeLocalName(int index)
|
||||
{
|
||||
Attribute a = (Attribute) attrs.get(index);
|
||||
return a.localName;
|
||||
@@ -579,7 +593,7 @@ public class XMLParser
|
||||
return a.prefix;
|
||||
}
|
||||
|
||||
public QName getAttributeQName(int index)
|
||||
public QName getAttributeName(int index)
|
||||
{
|
||||
Attribute a = (Attribute) attrs.get(index);
|
||||
String namespaceURI = getNamespaceURI(a.prefix);
|
||||
@@ -710,7 +724,7 @@ public class XMLParser
|
||||
|
||||
public int getNamespaceCount()
|
||||
{
|
||||
if (!namespaceAware)
|
||||
if (!namespaceAware || namespaces.isEmpty())
|
||||
return 0;
|
||||
switch (event)
|
||||
{
|
||||
@@ -984,10 +998,10 @@ public class XMLParser
|
||||
if (event == XMLStreamConstants.END_ELEMENT)
|
||||
{
|
||||
// Pop namespace context
|
||||
if (namespaceAware)
|
||||
if (namespaceAware && !namespaces.isEmpty())
|
||||
namespaces.removeFirst();
|
||||
// Pop base context
|
||||
if (baseAware)
|
||||
if (baseAware && !bases.isEmpty())
|
||||
bases.removeFirst();
|
||||
}
|
||||
if (!startEntityStack.isEmpty())
|
||||
@@ -995,16 +1009,16 @@ public class XMLParser
|
||||
String entityName = (String) startEntityStack.removeFirst();
|
||||
buf.setLength(0);
|
||||
buf.append(entityName);
|
||||
event = XMLStreamConstants.START_ENTITY;
|
||||
return event;
|
||||
event = START_ENTITY;
|
||||
return extendedEventTypes ? event : next();
|
||||
}
|
||||
else if (!endEntityStack.isEmpty())
|
||||
{
|
||||
String entityName = (String) endEntityStack.removeFirst();
|
||||
buf.setLength(0);
|
||||
buf.append(entityName);
|
||||
event = XMLStreamConstants.END_ENTITY;
|
||||
return event;
|
||||
event = END_ENTITY;
|
||||
return extendedEventTypes ? event : next();
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -1484,7 +1498,6 @@ public class XMLParser
|
||||
{
|
||||
if (!externalEntities)
|
||||
return;
|
||||
InputStream in = null;
|
||||
String url = absolutize(input.systemId, ids.systemId);
|
||||
// Check for recursion
|
||||
for (Iterator i = inputStack.iterator(); i.hasNext(); )
|
||||
@@ -1497,12 +1510,13 @@ public class XMLParser
|
||||
}
|
||||
if (name == null || "".equals(name))
|
||||
report = false;
|
||||
if (in == null && url != null && resolver != null)
|
||||
InputStream in = null;
|
||||
if (resolver != null)
|
||||
{
|
||||
if (resolver instanceof XMLResolver2)
|
||||
in = ((XMLResolver2) resolver).resolve(ids.publicId, url);
|
||||
else
|
||||
in = resolver.resolve(url);
|
||||
Object obj = resolver.resolveEntity(ids.publicId, url, getXMLBase(),
|
||||
null);
|
||||
if (obj instanceof InputStream)
|
||||
in = (InputStream) obj;
|
||||
}
|
||||
if (in == null)
|
||||
in = resolve(url);
|
||||
@@ -1535,12 +1549,13 @@ public class XMLParser
|
||||
* @param base the current base URL
|
||||
* @param href the (absolute or relative) URL to resolve
|
||||
*/
|
||||
static String absolutize(String base, String href)
|
||||
public static String absolutize(String base, String href)
|
||||
throws MalformedURLException
|
||||
{
|
||||
if (href == null)
|
||||
return null;
|
||||
int ci = href.indexOf(':');
|
||||
if (ci > 1 && isLowercaseAscii(href.substring(0, ci)))
|
||||
if (ci > 1 && isURLScheme(href.substring(0, ci)))
|
||||
{
|
||||
// href is absolute already
|
||||
return href;
|
||||
@@ -1565,40 +1580,23 @@ public class XMLParser
|
||||
if (!base.endsWith("/"))
|
||||
base += "/";
|
||||
}
|
||||
if (href.startsWith("/"))
|
||||
{
|
||||
if (base.startsWith("file:"))
|
||||
return "file://" + href;
|
||||
int i = base.indexOf("://");
|
||||
if (i != -1)
|
||||
{
|
||||
i = base.indexOf('/', i + 3);
|
||||
if (i != -1)
|
||||
base = base.substring(0, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (href.startsWith(".."))
|
||||
{
|
||||
int i = base.lastIndexOf('/', base.length() - 2);
|
||||
if (i != -1)
|
||||
base = base.substring(0, i + 1);
|
||||
href = href.substring(2);
|
||||
if (href.startsWith("/"))
|
||||
href = href.substring(1);
|
||||
}
|
||||
}
|
||||
return base + href;
|
||||
return new URL(new URL(base), href).toString();
|
||||
}
|
||||
|
||||
private static boolean isLowercaseAscii(String text)
|
||||
/**
|
||||
* Indicates whether the specified characters match the scheme portion of
|
||||
* a URL.
|
||||
* @see RFC 1738 section 2.1
|
||||
*/
|
||||
private static boolean isURLScheme(String text)
|
||||
{
|
||||
int len = text.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
char c = text.charAt(i);
|
||||
if (c < 97 || c > 122)
|
||||
if (c == '+' || c == '.' || c == '-')
|
||||
continue;
|
||||
if (c < 65 || (c > 90 && c < 97) || c > 122)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1607,7 +1605,7 @@ public class XMLParser
|
||||
/**
|
||||
* Returns an input stream for the given URL.
|
||||
*/
|
||||
private InputStream resolve(String url)
|
||||
static InputStream resolve(String url)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
@@ -1618,6 +1616,12 @@ public class XMLParser
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
IOException e2 = new IOException("error resolving " + url);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1891,7 +1895,10 @@ public class XMLParser
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
requireWhitespace();
|
||||
boolean saved = expandPE;
|
||||
expandPE = (inputStack.size() > 1);
|
||||
String name = readNmtoken(true);
|
||||
expandPE = saved;
|
||||
requireWhitespace();
|
||||
readContentspec(name);
|
||||
skipWhitespace();
|
||||
@@ -2106,7 +2113,10 @@ public class XMLParser
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
requireWhitespace();
|
||||
boolean saved = expandPE;
|
||||
expandPE = (inputStack.size() > 1);
|
||||
String elementName = readNmtoken(true);
|
||||
expandPE = saved;
|
||||
boolean white = tryWhitespace();
|
||||
while (!tryRead('>'))
|
||||
{
|
||||
@@ -2419,11 +2429,11 @@ public class XMLParser
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNameStartCharacter(cp[0]))
|
||||
if (!isNameStartCharacter(cp[0], input.xml11))
|
||||
error("malformed reference in entity value", value);
|
||||
for (int i = 1; i < cp.length; i++)
|
||||
{
|
||||
if (!isNameCharacter(cp[i]))
|
||||
if (!isNameCharacter(cp[i], input.xml11))
|
||||
error("malformed reference in entity value", value);
|
||||
}
|
||||
}
|
||||
@@ -2838,8 +2848,6 @@ public class XMLParser
|
||||
error("Duplicate default namespace declaration");
|
||||
if (XMLConstants.XML_NS_URI.equals(attr.value))
|
||||
error("can't bind XML namespace");
|
||||
if ("".equals(attr.value) && !input.xml11)
|
||||
error("illegal use of 1.1-style prefix unbinding in 1.0 document");
|
||||
ctx.put(XMLConstants.DEFAULT_NS_PREFIX, attr.value);
|
||||
return true;
|
||||
}
|
||||
@@ -3087,7 +3095,15 @@ public class XMLParser
|
||||
break;
|
||||
case 0x3c: // '<'
|
||||
reset();
|
||||
read(tmpBuf, 0, i);
|
||||
// read i characters
|
||||
int count = 0, remaining = i;
|
||||
do
|
||||
{
|
||||
int r = read(tmpBuf, 0, remaining);
|
||||
count += r;
|
||||
remaining -= r;
|
||||
}
|
||||
while (count < i);
|
||||
i = len;
|
||||
if (coalescing && tryRead(TEST_CDATA))
|
||||
readUntil(TEST_END_CDATA); // read CDATA section into buf
|
||||
@@ -3258,15 +3274,7 @@ public class XMLParser
|
||||
reset();
|
||||
char[] ref = readCharacterRef(hex ? 16 : 10);
|
||||
for (int i = 0; i < ref.length; i++)
|
||||
{
|
||||
char x = ref[i];
|
||||
if ((flags & (LIT_ATTRIBUTE | LIT_PUBID)) != 0 &&
|
||||
(x == 0x0a || x == 0x0d))
|
||||
x = 0x20; // normalize
|
||||
else if ((flags & LIT_ATTRIBUTE) != 0 && x == 0x09)
|
||||
x = 0x20; // normalize
|
||||
literalBuf.append(x);
|
||||
}
|
||||
literalBuf.append(ref[i]);
|
||||
entities = true;
|
||||
continue;
|
||||
}
|
||||
@@ -3469,13 +3477,13 @@ public class XMLParser
|
||||
int c = readCh();
|
||||
if (isName)
|
||||
{
|
||||
if (!isNameStartCharacter(c))
|
||||
if (!isNameStartCharacter(c, input.xml11))
|
||||
error("not a name start character",
|
||||
"U+" + Integer.toHexString(c));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNameCharacter(c))
|
||||
if (!isNameCharacter(c, input.xml11))
|
||||
error("not a name character",
|
||||
"U+" + Integer.toHexString(c));
|
||||
}
|
||||
@@ -3510,7 +3518,7 @@ public class XMLParser
|
||||
reset();
|
||||
return intern(buf.toString());
|
||||
default:
|
||||
if (!isNameCharacter(c))
|
||||
if (!isNameCharacter(c, input.xml11))
|
||||
error("not a name character",
|
||||
"U+" + Integer.toHexString(c));
|
||||
else
|
||||
@@ -3523,7 +3531,7 @@ public class XMLParser
|
||||
/**
|
||||
* Indicates whether the specified Unicode character is an XML 1.1 Char.
|
||||
*/
|
||||
private boolean isXML11Char(int c)
|
||||
public static boolean isXML11Char(int c)
|
||||
{
|
||||
return ((c >= 0x0001 && c <= 0xD7FF) ||
|
||||
(c >= 0xE000 && c < 0xFFFD) || // NB exclude 0xfffd
|
||||
@@ -3534,7 +3542,7 @@ public class XMLParser
|
||||
* Indicates whether the specified Unicode character is an XML 1.1
|
||||
* RestrictedChar.
|
||||
*/
|
||||
private boolean isXML11RestrictedChar(int c)
|
||||
public static boolean isXML11RestrictedChar(int c)
|
||||
{
|
||||
return ((c >= 0x0001 && c <= 0x0008) ||
|
||||
(c >= 0x000B && c <= 0x000C) ||
|
||||
@@ -3556,17 +3564,17 @@ public class XMLParser
|
||||
return false;
|
||||
if (isName)
|
||||
{
|
||||
if (!isNameStartCharacter(cp[0]))
|
||||
if (!isNameStartCharacter(cp[0], input.xml11))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNameCharacter(cp[0]))
|
||||
if (!isNameCharacter(cp[0], input.xml11))
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < cp.length; i++)
|
||||
{
|
||||
if (!isNameCharacter(cp[i]))
|
||||
if (!isNameCharacter(cp[i], input.xml11))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -3581,9 +3589,9 @@ public class XMLParser
|
||||
* Indicates whether the specified Unicode character is a Name start
|
||||
* character.
|
||||
*/
|
||||
private boolean isNameStartCharacter(int c)
|
||||
public static boolean isNameStartCharacter(int c, boolean xml11)
|
||||
{
|
||||
if (input.xml11)
|
||||
if (xml11)
|
||||
return ((c >= 0x0041 && c <= 0x005a) ||
|
||||
(c >= 0x0061 && c <= 0x007a) ||
|
||||
c == 0x3a |
|
||||
@@ -3608,9 +3616,9 @@ public class XMLParser
|
||||
* Indicates whether the specified Unicode character is a Name non-initial
|
||||
* character.
|
||||
*/
|
||||
private boolean isNameCharacter(int c)
|
||||
public static boolean isNameCharacter(int c, boolean xml11)
|
||||
{
|
||||
if (input.xml11)
|
||||
if (xml11)
|
||||
return ((c >= 0x0041 && c <= 0x005a) ||
|
||||
(c >= 0x0061 && c <= 0x007a) ||
|
||||
(c >= 0x0030 && c <= 0x0039) ||
|
||||
@@ -4255,6 +4263,7 @@ public class XMLParser
|
||||
true, // supportDTD
|
||||
true, // baseAware
|
||||
true, // stringInterning
|
||||
true, // extendedEventTypes
|
||||
null,
|
||||
null);
|
||||
XMLStreamReader reader = p;
|
||||
@@ -4286,7 +4295,7 @@ public class XMLParser
|
||||
"='"+reader.getNamespaceURI(i)+"'");
|
||||
l = reader.getAttributeCount();
|
||||
for (int i = 0; i < l; i++)
|
||||
System.out.println("\tattribute "+reader.getAttributeQName(i)+
|
||||
System.out.println("\tattribute "+reader.getAttributeName(i)+
|
||||
"='"+reader.getAttributeValue(i)+"'");
|
||||
break;
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
@@ -4314,10 +4323,10 @@ public class XMLParser
|
||||
System.out.println("PROCESSING_INSTRUCTION "+reader.getPITarget()+
|
||||
" "+reader.getPIData());
|
||||
break;
|
||||
case XMLStreamConstants.START_ENTITY:
|
||||
case START_ENTITY:
|
||||
System.out.println("START_ENTITY "+reader.getText());
|
||||
break;
|
||||
case XMLStreamConstants.END_ENTITY:
|
||||
case END_ENTITY:
|
||||
System.out.println("END_ENTITY "+reader.getText());
|
||||
break;
|
||||
default:
|
||||
@@ -4330,7 +4339,7 @@ public class XMLParser
|
||||
Location l = reader.getLocation();
|
||||
System.out.println("At line "+l.getLineNumber()+
|
||||
", column "+l.getColumnNumber()+
|
||||
" of "+l.getLocationURI());
|
||||
" of "+l.getSystemId());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -4938,19 +4947,6 @@ public class XMLParser
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility interface that can be used to resolve based on a public
|
||||
* ID, not just an URL.
|
||||
*/
|
||||
interface XMLResolver2
|
||||
extends XMLResolver
|
||||
{
|
||||
|
||||
InputStream resolve(String publicId, String systemId)
|
||||
throws XMLStreamException;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An XML input source.
|
||||
*/
|
||||
@@ -5019,7 +5015,12 @@ public class XMLParser
|
||||
return line;
|
||||
}
|
||||
|
||||
public String getLocationURI()
|
||||
public String getPublicId()
|
||||
{
|
||||
return publicId;
|
||||
}
|
||||
|
||||
public String getSystemId()
|
||||
{
|
||||
return systemId;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -104,6 +104,9 @@ public class XMLStreamWriterImpl
|
||||
private NamespaceSupport namespaces;
|
||||
private int count = 0;
|
||||
|
||||
private boolean xml11;
|
||||
private boolean hasXML11RestrictedChars;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @see #writer
|
||||
@@ -145,6 +148,9 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isName(localName))
|
||||
throw new IllegalArgumentException("illegal Name: " + localName);
|
||||
|
||||
endStartElement();
|
||||
namespaces.pushContext();
|
||||
|
||||
@@ -167,6 +173,11 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
if (namespaceURI != null && !isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
if (!isName(localName))
|
||||
throw new IllegalArgumentException("illegal Name: " + localName);
|
||||
|
||||
endStartElement();
|
||||
namespaces.pushContext();
|
||||
|
||||
@@ -190,7 +201,7 @@ public class XMLStreamWriterImpl
|
||||
inStartElement = true;
|
||||
if (!isDeclared)
|
||||
{
|
||||
writeNamespace(prefix, namespaceURI);
|
||||
writeNamespaceImpl(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
elements.addLast(new String[] { prefix, localName });
|
||||
@@ -229,6 +240,13 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
if (namespaceURI != null && !isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
if (prefix != null && !isNCName(prefix))
|
||||
throw new IllegalArgumentException("illegal NCName: " + prefix);
|
||||
if (!isNCName(localName))
|
||||
throw new IllegalArgumentException("illegal NCName: " + localName);
|
||||
|
||||
endStartElement();
|
||||
namespaces.pushContext();
|
||||
|
||||
@@ -243,7 +261,7 @@ public class XMLStreamWriterImpl
|
||||
writer.write(localName);
|
||||
if (prefixDefaulting && !isCurrent)
|
||||
{
|
||||
writeNamespace(prefix, namespaceURI);
|
||||
writeNamespaceImpl(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
elements.addLast(new String[] { prefix, localName });
|
||||
@@ -343,11 +361,19 @@ public class XMLStreamWriterImpl
|
||||
throw new IllegalStateException();
|
||||
try
|
||||
{
|
||||
if (!isName(localName))
|
||||
throw new IllegalArgumentException("illegal Name: " + localName);
|
||||
if (!isChars(value))
|
||||
throw new IllegalArgumentException("illegal character: " + value);
|
||||
|
||||
writer.write(' ');
|
||||
writer.write(localName);
|
||||
writer.write('=');
|
||||
writer.write('"');
|
||||
writeEncoded(value, true);
|
||||
if (hasXML11RestrictedChars)
|
||||
writeEncodedWithRestrictedChars(value, true);
|
||||
else
|
||||
writeEncoded(value, true);
|
||||
writer.write('"');
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -366,11 +392,20 @@ public class XMLStreamWriterImpl
|
||||
throw new IllegalStateException();
|
||||
try
|
||||
{
|
||||
if (namespaceURI != null && !isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
if (prefix != null && !isNCName(prefix))
|
||||
throw new IllegalArgumentException("illegal NCName: " + prefix);
|
||||
if (!isNCName(localName))
|
||||
throw new IllegalArgumentException("illegal NCName: " + localName);
|
||||
if (!isChars(value))
|
||||
throw new IllegalArgumentException("illegal character: " + value);
|
||||
|
||||
String currentPrefix = getPrefix(namespaceURI);
|
||||
if (currentPrefix == null)
|
||||
{
|
||||
if (prefixDefaulting)
|
||||
writeNamespace(prefix, namespaceURI);
|
||||
writeNamespaceImpl(prefix, namespaceURI);
|
||||
else
|
||||
throw new XMLStreamException("namespace " + namespaceURI +
|
||||
" is not bound");
|
||||
@@ -388,7 +423,10 @@ public class XMLStreamWriterImpl
|
||||
writer.write(localName);
|
||||
writer.write('=');
|
||||
writer.write('"');
|
||||
writeEncoded(value, true);
|
||||
if (hasXML11RestrictedChars)
|
||||
writeEncodedWithRestrictedChars(value, true);
|
||||
else
|
||||
writeEncoded(value, true);
|
||||
writer.write('"');
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -407,13 +445,20 @@ public class XMLStreamWriterImpl
|
||||
throw new IllegalStateException();
|
||||
try
|
||||
{
|
||||
if (namespaceURI != null && !isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
if (!isName(localName))
|
||||
throw new IllegalArgumentException("illegal Name: " + localName);
|
||||
if (!isChars(value))
|
||||
throw new IllegalArgumentException("illegal character: " + value);
|
||||
|
||||
String prefix = getPrefix(namespaceURI);
|
||||
if (prefix == null)
|
||||
{
|
||||
if (prefixDefaulting)
|
||||
{
|
||||
prefix = XMLConstants.DEFAULT_NS_PREFIX;
|
||||
writeNamespace(prefix, namespaceURI);
|
||||
writeNamespaceImpl(prefix, namespaceURI);
|
||||
}
|
||||
else
|
||||
throw new XMLStreamException("namespace " + namespaceURI +
|
||||
@@ -428,7 +473,10 @@ public class XMLStreamWriterImpl
|
||||
writer.write(localName);
|
||||
writer.write('=');
|
||||
writer.write('"');
|
||||
writeEncoded(value, true);
|
||||
if (hasXML11RestrictedChars)
|
||||
writeEncodedWithRestrictedChars(value, true);
|
||||
else
|
||||
writeEncoded(value, true);
|
||||
writer.write('"');
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -444,6 +492,25 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
if (!inStartElement)
|
||||
throw new IllegalStateException();
|
||||
try
|
||||
{
|
||||
if (!isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
if (!isNCName(prefix))
|
||||
throw new IllegalArgumentException("illegal NCName: " + prefix);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
XMLStreamException e2 = new XMLStreamException(e);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
writeNamespaceImpl(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
private void writeNamespaceImpl(String prefix, String namespaceURI)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (prefix == null)
|
||||
@@ -474,21 +541,41 @@ public class XMLStreamWriterImpl
|
||||
public void writeDefaultNamespace(String namespaceURI)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeNamespace(XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
|
||||
if (!inStartElement)
|
||||
throw new IllegalStateException();
|
||||
if (!isURI(namespaceURI))
|
||||
throw new IllegalArgumentException("illegal URI: " + namespaceURI);
|
||||
writeNamespaceImpl(XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeComment(String data)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (data == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (!isChars(data))
|
||||
throw new IllegalArgumentException("illegal XML character: " + data);
|
||||
if (data.indexOf("--") != -1)
|
||||
throw new IllegalArgumentException("illegal comment: " + data);
|
||||
|
||||
endStartElement();
|
||||
|
||||
if (data != null && data.indexOf("--") != -1)
|
||||
throw new IllegalArgumentException(data);
|
||||
|
||||
writer.write("<!--");
|
||||
if (data != null)
|
||||
if (hasXML11RestrictedChars)
|
||||
{
|
||||
int[] seq = UnicodeReader.toCodePointArray(data);
|
||||
for (int i = 0; i < seq.length; i++)
|
||||
{
|
||||
int c = seq[i];
|
||||
if (XMLParser.isXML11RestrictedChar(c))
|
||||
writer.write("&#x" + Integer.toHexString(c) + ";");
|
||||
else
|
||||
writer.write(Character.toChars(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
writer.write(data);
|
||||
writer.write("-->");
|
||||
}
|
||||
@@ -511,6 +598,11 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isName(target) || "xml".equalsIgnoreCase(target))
|
||||
throw new IllegalArgumentException("illegal PITarget: " + target);
|
||||
if (data != null && !isChars(data))
|
||||
throw new IllegalArgumentException("illegal XML character: " + data);
|
||||
|
||||
endStartElement();
|
||||
|
||||
writer.write('<');
|
||||
@@ -519,7 +611,20 @@ public class XMLStreamWriterImpl
|
||||
if (data != null)
|
||||
{
|
||||
writer.write(' ');
|
||||
writer.write(data);
|
||||
if (hasXML11RestrictedChars)
|
||||
{
|
||||
int[] seq = UnicodeReader.toCodePointArray(data);
|
||||
for (int i = 0; i < seq.length; i++)
|
||||
{
|
||||
int c = seq[i];
|
||||
if (XMLParser.isXML11RestrictedChar(c))
|
||||
writer.write("&#x" + Integer.toHexString(c) + ";");
|
||||
else
|
||||
writer.write(Character.toChars(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
writer.write(data);
|
||||
}
|
||||
writer.write('?');
|
||||
writer.write('>');
|
||||
@@ -537,10 +642,12 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
endStartElement();
|
||||
|
||||
if (!isChars(data) || hasXML11RestrictedChars)
|
||||
throw new IllegalArgumentException("illegal XML character: " + data);
|
||||
if (data.indexOf("]]") != -1)
|
||||
throw new IllegalArgumentException(data);
|
||||
throw new IllegalArgumentException("illegal CDATA section: " + data);
|
||||
|
||||
endStartElement();
|
||||
|
||||
writer.write("<![CDATA[");
|
||||
writer.write(data);
|
||||
@@ -557,8 +664,12 @@ public class XMLStreamWriterImpl
|
||||
public void writeDTD(String dtd)
|
||||
throws XMLStreamException
|
||||
{
|
||||
// Really thoroughly pointless method...
|
||||
try
|
||||
{
|
||||
if (!isName(dtd))
|
||||
throw new IllegalArgumentException("illegal Name: " + dtd);
|
||||
|
||||
writer.write("<!DOCTYPE ");
|
||||
writer.write(dtd);
|
||||
writer.write('>');
|
||||
@@ -576,6 +687,9 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isName(name))
|
||||
throw new IllegalArgumentException("illegal Name: " + name);
|
||||
|
||||
endStartElement();
|
||||
|
||||
writer.write('&');
|
||||
@@ -607,6 +721,8 @@ public class XMLStreamWriterImpl
|
||||
{
|
||||
if (version == null)
|
||||
version = "1.0";
|
||||
else if ("1.1".equals(version))
|
||||
xml11 = true;
|
||||
encoding = this.encoding; // YES: the parameter must be ignored
|
||||
if (encoding == null)
|
||||
encoding = "UTF-8";
|
||||
@@ -632,11 +748,18 @@ public class XMLStreamWriterImpl
|
||||
public void writeCharacters(String text)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (text == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (!isChars(text))
|
||||
throw new IllegalArgumentException("illegal XML character: " + text);
|
||||
|
||||
endStartElement();
|
||||
|
||||
if (text != null)
|
||||
if (hasXML11RestrictedChars)
|
||||
writeEncodedWithRestrictedChars(text, false);
|
||||
else
|
||||
writeEncoded(text, false);
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -650,39 +773,7 @@ public class XMLStreamWriterImpl
|
||||
public void writeCharacters(char[] text, int start, int len)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try
|
||||
{
|
||||
endStartElement();
|
||||
|
||||
int end = start + len;
|
||||
len = 0;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
char c = text[i];
|
||||
if (c == '<' || c == '>' || c == '&')
|
||||
{
|
||||
writer.write(text, start, len);
|
||||
if (c == '<')
|
||||
writer.write("<");
|
||||
else if (c == '>')
|
||||
writer.write(">");
|
||||
else
|
||||
writer.write("&");
|
||||
start = i + 1;
|
||||
len = 0;
|
||||
}
|
||||
else
|
||||
len++;
|
||||
}
|
||||
if (len > 0)
|
||||
writer.write(text, start, len);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
XMLStreamException e2 = new XMLStreamException(e);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
writeCharacters(new String(text, start, len));
|
||||
}
|
||||
|
||||
public String getPrefix(String uri)
|
||||
@@ -697,6 +788,19 @@ public class XMLStreamWriterImpl
|
||||
public void setPrefix(String prefix, String uri)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isURI(uri))
|
||||
throw new IllegalArgumentException("illegal URI: " + uri);
|
||||
if (!isNCName(prefix))
|
||||
throw new IllegalArgumentException("illegal NCName: " + prefix);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
XMLStreamException e2 = new XMLStreamException(e);
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
if (!namespaces.declarePrefix(prefix, uri))
|
||||
throw new XMLStreamException("illegal prefix " + prefix);
|
||||
}
|
||||
@@ -704,6 +808,8 @@ public class XMLStreamWriterImpl
|
||||
public void setDefaultNamespace(String uri)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (!isURI(uri))
|
||||
throw new IllegalArgumentException("illegal URI: " + uri);
|
||||
if (!namespaces.declarePrefix(XMLConstants.DEFAULT_NS_PREFIX, uri))
|
||||
throw new XMLStreamException("illegal default namespace prefix");
|
||||
}
|
||||
@@ -769,6 +875,131 @@ public class XMLStreamWriterImpl
|
||||
if (len > 0)
|
||||
writer.write(chars, start, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the specified text, in the knowledge that some of the
|
||||
* characters are XML 1.1 restricted characters.
|
||||
*/
|
||||
private void writeEncodedWithRestrictedChars(String text, boolean inAttr)
|
||||
throws IOException
|
||||
{
|
||||
int[] seq = UnicodeReader.toCodePointArray(text);
|
||||
for (int i = 0; i < seq.length; i++)
|
||||
{
|
||||
int c = seq[i];
|
||||
switch (c)
|
||||
{
|
||||
case 0x3c: // '<'
|
||||
writer.write("<");
|
||||
break;
|
||||
case 0x3e: // '>'
|
||||
writer.write(">");
|
||||
break;
|
||||
case 0x26: // '&'
|
||||
writer.write("&");
|
||||
break;
|
||||
case 0x22: // '"'
|
||||
if (inAttr)
|
||||
writer.write(""");
|
||||
else
|
||||
writer.write(c);
|
||||
break;
|
||||
case 0x27: // '\''
|
||||
if (inAttr)
|
||||
writer.write("'");
|
||||
else
|
||||
writer.write(c);
|
||||
break;
|
||||
default:
|
||||
if (XMLParser.isXML11RestrictedChar(c))
|
||||
writer.write("&#x" + Integer.toHexString(c) + ";");
|
||||
else
|
||||
{
|
||||
char[] chars = Character.toChars(c);
|
||||
writer.write(chars, 0, chars.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isName(String text)
|
||||
throws IOException
|
||||
{
|
||||
if (text == null)
|
||||
return false;
|
||||
int[] seq = UnicodeReader.toCodePointArray(text);
|
||||
if (seq.length < 1)
|
||||
return false;
|
||||
if (!XMLParser.isNameStartCharacter(seq[0], xml11))
|
||||
return false;
|
||||
for (int i = 1; i < seq.length; i++)
|
||||
{
|
||||
if (!XMLParser.isNameCharacter(seq[i], xml11))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isNCName(String text)
|
||||
throws IOException
|
||||
{
|
||||
if (text == null)
|
||||
return false;
|
||||
int[] seq = UnicodeReader.toCodePointArray(text);
|
||||
if (seq.length < 1)
|
||||
return false;
|
||||
if (!XMLParser.isNameStartCharacter(seq[0], xml11) || seq[0] == 0x3a)
|
||||
return false;
|
||||
for (int i = 1; i < seq.length; i++)
|
||||
{
|
||||
if (!XMLParser.isNameCharacter(seq[i], xml11) || seq[i] == 0x3a)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isChars(String text)
|
||||
throws IOException
|
||||
{
|
||||
if (text == null)
|
||||
return false;
|
||||
int[] seq = UnicodeReader.toCodePointArray(text);
|
||||
hasXML11RestrictedChars = false;
|
||||
if (xml11)
|
||||
{
|
||||
for (int i = 0; i < seq.length; i++)
|
||||
{
|
||||
if (!XMLParser.isXML11Char(seq[i]))
|
||||
return false;
|
||||
if (XMLParser.isXML11RestrictedChar(seq[i]))
|
||||
hasXML11RestrictedChars = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < seq.length; i++)
|
||||
{
|
||||
if (!XMLParser.isChar(seq[i]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isURI(String text)
|
||||
{
|
||||
if (text == null)
|
||||
return false;
|
||||
char[] chars = text.toCharArray();
|
||||
if (chars.length < 1)
|
||||
return false;
|
||||
for (int i = 0; i < chars.length; i++)
|
||||
{
|
||||
if (chars[i] < 0x20 || chars[i] >= 0x7f)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user