Initial revision

From-SVN: r104578
This commit is contained in:
Tom Tromey
2005-09-23 19:36:46 +00:00
parent acff2da93c
commit 9b044d1951
495 changed files with 82760 additions and 0 deletions
@@ -0,0 +1,124 @@
/* AttributeImpl.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.namespace.QName;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
/**
* An attribute event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class AttributeImpl
extends XMLEventImpl
implements Attribute
{
protected final QName name;
protected final String value;
protected final QName type;
protected final boolean specified;
protected AttributeImpl(Location location,
QName name, String value, QName type,
boolean specified)
{
super(location);
this.name = name;
this.value = value;
this.type = type;
this.specified = specified;
}
public int getEventType()
{
return ATTRIBUTE;
}
public QName getName()
{
return name;
}
public String getValue()
{
return value;
}
public QName getDTDType()
{
return type;
}
public boolean isSpecified()
{
return specified;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
String prefix = name.getPrefix();
if (prefix != null && !"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(name.getLocalPart());
writer.write('=');
writer.write('"');
writer.write(encode(value, true));
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,120 @@
/* CharactersImpl.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.Characters;
/**
* A character data (text) event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class CharactersImpl
extends XMLEventImpl
implements Characters
{
protected final String data;
protected final boolean whitespace;
protected final boolean cdata;
protected final boolean ignorableWhitespace;
protected CharactersImpl(Location location,
String data, boolean whitespace, boolean cdata,
boolean ignorableWhitespace)
{
super(location);
this.data = data;
this.whitespace = whitespace;
this.cdata = cdata;
this.ignorableWhitespace = ignorableWhitespace;
}
public int getEventType()
{
return cdata ? CDATA : whitespace ? SPACE : CHARACTERS;
}
public String getData()
{
return data;
}
public boolean isWhiteSpace()
{
return whitespace;
}
public boolean isCData()
{
return cdata;
}
public boolean isIgnorableWhiteSpace()
{
return ignorableWhitespace;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
if (cdata)
{
writer.write("<![CDATA[");
writer.write(data);
writer.write("]]>");
}
else
writer.write(encode(data, false));
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,92 @@
/* CommentImpl.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.Comment;
/**
* A comment event.
*
* @author <a href'mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class CommentImpl
extends XMLEventImpl
implements Comment
{
protected final String text;
protected CommentImpl(Location location, String text)
{
super(location);
this.text = text;
}
public int getEventType()
{
return COMMENT;
}
public String getText()
{
return text;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<!--");
writer.write(encode(text, false));
writer.write("-->");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,115 @@
/* DTDImpl.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 java.util.List;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.DTD;
/**
* A DOCTYPE declaration event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class DTDImpl
extends XMLEventImpl
implements DTD
{
protected final String body;
protected final Object impl;
protected final List notations;
protected final List entities;
protected DTDImpl(Location location,
String body, Object impl, List notations, List entities)
{
super(location);
this.body = body;
this.impl = impl;
this.notations = notations;
this.entities = entities;
}
public int getEventType()
{
return DTD;
}
public String getDocumentTypeDeclaration()
{
return body;
}
public Object getProcessedDTD()
{
return impl;
}
public List getNotations()
{
return notations;
}
public List getEntities()
{
return entities;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<!DOCTYPE ");
writer.write(body);
writer.write(">");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,72 @@
/* EndDocumentImpl.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.EndDocument;
/**
* An end-document event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class EndDocumentImpl
extends XMLEventImpl
implements EndDocument
{
protected EndDocumentImpl(Location location)
{
super(location);
}
public int getEventType()
{
return END_DOCUMENT;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
}
}
@@ -0,0 +1,108 @@
/* EndElementImpl.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 java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.EndElement;
/**
* An end-element event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class EndElementImpl
extends XMLEventImpl
implements EndElement
{
protected final QName name;
protected final List namespaces;
protected EndElementImpl(Location location, QName name, List namespaces)
{
super(location);
this.name = name;
this.namespaces = namespaces;
}
public int getEventType()
{
return END_ELEMENT;
}
public QName getName()
{
return name;
}
public Iterator getNamespaces()
{
return namespaces.iterator();
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("</");
String prefix = name.getPrefix();
if (prefix != null && !"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(name.getLocalPart());
writer.write(">");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,80 @@
/* 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
{
}
}
@@ -0,0 +1,164 @@
/* EntityDeclarationImpl.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.EntityDeclaration;
/**
* An entity declaration event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class EntityDeclarationImpl
extends XMLEventImpl
implements EntityDeclaration
{
protected final String publicId;
protected final String systemId;
protected final String name;
protected final String notationName;
protected final String replacementText;
protected final String baseUri;
protected EntityDeclarationImpl(Location location,
String publicId, String systemId,
String name, String notationName,
String replacementText, String baseUri)
{
super(location);
this.publicId = publicId;
this.systemId = systemId;
this.name = name;
this.notationName = notationName;
this.replacementText = replacementText;
this.baseUri = baseUri;
}
public int getEventType()
{
return ENTITY_DECLARATION;
}
public String getPublicId()
{
return publicId;
}
public String getSystemId()
{
return systemId;
}
public String getName()
{
return name;
}
public String getNotationName()
{
return notationName;
}
public String getReplacementText()
{
return replacementText;
}
public String getBaseURI()
{
return baseUri;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<!ENTITY ");
writer.write(name);
writer.write(' ');
if (systemId != null)
{
if (publicId != null)
{
writer.write(" PUBLIC ");
writer.write('"');
writer.write(publicId);
writer.write('"');
writer.write(' ');
writer.write('"');
writer.write(systemId);
writer.write('"');
}
else
{
writer.write(" SYSTEM ");
writer.write('"');
writer.write(systemId);
writer.write('"');
}
if (notationName != null)
{
writer.write(" NDATA ");
writer.write(notationName);
}
}
else
{
writer.write('"');
if (replacementText != null)
writer.write(replacementText);
writer.write('"');
}
writer.write(">");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,132 @@
/* EntityReferenceImpl.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.EntityDeclaration;
import javax.xml.stream.events.EntityReference;
/**
* An entity reference event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class EntityReferenceImpl
extends XMLEventImpl
implements EntityReference
{
//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)
{
super(location);
//this.decl = decl;
this.name = name;
this.baseUri = baseUri;
this.publicId = publicId;
this.systemId = systemId;
this.replacementText = replacementText;
}
public int getEventType()
{
return ENTITY_REFERENCE;
}
/*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
{
try
{
writer.write('&');
writer.write(name);
writer.write(';');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,102 @@
/* FilteredEventReader.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.EventFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.EventReaderDelegate;
class FilteredEventReader
extends EventReaderDelegate
{
final EventFilter filter;
FilteredEventReader(XMLEventReader reader, EventFilter filter)
{
super(reader);
this.filter = filter;
}
public boolean hasNext()
throws XMLStreamException
{
// XXX ???
return super.hasNext();
}
public XMLEvent next()
throws XMLStreamException
{
XMLEvent ret;
do
{
ret = super.next();
}
while (!filter.accept(ret));
return ret;
}
public XMLEvent peek()
throws XMLStreamException
{
XMLEvent ret;
do
{
ret = super.peek();
}
while (!filter.accept(ret));
return ret;
}
public XMLEvent nextTag()
throws XMLStreamException
{
XMLEvent ret;
do
{
ret = super.nextTag();
}
while (!filter.accept(ret));
return ret;
}
}
@@ -0,0 +1,91 @@
/* FilteredStreamReader.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.StreamFilter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.ReaderDelegate;
class FilteredStreamReader
extends ReaderDelegate
{
final XMLStreamReader reader;
final StreamFilter filter;
FilteredStreamReader(XMLStreamReader reader, StreamFilter filter)
{
super(reader);
this.reader = reader;
this.filter = filter;
}
public boolean hasNext()
throws XMLStreamException
{
// XXX ???
return super.hasNext();
}
public int next()
throws XMLStreamException
{
int ret;
do
{
ret = super.next();
}
while (!filter.accept(reader));
return ret;
}
public int nextTag()
throws XMLStreamException
{
int ret;
do
{
ret = super.nextTag();
}
while (!filter.accept(reader));
return ret;
}
}
@@ -0,0 +1,89 @@
/* 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;
}
}
@@ -0,0 +1,111 @@
/* NamespaceImpl.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.Namespace;
/**
* A namespace declaration event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class NamespaceImpl
extends XMLEventImpl
implements Namespace
{
protected final String prefix;
protected final String uri;
protected NamespaceImpl(Location location, String prefix, String uri)
{
super(location);
this.prefix = prefix;
this.uri = uri;
}
public int getEventType()
{
return NAMESPACE;
}
public String getPrefix()
{
return prefix;
}
public String getNamespaceURI()
{
return uri;
}
public boolean isDefaultNamespaceDeclaration()
{
return (prefix == null || "".equals(prefix));
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("xmlns");
if (prefix != null && !"".equals(prefix))
{
writer.write(':');
writer.write(prefix);
}
writer.write('=');
writer.write('"');
writer.write(encode(uri, true));
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,126 @@
/* NotationDeclarationImpl.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.NotationDeclaration;
/**
* A notation declaration event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class NotationDeclarationImpl
extends XMLEventImpl
implements NotationDeclaration
{
protected final String name;
protected final String publicId;
protected final String systemId;
protected NotationDeclarationImpl(Location location,
String name, String publicId,
String systemId)
{
super(location);
this.name = name;
this.publicId = publicId;
this.systemId = systemId;
}
public int getEventType()
{
return NOTATION_DECLARATION;
}
public String getName()
{
return name;
}
public String getPublicId()
{
return publicId;
}
public String getSystemId()
{
return systemId;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<!NOTATION ");
writer.write(name);
if (publicId != null)
{
writer.write(" PUBLIC ");
writer.write('"');
writer.write(publicId);
writer.write('"');
writer.write(' ');
writer.write('"');
writer.write(systemId);
writer.write('"');
}
else
{
writer.write(" SYSTEM ");
writer.write('"');
writer.write(systemId);
writer.write('"');
}
writer.write('>');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,105 @@
/* ProcessingInstructionImpl.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.ProcessingInstruction;
/**
* A processing instruction event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class ProcessingInstructionImpl
extends XMLEventImpl
implements ProcessingInstruction
{
protected final String target;
protected final String data;
protected ProcessingInstructionImpl(Location location,
String target, String data)
{
super(location);
this.target = target;
this.data = data;
}
public int getEventType()
{
return PROCESSING_INSTRUCTION;
}
public String getTarget()
{
return target;
}
public String getData()
{
return data;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<?");
writer.write(target);
if (data != null)
{
writer.write(' ');
writer.write(data);
}
writer.write("?>");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,144 @@
/* StartDocumentImpl.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.StartDocument;
/**
* A start-document event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class StartDocumentImpl
extends XMLEventImpl
implements StartDocument
{
protected final String systemId;
protected final String encoding;
protected final String xmlVersion;
protected final boolean xmlStandalone;
protected final boolean standaloneDeclared;
protected final boolean encodingDeclared;
protected StartDocumentImpl(Location location,
String systemId, String encoding,
String xmlVersion, boolean xmlStandalone,
boolean standaloneDeclared,
boolean encodingDeclared)
{
super(location);
this.systemId = systemId;
this.encoding = encoding;
this.xmlVersion = xmlVersion;
this.xmlStandalone = xmlStandalone;
this.standaloneDeclared = standaloneDeclared;
this.encodingDeclared = encodingDeclared;
}
public int getEventType()
{
return START_DOCUMENT;
}
public String getSystemId()
{
return systemId;
}
public String getCharacterEncodingScheme()
{
return encoding;
}
public boolean encodingSet()
{
return encodingDeclared;
}
public boolean isStandalone()
{
return xmlStandalone;
}
public boolean standaloneSet()
{
return standaloneDeclared;
}
public String getVersion()
{
return xmlVersion;
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write("<?xml version='");
writer.write(xmlVersion);
writer.write('\'');
if (standaloneDeclared)
{
writer.write(" standalone='");
writer.write(xmlStandalone ? "yes" : "no");
writer.write('\'');
}
if (encodingDeclared)
{
writer.write(" encoding='");
writer.write(encoding);
writer.write('\'');
}
writer.write("?>");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,153 @@
/* StartElementImpl.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 java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
/**
* A start-element event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class StartElementImpl
extends XMLEventImpl
implements StartElement
{
protected final QName name;
protected final List attributes;
protected final List namespaces;
protected final NamespaceContext namespaceContext;
protected StartElementImpl(Location location,
QName name, List attributes, List namespaces,
NamespaceContext namespaceContext)
{
super(location);
this.name = name;
this.attributes = attributes;
this.namespaces = namespaces;
this.namespaceContext = namespaceContext;
}
public int getEventType()
{
return START_ELEMENT;
}
public QName getName()
{
return name;
}
public Iterator getAttributes()
{
return attributes.iterator();
}
public Iterator getNamespaces()
{
return namespaces.iterator();
}
public Attribute getAttributeByName(QName name)
{
for (Iterator i = attributes.iterator(); i.hasNext(); )
{
Attribute attr = (Attribute) i.next();
if (name.equals(attr.getName()))
return attr;
}
return null;
}
public NamespaceContext getNamespaceContext()
{
return namespaceContext;
}
public String getNamespaceURI(String prefix)
{
return namespaceContext.getNamespaceURI(prefix);
}
public void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException
{
try
{
writer.write('<');
String prefix = name.getPrefix();
if (prefix != null && !"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(name.getLocalPart());
for (Iterator i = namespaces.iterator(); i.hasNext(); )
{
writer.write(' ');
((Namespace) i.next()).writeAsEncodedUnicode(writer);
}
for (Iterator i = attributes.iterator(); i.hasNext(); )
{
writer.write(' ');
((Attribute) i.next()).writeAsEncodedUnicode(writer);
}
writer.write('>');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,80 @@
/* 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
{
}
}
@@ -0,0 +1,204 @@
/* XMLEventAllocatorImpl.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.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
import javax.xml.stream.util.XMLEventConsumer;
/**
* Allocator for creating XML events based on a reader state.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLEventAllocatorImpl
implements XMLEventAllocator
{
protected Map entityDeclarations;
protected XMLEventAllocatorImpl()
{
entityDeclarations = new HashMap();
}
public XMLEvent allocate(XMLStreamReader reader)
throws XMLStreamException
{
String text;
boolean whitespace;
boolean ignorableWhitespace;
int len;
List namespaces;
int eventType = reader.getEventType();
Location location = reader.getLocation();
switch (eventType)
{
case XMLStreamConstants.CDATA:
text = reader.getText();
whitespace = isWhitespace(text);
// TODO ignorableWhitespace
ignorableWhitespace = whitespace && false;
return new CharactersImpl(location, text,
whitespace, true, ignorableWhitespace);
case XMLStreamConstants.CHARACTERS:
text = reader.getText();
whitespace = false;
// TODO ignorableWhitespace
ignorableWhitespace = whitespace && false;
return new CharactersImpl(location, text,
whitespace, false, ignorableWhitespace);
case XMLStreamConstants.COMMENT:
text = reader.getText();
return new CommentImpl(location, text);
case XMLStreamConstants.DTD:
text = reader.getText();
List notations = new LinkedList();
List entities = new LinkedList();
// TODO readDTDBody(notations, entities);
return new DTDImpl(location, text, null, notations, entities);
case XMLStreamConstants.END_DOCUMENT:
return new EndDocumentImpl(location);
case XMLStreamConstants.END_ELEMENT:
len = reader.getNamespaceCount();
namespaces = new LinkedList();
for (int i = 0; i < len; i++)
namespaces.add(new NamespaceImpl(location,
reader.getNamespacePrefix(i),
reader.getNamespaceURI(i)));
return new EndElementImpl(location,
reader.getName(),
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);
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return new ProcessingInstructionImpl(location,
reader.getPITarget(),
reader.getPIData());
case XMLStreamConstants.SPACE:
text = reader.getText();
whitespace = true;
// TODO ignorableWhitespace
ignorableWhitespace = whitespace && false;
return new CharactersImpl(location, text,
whitespace, false, ignorableWhitespace);
case XMLStreamConstants.START_DOCUMENT:
String systemId = location.getLocationURI();
String encoding = reader.getCharacterEncodingScheme();
boolean encodingDeclared = encoding != null;
if (encoding == null)
{
encoding = reader.getEncoding();
if (encoding == null)
encoding = "UTF-8";
}
String xmlVersion = reader.getVersion();
if (xmlVersion == null)
xmlVersion = "1.0";
boolean xmlStandalone = reader.isStandalone();
boolean standaloneDeclared = reader.standaloneSet();
return new StartDocumentImpl(location,
systemId,
encoding,
xmlVersion,
xmlStandalone,
standaloneDeclared,
encodingDeclared);
case XMLStreamConstants.START_ELEMENT:
len = reader.getNamespaceCount();
namespaces = new LinkedList();
for (int i = 0; i < len; i++)
namespaces.add(new NamespaceImpl(location,
reader.getNamespacePrefix(i),
reader.getNamespaceURI(i)));
len = reader.getAttributeCount();
List attributes = new LinkedList();
for (int i = 0; i < len; i++)
attributes.add(new AttributeImpl(location,
reader.getAttributeQName(i),
reader.getAttributeValue(i),
QName.valueOf(reader.getAttributeType(i)),
reader.isAttributeSpecified(i)));
return new StartElementImpl(location,
reader.getName(),
attributes, namespaces,
reader.getNamespaceContext());
default:
throw new XMLStreamException("Unknown event type: " + eventType);
}
}
public void allocate(XMLStreamReader reader, XMLEventConsumer consumer)
throws XMLStreamException
{
consumer.add(allocate(reader));
}
public XMLEventAllocator newInstance()
{
return new XMLEventAllocatorImpl();
}
protected boolean isWhitespace(String text)
{
int len = text.length();
for (int i = 0; i < len; i++)
{
char c = text.charAt(i);
if (c != 0x20 && c != 0x09 && c != 0x0a && c != 0x0d)
return false;
}
return true;
}
}
@@ -0,0 +1,271 @@
/* XMLEventFactoryImpl.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.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.Comment;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.EndDocument;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.EntityReference;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.ProcessingInstruction;
import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.StartElement;
/**
* Factory for XML events.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLEventFactoryImpl
extends XMLEventFactory
{
protected Location location;
public void setLocation(Location location)
{
this.location = location;
}
public Attribute createAttribute(String prefix, String namespaceURI,
String localName, String value)
{
return new AttributeImpl(location,
new QName(namespaceURI, localName, prefix),
value, QName.valueOf("CDATA"), true);
}
public Attribute createAttribute(String localName, String value)
{
return new AttributeImpl(location,
new QName(localName),
value, QName.valueOf("CDATA"), true);
}
public Attribute createAttribute(QName name, String value)
{
return new AttributeImpl(location, name, value,
QName.valueOf("CDATA"), true);
}
public Namespace createNamespace(String namespaceURI)
{
return new NamespaceImpl(location,
XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
}
public Namespace createNamespace(String prefix, String namespaceUri)
{
return new NamespaceImpl(location, prefix, namespaceUri);
}
public StartElement createStartElement(QName name,
Iterator attributes,
Iterator namespaces)
{
return new StartElementImpl(location, name,
createLinkedList(attributes),
createLinkedList(namespaces),
null);
}
public StartElement createStartElement(String prefix,
String namespaceUri,
String localName)
{
return new StartElementImpl(location,
new QName(namespaceUri, localName, prefix),
Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
null);
}
public StartElement createStartElement(String prefix,
String namespaceUri,
String localName,
Iterator attributes,
Iterator namespaces)
{
return new StartElementImpl(location,
new QName(namespaceUri, localName, prefix),
createLinkedList(attributes),
createLinkedList(namespaces),
null);
}
public StartElement createStartElement(String prefix,
String namespaceUri,
String localName,
Iterator attributes,
Iterator namespaces,
NamespaceContext context)
{
return new StartElementImpl(location,
new QName(namespaceUri, localName, prefix),
createLinkedList(attributes),
createLinkedList(namespaces),
context);
}
public EndElement createEndElement(QName name,
Iterator namespaces)
{
return new EndElementImpl(location, name,
createLinkedList(namespaces));
}
public EndElement createEndElement(String prefix,
String namespaceUri,
String localName)
{
return new EndElementImpl(location,
new QName(namespaceUri, localName, prefix),
Collections.EMPTY_LIST);
}
public EndElement createEndElement(String prefix,
String namespaceUri,
String localName,
Iterator namespaces)
{
return new EndElementImpl(location,
new QName(namespaceUri, localName, prefix),
createLinkedList(namespaces));
}
public Characters createCharacters(String content)
{
return new CharactersImpl(location, content, false, false, false);
}
public Characters createCData(String content)
{
return new CharactersImpl(location, content, false, true, false);
}
public Characters createSpace(String content)
{
return new CharactersImpl(location, content, true, false, false);
}
public Characters createIgnorableSpace(String content)
{
return new CharactersImpl(location, content, true, false, true);
}
public StartDocument createStartDocument()
{
return new StartDocumentImpl(location, null, "UTF-8", "1.0",
false, false, false);
}
public StartDocument createStartDocument(String encoding,
String version,
boolean standalone)
{
return new StartDocumentImpl(location, null, encoding, version,
standalone, true, true);
}
public StartDocument createStartDocument(String encoding,
String version)
{
return new StartDocumentImpl(location, null, encoding, version,
false, false, true);
}
public StartDocument createStartDocument(String encoding)
{
return new StartDocumentImpl(location, null, encoding, "1.0",
false, false, true);
}
public EndDocument createEndDocument()
{
return new EndDocumentImpl(location);
}
public EntityReference createEntityReference(String name,
//EntityDeclaration declaration)
String replacementText)
{
//return new EntityReferenceImpl(location, declaration, name);
return new EntityReferenceImpl(location, name, null, null, null,
replacementText);
}
public Comment createComment(String text)
{
return new CommentImpl(location, text);
}
public ProcessingInstruction createProcessingInstruction(String target,
String data)
{
return new ProcessingInstructionImpl(location, target, data);
}
public DTD createDTD(String dtd)
{
return new DTDImpl(location, dtd, null,
Collections.EMPTY_LIST,
Collections.EMPTY_LIST);
}
LinkedList createLinkedList(Iterator i)
{
LinkedList ret = new LinkedList();
while (i.hasNext())
ret.add(i.next());
return ret;
}
}
@@ -0,0 +1,208 @@
/* XMLEventImpl.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.Writer;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
/**
* An XML stream event.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public abstract class XMLEventImpl
implements XMLEvent
{
protected final Location location;
protected XMLEventImpl(Location location)
{
this.location = location;
}
public abstract int getEventType();
public Location getLocation()
{
return location;
}
public boolean isStartElement()
{
return getEventType() == START_ELEMENT;
}
public boolean isAttribute()
{
return getEventType() == ATTRIBUTE;
}
public boolean isNamespace()
{
return getEventType() == NAMESPACE;
}
public boolean isEndElement()
{
return getEventType() == END_ELEMENT;
}
public boolean isEntityReference()
{
return getEventType() == ENTITY_REFERENCE;
}
public boolean isProcessingInstruction()
{
return getEventType() == PROCESSING_INSTRUCTION;
}
public boolean isCharacters()
{
int et = getEventType();
return et == CHARACTERS || et == CDATA;
}
public boolean isStartDocument()
{
return getEventType() == START_DOCUMENT;
}
public boolean isEndDocument()
{
return getEventType() == END_DOCUMENT;
}
public boolean isStartEntity()
{
return getEventType() == START_ENTITY;
}
public boolean isEndEntity()
{
return getEventType() == END_ENTITY;
}
public StartElement asStartElement()
{
return (StartElement) this;
}
public EndElement asEndElement()
{
return (EndElement) this;
}
public Characters asCharacters()
{
return (Characters) this;
}
public QName getSchemaType()
{
return null;
}
public abstract void writeAsEncodedUnicode(Writer writer)
throws XMLStreamException;
protected String encode(String text, boolean inAttr)
{
int len = text.length();
StringBuffer buf = null;
for (int i = 0; i < len; i++)
{
char c = text.charAt(i);
if (c == '<')
{
if (buf == null)
{
buf = new StringBuffer(text.substring(0, i));
}
buf.append("&lt;");
}
else if (c == '>')
{
if (buf == null)
{
buf = new StringBuffer(text.substring(0, i));
}
buf.append("&gt;");
}
else if (c == '&')
{
if (buf == null)
{
buf = new StringBuffer(text.substring(0, i));
}
buf.append("&amp;");
}
else if (c == '\'' && inAttr)
{
if (buf == null)
{
buf = new StringBuffer(text.substring(0, i));
}
buf.append("&apos;");
}
else if (c == '"' && inAttr)
{
if (buf == null)
{
buf = new StringBuffer(text.substring(0, i));
}
buf.append("&quot;");
}
else if (buf != null)
{
buf.append(c);
}
}
return (buf == null) ? text : buf.toString();
}
}
@@ -0,0 +1,125 @@
/* XMLEventReaderImpl.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.XMLEventReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
/**
* Parser using XML events.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLEventReaderImpl
implements XMLEventReader
{
protected final XMLStreamReader reader;
protected final XMLEventAllocator allocator;
protected final String systemId;
protected XMLEvent peekEvent;
protected XMLEventReaderImpl(XMLStreamReader reader,
XMLEventAllocator allocator,
String systemId)
{
this.reader = reader;
this.allocator = allocator;
this.systemId = systemId;
}
public XMLEvent next()
throws XMLStreamException
{
XMLEvent ret = peek();
peekEvent = null;
return ret;
}
public boolean hasNext()
throws XMLStreamException
{
return peekEvent != null || reader.hasNext();
}
public XMLEvent peek()
throws XMLStreamException
{
if (peekEvent != null)
return peekEvent;
if (!reader.hasNext())
return null;
reader.next();
peekEvent = allocator.allocate(reader);
return peekEvent;
}
public String getElementText()
throws XMLStreamException
{
return reader.getElementText();
}
public XMLEvent nextTag()
throws XMLStreamException
{
if (peekEvent != null)
{
int eventType = peekEvent.getEventType();
if (eventType == XMLStreamConstants.START_ELEMENT ||
eventType == XMLStreamConstants.END_ELEMENT)
return peekEvent;
else
peekEvent = null;
}
reader.nextTag();
return allocator.allocate(reader);
}
public Object getProperty(String name)
throws IllegalArgumentException
{
return reader.getProperty(name);
}
}
@@ -0,0 +1,191 @@
/* XMLEventWriterImpl.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.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.Comment;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.ProcessingInstruction;
import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
/**
* Writer to write events to an underlying XML stream writer.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLEventWriterImpl
implements XMLEventWriter
{
protected final XMLStreamWriter writer;
protected XMLEventWriterImpl(XMLStreamWriter writer)
{
this.writer = writer;
}
public void flush()
throws XMLStreamException
{
writer.flush();
}
public void close()
throws XMLStreamException
{
writer.close();
}
public void add(XMLEvent event)
throws XMLStreamException
{
QName name;
String uri;
switch (event.getEventType())
{
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
name = startElement.getName();
uri = name.getNamespaceURI();
if (uri != null && !"".equals(uri))
writer.writeStartElement(name.getPrefix(), name.getLocalPart(), uri);
else
writer.writeStartElement(name.getLocalPart());
break;
case XMLStreamConstants.END_ELEMENT:
writer.writeEndElement();
break;
case XMLStreamConstants.ATTRIBUTE:
Attribute attribute = (Attribute) event;
name = attribute.getName();
uri = name.getNamespaceURI();
if (uri != null && !"".equals(uri))
writer.writeAttribute(name.getPrefix(), uri, name.getLocalPart(),
attribute.getValue());
else
writer.writeAttribute(name.getLocalPart(), attribute.getValue());
break;
case XMLStreamConstants.NAMESPACE:
Namespace namespace = (Namespace) event;
uri = namespace.getNamespaceURI();
writer.writeNamespace(namespace.getPrefix(), uri);
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction) event;
String data = pi.getData();
if (data == null)
writer.writeProcessingInstruction(pi.getTarget());
else
writer.writeProcessingInstruction(pi.getTarget(), data);
break;
case XMLStreamConstants.COMMENT:
Comment comment = (Comment) event;
writer.writeComment(comment.getText());
break;
case XMLStreamConstants.START_DOCUMENT:
StartDocument startDocument = (StartDocument) event;
writer.writeStartDocument(startDocument.getVersion());
break;
case XMLStreamConstants.END_DOCUMENT:
writer.writeEndDocument();
break;
case XMLStreamConstants.DTD:
DTD dtd = (DTD) event;
writer.writeDTD(dtd.getDocumentTypeDeclaration());
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
Characters characters = event.asCharacters();
writer.writeCharacters(characters.getData());
break;
case XMLStreamConstants.CDATA:
Characters cdata = event.asCharacters();
writer.writeCData(cdata.getData());
break;
}
}
public void add(XMLEventReader reader)
throws XMLStreamException
{
while (reader.hasNext())
add(reader.next());
}
public String getPrefix(String uri)
throws XMLStreamException
{
return writer.getPrefix(uri);
}
public void setPrefix(String prefix, String uri)
throws XMLStreamException
{
writer.setPrefix(prefix, uri);
}
public void setDefaultNamespace(String uri)
throws XMLStreamException
{
writer.setDefaultNamespace(uri);
}
public void setNamespaceContext(NamespaceContext context)
throws XMLStreamException
{
writer.setNamespaceContext(context);
}
public NamespaceContext getNamespaceContext()
{
return writer.getNamespaceContext();
}
}
@@ -0,0 +1,321 @@
/* XMLInputFactoryImpl.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.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.stream.EventFilter;
import javax.xml.stream.StreamFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLReporter;
import javax.xml.stream.XMLResolver;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.util.XMLEventAllocator;
/**
* Factory for creating parsers from various kinds of XML source.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLInputFactoryImpl
extends XMLInputFactory
{
protected XMLResolver resolver;
protected XMLReporter reporter;
protected XMLEventAllocator allocator;
protected boolean validating;
protected boolean namespaceAware = true;
protected boolean coalescing;
protected boolean replacingEntityReferences = true;
protected boolean externalEntities = true;
protected boolean supportDTD = true;
public XMLInputFactoryImpl()
{
allocator = new XMLEventAllocatorImpl();
}
public XMLStreamReader createXMLStreamReader(Reader reader)
throws XMLStreamException
{
return new XMLStreamReaderImpl(reader, null, null,
resolver, reporter,
validating, namespaceAware,
coalescing, replacingEntityReferences,
externalEntities, supportDTD);
}
public XMLStreamReader createXMLStreamReader(Source source)
throws XMLStreamException
{
String systemId = source.getSystemId();
InputStream in = getInputStream(source);
return new XMLStreamReaderImpl(in, null, systemId,
resolver, reporter,
validating, namespaceAware,
coalescing, replacingEntityReferences,
externalEntities, supportDTD);
}
public XMLStreamReader createXMLStreamReader(InputStream in)
throws XMLStreamException
{
return new XMLStreamReaderImpl(in, null, null,
resolver, reporter,
validating, namespaceAware,
coalescing, replacingEntityReferences,
externalEntities, supportDTD);
}
public XMLStreamReader createXMLStreamReader(InputStream in, String encoding)
throws XMLStreamException
{
return createXMLStreamReader(in);
}
public XMLEventReader createXMLEventReader(Reader reader)
throws XMLStreamException
{
XMLStreamReader sr = createXMLStreamReader(reader);
return new XMLEventReaderImpl(sr, allocator, null);
}
public XMLEventReader createXMLEventReader(XMLStreamReader reader)
throws XMLStreamException
{
return new XMLEventReaderImpl(reader, allocator, null);
}
public XMLEventReader createXMLEventReader(Source source)
throws XMLStreamException
{
XMLStreamReader sr = createXMLStreamReader(source);
return new XMLEventReaderImpl(sr, allocator, null);
}
public XMLEventReader createXMLEventReader(InputStream in)
throws XMLStreamException
{
XMLStreamReader sr = createXMLStreamReader(in);
return new XMLEventReaderImpl(sr, allocator, null);
}
public XMLEventReader createXMLEventReader(InputStream in, String encoding)
throws XMLStreamException
{
XMLStreamReader sr = createXMLStreamReader(in, encoding);
return new XMLEventReaderImpl(sr, allocator, null);
}
public XMLStreamReader createFilteredReader(XMLStreamReader reader,
StreamFilter filter)
throws XMLStreamException
{
return new FilteredStreamReader(reader, filter);
}
public XMLEventReader createFilteredReader(XMLEventReader reader,
EventFilter filter)
throws XMLStreamException
{
return new FilteredEventReader(reader, filter);
}
public XMLResolver getXMLResolver()
{
return resolver;
}
public void setXMLResolver(XMLResolver resolver)
{
this.resolver = resolver;
}
public XMLReporter getXMLReporter()
{
return reporter;
}
public void setXMLReporter(XMLReporter reporter)
{
this.reporter = reporter;
}
public void setProperty(String name, Object value)
throws IllegalArgumentException
{
if (name.equals(IS_NAMESPACE_AWARE))
namespaceAware = ((Boolean) value).booleanValue();
else if (name.equals(IS_VALIDATING))
validating = ((Boolean) value).booleanValue();
else if (name.equals(IS_COALESCING))
coalescing = ((Boolean) value).booleanValue();
else if (name.equals(IS_REPLACING_ENTITY_REFERENCES))
replacingEntityReferences = ((Boolean) value).booleanValue();
else if (name.equals(IS_SUPPORTING_EXTERNAL_ENTITIES))
externalEntities = ((Boolean) value).booleanValue();
else if (name.equals(SUPPORT_DTD))
supportDTD = ((Boolean) value).booleanValue();
else if (name.equals(REPORTER))
reporter = (XMLReporter) value;
else if (name.equals(RESOLVER))
resolver = (XMLResolver) value;
else if (name.equals(ALLOCATOR))
allocator = (XMLEventAllocator) value;
else
throw new IllegalArgumentException(name);
}
public Object getProperty(String name)
throws IllegalArgumentException
{
if (name.equals(IS_NAMESPACE_AWARE))
return namespaceAware ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(IS_VALIDATING))
return validating ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(IS_COALESCING))
return coalescing ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(IS_REPLACING_ENTITY_REFERENCES))
return replacingEntityReferences ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(IS_SUPPORTING_EXTERNAL_ENTITIES))
return externalEntities ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(SUPPORT_DTD))
return supportDTD ? Boolean.TRUE : Boolean.FALSE;
if (name.equals(REPORTER))
return reporter;
if (name.equals(RESOLVER))
return resolver;
if (name.equals(ALLOCATOR))
return allocator;
throw new IllegalArgumentException(name);
}
public boolean isPropertySupported(String name)
{
return name.equals(IS_NAMESPACE_AWARE) ||
name.equals(IS_VALIDATING) ||
name.equals(IS_COALESCING) ||
name.equals(IS_REPLACING_ENTITY_REFERENCES) ||
name.equals(IS_SUPPORTING_EXTERNAL_ENTITIES) ||
name.equals(SUPPORT_DTD) ||
name.equals(REPORTER) ||
name.equals(RESOLVER) ||
name.equals(ALLOCATOR);
}
public void setEventAllocator(XMLEventAllocator allocator)
{
this.allocator = allocator;
}
public XMLEventAllocator getEventAllocator()
{
return allocator;
}
public void setCoalescing(boolean coalescing)
{
this.coalescing = coalescing;
}
public boolean isCoalescing()
{
return coalescing;
}
protected InputStream getInputStream(Source source)
throws XMLStreamException
{
InputStream in = null;
if (source instanceof StreamSource)
{
StreamSource streamSource = (StreamSource) source;
in = streamSource.getInputStream();
}
if (in == null)
{
String systemId = source.getSystemId();
try
{
URL url = new URL(systemId);
try
{
in = url.openStream();
}
catch (IOException e2)
{
XMLStreamException e3 = new XMLStreamException(e2);
e3.initCause(e2);
throw e3;
}
}
catch (MalformedURLException e)
{
// Fall back to relative file
if (File.separatorChar != '/')
systemId = systemId.replace('/', File.separatorChar);
try
{
in = new FileInputStream(systemId);
}
catch (FileNotFoundException e2)
{
XMLStreamException e3 = new XMLStreamException(e2);
e3.initCause(e2);
throw e3;
}
}
}
return in;
}
}
@@ -0,0 +1,153 @@
/* XMLOutputFactoryImpl.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.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.UnsupportedEncodingException;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* Standard output factory.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLOutputFactoryImpl
extends XMLOutputFactory
{
protected boolean prefixDefaulting = false;
public XMLOutputFactoryImpl()
{
}
public XMLStreamWriter createXMLStreamWriter(Writer stream)
throws XMLStreamException
{
// XXX try to determine character encoding of writer?
return new XMLStreamWriterImpl(stream, null, prefixDefaulting);
}
public XMLStreamWriter createXMLStreamWriter(OutputStream stream)
throws XMLStreamException
{
return createXMLStreamWriter(stream, "UTF-8");
}
public XMLStreamWriter createXMLStreamWriter(OutputStream stream,
String encoding)
throws XMLStreamException
{
if (encoding == null)
encoding = "UTF-8";
try
{
Writer writer = new OutputStreamWriter(stream, encoding);
return new XMLStreamWriterImpl(writer, encoding, prefixDefaulting);
}
catch (UnsupportedEncodingException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public XMLEventWriter createXMLEventWriter(OutputStream stream)
throws XMLStreamException
{
XMLStreamWriter writer = createXMLStreamWriter(stream);
return new XMLEventWriterImpl(writer);
}
public XMLEventWriter createXMLEventWriter(OutputStream stream,
String encoding)
throws XMLStreamException
{
XMLStreamWriter writer = createXMLStreamWriter(stream, encoding);
return new XMLEventWriterImpl(writer);
}
public XMLEventWriter createXMLEventWriter(Writer stream)
throws XMLStreamException
{
XMLStreamWriter writer = createXMLStreamWriter(stream);
return new XMLEventWriterImpl(writer);
}
public void setProperty(String name, Object value)
throws IllegalArgumentException
{
if (IS_PREFIX_DEFAULTING.equals(name))
prefixDefaulting = ((Boolean) value).booleanValue();
throw new IllegalArgumentException(name);
}
public Object getProperty(String name)
throws IllegalArgumentException
{
if (IS_PREFIX_DEFAULTING.equals(name))
return new Boolean(prefixDefaulting);
throw new IllegalArgumentException(name);
}
public boolean isPropertySupported(String name)
{
if (IS_PREFIX_DEFAULTING.equals(name))
return true;
return false;
}
public boolean isPrefixDefaulting()
{
return prefixDefaulting;
}
public void setPrefixDefaulting(boolean value)
{
prefixDefaulting = value;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,699 @@
/* XMLStreamWriterImpl.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 java.util.LinkedList;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.helpers.NamespaceSupport;
/**
* Simple XML stream writer.
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class XMLStreamWriterImpl
implements XMLStreamWriter
{
protected final Writer writer;
protected final String encoding;
protected final boolean prefixDefaulting;
protected NamespaceContext namespaceContext;
private LinkedList elements;
private boolean inStartElement;
private boolean emptyElement;
private NamespaceSupport namespaces;
protected XMLStreamWriterImpl(Writer writer, String encoding,
boolean prefixDefaulting)
{
this.writer = writer;
this.encoding = encoding;
this.prefixDefaulting = prefixDefaulting;
elements = new LinkedList();
namespaces = new NamespaceSupport();
}
private void endStartElement()
throws IOException
{
if (!inStartElement)
return;
if (emptyElement)
{
writer.write('/');
elements.removeLast();
namespaces.popContext();
emptyElement = false;
}
writer.write('>');
inStartElement = false;
}
public void writeStartElement(String localName)
throws XMLStreamException
{
try
{
endStartElement();
namespaces.pushContext();
writer.write('<');
writer.write(localName);
elements.addLast(new String[] { null, localName });
inStartElement = true;
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeStartElement(String namespaceURI, String localName)
throws XMLStreamException
{
try
{
endStartElement();
namespaces.pushContext();
String prefix = getPrefix(namespaceURI);
boolean isDeclared = (prefix != null);
if (!isDeclared)
{
if (prefixDefaulting)
prefix = XMLConstants.DEFAULT_NS_PREFIX;
else
throw new XMLStreamException("namespace " + namespaceURI +
" has not been declared");
}
writer.write('<');
if (!"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(localName);
if (prefixDefaulting && !isDeclared)
{
writeNamespace(prefix, namespaceURI);
}
elements.addLast(new String[] { prefix, localName });
inStartElement = true;
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeStartElement(String prefix, String localName,
String namespaceURI)
throws XMLStreamException
{
try
{
endStartElement();
namespaces.pushContext();
String currentPrefix = getPrefix(namespaceURI);
boolean isCurrent = prefix.equals(currentPrefix);
writer.write('<');
if (!"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(localName);
if (prefixDefaulting && !isCurrent)
{
writeNamespace(prefix, namespaceURI);
}
elements.addLast(new String[] { prefix, localName });
inStartElement = true;
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeEmptyElement(String namespaceURI, String localName)
throws XMLStreamException
{
writeStartElement(namespaceURI, localName);
emptyElement = true;
}
public void writeEmptyElement(String prefix, String localName,
String namespaceURI)
throws XMLStreamException
{
writeStartElement(prefix, localName, namespaceURI);
emptyElement = true;
}
public void writeEmptyElement(String localName)
throws XMLStreamException
{
writeStartElement(localName);
emptyElement = true;
}
public void writeEndElement()
throws XMLStreamException
{
try
{
endStartElement();
String[] element = (String[]) elements.removeLast();
namespaces.popContext();
writer.write('<');
writer.write('/');
if (element[0] != null && !"".equals(element[0]))
{
writer.write(element[0]);
writer.write(':');
}
writer.write(element[1]);
writer.write('>');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeEndDocument()
throws XMLStreamException
{
while (!elements.isEmpty())
writeEndElement();
}
public void close()
throws XMLStreamException
{
flush();
}
public void flush()
throws XMLStreamException
{
try
{
writer.flush();
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeAttribute(String localName, String value)
throws XMLStreamException
{
if (!inStartElement)
throw new IllegalStateException();
try
{
writer.write(' ');
writer.write(localName);
writer.write('=');
writer.write('"');
writeEncoded(value, true);
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeAttribute(String prefix, String namespaceURI,
String localName, String value)
throws XMLStreamException
{
if (!inStartElement)
throw new IllegalStateException();
try
{
String currentPrefix = getPrefix(namespaceURI);
if (currentPrefix == null)
{
if (prefixDefaulting)
writeNamespace(prefix, namespaceURI);
else
throw new XMLStreamException("namespace " + namespaceURI +
" is not bound");
}
else if (!currentPrefix.equals(prefix))
throw new XMLStreamException("namespace " + namespaceURI +
" is bound to prefix " +
currentPrefix);
writer.write(' ');
if (!"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(localName);
writer.write('=');
writer.write('"');
writeEncoded(value, true);
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeAttribute(String namespaceURI, String localName,
String value)
throws XMLStreamException
{
if (!inStartElement)
throw new IllegalStateException();
try
{
String prefix = getPrefix(namespaceURI);
if (prefix == null)
{
if (prefixDefaulting)
{
prefix = XMLConstants.DEFAULT_NS_PREFIX;
writeNamespace(prefix, namespaceURI);
}
else
throw new XMLStreamException("namespace " + namespaceURI +
" is not bound");
}
writer.write(' ');
if (!"".equals(prefix))
{
writer.write(prefix);
writer.write(':');
}
writer.write(localName);
writer.write('=');
writer.write('"');
writeEncoded(value, true);
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeNamespace(String prefix, String namespaceURI)
throws XMLStreamException
{
if (!inStartElement)
throw new IllegalStateException();
try
{
if (prefix == null)
prefix = XMLConstants.DEFAULT_NS_PREFIX;
setPrefix(prefix, namespaceURI);
writer.write(' ');
writer.write("xmlns");
if (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix))
{
writer.write(':');
writer.write(prefix);
}
writer.write('=');
writer.write('"');
writer.write(namespaceURI);
writer.write('"');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeDefaultNamespace(String namespaceURI)
throws XMLStreamException
{
writeNamespace(XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
}
public void writeComment(String data)
throws XMLStreamException
{
try
{
endStartElement();
if (data != null && data.indexOf("--") != -1)
throw new IllegalArgumentException(data);
writer.write("<!--");
if (data != null)
writer.write(data);
writer.write("-->");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeProcessingInstruction(String target)
throws XMLStreamException
{
writeProcessingInstruction(target, null);
}
public void writeProcessingInstruction(String target, String data)
throws XMLStreamException
{
try
{
endStartElement();
writer.write('<');
writer.write('?');
writer.write(target);
if (data != null)
{
writer.write(' ');
writer.write(data);
}
writer.write('?');
writer.write('>');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeCData(String data)
throws XMLStreamException
{
try
{
endStartElement();
if (data.indexOf("]]") != -1)
throw new IllegalArgumentException(data);
writer.write("<![CDATA[");
writer.write(data);
writer.write("]]>");
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeDTD(String dtd)
throws XMLStreamException
{
try
{
writer.write("<!DOCTYPE ");
writer.write(dtd);
writer.write('>');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeEntityRef(String name)
throws XMLStreamException
{
try
{
endStartElement();
writer.write('&');
writer.write(name);
writer.write(';');
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeStartDocument()
throws XMLStreamException
{
writeStartDocument(null, null);
}
public void writeStartDocument(String version)
throws XMLStreamException
{
writeStartDocument(null, version);
}
public void writeStartDocument(String encoding, String version)
throws XMLStreamException
{
if (version == null)
version = "1.0";
encoding = this.encoding; // YES: the parameter must be ignored
if (encoding == null)
encoding = "UTF-8";
if (!"1.0".equals(version) && !"1.1".equals(version))
throw new IllegalArgumentException(version);
try
{
writer.write("<?xml version=\"");
writer.write(version);
writer.write("\" encoding=\"");
writer.write(encoding);
writer.write("\"?>");
writer.write(System.getProperty("line.separator"));
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
public void writeCharacters(String text)
throws XMLStreamException
{
try
{
endStartElement();
if (text != null)
writeEncoded(text, false);
}
catch (IOException e)
{
XMLStreamException e2 = new XMLStreamException(e);
e2.initCause(e);
throw e2;
}
}
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("&lt;");
else if (c == '>')
writer.write("&gt;");
else
writer.write("&amp;");
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;
}
}
public String getPrefix(String uri)
throws XMLStreamException
{
String prefix = namespaces.getPrefix(uri);
if (prefix == null && namespaceContext != null)
prefix = namespaceContext.getPrefix(uri);
return prefix;
}
public void setPrefix(String prefix, String uri)
throws XMLStreamException
{
if (!namespaces.declarePrefix(prefix, uri))
throw new XMLStreamException("illegal prefix " + prefix);
}
public void setDefaultNamespace(String uri)
throws XMLStreamException
{
if (!namespaces.declarePrefix(XMLConstants.DEFAULT_NS_PREFIX, uri))
throw new XMLStreamException("illegal default namespace prefix");
}
public void setNamespaceContext(NamespaceContext context)
throws XMLStreamException
{
namespaceContext = context;
}
public NamespaceContext getNamespaceContext()
{
return namespaceContext;
}
public Object getProperty(String name)
throws IllegalArgumentException
{
throw new IllegalArgumentException(name);
}
private void writeEncoded(String text, boolean inAttr)
throws IOException
{
char[] chars = text.toCharArray();
int start = 0;
int end = chars.length;
int len = 0;
for (int i = start; i < end; i++)
{
char c = chars[i];
if (c == '<' || c == '>' || c == '&')
{
writer.write(chars, start, len);
if (c == '<')
writer.write("&lt;");
else if (c == '>')
writer.write("&gt;");
else
writer.write("&amp;");
start = i + 1;
len = 0;
}
else if (inAttr && (c == '"' || c == '\''))
{
writer.write(chars, start, len);
if (c == '"')
writer.write("&quot;");
else
writer.write("&apos;");
start = i + 1;
len = 0;
}
else
len++;
}
if (len > 0)
writer.write(chars, start, len);
}
}