feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,137 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.namespace.QName;
import javax.xml.stream.events.Attribute;
public class AttributeBase extends EventBase implements Attribute
{
//an Attribute consists of a qualified name and value
private QName _QName;
private String _value;
private String _attributeType = null;
//A flag indicating whether this attribute was actually specified in the start-tag
//of its element or was defaulted from the schema.
private boolean _specified = false;
public AttributeBase(){
super(ATTRIBUTE);
}
public AttributeBase(String name, String value) {
super(ATTRIBUTE);
_QName = new QName(name);
_value = value;
}
public AttributeBase(QName qname, String value) {
_QName = qname;
_value = value;
}
public AttributeBase(String prefix, String localName, String value) {
this(prefix, null,localName, value, null);
}
public AttributeBase(String prefix, String namespaceURI, String localName,
String value, String attributeType) {
if (prefix == null) prefix = "";
_QName = new QName(namespaceURI, localName,prefix);
_value = value;
_attributeType = (attributeType == null) ? "CDATA":attributeType;
}
public void setName(QName name){
_QName = name ;
}
/**
* Returns the QName for this attribute
*/
public QName getName() {
return _QName;
}
public void setValue(String value){
_value = value;
}
public String getLocalName() {
return _QName.getLocalPart();
}
/**
* Gets the normalized value of this attribute
*/
public String getValue() {
return _value;
}
public void setAttributeType(String attributeType){
_attributeType = attributeType ;
}
/**
* Gets the type of this attribute, default is
* the String "CDATA"
* @return the type as a String, default is "CDATA"
*/
public String getDTDType() {
return _attributeType;
}
/**
* A flag indicating whether this attribute was actually
* specified in the start-tag of its element, or was defaulted from the schema.
* @return returns true if this was specified in the start element
*/
public boolean isSpecified() {
return _specified ;
}
public void setSpecified(boolean isSpecified){
_specified = isSpecified ;
}
public String toString() {
String prefix = _QName.getPrefix();
if (!Util.isEmptyString(prefix))
return prefix + ":" + _QName.getLocalPart() + "='" + _value + "'";
return _QName.getLocalPart() + "='" + _value + "'";
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar;
import javax.xml.stream.events.Characters;
public class CharactersEvent extends EventBase implements Characters {
private String _text;
private boolean isCData=false;
private boolean isSpace=false;
private boolean isIgnorable=false;
private boolean needtoCheck = true;
public CharactersEvent() {
super(CHARACTERS);
}
/**
*
* @param data Character Data.
*/
public CharactersEvent(String data) {
super(CHARACTERS);
_text = data;
}
/**
*
* @param data Character Data.
* @param isCData true if is CData
*/
public CharactersEvent(String data, boolean isCData) {
super(CHARACTERS);
_text = data;
this.isCData = isCData;
}
/**
* Get the character data of this event
*/
public String getData() {
return _text;
}
public void setData(String data){
_text = data;
}
/**
*
* @return boolean returns true if the data is CData
*/
public boolean isCData() {
return isCData;
}
/**
*
* @return String return the String representation of this event.
*/
public String toString() {
if(isCData)
return "<![CDATA[" + _text + "]]>";
else
return _text;
}
/**
* Return true if this is ignorableWhiteSpace. If
* this event is ignorableWhiteSpace its event type will
* be SPACE.
* @return boolean true if this is ignorableWhiteSpace.
*/
public boolean isIgnorableWhiteSpace() {
return isIgnorable;
}
/**
* Returns true if this set of Characters are all whitespace. Whitspace inside a document
* is reported as CHARACTERS. This method allows checking of CHARACTERS events to see
* if they are composed of only whitespace characters
* @return boolean true if this set of Characters are all whitespace
*/
public boolean isWhiteSpace() {
//no synchronization checks made.
if(needtoCheck){
checkWhiteSpace();
needtoCheck = false;
}
return isSpace;
}
public void setSpace(boolean isSpace) {
this.isSpace = isSpace;
needtoCheck = false;
}
public void setIgnorable(boolean isIgnorable){
this.isIgnorable = isIgnorable;
setEventType(SPACE);
}
private void checkWhiteSpace(){
//refer to xerces XMLChar
if(!Util.isEmptyString(_text)){
isSpace = true;
for(int i=0;i<_text.length();i++){
if(!XMLChar.isSpace(_text.charAt(i))){
isSpace = false;
break;
}
}
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.events.Comment;
public class CommentEvent extends EventBase implements Comment {
/* String data for this event */
private String _text;
public CommentEvent() {
super(COMMENT);
}
public CommentEvent(String text) {
this();
_text = text;
}
/**
* @return String String representation of this event
*/
public String toString() {
return "<!--" + _text + "-->";
}
/**
* Return the string data of the comment, returns empty string if it
* does not exist
*/
public String getText() {
return _text ;
}
public void setText(String text) {
_text = text;
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.List;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.NotationDeclaration;
/**
* DTDEvent. Notations and Entities are not used
*/
public class DTDEvent extends EventBase implements DTD{
private String _dtd;
private List _notations;
private List _entities;
/** Creates a new instance of DTDEvent */
public DTDEvent() {
setEventType(DTD);
}
public DTDEvent(String dtd){
setEventType(DTD);
_dtd = dtd;
}
/**
* Returns the entire Document Type Declaration as a string, including
* the internal DTD subset.
* This may be null if there is not an internal subset.
* If it is not null it must return the entire
* Document Type Declaration which matches the doctypedecl
* production in the XML 1.0 specification
*/
public String getDocumentTypeDeclaration() {
return _dtd;
}
public void setDTD(String dtd){
_dtd = dtd;
}
/**
* Return a List containing the general entities,
* both external and internal, declared in the DTD.
* This list must contain EntityDeclaration events.
* @see EntityDeclaration
* @return an unordered list of EntityDeclaration events
*/
public List getEntities() {
return _entities;
}
/**
* Return a List containing the notations declared in the DTD.
* This list must contain NotationDeclaration events.
* @see NotationDeclaration
* @return an unordered list of NotationDeclaration events
*/
public List getNotations() {
return _notations;
}
/**
*Returns an implementation defined representation of the DTD.
* This method may return null if no representation is available.
*
*/
public Object getProcessedDTD() {
return null;
}
public void setEntities(List entites){
_entities = entites;
}
public void setNotations(List notations){
_notations = notations;
}
public String toString(){
return _dtd ;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.Iterator;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
import java.util.NoSuchElementException;
public class EmptyIterator implements Iterator {
public static final EmptyIterator instance = new EmptyIterator();
/** Creates a new instance of EmptyIterator */
private EmptyIterator() {
}
public static EmptyIterator getInstance() {
return instance;
}
public boolean hasNext() {
return false;
}
public Object next() throws NoSuchElementException {
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.emptyIterator"));
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.events.EndDocument;
public class EndDocumentEvent extends EventBase implements EndDocument {
public EndDocumentEvent() {
super(END_DOCUMENT);
}
public String toString() {
return "<? EndDocument ?>";
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.Namespace;
import com.sun.xml.internal.fastinfoset.stax.events.EmptyIterator;
public class EndElementEvent extends EventBase implements EndElement {
List _namespaces = null;
QName _qname ;
public void reset() {
if (_namespaces != null) _namespaces.clear();
}
public EndElementEvent() {
setEventType(END_ELEMENT);
}
public EndElementEvent(String prefix, String namespaceURI, String localpart) {
_qname = getQName(namespaceURI,localpart,prefix);
setEventType(END_ELEMENT);
}
public EndElementEvent(QName qname) {
_qname = qname;
setEventType(END_ELEMENT);
}
/**
* Get the name of this event
* @return the qualified name of this event
*/
public QName getName() {
return _qname;
}
public void setName(QName qname) {
_qname = qname;
}
/** Returns an Iterator of namespaces that have gone out
* of scope. Returns an empty iterator if no namespaces have gone
* out of scope.
* @return an Iterator over Namespace interfaces, or an
* empty iterator
*/
public Iterator getNamespaces() {
if(_namespaces != null)
return _namespaces.iterator();
return EmptyIterator.getInstance();
}
public void addNamespace(Namespace namespace){
if (_namespaces == null) {
_namespaces = new ArrayList();
}
_namespaces.add(namespace);
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("</").append(nameAsString());
Iterator namespaces = getNamespaces();
while(namespaces.hasNext()) {
sb.append(" ").append(namespaces.next().toString());
}
sb.append(">");
return sb.toString();
}
private String nameAsString() {
if("".equals(_qname.getNamespaceURI()))
return _qname.getLocalPart();
if(_qname.getPrefix() != null)
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart();
else
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart();
}
private QName getQName(String uri, String localPart, String prefix){
QName qn = null;
if(prefix != null && uri != null)
qn = new QName(uri, localPart, prefix);
else if(prefix == null && uri != null)
qn = new QName(uri, localPart);
else if(prefix == null && uri == null)
qn = new QName(localPart);
return qn;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.events.EntityDeclaration;
public class EntityDeclarationImpl extends EventBase implements EntityDeclaration {
private String _publicId;
private String _systemId;
private String _baseURI;
private String _entityName;
private String _replacement;
private String _notationName;
/** Creates a new instance of EntityDeclarationImpl */
public EntityDeclarationImpl() {
init();
}
public EntityDeclarationImpl(String entityName , String replacement){
init();
_entityName = entityName;
_replacement = replacement;
}
/**
* The entity's public identifier, or null if none was given
* @return the public ID for this declaration or null
*/
public String getPublicId(){
return _publicId;
}
/**
* The entity's system identifier.
* @return the system ID for this declaration or null
*/
public String getSystemId(){
return _systemId;
}
/**
* The entity's name
* @return the name, may not be null
*/
public String getName(){
return _entityName;
}
/**
* The name of the associated notation.
* @return the notation name
*/
public String getNotationName() {
return _notationName;
}
/**
* The replacement text of the entity.
* This method will only return non-null
* if this is an internal entity.
* @return null or the replacment text
*/
public String getReplacementText() {
return _replacement;
}
/**
* Get the base URI for this reference
* or null if this information is not available
* @return the base URI or null
*/
public String getBaseURI() {
return _baseURI;
}
public void setPublicId(String publicId) {
_publicId = publicId;
}
public void setSystemId(String systemId) {
_systemId = systemId;
}
public void setBaseURI(String baseURI) {
_baseURI = baseURI;
}
public void setName(String entityName){
_entityName = entityName;
}
public void setReplacementText(String replacement){
_replacement = replacement;
}
public void setNotationName(String notationName){
_notationName = notationName;
}
protected void init(){
setEventType(ENTITY_DECLARATION);
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.events.EntityDeclaration;
import javax.xml.stream.events.EntityReference;
public class EntityReferenceEvent extends EventBase implements EntityReference {
private EntityDeclaration _entityDeclaration ;
private String _entityName;
public EntityReferenceEvent() {
init();
}
public EntityReferenceEvent(String entityName , EntityDeclaration entityDeclaration) {
init();
_entityName = entityName;
_entityDeclaration = entityDeclaration;
}
/**
* The name of the entity
* @return the entity's name, may not be null
*/
public String getName() {
return _entityName;
}
/**
* Return the declaration of this entity.
*/
public EntityDeclaration getDeclaration(){
return _entityDeclaration ;
}
public void setName(String name){
_entityName = name;
}
public void setDeclaration(EntityDeclaration declaration) {
_entityDeclaration = declaration ;
}
public String toString() {
String text = _entityDeclaration.getReplacementText();
if(text == null)
text = "";
return "&" + getName() + ";='" + text + "'";
}
protected void init() {
setEventType(ENTITY_REFERENCE);
}
}

View File

@@ -0,0 +1,220 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.Location;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.namespace.QName;
import java.io.Writer;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public abstract class EventBase implements XMLEvent {
/* Event type this event corresponds to */
protected int _eventType;
protected Location _location = null;
public EventBase() {
}
public EventBase(int eventType) {
_eventType = eventType;
}
/**
* Returns an integer code for this event.
*/
public int getEventType() {
return _eventType;
}
protected void setEventType(int eventType){
_eventType = eventType;
}
public boolean isStartElement() {
return _eventType == START_ELEMENT;
}
public boolean isEndElement() {
return _eventType == END_ELEMENT;
}
public boolean isEntityReference() {
return _eventType == ENTITY_REFERENCE;
}
public boolean isProcessingInstruction() {
return _eventType == PROCESSING_INSTRUCTION;
}
public boolean isStartDocument() {
return _eventType == START_DOCUMENT;
}
public boolean isEndDocument() {
return _eventType == END_DOCUMENT;
}
/**
* Return the location of this event. The Location
* returned from this method is non-volatile and
* will retain its information.
* @see javax.xml.stream.Location
*/
public Location getLocation(){
return _location;
}
public void setLocation(Location loc){
_location = loc;
}
public String getSystemId() {
if(_location == null )
return "";
else
return _location.getSystemId();
}
/** Returns this event as Characters, may result in
* a class cast exception if this event is not Characters.
*/
public Characters asCharacters() {
if (isCharacters()) {
return (Characters)this;
} else
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.charactersCast", new Object[]{getEventTypeString()}));
}
/** Returns this event as an end element event, may result in
* a class cast exception if this event is not a end element.
*/
public EndElement asEndElement() {
if (isEndElement()) {
return (EndElement)this;
} else
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
}
/**
* Returns this event as a start element event, may result in
* a class cast exception if this event is not a start element.
*/
public StartElement asStartElement() {
if (isStartElement()) {
return (StartElement)this;
} else
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.startElementCase", new Object[]{getEventTypeString()}));
}
/**
* This method is provided for implementations to provide
* optional type information about the associated event.
* It is optional and will return null if no information
* is available.
*/
public QName getSchemaType() {
return null;
}
/** A utility function to check if this event is an Attribute.
* @see javax.xml.stream.events.Attribute
*/
public boolean isAttribute() {
return _eventType == ATTRIBUTE;
}
/** A utility function to check if this event is Characters.
* @see javax.xml.stream.events.Characters
*/
public boolean isCharacters() {
return _eventType == CHARACTERS;
}
/** A utility function to check if this event is a Namespace.
* @see javax.xml.stream.events.Namespace
*/
public boolean isNamespace() {
return _eventType == NAMESPACE;
}
/**
* This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
* No indentation or whitespace should be outputted.
*
* Any user defined event type SHALL have this method
* called when being written to on an output stream.
* Built in Event types MUST implement this method,
* but implementations MAY choose not call these methods
* for optimizations reasons when writing out built in
* Events to an output stream.
* The output generated MUST be equivalent in terms of the
* infoset expressed.
*
* @param writer The writer that will output the data
* @throws XMLStreamException if there is a fatal error writing the event
*/
public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException {
}
private String getEventTypeString() {
switch (_eventType){
case START_ELEMENT:
return "StartElementEvent";
case END_ELEMENT:
return "EndElementEvent";
case PROCESSING_INSTRUCTION:
return "ProcessingInstructionEvent";
case CHARACTERS:
return "CharacterEvent";
case COMMENT:
return "CommentEvent";
case START_DOCUMENT:
return "StartDocumentEvent";
case END_DOCUMENT:
return "EndDocumentEvent";
case ENTITY_REFERENCE:
return "EntityReferenceEvent";
case ATTRIBUTE:
return "AttributeBase";
case DTD:
return "DTDEvent";
case CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.namespace.QName;
import javax.xml.stream.events.Namespace;
public class NamespaceBase extends AttributeBase implements Namespace{
//J2SE1.5.0 javax.xml.XMLConstants
static final String DEFAULT_NS_PREFIX = "";
static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace";
static final String XML_NS_PREFIX = "xml";
static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/";
static final String XMLNS_ATTRIBUTE = "xmlns";
static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema";
static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = "http://www.w3.org/2001/XMLSchema-instance";
//is this namespace default declaration?
private boolean defaultDeclaration = false;
/** a namespace attribute has a form: xmlns:NCName="URI reference" */
public NamespaceBase(String namespaceURI) {
super(XMLNS_ATTRIBUTE, "", namespaceURI);
setEventType(NAMESPACE);
}
/**
* Create a new Namespace
* @param prefix prefix of a namespace is the local name for an attribute
* @param namespaceURI the uri reference of a namespace is the value for an attribute
*/
public NamespaceBase(String prefix, String namespaceURI){
super(XMLNS_ATTRIBUTE, prefix, namespaceURI);
setEventType(NAMESPACE);
if (Util.isEmptyString(prefix)) {
defaultDeclaration=true;
}
}
void setPrefix(String prefix){
if(prefix == null)
setName(new QName(XMLNS_ATTRIBUTE_NS_URI,DEFAULT_NS_PREFIX,XMLNS_ATTRIBUTE));
else// new QName(uri, localpart, prefix)
setName(new QName(XMLNS_ATTRIBUTE_NS_URI,prefix,XMLNS_ATTRIBUTE));
}
public String getPrefix() {
if (defaultDeclaration) return "";
return super.getLocalName();
}
/**
* set Namespace URI reference (xmlns:prefix = "uri")
* @param uri the uri reference of a namespace is the value for an attribute
*/
void setNamespaceURI(String uri) {
setValue(uri);
}
public String getNamespaceURI() {
return getValue();
}
public boolean isNamespace(){
return true;
}
public boolean isDefaultNamespaceDeclaration() {
return defaultDeclaration;
}
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.ProcessingInstruction;
public class ProcessingInstructionEvent extends EventBase implements ProcessingInstruction {
private String targetName;
private String _data;
public ProcessingInstructionEvent() {
init();
}
public ProcessingInstructionEvent(String targetName, String data) {
this.targetName = targetName;
_data = data;
init();
}
protected void init() {
setEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
}
public String getTarget() {
return targetName;
}
public void setTarget(String targetName) {
this.targetName = targetName;
}
public void setData(String data) {
_data = data;
}
public String getData() {
return _data;
}
public String toString() {
if(_data != null && targetName != null)
return "<?" + targetName + " " + _data + "?>";
if(targetName != null)
return "<?" + targetName + "?>";
if(_data != null)
return "<?" + _data + "?>";
else
return "<??>";
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.Iterator;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class ReadIterator implements Iterator {
Iterator iterator = EmptyIterator.getInstance();
public ReadIterator(){
}
public ReadIterator(Iterator iterator){
if (iterator != null) {
this.iterator = iterator;
}
}
public boolean hasNext() {
return iterator.hasNext();
}
public Object next() {
return iterator.next();
}
public void remove() {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.readonlyList"));
}
}

View File

@@ -0,0 +1,225 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
import javax.xml.stream.util.XMLEventConsumer;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
/**
* allows a user to register a way to allocate events given an XMLStreamReader.
* The XMLEventAllocator can be set on an XMLInputFactory
* using the property "javax.xml.stream.allocator"
*
* This base class uses EventFactory to create events as recommended in the JavaDoc of XMLEventAllocator.
* However, creating new object per each event reduces performance. The implementation of
* EventReader therefore will set the Allocator to StAXEventAllocator which implements the
* Allocate methods without creating new objects.
*
* The spec for the first Allocate method states that it must NOT modify the state of the Reader
* while the second MAY. For consistency, both Allocate methods in this implementation will
* NOT modify the state.
*
*/
public class StAXEventAllocatorBase implements XMLEventAllocator {
XMLEventFactory factory;
/** Creates a new instance of XMLEventAllocator */
public StAXEventAllocatorBase() {
if (System.getProperty("javax.xml.stream.XMLEventFactory")==null) {
System.setProperty("javax.xml.stream.XMLEventFactory",
"com.sun.xml.internal.fastinfoset.stax.factory.StAXEventFactory");
}
factory = XMLEventFactory.newInstance();
}
// ---------------------methods defined by XMLEventAllocator-----------------//
/**
* This method creates an instance of the XMLEventAllocator. This
* allows the XMLInputFactory to allocate a new instance per reader.
*/
public XMLEventAllocator newInstance() {
return new StAXEventAllocatorBase();
}
/**
* This method allocates an event given the current state of the XMLStreamReader.
* If this XMLEventAllocator does not have a one-to-one mapping between reader state
* and events this method will return null.
* @param streamReader The XMLStreamReader to allocate from
* @return the event corresponding to the current reader state
*/
public XMLEvent allocate(XMLStreamReader streamReader) throws XMLStreamException {
if(streamReader == null )
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.nullReader"));
return getXMLEvent(streamReader);
}
/**
* This method allocates an event or set of events given the current state of
* the XMLStreamReader and adds the event or set of events to the consumer that
* was passed in.
* @param streamReader The XMLStreamReader to allocate from
* @param consumer The XMLEventConsumer to add to.
*/
public void allocate(XMLStreamReader streamReader, XMLEventConsumer consumer) throws XMLStreamException {
consumer.add(getXMLEvent(streamReader));
}
// ---------------------end of methods defined by XMLEventAllocator-----------------//
XMLEvent getXMLEvent(XMLStreamReader reader){
XMLEvent event = null;
//returns the current event
int eventType = reader.getEventType();
//this needs to be set before creating events
factory.setLocation(reader.getLocation());
switch(eventType){
case XMLEvent.START_ELEMENT:
{
StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(),
reader.getNamespaceURI(), reader.getLocalName());
addAttributes(startElement,reader);
addNamespaces(startElement, reader);
//need to fix it along with the Reader
//setNamespaceContext(startElement,reader);
event = startElement;
break;
}
case XMLEvent.END_ELEMENT:
{
EndElementEvent endElement = (EndElementEvent)factory.createEndElement(
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
addNamespaces(endElement,reader);
event = endElement ;
break;
}
case XMLEvent.PROCESSING_INSTRUCTION:
{
event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData());
break;
}
case XMLEvent.CHARACTERS:
{
if (reader.isWhiteSpace())
event = factory.createSpace(reader.getText());
else
event = factory.createCharacters(reader.getText());
break;
}
case XMLEvent.COMMENT:
{
event = factory.createComment(reader.getText());
break;
}
case XMLEvent.START_DOCUMENT:
{
StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument(
reader.getVersion(), reader.getEncoding(), reader.isStandalone());
if(reader.getCharacterEncodingScheme() != null){
docEvent.setDeclaredEncoding(true);
}else{
docEvent.setDeclaredEncoding(false);
}
event = docEvent ;
break;
}
case XMLEvent.END_DOCUMENT:{
EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ;
event = endDocumentEvent ;
break;
}
case XMLEvent.ENTITY_REFERENCE:{
event = factory.createEntityReference(reader.getLocalName(),
new EntityDeclarationImpl(reader.getLocalName(),reader.getText()));
break;
}
case XMLEvent.ATTRIBUTE:{
event = null ;
break;
}
case XMLEvent.DTD:{
event = factory.createDTD(reader.getText());
break;
}
case XMLEvent.CDATA:{
event = factory.createCData(reader.getText());
break;
}
case XMLEvent.SPACE:{
event = factory.createSpace(reader.getText());
break;
}
}
return event ;
}
//use event.addAttribute instead of addAttributes to avoid creating another list
protected void addAttributes(StartElementEvent event,XMLStreamReader streamReader){
AttributeBase attr = null;
for(int i=0; i<streamReader.getAttributeCount() ;i++){
attr = (AttributeBase)factory.createAttribute(streamReader.getAttributeName(i),
streamReader.getAttributeValue(i));
attr.setAttributeType(streamReader.getAttributeType(i));
attr.setSpecified(streamReader.isAttributeSpecified(i));
event.addAttribute(attr);
}
}
//add namespaces to StartElement/EndElement
protected void addNamespaces(StartElementEvent event,XMLStreamReader streamReader){
Namespace namespace = null;
for(int i=0; i<streamReader.getNamespaceCount(); i++){
namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
streamReader.getNamespaceURI(i));
event.addNamespace(namespace);
}
}
protected void addNamespaces(EndElementEvent event,XMLStreamReader streamReader){
Namespace namespace = null;
for(int i=0; i<streamReader.getNamespaceCount(); i++){
namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
streamReader.getNamespaceURI(i));
event.addNamespace(namespace);
}
}
}

View File

@@ -0,0 +1,179 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import com.sun.xml.internal.fastinfoset.stax.*;
import java.util.NoSuchElementException;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXEventReader implements javax.xml.stream.XMLEventReader{
protected XMLStreamReader _streamReader ;
protected XMLEventAllocator _eventAllocator;
private XMLEvent _currentEvent; //the current event
private XMLEvent[] events = new XMLEvent[3];
private int size = 3;
private int currentIndex = 0;
private boolean hasEvent = false; //true when current event exists, false initially & at end
//only constructor will do because we delegate everything to underlying XMLStreamReader
public StAXEventReader(XMLStreamReader reader) throws XMLStreamException {
_streamReader = reader ;
_eventAllocator = (XMLEventAllocator)reader.getProperty(XMLInputFactory.ALLOCATOR);
if(_eventAllocator == null){
_eventAllocator = new StAXEventAllocatorBase();
}
//initialize
if (_streamReader.hasNext())
{
_streamReader.next();
_currentEvent =_eventAllocator.allocate(_streamReader);
events[0] = _currentEvent;
hasEvent = true;
} else {
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.noElement"));
}
}
public boolean hasNext() {
return hasEvent;
}
public XMLEvent nextEvent() throws XMLStreamException {
XMLEvent event = null;
XMLEvent nextEvent = null;
if (hasEvent)
{
event = events[currentIndex];
events[currentIndex] = null;
if (_streamReader.hasNext())
{
//advance and read the next
_streamReader.next();
nextEvent = _eventAllocator.allocate(_streamReader);
if (++currentIndex==size)
currentIndex = 0;
events[currentIndex] = nextEvent;
hasEvent = true;
} else {
_currentEvent = null;
hasEvent = false;
}
return event;
}
else{
throw new NoSuchElementException();
}
}
public void remove(){
//stream reader is read-only.
throw new java.lang.UnsupportedOperationException();
}
public void close() throws XMLStreamException {
_streamReader.close();
}
/** Reads the content of a text-only element. Precondition:
* the current event is START_ELEMENT. Postcondition:
* The current event is the corresponding END_ELEMENT.
* @throws XMLStreamException if the current event is not a START_ELEMENT
* or if a non text element is encountered
*/
public String getElementText() throws XMLStreamException {
if(!hasEvent) {
throw new NoSuchElementException();
}
if(!_currentEvent.isStartElement()) {
StAXDocumentParser parser = (StAXDocumentParser)_streamReader;
return parser.getElementText(true);
} else {
return _streamReader.getElementText();
}
}
/** Get the value of a feature/property from the underlying implementation
* @param name The name of the property
* @return The value of the property
* @throws IllegalArgumentException if the property is not supported
*/
public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException {
return _streamReader.getProperty(name) ;
}
/** Skips any insignificant space events until a START_ELEMENT or
* END_ELEMENT is reached. If anything other than space characters are
* encountered, an exception is thrown. This method should
* be used when processing element-only content because
* the parser is not able to recognize ignorable whitespace if
* the DTD is missing or not interpreted.
* @throws XMLStreamException if anything other than space characters are encountered
*/
public XMLEvent nextTag() throws XMLStreamException {
if(!hasEvent) {
throw new NoSuchElementException();
}
StAXDocumentParser parser = (StAXDocumentParser)_streamReader;
parser.nextTag(true);
return _eventAllocator.allocate(_streamReader);
}
//XMLEventReader extends Iterator;
public Object next() {
try{
return nextEvent();
}catch(XMLStreamException streamException){
return null;
}
}
public XMLEvent peek() throws XMLStreamException{
if (!hasEvent)
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.noElement"));
_currentEvent = events[currentIndex];
return _currentEvent;
}
public void setAllocator(XMLEventAllocator allocator) {
if (allocator == null)
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullXMLEventAllocator"));
_eventAllocator = allocator;
}
}

View File

@@ -0,0 +1,239 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.*;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXEventWriter implements XMLEventWriter {
private XMLStreamWriter _streamWriter ;
/**
*
* @param streamWriter
*/
public StAXEventWriter(XMLStreamWriter streamWriter){
_streamWriter = streamWriter;
}
/**
* Writes any cached events to the underlying output mechanism
* @throws XMLStreamException
*/
public void flush() throws XMLStreamException {
_streamWriter.flush();
}
/**
* Frees any resources associated with this stream
* @throws XMLStreamException
*/
public void close() throws javax.xml.stream.XMLStreamException {
_streamWriter.close();
}
/**
*
* @param eventReader
* @throws XMLStreamException
*/
public void add(XMLEventReader eventReader) throws XMLStreamException {
if(eventReader == null) throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.nullEventReader"));
while(eventReader.hasNext()){
add(eventReader.nextEvent());
}
}
/**
* Add an event to the output stream
* Adding a START_ELEMENT will open a new namespace scope that
* will be closed when the corresponding END_ELEMENT is written.
*
* @param event
* @throws XMLStreamException
*/
public void add(XMLEvent event) throws XMLStreamException {
int type = event.getEventType();
switch(type){
case XMLEvent.DTD:{
DTD dtd = (DTD)event ;
_streamWriter.writeDTD(dtd.getDocumentTypeDeclaration());
break;
}
case XMLEvent.START_DOCUMENT :{
StartDocument startDocument = (StartDocument)event ;
_streamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion());
break;
}
case XMLEvent.START_ELEMENT :{
StartElement startElement = event.asStartElement() ;
QName qname = startElement.getName();
_streamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
Iterator iterator = startElement.getNamespaces();
while(iterator.hasNext()){
Namespace namespace = (Namespace)iterator.next();
_streamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
}
Iterator attributes = startElement.getAttributes();
while(attributes.hasNext()){
Attribute attribute = (Attribute)attributes.next();
QName name = attribute.getName();
_streamWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(),
name.getLocalPart(),attribute.getValue());
}
break;
}
case XMLEvent.NAMESPACE:{
Namespace namespace = (Namespace)event;
_streamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
break ;
}
case XMLEvent.COMMENT: {
Comment comment = (Comment)event ;
_streamWriter.writeComment(comment.getText());
break;
}
case XMLEvent.PROCESSING_INSTRUCTION:{
ProcessingInstruction processingInstruction = (ProcessingInstruction)event ;
_streamWriter.writeProcessingInstruction(processingInstruction.getTarget(), processingInstruction.getData());
break;
}
case XMLEvent.CHARACTERS:{
Characters characters = event.asCharacters();
//check if the CHARACTERS are CDATA
if(characters.isCData()){
_streamWriter.writeCData(characters.getData());
}
else{
_streamWriter.writeCharacters(characters.getData());
}
break;
}
case XMLEvent.ENTITY_REFERENCE:{
EntityReference entityReference = (EntityReference)event ;
_streamWriter.writeEntityRef(entityReference.getName());
break;
}
case XMLEvent.ATTRIBUTE:{
Attribute attribute = (Attribute)event;
QName qname = attribute.getName();
_streamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(), qname.getLocalPart(),attribute.getValue());
break;
}
case XMLEvent.CDATA:{
//there is no separate CDATA datatype but CDATA event can be reported
//by using vendor specific CDATA property.
Characters characters = (Characters)event;
if(characters.isCData()){
_streamWriter.writeCData(characters.getData());
}
break;
}
case XMLEvent.END_ELEMENT:{
_streamWriter.writeEndElement();
break;
}
case XMLEvent.END_DOCUMENT:{
_streamWriter.writeEndDocument();
break;
}
default:
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.eventTypeNotSupported", new Object[]{Util.getEventTypeString(type)}));
//throw new XMLStreamException("Unknown Event type = " + type);
};
}
/**
* Gets the prefix the uri is bound to
* @param uri the uri to look up
* @throws XMLStreamException
*/
public String getPrefix(String uri) throws XMLStreamException {
return _streamWriter.getPrefix(uri);
}
/**
* Returns the current namespace context.
* @return the current namespace context
*/
public NamespaceContext getNamespaceContext() {
return _streamWriter.getNamespaceContext();
}
/**
* Binds a URI to the default namespace
* This URI is bound
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
* If this method is called before a START_ELEMENT has been written
* the uri is bound in the root scope.
* @param uri the uri to bind to the default namespace
* @throws XMLStreamException
*/
public void setDefaultNamespace(String uri) throws XMLStreamException {
_streamWriter.setDefaultNamespace(uri);
}
/**
* Sets the current namespace context for prefix and uri bindings.
* This context becomes the root namespace context for writing and
* will replace the current root namespace context. Subsequent calls
* to setPrefix and setDefaultNamespace will bind namespaces using
* the context passed to the method as the root context for resolving
* namespaces.
* @param namespaceContext the namespace context to use for this writer
* @throws XMLStreamException
*/
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
_streamWriter.setNamespaceContext(namespaceContext);
}
/**
* Sets the prefix the uri is bound to. This prefix is bound
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
* If this method is called before a START_ELEMENT has been written
* the prefix is bound in the root scope.
* @param prefix the prefix to bind to the uri
* @param uri the uri to bind to the prefix
* @throws XMLStreamException
*/
public void setPrefix(String prefix, String uri) throws XMLStreamException {
_streamWriter.setPrefix(prefix, uri);
}
}

View File

@@ -0,0 +1,138 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.EventFilter;
import javax.xml.stream.events.Characters;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLEventReader;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXFilteredEvent implements XMLEventReader {
private XMLEventReader eventReader;
private EventFilter _filter;
/** Creates a new instance of StAXFilteredEvent */
public StAXFilteredEvent() {
}
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
{
eventReader = reader;
_filter = filter;
}
public void setEventReader(XMLEventReader reader) {
eventReader = reader;
}
public void setFilter(EventFilter filter) {
_filter = filter;
}
public Object next() {
try {
return nextEvent();
} catch (XMLStreamException e) {
return null;
}
}
public XMLEvent nextEvent() throws XMLStreamException
{
if (hasNext())
return eventReader.nextEvent();
return null;
}
public String getElementText() throws XMLStreamException
{
StringBuffer buffer = new StringBuffer();
XMLEvent e = nextEvent();
if (!e.isStartElement())
throw new XMLStreamException(
CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));
while(hasNext()) {
e = nextEvent();
if(e.isStartElement())
throw new XMLStreamException(
CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
if(e.isCharacters())
buffer.append(((Characters) e).getData());
if(e.isEndElement())
return buffer.toString();
}
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
}
public XMLEvent nextTag() throws XMLStreamException {
while(hasNext()) {
XMLEvent e = nextEvent();
if (e.isStartElement() || e.isEndElement())
return e;
}
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.startOrEndNotFound"));
}
public boolean hasNext()
{
try {
while(eventReader.hasNext()) {
if (_filter.accept(eventReader.peek())) return true;
eventReader.nextEvent();
}
return false;
} catch (XMLStreamException e) {
return false;
}
}
public void remove() {
throw new UnsupportedOperationException();
}
public XMLEvent peek() throws XMLStreamException
{
if (hasNext())
return eventReader.peek();
return null;
}
public void close() throws XMLStreamException
{
eventReader.close();
}
public Object getProperty(String name) {
return eventReader.getProperty(name);
}
}

View File

@@ -0,0 +1,174 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.StartDocument;
public class StartDocumentEvent extends EventBase implements StartDocument {
protected String _systemId;
protected String _encoding = XMLConstants.ENCODING; //default
protected boolean _standalone = true;
protected String _version = XMLConstants.XMLVERSION;
private boolean _encodingSet = false;
private boolean _standaloneSet = false;
public void reset() {
_encoding = XMLConstants.ENCODING;
_standalone = true;
_version = XMLConstants.XMLVERSION;
_encodingSet = false;
_standaloneSet=false;
}
public StartDocumentEvent() {
this(null ,null);
}
public StartDocumentEvent(String encoding){
this(encoding, null);
}
public StartDocumentEvent(String encoding, String version){
if (encoding != null) {
_encoding = encoding;
_encodingSet = true;
}
if (version != null)
_version = version;
setEventType(XMLStreamConstants.START_DOCUMENT);
}
// ------------------- methods defined in StartDocument -------------------------
/**
* Returns the system ID of the XML data
* @return the system ID, defaults to ""
*/
public String getSystemId() {
return super.getSystemId();
}
/**
* Returns the encoding style of the XML data
* @return the character encoding, defaults to "UTF-8"
*/
public String getCharacterEncodingScheme() {
return _encoding;
}
/**
* Returns true if CharacterEncodingScheme was set in
* the encoding declaration of the document
*/
public boolean encodingSet() {
return _encodingSet;
}
/**
* Returns if this XML is standalone
* @return the standalone state of XML, defaults to "no"
*/
public boolean isStandalone() {
return _standalone;
}
/**
* Returns true if the standalone attribute was set in
* the encoding declaration of the document.
*/
public boolean standaloneSet() {
return _standaloneSet;
}
/**
* Returns the version of XML of this XML stream
* @return the version of XML, defaults to "1.0"
*/
public String getVersion() {
return _version;
}
// ------------------- end of methods defined in StartDocument -------------------------
public void setStandalone(boolean standalone) {
_standaloneSet = true;
_standalone = standalone;
}
public void setStandalone(String s) {
_standaloneSet = true;
if(s == null) {
_standalone = true;
return;
}
if(s.equals("yes"))
_standalone = true;
else
_standalone = false;
}
public void setEncoding(String encoding) {
_encoding = encoding;
_encodingSet = true;
}
void setDeclaredEncoding(boolean value){
_encodingSet = value;
}
public void setVersion(String s) {
_version = s;
}
void clear() {
_encoding = "UTF-8";
_standalone = true;
_version = "1.0";
_encodingSet = false;
_standaloneSet = false;
}
public String toString() {
String s = "<?xml version=\"" + _version + "\"";
s = s + " encoding='" + _encoding + "'";
if(_standaloneSet) {
if(_standalone)
s = s + " standalone='yes'?>";
else
s = s + " standalone='no'?>";
} else {
s = s + "?>";
}
return s;
}
public boolean isStartDocument() {
return true;
}
}

View File

@@ -0,0 +1,260 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
public class StartElementEvent extends EventBase implements StartElement {
private Map _attributes;
private List _namespaces;
private NamespaceContext _context = null;
private QName _qname;
public void reset() {
if (_attributes != null) _attributes.clear();
if (_namespaces != null) _namespaces.clear();
if (_context != null) _context = null;
}
public StartElementEvent() {
init();
}
public StartElementEvent(String prefix, String uri, String localpart) {
init();
if (uri == null) uri = "";
if (prefix == null) prefix ="";
_qname = new QName(uri, localpart, prefix);
setEventType(START_ELEMENT);
}
public StartElementEvent(QName qname) {
init();
_qname = qname;
}
public StartElementEvent(StartElement startelement) {
this(startelement.getName());
addAttributes(startelement.getAttributes());
addNamespaces(startelement.getNamespaces());
}
protected void init() {
setEventType(XMLStreamConstants.START_ELEMENT);
_attributes = new HashMap();
_namespaces = new ArrayList();
}
// ---------------------methods defined by StartElement-----------------//
/**
* Get the name of this event
* @return the qualified name of this event
*/
public QName getName() {
return _qname;
}
/**
* Returns an Iterator of non-namespace declared attributes
* returns an empty iterator if there are no attributes. The
* iterator must contain only implementations of the javax.xml.stream.Attribute
* interface. Attributes are fundamentally unordered and may not be reported
* in any order.
*
* @return a readonly Iterator over Attribute interfaces, or an
* empty iterator
*/
public Iterator getAttributes() {
if(_attributes != null){
Collection coll = _attributes.values();
return new ReadIterator(coll.iterator());
}
return EmptyIterator.getInstance();
}
/**
* Returns an Iterator of namespaces declared on this element.
* This Iterator does not contain previously declared namespaces
* unless they appear on the current START_ELEMENT.
* Therefore this list may contain redeclared namespaces and duplicate namespace
* declarations. Use the getNamespaceContext() method to get the
* current context of namespace declarations.
*
* <p>The iterator must contain only implementations of the
* javax.xml.stream.Namespace interface.
*
* <p>A Namespace is an Attribute. One
* can iterate over a list of namespaces as a list of attributes.
* However this method returns only the list of namespaces
* declared on this START_ELEMENT and does not
* include the attributes declared on this START_ELEMENT.
*
* @return a readonly Iterator over Namespace interfaces, or an
* empty iterator if there are no namespaces.
*
*/
public Iterator getNamespaces() {
if(_namespaces != null){
return new ReadIterator(_namespaces.iterator());
}
return EmptyIterator.getInstance();
}
/**
* Returns the attribute referred to by this name
* @param qname the qname of the desired name
* @return the attribute corresponding to the name value or null
*/
public Attribute getAttributeByName(QName qname) {
if(qname == null)
return null;
return (Attribute)_attributes.get(qname);
}
/** Gets a read-only namespace context. If no context is
* available this method will return an empty namespace context.
* The NamespaceContext contains information about all namespaces
* in scope for this StartElement.
*
* @return the current namespace context
*/
public NamespaceContext getNamespaceContext() {
return _context;
}
// ---------------------end of methods defined by StartElement-----------------//
public void setName(QName qname) {
this._qname = qname;
}
public String getNamespace(){
return _qname.getNamespaceURI();
}
/**
* Gets the value that the prefix is bound to in the
* context of this element. Returns null if
* the prefix is not bound in this context
* @param prefix the prefix to lookup
* @return the uri bound to the prefix or null
*/
public String getNamespaceURI(String prefix) {
//first check if the URI was supplied when creating this startElement event
if( getNamespace() != null ) return getNamespace();
//else check the namespace context
if(_context != null)
return _context.getNamespaceURI(prefix);
return null;
}
public String toString() {
final StringBuilder sb = new StringBuilder(64);
sb.append('<').append(nameAsString());
if(_attributes != null){
Iterator it = this.getAttributes();
Attribute attr = null;
while(it.hasNext()){
attr = (Attribute)it.next();
sb.append(' ').append(attr.toString());
}
}
if(_namespaces != null){
Iterator it = _namespaces.iterator();
Namespace attr = null;
while(it.hasNext()){
attr = (Namespace)it.next();
sb.append(' ').append(attr.toString());
}
}
sb.append('>');
return sb.toString();
}
/** Return this event as String
* @return String Event returned as string.
*/
public String nameAsString() {
if("".equals(_qname.getNamespaceURI()))
return _qname.getLocalPart();
if(_qname.getPrefix() != null)
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart();
else
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart();
}
public void setNamespaceContext(NamespaceContext context) {
_context = context;
}
public void addAttribute(Attribute attr){
_attributes.put(attr.getName(),attr);
}
public void addAttributes(Iterator attrs){
if(attrs != null) {
while(attrs.hasNext()){
Attribute attr = (Attribute)attrs.next();
_attributes.put(attr.getName(),attr);
}
}
}
public void addNamespace(Namespace namespace){
if(namespace != null) {
_namespaces.add(namespace);
}
}
public void addNamespaces(Iterator namespaces){
if(namespaces != null) {
while(namespaces.hasNext()){
Namespace namespace = (Namespace)namespaces.next();
_namespaces.add(namespace);
}
}
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
import javax.xml.stream.XMLStreamConstants;
/** A Utility class for the StAX Events implementation.
*/
public class Util {
/**
* A string is empty if it's null or contains nothing
*
* @param s The string to check.
*/
public static boolean isEmptyString(String s) {
if (s != null && !s.equals(""))
return false;
else
return true;
}
public final static String getEventTypeString(int eventType) {
switch (eventType){
case XMLStreamConstants.START_ELEMENT:
return "START_ELEMENT";
case XMLStreamConstants.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamConstants.CHARACTERS:
return "CHARACTERS";
case XMLStreamConstants.COMMENT:
return "COMMENT";
case XMLStreamConstants.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamConstants.END_DOCUMENT:
return "END_DOCUMENT";
case XMLStreamConstants.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamConstants.ATTRIBUTE:
return "ATTRIBUTE";
case XMLStreamConstants.DTD:
return "DTD";
case XMLStreamConstants.CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.stax.events;
public class XMLConstants {
public static final String ENCODING = "UTF-8";
public static final String XMLVERSION = "1.0";
}