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,123 @@
/*
* 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;
import javax.xml.stream.Location;
public class EventLocation implements Location{
String _systemId = null;
String _publicId = null;
int _column = -1;
int _line = -1;
int _charOffset = -1;
EventLocation() {
}
//explicitly create a nil location
public static Location getNilLocation() {
return new EventLocation();
}
/**
* Return the line number where the current event ends,
* returns -1 if none is available.
* @return the current line number
*/
public int getLineNumber(){
return _line;
}
/**
* Return the column number where the current event ends,
* returns -1 if none is available.
* @return the current column number
*/
public int getColumnNumber() {
return _column;
}
/**
* Return the byte or character offset into the input source this location
* is pointing to. If the input source is a file or a byte stream then
* this is the byte offset into that stream, but if the input source is
* a character media then the offset is the character offset.
* Returns -1 if there is no offset available.
* @return the current offset
*/
public int getCharacterOffset(){
return _charOffset;
}
/**
* Returns the public ID of the XML
* @return the public ID, or null if not available
*/
public String getPublicId(){
return _publicId;
}
/**
* Returns the system ID of the XML
* @return the system ID, or null if not available
*/
public String getSystemId(){
return _systemId;
}
public void setLineNumber(int line) {
_line = line;
}
public void setColumnNumber(int col) {
_column = col;
}
public void setCharacterOffset(int offset) {
_charOffset = offset;
}
public void setPublicId(String id) {
_publicId = id;
}
public void setSystemId(String id) {
_systemId = id;
}
public String toString(){
StringBuffer sbuffer = new StringBuffer() ;
sbuffer.append("Line number = " + _line);
sbuffer.append("\n") ;
sbuffer.append("Column number = " + _column);
sbuffer.append("\n") ;
sbuffer.append("System Id = " + _systemId);
sbuffer.append("\n") ;
sbuffer.append("Public Id = " + _publicId);
sbuffer.append("\n") ;
sbuffer.append("CharacterOffset = " + _charOffset);
sbuffer.append("\n") ;
return sbuffer.toString();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,856 @@
/*
* 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;
import com.sun.xml.internal.fastinfoset.Encoder;
import com.sun.xml.internal.fastinfoset.EncodingConstants;
import com.sun.xml.internal.fastinfoset.util.NamespaceContextImplementation;
import java.io.IOException;
import java.io.OutputStream;
import java.util.EmptyStackException;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
import com.sun.xml.internal.org.jvnet.fastinfoset.stax.LowLevelFastInfosetStreamWriter;
/**
* The Fast Infoset StAX serializer.
* <p>
* Instantiate this serializer to serialize a fast infoset document in accordance
* with the StAX API.
*
* <p>
* More than one fast infoset document may be encoded to the
* {@link java.io.OutputStream}.
*/
public class StAXDocumentSerializer extends Encoder
implements XMLStreamWriter, LowLevelFastInfosetStreamWriter {
protected StAXManager _manager;
protected String _encoding;
/**
* Local name of current element.
*/
protected String _currentLocalName;
/**
* Namespace of current element.
*/
protected String _currentUri;
/**
* Prefix of current element.
*/
protected String _currentPrefix;
/**
* This flag indicates when there is a pending start element event.
*/
protected boolean _inStartElement = false;
/**
* This flag indicates if the current element is empty.
*/
protected boolean _isEmptyElement = false;
/**
* List of attributes qnames and values defined in the current element.
*/
protected String[] _attributesArray = new String[4 * 16];
protected int _attributesArrayIndex = 0;
protected boolean[] _nsSupportContextStack = new boolean[32];
protected int _stackCount = -1;
/**
* Mapping between uris and prefixes.
*/
protected NamespaceContextImplementation _nsContext =
new NamespaceContextImplementation();
/**
* List of namespaces defined in the current element.
*/
protected String[] _namespacesArray = new String[2 * 8];
protected int _namespacesArrayIndex = 0;
public StAXDocumentSerializer() {
super(true);
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
}
public StAXDocumentSerializer(OutputStream outputStream) {
super(true);
setOutputStream(outputStream);
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
}
public StAXDocumentSerializer(OutputStream outputStream, StAXManager manager) {
super(true);
setOutputStream(outputStream);
_manager = manager;
}
public void reset() {
super.reset();
_attributesArrayIndex = 0;
_namespacesArrayIndex = 0;
_nsContext.reset();
_stackCount = -1;
_currentUri = _currentPrefix = null;
_currentLocalName = null;
_inStartElement = _isEmptyElement = false;
}
// -- XMLStreamWriter Interface -------------------------------------------
public void writeStartDocument() throws XMLStreamException {
writeStartDocument("finf", "1.0");
}
public void writeStartDocument(String version) throws XMLStreamException {
writeStartDocument("finf", version);
}
public void writeStartDocument(String encoding, String version)
throws XMLStreamException
{
reset();
try {
encodeHeader(false);
encodeInitialVocabulary();
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeEndDocument() throws XMLStreamException {
try {
// terminate all elements not terminated
// by writeEndElement
for(;_stackCount >= 0; _stackCount--) {
writeEndElement();
}
encodeDocumentTermination();
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void close() throws XMLStreamException {
reset();
}
public void flush() throws XMLStreamException {
try {
_s.flush();
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeStartElement(String localName)
throws XMLStreamException
{
// TODO is it necessary for FI to obtain the default namespace in scope?
writeStartElement("", localName, "");
}
public void writeStartElement(String namespaceURI, String localName)
throws XMLStreamException
{
writeStartElement("", localName, namespaceURI);
}
public void writeStartElement(String prefix, String localName,
String namespaceURI) throws XMLStreamException
{
encodeTerminationAndCurrentElement(false);
_inStartElement = true;
_isEmptyElement = false;
_currentLocalName = localName;
_currentPrefix = prefix;
_currentUri = namespaceURI;
_stackCount++;
if (_stackCount == _nsSupportContextStack.length) {
boolean[] nsSupportContextStack = new boolean[_stackCount * 2];
System.arraycopy(_nsSupportContextStack, 0, nsSupportContextStack, 0, _nsSupportContextStack.length);
_nsSupportContextStack = nsSupportContextStack;
}
_nsSupportContextStack[_stackCount] = false;
}
public void writeEmptyElement(String localName)
throws XMLStreamException
{
writeEmptyElement("", localName, "");
}
public void writeEmptyElement(String namespaceURI, String localName)
throws XMLStreamException
{
writeEmptyElement("", localName, namespaceURI);
}
public void writeEmptyElement(String prefix, String localName,
String namespaceURI) throws XMLStreamException
{
encodeTerminationAndCurrentElement(false);
_isEmptyElement = _inStartElement = true;
_currentLocalName = localName;
_currentPrefix = prefix;
_currentUri = namespaceURI;
_stackCount++;
if (_stackCount == _nsSupportContextStack.length) {
boolean[] nsSupportContextStack = new boolean[_stackCount * 2];
System.arraycopy(_nsSupportContextStack, 0, nsSupportContextStack, 0, _nsSupportContextStack.length);
_nsSupportContextStack = nsSupportContextStack;
}
_nsSupportContextStack[_stackCount] = false;
}
public void writeEndElement() throws XMLStreamException {
if (_inStartElement) {
encodeTerminationAndCurrentElement(false);
}
try {
encodeElementTermination();
if (_nsSupportContextStack[_stackCount--] == true) {
_nsContext.popContext();
}
}
catch (IOException e) {
throw new XMLStreamException(e);
}
catch (EmptyStackException e) {
throw new XMLStreamException(e);
}
}
public void writeAttribute(String localName, String value)
throws XMLStreamException
{
writeAttribute("", "", localName, value);
}
public void writeAttribute(String namespaceURI, String localName,
String value) throws XMLStreamException
{
String prefix = "";
// Find prefix for attribute, ignoring default namespace
if (namespaceURI.length() > 0) {
prefix = _nsContext.getNonDefaultPrefix(namespaceURI);
// Undeclared prefix or ignorable default ns?
if (prefix == null || prefix.length() == 0) {
// Workaround for BUG in SAX NamespaceSupport helper
// which incorrectly defines namespace declaration URI
if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
// TODO
// Need to check carefully the rule for the writing of
// namespaces in StAX. Is it safe to ignore such
// attributes, as declarations will be made using the
// writeNamespace method
return;
}
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.URIUnbound", new Object[]{namespaceURI}));
}
}
writeAttribute(prefix, namespaceURI, localName, value);
}
public void writeAttribute(String prefix, String namespaceURI,
String localName, String value) throws XMLStreamException
{
if (!_inStartElement) {
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
}
// TODO
// Need to check carefully the rule for the writing of
// namespaces in StAX. Is it safe to ignore such
// attributes, as declarations will be made using the
// writeNamespace method
if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
return;
}
if (_attributesArrayIndex == _attributesArray.length) {
final String[] attributesArray = new String[_attributesArrayIndex * 2];
System.arraycopy(_attributesArray, 0, attributesArray, 0, _attributesArrayIndex);
_attributesArray = attributesArray;
}
_attributesArray[_attributesArrayIndex++] = namespaceURI;
_attributesArray[_attributesArrayIndex++] = prefix;
_attributesArray[_attributesArrayIndex++] = localName;
_attributesArray[_attributesArrayIndex++] = value;
}
public void writeNamespace(String prefix, String namespaceURI)
throws XMLStreamException
{
if (prefix == null || prefix.length() == 0 || prefix.equals(EncodingConstants.XMLNS_NAMESPACE_PREFIX)) {
writeDefaultNamespace(namespaceURI);
}
else {
if (!_inStartElement) {
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
}
if (_namespacesArrayIndex == _namespacesArray.length) {
final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
_namespacesArray = namespacesArray;
}
_namespacesArray[_namespacesArrayIndex++] = prefix;
_namespacesArray[_namespacesArrayIndex++] = namespaceURI;
setPrefix(prefix, namespaceURI);
}
}
public void writeDefaultNamespace(String namespaceURI)
throws XMLStreamException
{
if (!_inStartElement) {
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
}
if (_namespacesArrayIndex == _namespacesArray.length) {
final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
_namespacesArray = namespacesArray;
}
_namespacesArray[_namespacesArrayIndex++] = "";
_namespacesArray[_namespacesArrayIndex++] = namespaceURI;
setPrefix("", namespaceURI);
}
public void writeComment(String data) throws XMLStreamException {
try {
if (getIgnoreComments()) return;
encodeTerminationAndCurrentElement(true);
// TODO: avoid array copy here
encodeComment(data.toCharArray(), 0, data.length());
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeProcessingInstruction(String target)
throws XMLStreamException
{
writeProcessingInstruction(target, "");
}
public void writeProcessingInstruction(String target, String data)
throws XMLStreamException
{
try {
if (getIgnoreProcesingInstructions()) return;
encodeTerminationAndCurrentElement(true);
encodeProcessingInstruction(target, data);
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeCData(String text) throws XMLStreamException {
try {
final int length = text.length();
if (length == 0) {
return;
} else if (length < _charBuffer.length) {
if (getIgnoreWhiteSpaceTextContent() &&
isWhiteSpace(text)) return;
// Warning: this method must be called before any state
// is modified, such as the _charBuffer contents,
// so the characters of text cannot be copied to _charBuffer
// before this call
encodeTerminationAndCurrentElement(true);
text.getChars(0, length, _charBuffer, 0);
encodeCIIBuiltInAlgorithmDataAsCDATA(_charBuffer, 0, length);
} else {
final char ch[] = text.toCharArray();
if (getIgnoreWhiteSpaceTextContent() &&
isWhiteSpace(ch, 0, length)) return;
encodeTerminationAndCurrentElement(true);
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, 0, length);
}
} catch (Exception e) {
throw new XMLStreamException(e);
}
}
public void writeDTD(String dtd) throws XMLStreamException {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
}
public void writeEntityRef(String name) throws XMLStreamException {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
}
public void writeCharacters(String text) throws XMLStreamException {
try {
final int length = text.length();
if (length == 0) {
return;
} else if (length < _charBuffer.length) {
if (getIgnoreWhiteSpaceTextContent() &&
isWhiteSpace(text)) return;
// Warning: this method must be called before any state
// is modified, such as the _charBuffer contents,
// so the characters of text cannot be copied to _charBuffer
// before this call
encodeTerminationAndCurrentElement(true);
text.getChars(0, length, _charBuffer, 0);
encodeCharacters(_charBuffer, 0, length);
} else {
final char ch[] = text.toCharArray();
if (getIgnoreWhiteSpaceTextContent() &&
isWhiteSpace(ch, 0, length)) return;
encodeTerminationAndCurrentElement(true);
encodeCharactersNoClone(ch, 0, length);
}
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeCharacters(char[] text, int start, int len)
throws XMLStreamException
{
try {
if (len <= 0) {
return;
}
if (getIgnoreWhiteSpaceTextContent() &&
isWhiteSpace(text, start, len)) return;
encodeTerminationAndCurrentElement(true);
encodeCharacters(text, start, len);
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
public String getPrefix(String uri) throws XMLStreamException {
return _nsContext.getPrefix(uri);
}
public void setPrefix(String prefix, String uri)
throws XMLStreamException
{
if (_stackCount > -1 && _nsSupportContextStack[_stackCount] == false) {
_nsSupportContextStack[_stackCount] = true;
_nsContext.pushContext();
}
_nsContext.declarePrefix(prefix, uri);
}
public void setDefaultNamespace(String uri) throws XMLStreamException {
setPrefix("", 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. This method may only be called once at the start of
* the document. It does not cause the namespaces to be declared.
* If a namespace URI to prefix mapping is found in the namespace
* context it is treated as declared and the prefix may be used
* by the StreamWriter.
* @param context the namespace context to use for this writer, may not be null
* @throws XMLStreamException
*/
public void setNamespaceContext(NamespaceContext context)
throws XMLStreamException
{
throw new UnsupportedOperationException("setNamespaceContext");
}
public NamespaceContext getNamespaceContext() {
return _nsContext;
}
public Object getProperty(java.lang.String name)
throws IllegalArgumentException
{
if (_manager != null) {
return _manager.getProperty(name);
}
return null;
}
public void setManager(StAXManager manager) {
_manager = manager;
}
public void setEncoding(String encoding) {
_encoding = encoding;
}
public void writeOctets(byte[] b, int start, int len)
throws XMLStreamException
{
try {
if (len == 0) {
return;
}
encodeTerminationAndCurrentElement(true);
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, b, start, len);
}
catch (IOException e) {
throw new XMLStreamException(e);
}
}
protected void encodeTerminationAndCurrentElement(boolean terminateAfter) throws XMLStreamException {
try {
encodeTermination();
if (_inStartElement) {
_b = EncodingConstants.ELEMENT;
if (_attributesArrayIndex > 0) {
_b |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
}
// Encode namespace decls associated with this element
if (_namespacesArrayIndex > 0) {
write(_b | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
for (int i = 0; i < _namespacesArrayIndex;) {
encodeNamespaceAttribute(_namespacesArray[i++], _namespacesArray[i++]);
}
_namespacesArrayIndex = 0;
write(EncodingConstants.TERMINATOR);
_b = 0;
}
// If element's prefix is empty - apply default scope namespace
if (_currentPrefix.length() == 0) {
if (_currentUri.length() == 0) {
_currentUri = _nsContext.getNamespaceURI("");
} else {
String tmpPrefix = getPrefix(_currentUri);
if (tmpPrefix != null) {
_currentPrefix = tmpPrefix;
}
}
}
encodeElementQualifiedNameOnThirdBit(_currentUri, _currentPrefix, _currentLocalName);
for (int i = 0; i < _attributesArrayIndex;) {
encodeAttributeQualifiedNameOnSecondBit(
_attributesArray[i++], _attributesArray[i++], _attributesArray[i++]);
final String value = _attributesArray[i];
_attributesArray[i++] = null;
final boolean addToTable = isAttributeValueLengthMatchesLimit(value.length());
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
_b = EncodingConstants.TERMINATOR;
_terminate = true;
}
_attributesArrayIndex = 0;
_inStartElement = false;
if (_isEmptyElement) {
encodeElementTermination();
if (_nsSupportContextStack[_stackCount--] == true) {
_nsContext.popContext();
}
_isEmptyElement = false;
}
if (terminateAfter) {
encodeTermination();
}
}
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
// LowLevelFastInfosetSerializer
public final void initiateLowLevelWriting() throws XMLStreamException {
encodeTerminationAndCurrentElement(false);
}
public final int getNextElementIndex() {
return _v.elementName.getNextIndex();
}
public final int getNextAttributeIndex() {
return _v.attributeName.getNextIndex();
}
public final int getLocalNameIndex() {
return _v.localName.getIndex();
}
public final int getNextLocalNameIndex() {
return _v.localName.getNextIndex();
}
public final void writeLowLevelTerminationAndMark() throws IOException {
encodeTermination();
mark();
}
public final void writeLowLevelStartElementIndexed(int type, int index) throws IOException {
_b = type;
encodeNonZeroIntegerOnThirdBit(index);
}
public final boolean writeLowLevelStartElement(int type, String prefix, String localName,
String namespaceURI) throws IOException {
final boolean isIndexed = encodeElement(type, namespaceURI, prefix, localName);
if (!isIndexed)
encodeLiteral(type | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG,
namespaceURI, prefix, localName);
return isIndexed;
}
public final void writeLowLevelStartNamespaces() throws IOException {
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
}
public final void writeLowLevelNamespace(String prefix, String namespaceName)
throws IOException {
encodeNamespaceAttribute(prefix, namespaceName);
}
public final void writeLowLevelEndNamespaces() throws IOException {
write(EncodingConstants.TERMINATOR);
}
public final void writeLowLevelStartAttributes() throws IOException {
if (hasMark()) {
_octetBuffer[_markIndex] |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
resetMark();
}
}
public final void writeLowLevelAttributeIndexed(int index) throws IOException {
encodeNonZeroIntegerOnSecondBitFirstBitZero(index);
}
public final boolean writeLowLevelAttribute(String prefix, String namespaceURI, String localName) throws IOException {
final boolean isIndexed = encodeAttribute(namespaceURI, prefix, localName);
if (!isIndexed)
encodeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
namespaceURI, prefix, localName);
return isIndexed;
}
public final void writeLowLevelAttributeValue(String value) throws IOException
{
final boolean addToTable = isAttributeValueLengthMatchesLimit(value.length());
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
}
public final void writeLowLevelStartNameLiteral(int type, String prefix, byte[] utf8LocalName,
String namespaceURI) throws IOException {
encodeLiteralHeader(type, namespaceURI, prefix);
encodeNonZeroOctetStringLengthOnSecondBit(utf8LocalName.length);
write(utf8LocalName, 0, utf8LocalName.length);
}
public final void writeLowLevelStartNameLiteral(int type, String prefix, int localNameIndex,
String namespaceURI) throws IOException {
encodeLiteralHeader(type, namespaceURI, prefix);
encodeNonZeroIntegerOnSecondBitFirstBitOne(localNameIndex);
}
public final void writeLowLevelEndStartElement() throws IOException {
if (hasMark()) {
resetMark();
} else {
// Terminate the attributes
_b = EncodingConstants.TERMINATOR;
_terminate = true;
}
}
public final void writeLowLevelEndElement() throws IOException {
encodeElementTermination();
}
public final void writeLowLevelText(char[] text, int length) throws IOException {
if (length == 0)
return;
encodeTermination();
encodeCharacters(text, 0, length);
}
public final void writeLowLevelText(String text) throws IOException {
final int length = text.length();
if (length == 0)
return;
encodeTermination();
if (length < _charBuffer.length) {
text.getChars(0, length, _charBuffer, 0);
encodeCharacters(_charBuffer, 0, length);
} else {
final char ch[] = text.toCharArray();
encodeCharactersNoClone(ch, 0, length);
}
}
public final void writeLowLevelOctets(byte[] octets, int length) throws IOException {
if (length == 0)
return;
encodeTermination();
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, octets, 0, length);
}
private boolean encodeElement(int type, String namespaceURI, String prefix, String localName) throws IOException {
final LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(localName);
for (int i = 0; i < entry._valueIndex; i++) {
final QualifiedName name = entry._value[i];
if ((prefix == name.prefix || prefix.equals(name.prefix))
&& (namespaceURI == name.namespaceName || namespaceURI.equals(name.namespaceName))) {
_b = type;
encodeNonZeroIntegerOnThirdBit(name.index);
return true;
}
}
entry.addQualifiedName(new QualifiedName(prefix, namespaceURI, localName, "", _v.elementName.getNextIndex()));
return false;
}
private boolean encodeAttribute(String namespaceURI, String prefix, String localName) throws IOException {
final LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(localName);
for (int i = 0; i < entry._valueIndex; i++) {
final QualifiedName name = entry._value[i];
if ((prefix == name.prefix || prefix.equals(name.prefix))
&& (namespaceURI == name.namespaceName || namespaceURI.equals(name.namespaceName))) {
encodeNonZeroIntegerOnSecondBitFirstBitZero(name.index);
return true;
}
}
entry.addQualifiedName(new QualifiedName(prefix, namespaceURI, localName, "", _v.attributeName.getNextIndex()));
return false;
}
private void encodeLiteralHeader(int type, String namespaceURI, String prefix) throws IOException {
if (namespaceURI != "") {
type |= EncodingConstants.LITERAL_QNAME_NAMESPACE_NAME_FLAG;
if (prefix != "")
type |= EncodingConstants.LITERAL_QNAME_PREFIX_FLAG;
write(type);
if (prefix != "")
encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.prefix.get(prefix));
encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.namespaceName.get(namespaceURI));
} else
write(type);
}
private void encodeLiteral(int type, String namespaceURI, String prefix, String localName) throws IOException {
encodeLiteralHeader(type, namespaceURI, prefix);
final int localNameIndex = _v.localName.obtainIndex(localName);
if (localNameIndex == -1) {
encodeNonEmptyOctetStringOnSecondBit(localName);
} else
encodeNonZeroIntegerOnSecondBitFirstBitOne(localNameIndex);
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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;
import java.util.HashMap;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXManager {
protected static final String STAX_NOTATIONS = "javax.xml.stream.notations";
protected static final String STAX_ENTITIES = "javax.xml.stream.entities";
HashMap features = new HashMap();
public static final int CONTEXT_READER = 1;
public static final int CONTEXT_WRITER = 2;
/** Creates a new instance of StAXManager */
public StAXManager() {
}
public StAXManager(int context) {
switch(context){
case CONTEXT_READER:{
initConfigurableReaderProperties();
break;
}
case CONTEXT_WRITER:{
initWriterProps();
break;
}
}
}
public StAXManager(StAXManager manager){
HashMap properties = manager.getProperties();
features.putAll(properties);
}
private HashMap getProperties(){
return features ;
}
private void initConfigurableReaderProperties(){
//spec v1.0 default values
features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
features.put(XMLInputFactory.REPORTER, null);
features.put(XMLInputFactory.RESOLVER, null);
features.put(XMLInputFactory.ALLOCATOR, null);
features.put(STAX_NOTATIONS,null );
}
private void initWriterProps(){
features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE);
}
/**
* public void reset(){
* features.clear() ;
* }
*/
public boolean containsProperty(String property){
return features.containsKey(property) ;
}
public Object getProperty(String name){
checkProperty(name);
return features.get(name);
}
public void setProperty(String name, Object value){
checkProperty(name);
if (name.equals(XMLInputFactory.IS_VALIDATING) &&
Boolean.TRUE.equals(value)){
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.validationNotSupported") +
CommonResourceBundle.getInstance().getString("support_validation"));
} else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) &&
Boolean.TRUE.equals(value)) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.externalEntities") +
CommonResourceBundle.getInstance().getString("resolve_external_entities_"));
}
features.put(name,value);
}
public void checkProperty(String name) {
if (!features.containsKey(name))
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
}
public String toString(){
return features.toString();
}
}

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";
}

View File

@@ -0,0 +1,342 @@
/*
* 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.factory;
import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.events.*;
import java.util.Iterator;
import com.sun.xml.internal.fastinfoset.stax.events.*;
public class StAXEventFactory extends XMLEventFactory {
Location location = null;
/** Creates a new instance of StAXEventFactory */
public StAXEventFactory() {
}
/**
* This method allows setting of the Location on each event that
* is created by this factory. The values are copied by value into
* the events created by this factory. To reset the location
* information set the location to null.
* @param location the location to set on each event created
*/
public void setLocation(Location location) {
this.location = location;
}
/**
* Create a new Attribute
* @param prefix the prefix of this attribute, may not be null
* @param namespaceURI the attribute value is set to this value, may not be null
* @param localName the local name of the XML name of the attribute, localName cannot be null
* @param value the attribute value to set, may not be null
* @return the Attribute with specified values
*/
public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) {
AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null);
if(location != null)attr.setLocation(location);
return attr;
}
/**
* Create a new Attribute
* @param localName the local name of the XML name of the attribute, localName cannot be null
* @param value the attribute value to set, may not be null
* @return the Attribute with specified values
*/
public Attribute createAttribute(String localName, String value) {
AttributeBase attr = new AttributeBase(localName, value);
if(location != null)attr.setLocation(location);
return attr;
}
public Attribute createAttribute(QName name, String value) {
AttributeBase attr = new AttributeBase(name, value);
if(location != null)attr.setLocation(location);
return attr;
}
/**
* Create a new default Namespace
* @param namespaceURI the default namespace uri
* @return the Namespace with the specified value
*/
public Namespace createNamespace(String namespaceURI) {
NamespaceBase event = new NamespaceBase(namespaceURI);
if(location != null)event.setLocation(location);
return event;
}
/**
* Create a new Namespace
* @param prefix the prefix of this namespace, may not be null
* @param namespaceURI the attribute value is set to this value, may not be null
* @return the Namespace with the specified values
*/
public Namespace createNamespace(String prefix, String namespaceURI) {
NamespaceBase event = new NamespaceBase(prefix, namespaceURI);
if(location != null)event.setLocation(location);
return event;
}
/**
* Create a new StartElement.
* @param name the qualified name of the attribute, may not be null
* @param attributes an optional unordered set of objects that
* implement Attribute to add to the new StartElement, may be null
* @param namespaces an optional unordered set of objects that
* implement Namespace to add to the new StartElement, may be null
* @return an instance of the requested StartElement
*/
public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) {
return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces);
}
public StartElement createStartElement(String prefix, String namespaceUri, String localName) {
StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName);
if(location != null)event.setLocation(location);
return event;
}
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) {
return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null);
}
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) {
StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName);
elem.addAttributes(attributes);
elem.addNamespaces(namespaces);
elem.setNamespaceContext(context);
if(location != null)elem.setLocation(location);
return elem;
}
/**
* Create a new EndElement
* @param name the qualified name of the EndElement
* @param namespaces an optional unordered set of objects that
* implement Namespace that have gone out of scope, may be null
* @return an instance of the requested EndElement
*/
public EndElement createEndElement(QName name, Iterator namespaces) {
return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces);
}
/**
* Create a new EndElement
* @param namespaceUri the uri of the QName of the new StartElement
* @param localName the local name of the QName of the new StartElement
* @param prefix the prefix of the QName of the new StartElement
* @return an instance of the requested EndElement
*/
public EndElement createEndElement(String prefix, String namespaceUri, String localName) {
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
if(location != null)event.setLocation(location);
return event;
}
/**
* Create a new EndElement
* @param namespaceUri the uri of the QName of the new StartElement
* @param localName the local name of the QName of the new StartElement
* @param prefix the prefix of the QName of the new StartElement
* @param namespaces an unordered set of objects that implement
* Namespace that have gone out of scope, may be null
* @return an instance of the requested EndElement
*/
public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) {
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
if(namespaces!=null){
while(namespaces.hasNext())
event.addNamespace((Namespace)namespaces.next());
}
if(location != null)event.setLocation(location);
return event;
}
/**
* Create a Characters event, this method does not check if the content
* is all whitespace. To create a space event use #createSpace(String)
* @param content the string to create
* @return a Characters event
*/
public Characters createCharacters(String content) {
CharactersEvent charEvent = new CharactersEvent(content);
if(location != null)charEvent.setLocation(location);
return charEvent;
}
/**
* Create a Characters event with the CData flag set to true
* @param content the string to create
* @return a Characters event
*/
public Characters createCData(String content) {
CharactersEvent charEvent = new CharactersEvent(content, true);
if(location != null)charEvent.setLocation(location);
return charEvent;
}
/**
* Create a Characters event with the isSpace flag set to true
* @param content the content of the space to create
* @return a Characters event
*/
public Characters createSpace(String content) {
CharactersEvent event = new CharactersEvent(content);
event.setSpace(true);
if(location != null)event.setLocation(location);
return event;
}
/**
* Create an ignorable space
* @param content the space to create
* @return a Characters event
*/
public Characters createIgnorableSpace(String content) {
CharactersEvent event = new CharactersEvent(content, false);
event.setSpace(true);
event.setIgnorable(true);
if(location != null)event.setLocation(location);
return event;
}
/**
* Creates a new instance of a StartDocument event
* @return a StartDocument event
*/
public StartDocument createStartDocument() {
StartDocumentEvent event = new StartDocumentEvent();
if(location != null)event.setLocation(location);
return event;
}
/**
* Creates a new instance of a StartDocument event
*
* @param encoding the encoding style
* @return a StartDocument event
*/
public StartDocument createStartDocument(String encoding) {
StartDocumentEvent event = new StartDocumentEvent(encoding);
if(location != null)event.setLocation(location);
return event;
}
/**
* Creates a new instance of a StartDocument event
*
* @param encoding the encoding style
* @param version the XML version
* @return a StartDocument event
*/
public StartDocument createStartDocument(String encoding, String version) {
StartDocumentEvent event = new StartDocumentEvent(encoding, version);
if(location != null)event.setLocation(location);
return event;
}
/**
* Creates a new instance of a StartDocument event
*
* @param encoding the encoding style
* @param version the XML version
* @param standalone the status of standalone may be set to "true" or "false"
* @return a StartDocument event
*/
public StartDocument createStartDocument(String encoding, String version, boolean standalone) {
StartDocumentEvent event = new StartDocumentEvent(encoding, version);
event.setStandalone(standalone);
if(location != null)event.setLocation(location);
return event;
}
public EndDocument createEndDocument() {
EndDocumentEvent event =new EndDocumentEvent();
if(location != null)event.setLocation(location);
return event;
}
/** Creates a new instance of a EntityReference event
*
* @param name The name of the reference
* @param entityDeclaration the declaration for the event
* @return an EntityReference event
*/
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
if(location != null)event.setLocation(location);
return event;
}
/**
* Create a comment
* @param text The text of the comment
* a Comment event
*/
public Comment createComment(String text) {
CommentEvent charEvent = new CommentEvent(text);
if(location != null)charEvent.setLocation(location);
return charEvent;
}
/**
* Create a document type definition event
* This string contains the entire document type declaration that matches
* the doctypedecl in the XML 1.0 specification
* @param dtd the text of the document type definition
* @return a DTD event
*/
public DTD createDTD(String dtd) {
DTDEvent dtdEvent = new DTDEvent(dtd);
if(location != null)dtdEvent.setLocation(location);
return dtdEvent;
}
/**
* Create a processing instruction
* @param target The target of the processing instruction
* @param data The text of the processing instruction
* @return a ProcessingInstruction event
*/
public ProcessingInstruction createProcessingInstruction(String target, String data) {
ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data);
if(location != null)event.setLocation(location);
return event;
}
}

View File

@@ -0,0 +1,256 @@
/*
* 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.factory;
import com.sun.xml.internal.fastinfoset.stax.*;
import com.sun.xml.internal.fastinfoset.stax.events.StAXEventReader;
import com.sun.xml.internal.fastinfoset.stax.events.StAXFilteredEvent;
import com.sun.xml.internal.fastinfoset.stax.util.StAXFilteredParser;
import com.sun.xml.internal.fastinfoset.tools.XML_SAX_FI;
import java.io.InputStream;
import java.io.Reader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import javax.xml.stream.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.util.XMLEventAllocator ;
import javax.xml.transform.Source;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXInputFactory extends XMLInputFactory {
//List of supported properties and default values.
private StAXManager _manager = new StAXManager(StAXManager.CONTEXT_READER) ;
public StAXInputFactory() {
}
public static XMLInputFactory newInstance() {
return XMLInputFactory.newInstance();
}
/**
* Create a new XMLStreamReader from a reader
* @param xmlfile the XML data to read from
* @throws XMLStreamException
*/
public XMLStreamReader createXMLStreamReader(Reader xmlfile) throws XMLStreamException {
return getXMLStreamReader(xmlfile);
}
public XMLStreamReader createXMLStreamReader(InputStream s) throws XMLStreamException {
return new StAXDocumentParser(s, _manager);
}
public XMLStreamReader createXMLStreamReader(String systemId, Reader xmlfile) throws XMLStreamException {
return getXMLStreamReader(xmlfile);
}
public XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException {
return null;
}
public XMLStreamReader createXMLStreamReader(String systemId, InputStream inputstream) throws XMLStreamException {
return createXMLStreamReader(inputstream);
}
public XMLStreamReader createXMLStreamReader(InputStream inputstream, String encoding) throws XMLStreamException {
return createXMLStreamReader(inputstream);
}
XMLStreamReader getXMLStreamReader(String systemId, InputStream inputstream, String encoding)
throws XMLStreamException{
return createXMLStreamReader(inputstream);
}
/**
* @param inputstream
* @throws XMLStreamException
* @return
*/
XMLStreamReader getXMLStreamReader(Reader xmlfile)
throws XMLStreamException{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedStream = new BufferedOutputStream(byteStream);
StAXDocumentParser sr = null;
try {
XML_SAX_FI convertor = new XML_SAX_FI();
convertor.convert(xmlfile, bufferedStream);
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteStream.toByteArray());
InputStream document = new BufferedInputStream(byteInputStream);
sr = new StAXDocumentParser();
sr.setInputStream(document);
sr.setManager(_manager);
return sr;
//return new StAXDocumentParser(document, _manager);
} catch (Exception e) {
return null;
}
}
/**
* @param inputstream
* @throws XMLStreamException
* @return XMLEventReader
*/
public XMLEventReader createXMLEventReader(InputStream inputstream) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(inputstream));
}
public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(reader));
}
public XMLEventReader createXMLEventReader(Source source) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(source));
}
public XMLEventReader createXMLEventReader(String systemId, InputStream inputstream) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(systemId, inputstream));
}
public XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(stream, encoding));
}
public XMLEventReader createXMLEventReader(String systemId, Reader reader) throws XMLStreamException {
return new StAXEventReader(createXMLStreamReader(systemId, reader));
}
/** Create a new XMLEventReader from an XMLStreamReader. After being used
* to construct the XMLEventReader instance returned from this method
* the XMLStreamReader must not be used.
* @param streamReader the XMLStreamReader to read from (may not be modified)
* @return a new XMLEventReader
* @throws XMLStreamException
*/
public XMLEventReader createXMLEventReader(XMLStreamReader streamReader) throws XMLStreamException {
return new StAXEventReader(streamReader);
}
public XMLEventAllocator getEventAllocator() {
return (XMLEventAllocator)getProperty(XMLInputFactory.ALLOCATOR);
}
public XMLReporter getXMLReporter() {
return (XMLReporter)_manager.getProperty(XMLInputFactory.REPORTER);
}
public XMLResolver getXMLResolver() {
Object object = _manager.getProperty(XMLInputFactory.RESOLVER);
return (XMLResolver)object;
//return (XMLResolver)_manager.getProperty(XMLInputFactory.RESOLVER);
}
public void setXMLReporter(XMLReporter xmlreporter) {
_manager.setProperty(XMLInputFactory.REPORTER, xmlreporter);
}
public void setXMLResolver(XMLResolver xmlresolver) {
_manager.setProperty(XMLInputFactory.RESOLVER, xmlresolver);
}
/** Create a filtered event reader that wraps the filter around the event reader
* @param reader the event reader to wrap
* @param filter the filter to apply to the event reader
* @throws XMLStreamException
*/
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException {
return new StAXFilteredEvent(reader, filter);
}
/** Create a filtered reader that wraps the filter around the reader
* @param reader the reader to filter
* @param filter the filter to apply to the reader
* @throws XMLStreamException
*/
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException {
if( reader != null && filter != null )
return new StAXFilteredParser(reader,filter);
return null;
}
/** Get the value of a feature/property from the underlying implementation
* @param name The name of the property (may not be null)
* @return The value of the property
* @throws IllegalArgumentException if the property is not supported
*/
public Object getProperty(String name) throws IllegalArgumentException {
if(name == null){
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullPropertyName"));
}
if(_manager.containsProperty(name))
return _manager.getProperty(name);
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
}
/** Query the set of Properties that this factory supports.
*
* @param name The name of the property (may not be null)
* @return true if the property is supported and false otherwise
*/
public boolean isPropertySupported(String name) {
if(name == null)
return false ;
else
return _manager.containsProperty(name);
}
/** Set a user defined event allocator for events
* @param allocator the user defined allocator
*/
public void setEventAllocator(XMLEventAllocator allocator) {
_manager.setProperty(XMLInputFactory.ALLOCATOR, allocator);
}
/** Allows the user to set specific feature/property on the underlying implementation. The underlying implementation
* is not required to support every setting of every property in the specification and may use IllegalArgumentException
* to signal that an unsupported property may not be set with the specified value.
* @param name The name of the property (may not be null)
* @param value The value of the property
* @throws IllegalArgumentException if the property is not supported
*/
public void setProperty(String name, Object value) throws IllegalArgumentException {
_manager.setProperty(name,value);
}
}

View File

@@ -0,0 +1,162 @@
/*
* 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.factory;
import com.sun.xml.internal.fastinfoset.stax.*;
import com.sun.xml.internal.fastinfoset.stax.events.StAXEventWriter;
import javax.xml.transform.Result;
import javax.xml.stream.XMLOutputFactory ;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXOutputFactory extends XMLOutputFactory {
//List of supported properties and default values.
private StAXManager _manager = null ;
/** Creates a new instance of StAXOutputFactory */
public StAXOutputFactory() {
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
}
public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
return new StAXEventWriter(createXMLStreamWriter(result));
}
public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException {
return new StAXEventWriter(createXMLStreamWriter(writer));
}
public XMLEventWriter createXMLEventWriter(OutputStream outputStream) throws XMLStreamException {
return new StAXEventWriter(createXMLStreamWriter(outputStream));
}
public XMLEventWriter createXMLEventWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
return new StAXEventWriter(createXMLStreamWriter(outputStream, encoding));
}
public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
if (result instanceof StreamResult) {
StreamResult streamResult = (StreamResult) result;
if (streamResult.getWriter() != null) {
return createXMLStreamWriter(streamResult.getWriter());
} else if (streamResult.getOutputStream() != null) {
return createXMLStreamWriter(streamResult.getOutputStream());
} else if (streamResult.getSystemId() != null) {
FileWriter writer = null;
boolean isError = true;
try {
writer = new FileWriter(new File(streamResult.getSystemId()));
final XMLStreamWriter streamWriter = createXMLStreamWriter(writer);
isError = false;
return streamWriter;
} catch (IOException ie) {
throw new XMLStreamException(ie);
} finally {
if (isError && writer != null) {
try {
writer.close();
} catch (IOException ignored) {
}
}
}
}
} else {
FileWriter writer = null;
boolean isError = true;
try {
//xxx: should we be using FileOutputStream - nb.
writer = new FileWriter(new File(result.getSystemId()));
final XMLStreamWriter streamWriter = createXMLStreamWriter(writer);
isError = false;
return streamWriter;
} catch (IOException ie) {
throw new XMLStreamException(ie);
} finally {
if (isError && writer != null) {
try {
writer.close();
} catch (IOException ignored) {
}
}
}
}
throw new java.lang.UnsupportedOperationException();
}
/** this is assumed that user wants to write the file in xml format
*
*/
public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
throw new java.lang.UnsupportedOperationException();
}
public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream) throws XMLStreamException {
return new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
}
public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
StAXDocumentSerializer serializer = new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
serializer.setEncoding(encoding);
return serializer;
}
public Object getProperty(String name) throws java.lang.IllegalArgumentException {
if(name == null){
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{null}));
}
if(_manager.containsProperty(name))
return _manager.getProperty(name);
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
}
public boolean isPropertySupported(String name) {
if(name == null)
return false ;
else
return _manager.containsProperty(name);
}
public void setProperty(String name, Object value) throws java.lang.IllegalArgumentException {
_manager.setProperty(name,value);
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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.util;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.StreamFilter;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAXFilteredParser extends StAXParserWrapper {
private StreamFilter _filter;
/** Creates a new instance of StAXFilteredParser */
public StAXFilteredParser() {
}
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
super(reader);
_filter = filter;
}
public void setFilter(StreamFilter filter) {
_filter = filter;
}
public int next() throws XMLStreamException
{
if (hasNext())
return super.next();
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.noMoreItems"));
}
public boolean hasNext() throws XMLStreamException
{
while (super.hasNext()) {
if (_filter.accept(getReader())) return true;
super.next();
}
return false;
}
}

View File

@@ -0,0 +1,236 @@
/*
* 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.util;
import javax.xml.namespace.QName;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
public class StAXParserWrapper implements XMLStreamReader{
private XMLStreamReader _reader;
/** Creates a new instance of StAXParserWrapper */
public StAXParserWrapper() {
}
public StAXParserWrapper(XMLStreamReader reader) {
_reader = reader;
}
public void setReader(XMLStreamReader reader) {
_reader = reader;
}
public XMLStreamReader getReader() {
return _reader;
}
public int next() throws XMLStreamException
{
return _reader.next();
}
public int nextTag() throws XMLStreamException
{
return _reader.nextTag();
}
public String getElementText() throws XMLStreamException
{
return _reader.getElementText();
}
public void require(int type, String namespaceURI, String localName) throws XMLStreamException
{
_reader.require(type,namespaceURI,localName);
}
public boolean hasNext() throws XMLStreamException
{
return _reader.hasNext();
}
public void close() throws XMLStreamException
{
_reader.close();
}
public String getNamespaceURI(String prefix)
{
return _reader.getNamespaceURI(prefix);
}
public NamespaceContext getNamespaceContext() {
return _reader.getNamespaceContext();
}
public boolean isStartElement() {
return _reader.isStartElement();
}
public boolean isEndElement() {
return _reader.isEndElement();
}
public boolean isCharacters() {
return _reader.isCharacters();
}
public boolean isWhiteSpace() {
return _reader.isWhiteSpace();
}
public QName getAttributeName(int index) {
return _reader.getAttributeName(index);
}
public int getTextCharacters(int sourceStart, char[] target, int targetStart,
int length) throws XMLStreamException
{
return _reader.getTextCharacters(sourceStart, target, targetStart, length);
}
public String getAttributeValue(String namespaceUri,
String localName)
{
return _reader.getAttributeValue(namespaceUri,localName);
}
public int getAttributeCount() {
return _reader.getAttributeCount();
}
public String getAttributePrefix(int index) {
return _reader.getAttributePrefix(index);
}
public String getAttributeNamespace(int index) {
return _reader.getAttributeNamespace(index);
}
public String getAttributeLocalName(int index) {
return _reader.getAttributeLocalName(index);
}
public String getAttributeType(int index) {
return _reader.getAttributeType(index);
}
public String getAttributeValue(int index) {
return _reader.getAttributeValue(index);
}
public boolean isAttributeSpecified(int index) {
return _reader.isAttributeSpecified(index);
}
public int getNamespaceCount() {
return _reader.getNamespaceCount();
}
public String getNamespacePrefix(int index) {
return _reader.getNamespacePrefix(index);
}
public String getNamespaceURI(int index) {
return _reader.getNamespaceURI(index);
}
public int getEventType() {
return _reader.getEventType();
}
public String getText() {
return _reader.getText();
}
public char[] getTextCharacters() {
return _reader.getTextCharacters();
}
public int getTextStart() {
return _reader.getTextStart();
}
public int getTextLength() {
return _reader.getTextLength();
}
public String getEncoding() {
return _reader.getEncoding();
}
public boolean hasText() {
return _reader.hasText();
}
public Location getLocation() {
return _reader.getLocation();
}
public QName getName() {
return _reader.getName();
}
public String getLocalName() {
return _reader.getLocalName();
}
public boolean hasName() {
return _reader.hasName();
}
public String getNamespaceURI() {
return _reader.getNamespaceURI();
}
public String getPrefix() {
return _reader.getPrefix();
}
public String getVersion() {
return _reader.getVersion();
}
public boolean isStandalone() {
return _reader.isStandalone();
}
public boolean standaloneSet() {
return _reader.standaloneSet();
}
public String getCharacterEncodingScheme() {
return _reader.getCharacterEncodingScheme();
}
public String getPITarget() {
return _reader.getPITarget();
}
public String getPIData() {
return _reader.getPIData();
}
public Object getProperty(String name) {
return _reader.getProperty(name);
}
}