pax_global_header 0000666 0000000 0000000 00000000064 12263200227 0014506 g ustar 00root root 0000000 0000000 52 comment=7f8125d8bdbcf21cfd409b0c33eaa9aeac033058
xmlstreambuffer-1.5.1/ 0000775 0000000 0000000 00000000000 12263200227 0014720 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/docs/ 0000775 0000000 0000000 00000000000 12263200227 0015650 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/docs/manifest/ 0000775 0000000 0000000 00000000000 12263200227 0017456 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/docs/manifest/manifest.mf 0000664 0000000 0000000 00000000407 12263200227 0021611 0 ustar 00root root 0000000 0000000 Manifest-Version: 1.0
Implementation-Title: XML Stream Buffer Implementation
Implementation-Version: @@IMPL_VERSION@@
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: @@VENDOR_ID@@
Extension-Name: @@EXTENSION_NAME@@
Build-Id: @@BUILD_ID@@
xmlstreambuffer-1.5.1/nbproject/ 0000775 0000000 0000000 00000000000 12263200227 0016706 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/nbproject/build-impl.xml 0000664 0000000 0000000 00000063570 12263200227 0021501 0 ustar 00root root 0000000 0000000
Must set src.dir
Must set test.src.dir
Must set build.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.jar
Must select some files in the IDE or set javac.includes
To run this application from the command line without Ant, try:
java -cp "${run.classpath.with.dist.jar}" ${main.class}
To run this application from the command line without Ant, try:
java -jar "${dist.jar.resolved}"
Must select one file in the IDE or set run.class
Must select one file in the IDE or set debug.class
Must set fix.includes
Must select some files in the IDE or set javac.includes
Some tests failed; see details above.
Must select some files in the IDE or set test.includes
Some tests failed; see details above.
Must select one file in the IDE or set test.class
Must select one file in the IDE or set applet.url
Must select one file in the IDE or set applet.url
xmlstreambuffer-1.5.1/nbproject/genfiles.properties 0000664 0000000 0000000 00000000677 12263200227 0022632 0 ustar 00root root 0000000 0000000 build.xml.data.CRC32=d6b9b3a0
build.xml.script.CRC32=686dbc1d
build.xml.stylesheet.CRC32=d5b6853a
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=d6b9b3a0
nbproject/build-impl.xml.script.CRC32=87cc9298
nbproject/build-impl.xml.stylesheet.CRC32=99b91518
xmlstreambuffer-1.5.1/nbproject/project.properties 0000664 0000000 0000000 00000004625 12263200227 0022501 0 ustar 00root root 0000000 0000000 application.args=
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/streambuffer.jar
dist.javadoc.dir=${dist.dir}/javadoc
file.reference.activation.jar=lib/activation.jar
file.reference.jsr173_1.0_src.zip=lib/jsr173_1.0_src.zip
file.reference.jsr173_api.jar=lib/jsr173_api.jar
file.reference.sjsxp-src.zip=lib/sjsxp-src.zip
file.reference.sjsxp.jar=lib/sjsxp.jar
file.reference.woodstox-src.zip=lib/woodstox-src.zip
file.reference.woodstox.jar=lib/woodstox.jar
file.reference.stax-ex-src.zip=lib/stax-ex-src.zip
file.reference.stax-ex.jar=lib/stax-ex.jar
jar.compress=false
javac.classpath=\
${file.reference.jsr173_1.0_src.zip}:\
${file.reference.jsr173_api.jar}:\
${file.reference.activation.jar}:\
${file.reference.woodstox-src.zip}:\
${file.reference.woodstox.jar}:\
${file.reference.sjsxp-src.zip}:\
${file.reference.sjsxp.jar}:\
${file.reference.stax-ex-src.zip}:\
${file.reference.stax-ex.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}:\
${file.reference.sjsxp.jar}
src.dir=src
test.src.dir=test
xmlstreambuffer-1.5.1/nbproject/project.xml 0000664 0000000 0000000 00000001066 12263200227 0021101 0 ustar 00root root 0000000 0000000
org.netbeans.modules.java.j2seproject
streambuffer
1.6.5
xmlstreambuffer-1.5.1/pom.xml 0000664 0000000 0000000 00000015121 12263200227 0016235 0 ustar 00root root 0000000 0000000
net.java
jvnet-parent
3
4.0.0
com.sun.xml.stream.buffer
streambuffer
1.5.1
jar
xmlstreambuffer
2006
Stream based representation for XML infoset
http://xmlstreambuffer.java.net/
scm:svn:https://svn.java.net/svn/xmlstreambuffer~svn/tags/streambuffer-1.5.1
scm:svn:https://svn.java.net/svn/xmlstreambuffer~svn/tags/streambuffer-1.5.1
http://java.net/projects/xmlstreambuffer/sources/svn/show/tags/streambuffer-1.5.1
Dual license consisting of the CDDL v1.1 and GPL v2
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
repo
Jitendra Kotamraju
jitendra.kotamraju@oracle.com
Oracle Corporation
Rama Pulavarthi
rama.pulavarthi@oracle.com
Oracle Corporation
Martin Grebac
martin.grebac@oracle.com
Oracle Corporation
javax.xml.stream
stax-api
1.0-2
org.jvnet.staxex
stax-ex
1.7.1
javax.activation
activation
1.1
junit
junit
3.8
test
org.codehaus.woodstox
wstx-asl
3.2.1
test
src
test
org.apache.maven.plugins
maven-compiler-plugin
2.5.1
1.5
1.5
org.apache.maven.plugins
maven-release-plugin
forked-path
false
${release.arguments}
org.apache.maven.plugins
maven-surefire-plugin
2.9
test
org.codehaus.mojo
findbugs-maven-plugin
2.5.2
xmlstreambuffer-1.5.1/src/ 0000775 0000000 0000000 00000000000 12263200227 0015507 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/ 0000775 0000000 0000000 00000000000 12263200227 0016265 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/ 0000775 0000000 0000000 00000000000 12263200227 0017072 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/ 0000775 0000000 0000000 00000000000 12263200227 0017672 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/stream/ 0000775 0000000 0000000 00000000000 12263200227 0021165 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/ 0000775 0000000 0000000 00000000000 12263200227 0022436 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/AbstractCreator.java 0000664 0000000 0000000 00000020251 12263200227 0026364 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
/**
* Base class for classes that creates {@link MutableXMLStreamBuffer}
* and from infoset in API-specific form.
*/
public class AbstractCreator extends AbstractCreatorProcessor {
protected MutableXMLStreamBuffer _buffer;
public void setXMLStreamBuffer(MutableXMLStreamBuffer buffer) {
if (buffer == null) {
throw new NullPointerException("buffer cannot be null");
}
setBuffer(buffer);
}
public MutableXMLStreamBuffer getXMLStreamBuffer() {
return _buffer;
}
protected final void createBuffer() {
setBuffer(new MutableXMLStreamBuffer());
}
/**
* Should be called whenever a new tree is stored on the buffer.
*/
protected final void increaseTreeCount() {
_buffer.treeCount++;
}
protected final void setBuffer(MutableXMLStreamBuffer buffer) {
_buffer = buffer;
_currentStructureFragment = _buffer.getStructure();
_structure = _currentStructureFragment.getArray();
_structurePtr = 0;
_currentStructureStringFragment = _buffer.getStructureStrings();
_structureStrings = _currentStructureStringFragment.getArray();
_structureStringsPtr = 0;
_currentContentCharactersBufferFragment = _buffer.getContentCharactersBuffer();
_contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray();
_contentCharactersBufferPtr = 0;
_currentContentObjectFragment = _buffer.getContentObjects();
_contentObjects = _currentContentObjectFragment.getArray();
_contentObjectsPtr = 0;
}
protected final void setHasInternedStrings(boolean hasInternedStrings) {
_buffer.setHasInternedStrings(hasInternedStrings);
}
protected final void storeStructure(int b) {
_structure[_structurePtr++] = (byte)b;
if (_structurePtr == _structure.length) {
resizeStructure();
}
}
protected final void resizeStructure() {
_structurePtr = 0;
if (_currentStructureFragment.getNext() != null) {
_currentStructureFragment = _currentStructureFragment.getNext();
_structure = _currentStructureFragment.getArray();
} else {
_structure = new byte[_structure.length];
_currentStructureFragment = new FragmentedArray(_structure, _currentStructureFragment);
}
}
protected final void storeStructureString(String s) {
_structureStrings[_structureStringsPtr++] = s;
if (_structureStringsPtr == _structureStrings.length) {
resizeStructureStrings();
}
}
protected final void resizeStructureStrings() {
_structureStringsPtr = 0;
if (_currentStructureStringFragment.getNext() != null) {
_currentStructureStringFragment = _currentStructureStringFragment.getNext();
_structureStrings = _currentStructureStringFragment.getArray();
} else {
_structureStrings = new String[_structureStrings.length];
_currentStructureStringFragment = new FragmentedArray(_structureStrings, _currentStructureStringFragment);
}
}
protected final void storeContentString(String s) {
storeContentObject(s);
}
protected final void storeContentCharacters(int type, char[] ch, int start, int length) {
if (_contentCharactersBufferPtr + length >= _contentCharactersBuffer.length) {
if (length >= 512) {
storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY);
storeContentCharactersCopy(ch, start, length);
return;
}
resizeContentCharacters();
}
if (length < CHAR_ARRAY_LENGTH_SMALL_SIZE) {
storeStructure(type);
storeStructure(length);
System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length);
_contentCharactersBufferPtr += length;
} else if (length < CHAR_ARRAY_LENGTH_MEDIUM_SIZE) {
storeStructure(type | CHAR_ARRAY_LENGTH_MEDIUM);
storeStructure(length >> 8);
storeStructure(length & 255);
System.arraycopy(ch, start, _contentCharactersBuffer, _contentCharactersBufferPtr, length);
_contentCharactersBufferPtr += length;
} else {
storeStructure(type | CONTENT_TYPE_CHAR_ARRAY_COPY);
storeContentCharactersCopy(ch, start, length);
}
}
protected final void resizeContentCharacters() {
_contentCharactersBufferPtr = 0;
if (_currentContentCharactersBufferFragment.getNext() != null) {
_currentContentCharactersBufferFragment = _currentContentCharactersBufferFragment.getNext();
_contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray();
} else {
_contentCharactersBuffer = new char[_contentCharactersBuffer.length];
_currentContentCharactersBufferFragment = new FragmentedArray(_contentCharactersBuffer,
_currentContentCharactersBufferFragment);
}
}
protected final void storeContentCharactersCopy(char[] ch, int start, int length) {
char[] copyOfCh = new char[length];
System.arraycopy(ch, start, copyOfCh, 0, length);
storeContentObject(copyOfCh);
}
protected final Object peekAtContentObject() {
return _contentObjects[_contentObjectsPtr];
}
protected final void storeContentObject(Object s) {
_contentObjects[_contentObjectsPtr++] = s;
if (_contentObjectsPtr == _contentObjects.length) {
resizeContentObjects();
}
}
protected final void resizeContentObjects() {
_contentObjectsPtr = 0;
if (_currentContentObjectFragment.getNext() != null) {
_currentContentObjectFragment = _currentContentObjectFragment.getNext();
_contentObjects = _currentContentObjectFragment.getArray();
} else {
_contentObjects = new Object[_contentObjects.length];
_currentContentObjectFragment = new FragmentedArray(_contentObjects, _currentContentObjectFragment);
}
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/AbstractCreatorProcessor.java 0000664 0000000 0000000 00000017211 12263200227 0030266 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
public abstract class AbstractCreatorProcessor {
/**
* Flag on a T_DOCUMENT to indicate if a fragment
*/
protected static final int FLAG_DOCUMENT_FRAGMENT = 1 << 0;
/*
* Flags on T_ELEMENT, T_ATTRIBUTE, T_NAMESPACE_ATTRIBUTE
* to indicate namespace information is represent
*/
protected static final int FLAG_PREFIX = 1 << 0;
protected static final int FLAG_URI = 1 << 1;
protected static final int FLAG_QUALIFIED_NAME = 1 << 2;
/*
* Types of content for T_TEXT and T_COMMENT
*
* Highest 2 bits of lower nibble are used.
*/
protected static final int CONTENT_TYPE_CHAR_ARRAY = 0 << 2;
protected static final int CONTENT_TYPE_CHAR_ARRAY_COPY = 1 << 2;
protected static final int CONTENT_TYPE_STRING = 2 << 2;
protected static final int CONTENT_TYPE_OBJECT = 3 << 2;
/*
* Size of the length of character content for CONTENT_TYPE_CHAR_ARRAY
*
* Last bit of lower nibble is used.
*/
protected static final int CHAR_ARRAY_LENGTH_SMALL = 0;
protected static final int CHAR_ARRAY_LENGTH_MEDIUM = 1;
protected static final int CHAR_ARRAY_LENGTH_SMALL_SIZE = 1 << 8;
protected static final int CHAR_ARRAY_LENGTH_MEDIUM_SIZE = 1 << 16;
/*
* Types of value for T_ATTRIBUTE
*
* Highest bit of lower nibble is used.
*/
protected static final int VALUE_TYPE_STRING = 0;
protected static final int VALUE_TYPE_OBJECT = 1 << 3;
/*
* Mask for types.
*
* Highest nibble is used.
*/
protected static final int TYPE_MASK = 0xF0;
protected static final int T_DOCUMENT = 0x10;
protected static final int T_ELEMENT = 0x20;
protected static final int T_ATTRIBUTE = 0x30;
protected static final int T_NAMESPACE_ATTRIBUTE = 0x40;
protected static final int T_TEXT = 0x50;
protected static final int T_COMMENT = 0x60;
protected static final int T_PROCESSING_INSTRUCTION = 0x70;
protected static final int T_UNEXPANDED_ENTITY_REFERENCE = 0x80;
protected static final int T_END = 0x90;
/*
* Composed types.
*
* One octet is used.
*/
protected static final int T_DOCUMENT_FRAGMENT = T_DOCUMENT | FLAG_DOCUMENT_FRAGMENT;
protected static final int T_ELEMENT_U_LN_QN = T_ELEMENT | FLAG_URI | FLAG_QUALIFIED_NAME;
protected static final int T_ELEMENT_P_U_LN = T_ELEMENT | FLAG_PREFIX | FLAG_URI;
protected static final int T_ELEMENT_U_LN = T_ELEMENT | FLAG_URI;
protected static final int T_ELEMENT_LN = T_ELEMENT;
protected static final int T_NAMESPACE_ATTRIBUTE_P = T_NAMESPACE_ATTRIBUTE | FLAG_PREFIX;
protected static final int T_NAMESPACE_ATTRIBUTE_P_U = T_NAMESPACE_ATTRIBUTE | FLAG_PREFIX | FLAG_URI;
protected static final int T_NAMESPACE_ATTRIBUTE_U = T_NAMESPACE_ATTRIBUTE | FLAG_URI;
protected static final int T_ATTRIBUTE_U_LN_QN = T_ATTRIBUTE | FLAG_URI | FLAG_QUALIFIED_NAME;
protected static final int T_ATTRIBUTE_P_U_LN = T_ATTRIBUTE | FLAG_PREFIX | FLAG_URI;
protected static final int T_ATTRIBUTE_U_LN = T_ATTRIBUTE | FLAG_URI;
protected static final int T_ATTRIBUTE_LN = T_ATTRIBUTE;
protected static final int T_ATTRIBUTE_U_LN_QN_OBJECT = T_ATTRIBUTE_U_LN_QN | VALUE_TYPE_OBJECT;
protected static final int T_ATTRIBUTE_P_U_LN_OBJECT = T_ATTRIBUTE_P_U_LN | VALUE_TYPE_OBJECT;
protected static final int T_ATTRIBUTE_U_LN_OBJECT = T_ATTRIBUTE_U_LN | VALUE_TYPE_OBJECT;
protected static final int T_ATTRIBUTE_LN_OBJECT = T_ATTRIBUTE_LN | VALUE_TYPE_OBJECT;
protected static final int T_TEXT_AS_CHAR_ARRAY = T_TEXT;
protected static final int T_TEXT_AS_CHAR_ARRAY_SMALL = T_TEXT | CHAR_ARRAY_LENGTH_SMALL;
protected static final int T_TEXT_AS_CHAR_ARRAY_MEDIUM = T_TEXT | CHAR_ARRAY_LENGTH_MEDIUM;
protected static final int T_TEXT_AS_CHAR_ARRAY_COPY = T_TEXT | CONTENT_TYPE_CHAR_ARRAY_COPY;
protected static final int T_TEXT_AS_STRING = T_TEXT | CONTENT_TYPE_STRING;
protected static final int T_TEXT_AS_OBJECT = T_TEXT | CONTENT_TYPE_OBJECT;
protected static final int T_COMMENT_AS_CHAR_ARRAY = T_COMMENT;
protected static final int T_COMMENT_AS_CHAR_ARRAY_SMALL = T_COMMENT | CHAR_ARRAY_LENGTH_SMALL;
protected static final int T_COMMENT_AS_CHAR_ARRAY_MEDIUM = T_COMMENT | CHAR_ARRAY_LENGTH_MEDIUM;
protected static final int T_COMMENT_AS_CHAR_ARRAY_COPY = T_COMMENT | CONTENT_TYPE_CHAR_ARRAY_COPY;
protected static final int T_COMMENT_AS_STRING = T_COMMENT | CONTENT_TYPE_STRING;
protected static final int T_END_OF_BUFFER = -1;
protected FragmentedArray _currentStructureFragment;
protected byte[] _structure;
protected int _structurePtr;
protected FragmentedArray _currentStructureStringFragment;
protected String[] _structureStrings;
protected int _structureStringsPtr;
protected FragmentedArray _currentContentCharactersBufferFragment;
protected char[] _contentCharactersBuffer;
protected int _contentCharactersBufferPtr;
protected FragmentedArray _currentContentObjectFragment;
protected Object[] _contentObjects;
protected int _contentObjectsPtr;
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/AbstractProcessor.java 0000664 0000000 0000000 00000030036 12263200227 0026746 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
/**
* Base class for classes that processes {@link XMLStreamBuffer}
* and produces infoset in API-specific form.
*/
public abstract class AbstractProcessor extends AbstractCreatorProcessor {
protected static final int STATE_ILLEGAL = 0;
protected static final int STATE_DOCUMENT = 1;
protected static final int STATE_DOCUMENT_FRAGMENT = 2;
protected static final int STATE_ELEMENT_U_LN_QN = 3;
protected static final int STATE_ELEMENT_P_U_LN = 4;
protected static final int STATE_ELEMENT_U_LN = 5;
protected static final int STATE_ELEMENT_LN = 6;
protected static final int STATE_TEXT_AS_CHAR_ARRAY_SMALL = 7;
protected static final int STATE_TEXT_AS_CHAR_ARRAY_MEDIUM = 8;
protected static final int STATE_TEXT_AS_CHAR_ARRAY_COPY = 9;
protected static final int STATE_TEXT_AS_STRING = 10;
protected static final int STATE_TEXT_AS_OBJECT = 11;
protected static final int STATE_COMMENT_AS_CHAR_ARRAY_SMALL = 12;
protected static final int STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM = 13;
protected static final int STATE_COMMENT_AS_CHAR_ARRAY_COPY = 14;
protected static final int STATE_COMMENT_AS_STRING = 15;
protected static final int STATE_PROCESSING_INSTRUCTION = 16;
protected static final int STATE_END = 17;
private static final int[] _eiiStateTable = new int[256];
protected static final int STATE_NAMESPACE_ATTRIBUTE = 1;
protected static final int STATE_NAMESPACE_ATTRIBUTE_P = 2;
protected static final int STATE_NAMESPACE_ATTRIBUTE_P_U = 3;
protected static final int STATE_NAMESPACE_ATTRIBUTE_U = 4;
private static final int[] _niiStateTable = new int[256];
protected static final int STATE_ATTRIBUTE_U_LN_QN = 1;
protected static final int STATE_ATTRIBUTE_P_U_LN = 2;
protected static final int STATE_ATTRIBUTE_U_LN = 3;
protected static final int STATE_ATTRIBUTE_LN = 4;
protected static final int STATE_ATTRIBUTE_U_LN_QN_OBJECT = 5;
protected static final int STATE_ATTRIBUTE_P_U_LN_OBJECT = 6;
protected static final int STATE_ATTRIBUTE_U_LN_OBJECT = 7;
protected static final int STATE_ATTRIBUTE_LN_OBJECT = 8;
private static final int[] _aiiStateTable = new int[256];
static {
/*
* Create a state table from information items and options.
* The swtich statement using such states will often generate a more
* efficient byte code representation that can be hotspotted using
* jump tables.
*/
_eiiStateTable[T_DOCUMENT] = STATE_DOCUMENT;
_eiiStateTable[T_DOCUMENT_FRAGMENT] = STATE_DOCUMENT_FRAGMENT;
_eiiStateTable[T_ELEMENT_U_LN_QN] = STATE_ELEMENT_U_LN_QN;
_eiiStateTable[T_ELEMENT_P_U_LN] = STATE_ELEMENT_P_U_LN;
_eiiStateTable[T_ELEMENT_U_LN] = STATE_ELEMENT_U_LN;
_eiiStateTable[T_ELEMENT_LN] = STATE_ELEMENT_LN;
_eiiStateTable[T_TEXT_AS_CHAR_ARRAY_SMALL] = STATE_TEXT_AS_CHAR_ARRAY_SMALL;
_eiiStateTable[T_TEXT_AS_CHAR_ARRAY_MEDIUM] = STATE_TEXT_AS_CHAR_ARRAY_MEDIUM;
_eiiStateTable[T_TEXT_AS_CHAR_ARRAY_COPY] = STATE_TEXT_AS_CHAR_ARRAY_COPY;
_eiiStateTable[T_TEXT_AS_STRING] = STATE_TEXT_AS_STRING;
_eiiStateTable[T_TEXT_AS_OBJECT] = STATE_TEXT_AS_OBJECT;
_eiiStateTable[T_COMMENT_AS_CHAR_ARRAY_SMALL] = STATE_COMMENT_AS_CHAR_ARRAY_SMALL;
_eiiStateTable[T_COMMENT_AS_CHAR_ARRAY_MEDIUM] = STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM;
_eiiStateTable[T_COMMENT_AS_CHAR_ARRAY_COPY] = STATE_COMMENT_AS_CHAR_ARRAY_COPY;
_eiiStateTable[T_COMMENT_AS_STRING] = STATE_COMMENT_AS_STRING;
_eiiStateTable[T_PROCESSING_INSTRUCTION] = STATE_PROCESSING_INSTRUCTION;
_eiiStateTable[T_END] = STATE_END;
_niiStateTable[T_NAMESPACE_ATTRIBUTE] = STATE_NAMESPACE_ATTRIBUTE;
_niiStateTable[T_NAMESPACE_ATTRIBUTE_P] = STATE_NAMESPACE_ATTRIBUTE_P;
_niiStateTable[T_NAMESPACE_ATTRIBUTE_P_U] = STATE_NAMESPACE_ATTRIBUTE_P_U;
_niiStateTable[T_NAMESPACE_ATTRIBUTE_U] = STATE_NAMESPACE_ATTRIBUTE_U;
_aiiStateTable[T_ATTRIBUTE_U_LN_QN] = STATE_ATTRIBUTE_U_LN_QN;
_aiiStateTable[T_ATTRIBUTE_P_U_LN] = STATE_ATTRIBUTE_P_U_LN;
_aiiStateTable[T_ATTRIBUTE_U_LN] = STATE_ATTRIBUTE_U_LN;
_aiiStateTable[T_ATTRIBUTE_LN] = STATE_ATTRIBUTE_LN;
_aiiStateTable[T_ATTRIBUTE_U_LN_QN_OBJECT] = STATE_ATTRIBUTE_U_LN_QN_OBJECT;
_aiiStateTable[T_ATTRIBUTE_P_U_LN_OBJECT] = STATE_ATTRIBUTE_P_U_LN_OBJECT;
_aiiStateTable[T_ATTRIBUTE_U_LN_OBJECT] = STATE_ATTRIBUTE_U_LN_OBJECT;
_aiiStateTable[T_ATTRIBUTE_LN_OBJECT] = STATE_ATTRIBUTE_LN_OBJECT;
}
protected XMLStreamBuffer _buffer;
/**
* True if this processor should create a fragment of XML, without the start/end document markers.
*/
protected boolean _fragmentMode;
protected boolean _stringInterningFeature = false;
/**
* Number of remaining XML element trees that should be visible
* through this {@link AbstractProcessor}.
*/
protected int _treeCount;
/**
* @deprecated
* Use {@link #setBuffer(XMLStreamBuffer, boolean)}
*/
protected final void setBuffer(XMLStreamBuffer buffer) {
setBuffer(buffer,buffer.isFragment());
}
protected final void setBuffer(XMLStreamBuffer buffer, boolean fragmentMode) {
_buffer = buffer;
_fragmentMode = fragmentMode;
_currentStructureFragment = _buffer.getStructure();
_structure = _currentStructureFragment.getArray();
_structurePtr = _buffer.getStructurePtr();
_currentStructureStringFragment = _buffer.getStructureStrings();
_structureStrings = _currentStructureStringFragment.getArray();
_structureStringsPtr = _buffer.getStructureStringsPtr();
_currentContentCharactersBufferFragment = _buffer.getContentCharactersBuffer();
_contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray();
_contentCharactersBufferPtr = _buffer.getContentCharactersBufferPtr();
_currentContentObjectFragment = _buffer.getContentObjects();
_contentObjects = _currentContentObjectFragment.getArray();
_contentObjectsPtr = _buffer.getContentObjectsPtr();
_stringInterningFeature = _buffer.hasInternedStrings();
_treeCount = _buffer.treeCount;
}
protected final int peekStructure() {
if (_structurePtr < _structure.length) {
return _structure[_structurePtr] & 255;
}
return readFromNextStructure(0);
}
protected final int readStructure() {
if (_structurePtr < _structure.length) {
return _structure[_structurePtr++] & 255;
}
return readFromNextStructure(1);
}
protected final int readEiiState() {
return _eiiStateTable[readStructure()];
}
protected static int getEIIState(int item) {
return _eiiStateTable[item];
}
protected static int getNIIState(int item) {
return _niiStateTable[item];
}
protected static int getAIIState(int item) {
return _aiiStateTable[item];
}
protected final int readStructure16() {
return (readStructure() << 8) | readStructure();
}
private int readFromNextStructure(int v) {
_structurePtr = v;
_currentStructureFragment = _currentStructureFragment.getNext();
_structure = _currentStructureFragment.getArray();
return _structure[0] & 255;
}
protected final String readStructureString() {
if (_structureStringsPtr < _structureStrings.length) {
return _structureStrings[_structureStringsPtr++];
}
_structureStringsPtr = 1;
_currentStructureStringFragment = _currentStructureStringFragment.getNext();
_structureStrings = _currentStructureStringFragment.getArray();
return _structureStrings[0];
}
protected final String readContentString() {
return (String)readContentObject();
}
protected final char[] readContentCharactersCopy() {
return (char[])readContentObject();
}
protected final int readContentCharactersBuffer(int length) {
if (_contentCharactersBufferPtr + length < _contentCharactersBuffer.length) {
final int start = _contentCharactersBufferPtr;
_contentCharactersBufferPtr += length;
return start;
}
_contentCharactersBufferPtr = length;
_currentContentCharactersBufferFragment = _currentContentCharactersBufferFragment.getNext();
_contentCharactersBuffer = _currentContentCharactersBufferFragment.getArray();
return 0;
}
protected final Object readContentObject() {
if (_contentObjectsPtr < _contentObjects.length) {
return _contentObjects[_contentObjectsPtr++];
}
_contentObjectsPtr = 1;
_currentContentObjectFragment = _currentContentObjectFragment.getNext();
_contentObjects = _currentContentObjectFragment.getArray();
return _contentObjects[0];
}
protected final StringBuilder _qNameBuffer = new StringBuilder();
protected final String getQName(String prefix, String localName) {
_qNameBuffer.append(prefix).append(':').append(localName);
final String qName = _qNameBuffer.toString();
_qNameBuffer.setLength(0);
return (_stringInterningFeature) ? qName.intern() : qName;
}
protected final String getPrefixFromQName(String qName) {
int pIndex = qName.indexOf(':');
if (_stringInterningFeature) {
return (pIndex != -1) ? qName.substring(0,pIndex).intern() : "";
} else {
return (pIndex != -1) ? qName.substring(0,pIndex) : "";
}
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/AttributesHolder.java 0000664 0000000 0000000 00000015643 12263200227 0026576 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import org.xml.sax.Attributes;
/**
* Class for holding attributes.
*
* Since it implements {@link Attributes}, this class follows the SAX convention
* of using "" instead of null.
*/
@SuppressWarnings({"PointlessArithmeticExpression"})
public final class AttributesHolder implements Attributes {
protected static final int DEFAULT_CAPACITY = 8;
protected static final int ITEM_SIZE = 1 << 3;
protected static final int PREFIX = 0;
protected static final int URI = 1;
protected static final int LOCAL_NAME = 2;
protected static final int QNAME = 3;
protected static final int TYPE = 4;
protected static final int VALUE = 5;
protected int _attributeCount;
protected String[] _strings;
public AttributesHolder() {
_strings = new String[DEFAULT_CAPACITY * ITEM_SIZE];
}
public final int getLength() {
return _attributeCount;
}
public final String getPrefix(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + PREFIX] : null;
}
public final String getLocalName(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + LOCAL_NAME] : null;
}
public final String getQName(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + QNAME] : null;
}
public final String getType(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + TYPE] : null;
}
public final String getURI(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + URI] : null;
}
public final String getValue(int index) {
return (index >= 0 && index < _attributeCount) ?
_strings[(index << 3) + VALUE] : null;
}
public final int getIndex(String qName) {
for (int i = 0; i < _attributeCount; i++) {
if (qName.equals(_strings[(i << 3) + QNAME])) {
return i;
}
}
return -1;
}
public final String getType(String qName) {
final int i = (getIndex(qName) << 3) + TYPE;
return (i >= 0) ? _strings[i] : null;
}
public final String getValue(String qName) {
final int i = (getIndex(qName) << 3) + VALUE;
return (i >= 0) ? _strings[i] : null;
}
public final int getIndex(String uri, String localName) {
for (int i = 0; i < _attributeCount; i++) {
if (localName.equals(_strings[(i << 3) + LOCAL_NAME]) &&
uri.equals(_strings[(i << 3) + URI])) {
return i;
}
}
return -1;
}
public final String getType(String uri, String localName) {
final int i = (getIndex(uri, localName) << 3) + TYPE;
return (i >= 0) ? _strings[i] : null;
}
public final String getValue(String uri, String localName) {
final int i = (getIndex(uri, localName) << 3) + VALUE;
return (i >= 0) ? _strings[i] : null;
}
public final void clear() {
if (_attributeCount > 0) {
for (int i = 0; i < _attributeCount; i++) {
_strings[(i << 3) + VALUE] = null;
}
_attributeCount = 0;
}
}
/**
* Add an attribute using a qualified name that contains the
* prefix and local name.
*
* @param uri
* This can be empty but not null, just like everywhere else in SAX.
*/
public final void addAttributeWithQName(String uri, String localName, String qName, String type, String value) {
final int i = _attributeCount << 3;
if (i == _strings.length) {
resize(i);
}
_strings[i + PREFIX] = null;
_strings[i + URI] = uri;
_strings[i + LOCAL_NAME] = localName;
_strings[i + QNAME] = qName;
_strings[i + TYPE] = type;
_strings[i + VALUE] = value;
_attributeCount++;
}
/**
* Add an attribute using a prefix.
*
* @param prefix
* This can be empty but not null, just like everywhere else in SAX.
* @param uri
* This can be empty but not null, just like everywhere else in SAX.
*/
public final void addAttributeWithPrefix(String prefix, String uri, String localName, String type, String value) {
final int i = _attributeCount << 3;
if (i == _strings.length) {
resize(i);
}
_strings[i + PREFIX] = prefix;
_strings[i + URI] = uri;
_strings[i + LOCAL_NAME] = localName;
_strings[i + QNAME] = null;
_strings[i + TYPE] = type;
_strings[i + VALUE] = value;
_attributeCount++;
}
private void resize(int length) {
final int newLength = length * 2;
final String[] strings = new String[newLength];
System.arraycopy(_strings, 0, strings, 0, length);
_strings = strings;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/FragmentedArray.java 0000664 0000000 0000000 00000005763 12263200227 0026367 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
class FragmentedArray {
protected T _item;
protected FragmentedArray _next;
protected FragmentedArray _previous;
FragmentedArray(T item) {
this(item, null);
}
FragmentedArray(T item, FragmentedArray previous) {
setArray(item);
if (previous != null) {
previous._next = this;
_previous = previous;
}
}
T getArray() {
return _item;
}
void setArray(T item) {
assert(item.getClass().isArray());
_item = item;
}
FragmentedArray getNext() {
return _next;
}
void setNext(FragmentedArray next) {
_next = next;
if (next != null) {
next._previous = this;
}
}
FragmentedArray getPrevious() {
return _previous;
}
void setPrevious(FragmentedArray previous) {
_previous = previous;
if (previous != null) {
previous._next = this;
}
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/MutableXMLStreamBuffer.java 0000664 0000000 0000000 00000022413 12263200227 0027563 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import com.sun.xml.stream.buffer.sax.Properties;
import com.sun.xml.stream.buffer.sax.SAXBufferCreator;
import com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator;
import com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
import java.io.InputStream;
/**
*
* A mutable stream-based buffer of an XML infoset.
*
*
* A MutableXMLStreamBuffer is created using specific SAX and StAX-based
* creators. Utility methods on MutableXMLStreamBuffer are provided for
* such functionality that utilize SAX and StAX-based creators.
*
*
* Once instantiated the same instance of a MutableXMLStreamBuffer may be reused for
* creation to reduce the amount of Objects instantiated and garbage
* collected that are required for internally representing an XML infoset.
*
*
* A MutableXMLStreamBuffer is not designed to be created and processed
* concurrently. If done so unspecified behaviour may occur.
*/
public class MutableXMLStreamBuffer extends XMLStreamBuffer {
/**
* The default array size for the arrays used in internal representation
* of the XML infoset.
*/
public static final int DEFAULT_ARRAY_SIZE = 512;
/**
* Create a new MutableXMLStreamBuffer using the
* {@link MutableXMLStreamBuffer#DEFAULT_ARRAY_SIZE}.
*/
public MutableXMLStreamBuffer() {
this(DEFAULT_ARRAY_SIZE);
}
/**
* Set the system identifier for this buffer.
* @param systemId The system identifier.
*/
public void setSystemId(String systemId) {
this.systemId = systemId;
}
/**
* Create a new MutableXMLStreamBuffer.
*
* @param size
* The size of the arrays used in the internal representation
* of the XML infoset.
* @throws NegativeArraySizeException
* If the size
argument is less than 0
.
*/
public MutableXMLStreamBuffer(int size) {
_structure = new FragmentedArray(new byte[size]);
_structureStrings = new FragmentedArray(new String[size]);
_contentCharactersBuffer = new FragmentedArray(new char[4096]);
_contentObjects = new FragmentedArray(new Object[size]);
// Set the first element of structure array to indicate an empty buffer
// that has not been created
_structure.getArray()[0] = (byte) AbstractCreatorProcessor.T_END;
}
/**
* Create contents of a buffer from a XMLStreamReader.
*
*
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
*
* The MutableXMLStreamBuffer is created by consuming the events on the XMLStreamReader using
* an instance of {@link StreamReaderBufferCreator}.
*
* @param reader
* A XMLStreamReader to read from to create.
*/
public void createFromXMLStreamReader(XMLStreamReader reader) throws XMLStreamException {
reset();
StreamReaderBufferCreator c = new StreamReaderBufferCreator(this);
c.create(reader);
}
/**
* Create contents of a buffer from a XMLStreamWriter.
*
*
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
*
* The MutableXMLStreamBuffer is created by consuming events on a XMLStreamWriter using
* an instance of {@link StreamWriterBufferCreator}.
*/
public XMLStreamWriter createFromXMLStreamWriter() {
reset();
return new StreamWriterBufferCreator(this);
}
/**
* Create contents of a buffer from a {@link SAXBufferCreator}.
*
*
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
*
* The MutableXMLStreamBuffer is created by consuming events from a {@link ContentHandler} using
* an instance of {@link SAXBufferCreator}.
*
* @return The {@link SAXBufferCreator} to create from.
*/
public SAXBufferCreator createFromSAXBufferCreator() {
reset();
SAXBufferCreator c = new SAXBufferCreator();
c.setBuffer(this);
return c;
}
/**
* Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
*
*
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
*
* The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
* and registering associated handlers on the {@link XMLReader}.
*
* @param reader
* The {@link XMLReader} to use for parsing.
* @param in
* The {@link InputStream} to be parsed.
*/
public void createFromXMLReader(XMLReader reader, InputStream in) throws SAXException, IOException {
createFromXMLReader(reader, in, null);
}
/**
* Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
*
*
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
*
* The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
* and registering associated handlers on the {@link XMLReader}.
*
* @param reader
* The {@link XMLReader} to use for parsing.
* @param in
* The {@link InputStream} to be parsed.
* @param systemId
* The system ID of the input stream.
*/
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
reset();
SAXBufferCreator c = new SAXBufferCreator(this);
reader.setContentHandler(c);
reader.setDTDHandler(c);
reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);
c.create(reader, in, systemId);
}
/**
* Reset the MutableXMLStreamBuffer.
*
*
* This method will reset the MutableXMLStreamBuffer to a state of being "uncreated"
* similar to the state of a newly instantiated MutableXMLStreamBuffer.
*
*
* As many Objects as possible will be retained for reuse in future creation.
*/
public void reset() {
// Reset the ptrs in arrays to 0
_structurePtr =
_structureStringsPtr =
_contentCharactersBufferPtr =
_contentObjectsPtr = 0;
// Set the first element of structure array to indicate an empty buffer
// that has not been created
_structure.getArray()[0] = (byte)AbstractCreatorProcessor.T_END;
// Clean up content objects
_contentObjects.setNext(null);
final Object[] o = _contentObjects.getArray();
for (int i = 0; i < o.length; i++) {
if (o[i] != null) {
o[i] = null;
} else {
break;
}
}
treeCount = 0;
/*
* TODO consider truncating the size of _structureStrings and
* _contentCharactersBuffer to limit the memory used by the buffer
*/
}
protected void setHasInternedStrings(boolean hasInternedStrings) {
_hasInternedStrings = hasInternedStrings;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/XMLStreamBuffer.java 0000664 0000000 0000000 00000043256 12263200227 0026261 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import com.sun.xml.stream.buffer.sax.SAXBufferProcessor;
import com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor;
import com.sun.xml.stream.buffer.stax.StreamWriterBufferProcessor;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.w3c.dom.Node;
/**
* An immutable stream-based buffer of an XML infoset.
*
*
* A XMLStreamBuffer is an abstract class. It is immutable with
* respect to the methods on the class, which are non-modifying in terms
* of state.
*
*
* A XMLStreamBuffer can be processed using specific SAX and StAX-based
* processors. Utility methods on XMLStreamBuffer are provided for
* such functionality that utilize SAX and StAX-based processors.
* The same instance of a XMLStreamBuffer may be processed
* multiple times and concurrently by more than one processor.
*
*
* There are two concrete implementations of XMLStreamBuffer.
* The first, {@link MutableXMLStreamBuffer}, can be instantiated for the creation
* of a buffer using SAX and StAX-based creators, and from which may be
* processed as an XMLStreamBuffer. The second,
* {@link XMLStreamBufferMark}, can be instantiated to mark into an existing
* buffer that is being created or processed. This allows a subtree of
* {@link XMLStreamBuffer} to be treated as its own {@link XMLStreamBuffer}.
*
*
* A XMLStreamBuffer can represent a complete XML infoset or a subtree
* of an XML infoset. It is also capable of representing a "forest",
* where the buffer represents multiple adjacent XML elements, although
* in this mode there are restrictions about how you can consume such
* forest, because not all XML APIs handle forests very well.
*/
public abstract class XMLStreamBuffer {
/**
* In scope namespaces on a fragment
*/
protected Map _inscopeNamespaces = Collections.emptyMap();
/**
* True if the buffer was created from a parser that interns Strings
* as specified by the SAX interning features
*/
protected boolean _hasInternedStrings;
/**
* Fragmented array to hold structural information
*/
protected FragmentedArray _structure;
protected int _structurePtr;
/**
* Fragmented array to hold structural information as strings
*/
protected FragmentedArray _structureStrings;
protected int _structureStringsPtr;
/**
* Fragmented array to hold content information in a shared char[]
*/
protected FragmentedArray _contentCharactersBuffer;
protected int _contentCharactersBufferPtr;
/**
* Fragmented array to hold content information as objects
*/
protected FragmentedArray _contentObjects;
protected int _contentObjectsPtr;
/**
* Number of trees in this stream buffer.
*
*
* 1 if there's only one, which is the normal case. When the buffer
* holds a forest, this value is greater than 1. If the buffer is empty, then 0.
*
*
* Notice that we cannot infer this value by looking at the {@link FragmentedArray}s,
* because this {@link XMLStreamBuffer} maybe a view of a portion of another bigger
* {@link XMLStreamBuffer}.
*/
protected int treeCount;
/**
* The system identifier associated with the buffer
*/
protected String systemId;
/**
* Is the buffer created by creator.
*
* @return
* true
if the buffer has been created.
*/
public final boolean isCreated() {
return _structure.getArray()[0] != AbstractCreatorProcessor.T_END;
}
/**
* Is the buffer a representation of a fragment of an XML infoset.
*
* @return
* true
if the buffer is a representation of a fragment
* of an XML infoset.
*/
public final boolean isFragment() {
return (isCreated() && (_structure.getArray()[_structurePtr] & AbstractCreatorProcessor.TYPE_MASK)
!= AbstractCreatorProcessor.T_DOCUMENT);
}
/**
* Is the buffer a representation of a fragment of an XML infoset
* that is an element (and its contents).
*
* @return
* true
if the buffer a representation
* of a fragment of an XML infoset that is an element (and its contents).
*/
public final boolean isElementFragment() {
return (isCreated() && (_structure.getArray()[_structurePtr] & AbstractCreatorProcessor.TYPE_MASK)
== AbstractCreatorProcessor.T_ELEMENT);
}
/**
* Returns ture if this buffer represents a forest, which is
* are more than one adjacent XML elements.
*/
public final boolean isForest() {
return isCreated() && treeCount>1;
}
/**
* Get the system identifier associated with the buffer.
* @return The system identifier.
*/
public final String getSystemId() {
return systemId;
}
/**
* Get the in-scope namespaces.
*
*
*
* The in-scope namespaces will be empty if the buffer is not a
* fragment ({@link #isFragment} returns false
).
*
* The in-scope namespace will correspond to the in-scope namespaces of the
* fragment if the buffer is a fragment ({@link #isFragment}
* returns false
). The in-scope namespaces will include any
* namespace delcarations on an element if the fragment correspond to that
* of an element ({@link #isElementFragment} returns false
).
*
* @return
* The in-scope namespaces of the XMLStreamBuffer.
* Prefix to namespace URI.
*/
public final Map getInscopeNamespaces() {
return _inscopeNamespaces;
}
/**
* Has the buffer been created using Strings that have been interned
* for certain properties of information items. The Strings that are interned
* are those that correspond to Strings that are specified by the SAX API
* "string-interning" property
* (see here ).
*
*
* An buffer may have been created, for example, from an XML document parsed
* using the Xerces SAX parser. The Xerces SAX parser will have interned certain Strings
* according to the SAX string interning property.
* This method enables processors to avoid the duplication of
* String interning if such a feature is required by a procesing application and the
* buffer being processed was created using Strings that have been interned.
*
* @return
* true
if the buffer has been created using Strings that
* have been interned.
*/
public final boolean hasInternedStrings() {
return _hasInternedStrings;
}
/**
* Read the contents of the buffer as a {@link XMLStreamReader}.
*
* @return
* A an instance of a {@link StreamReaderBufferProcessor}. Always non-null.
*/
public final StreamReaderBufferProcessor readAsXMLStreamReader() throws XMLStreamException {
return new StreamReaderBufferProcessor(this);
}
/**
* Write the contents of the buffer to an XMLStreamWriter.
*
*
* The XMLStreamBuffer will be written out to the XMLStreamWriter using
* an instance of {@link StreamWriterBufferProcessor}.
*
* @param writer
* A XMLStreamWriter to write to.
* @param writeAsFragment
* If true, {@link XMLStreamWriter} will not receive {@link XMLStreamWriter#writeStartDocument()}
* nor {@link XMLStreamWriter#writeEndDocument()}. This is desirable behavior when
* you are writing the contents of a buffer into a bigger document.
*/
public final void writeToXMLStreamWriter(XMLStreamWriter writer, boolean writeAsFragment) throws XMLStreamException {
StreamWriterBufferProcessor p = new StreamWriterBufferProcessor(this,writeAsFragment);
p.process(writer);
}
/**
* @deprecated
* Use {@link #writeToXMLStreamWriter(XMLStreamWriter, boolean)}
*/
public final void writeToXMLStreamWriter(XMLStreamWriter writer) throws XMLStreamException {
writeToXMLStreamWriter(writer, this.isFragment());
}
/**
* Reads the contents of the buffer from a {@link XMLReader}.
*
* @return
* A an instance of a {@link SAXBufferProcessor}.
* @deprecated
* Use {@link #readAsXMLReader(boolean)}
*/
public final SAXBufferProcessor readAsXMLReader() {
return new SAXBufferProcessor(this,isFragment());
}
/**
* Reads the contents of the buffer from a {@link XMLReader}.
*
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
* @return
* A an instance of a {@link SAXBufferProcessor}.
*/
public final SAXBufferProcessor readAsXMLReader(boolean produceFragmentEvent) {
return new SAXBufferProcessor(this,produceFragmentEvent);
}
/**
* Write the contents of the buffer to a {@link ContentHandler}.
*
*
* If the handler
is also an instance of other SAX-based
* handlers, such as {@link LexicalHandler}, than corresponding SAX events
* will be reported to those handlers.
*
* @param handler
* The ContentHandler to receive SAX events.
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*
* @throws SAXException
* if a parsing fails, or if {@link ContentHandler} throws a {@link SAXException}.
*/
public final void writeTo(ContentHandler handler, boolean produceFragmentEvent) throws SAXException {
SAXBufferProcessor p = readAsXMLReader(produceFragmentEvent);
p.setContentHandler(handler);
if (p instanceof LexicalHandler) {
p.setLexicalHandler((LexicalHandler)handler);
}
if (p instanceof DTDHandler) {
p.setDTDHandler((DTDHandler)handler);
}
if (p instanceof ErrorHandler) {
p.setErrorHandler((ErrorHandler)handler);
}
p.process();
}
/**
* @deprecated
* Use {@link #writeTo(ContentHandler,boolean)}
*/
public final void writeTo(ContentHandler handler) throws SAXException {
writeTo(handler,isFragment());
}
/**
* Write the contents of the buffer to a {@link ContentHandler} with errors
* report to a {@link ErrorHandler}.
*
*
* If the handler
is also an instance of other SAX-based
* handlers, such as {@link LexicalHandler}, than corresponding SAX events
* will be reported to those handlers.
*
* @param handler
* The ContentHandler to receive SAX events.
* @param errorHandler
* The ErrorHandler to receive error events.
*
* @throws SAXException
* if a parsing fails and {@link ErrorHandler} throws a {@link SAXException},
* or if {@link ContentHandler} throws a {@link SAXException}.
*/
public final void writeTo(ContentHandler handler, ErrorHandler errorHandler, boolean produceFragmentEvent) throws SAXException {
SAXBufferProcessor p = readAsXMLReader(produceFragmentEvent);
p.setContentHandler(handler);
if (p instanceof LexicalHandler) {
p.setLexicalHandler((LexicalHandler)handler);
}
if (p instanceof DTDHandler) {
p.setDTDHandler((DTDHandler)handler);
}
p.setErrorHandler(errorHandler);
p.process();
}
public final void writeTo(ContentHandler handler, ErrorHandler errorHandler) throws SAXException {
writeTo(handler, errorHandler, isFragment());
}
private static final TransformerFactory trnsformerFactory = TransformerFactory.newInstance();
/**
* Writes out the contents of this buffer as DOM node and append that to the given node.
*
* Faster implementation would be desirable.
*
* @return
* The newly added child node.
*/
public final Node writeTo(Node n) throws XMLStreamBufferException {
try {
Transformer t = trnsformerFactory.newTransformer();
t.transform(new XMLStreamBufferSource(this), new DOMResult(n));
return n.getLastChild();
} catch (TransformerException e) {
throw new XMLStreamBufferException(e);
}
}
/**
* Create a new buffer from a XMLStreamReader.
*
* @param reader
* A XMLStreamReader to read from to create.
* @return XMLStreamBuffer the created buffer
* @see MutableXMLStreamBuffer#createFromXMLStreamReader(XMLStreamReader)
*/
public static XMLStreamBuffer createNewBufferFromXMLStreamReader(XMLStreamReader reader)
throws XMLStreamException {
MutableXMLStreamBuffer b = new MutableXMLStreamBuffer();
b.createFromXMLStreamReader(reader);
return b;
}
/**
* Create a new buffer from a {@link XMLReader} and {@link InputStream}.
*
* @param reader
* The {@link XMLReader} to use for parsing.
* @param in
* The {@link InputStream} to be parsed.
* @return XMLStreamBuffer the created buffer
* @see MutableXMLStreamBuffer#createFromXMLReader(XMLReader, InputStream)
*/
public static XMLStreamBuffer createNewBufferFromXMLReader(XMLReader reader, InputStream in) throws SAXException, IOException {
MutableXMLStreamBuffer b = new MutableXMLStreamBuffer();
b.createFromXMLReader(reader, in);
return b;
}
/**
* Create a new buffer from a {@link XMLReader} and {@link InputStream}.
*
* @param reader
* The {@link XMLReader} to use for parsing.
* @param in
* The {@link InputStream} to be parsed.
* @param systemId
* The system ID of the input stream.
* @return XMLStreamBuffer the created buffer
* @see MutableXMLStreamBuffer#createFromXMLReader(XMLReader, InputStream, String)
*/
public static XMLStreamBuffer createNewBufferFromXMLReader(XMLReader reader, InputStream in,
String systemId) throws SAXException, IOException {
MutableXMLStreamBuffer b = new MutableXMLStreamBuffer();
b.createFromXMLReader(reader, in, systemId);
return b;
}
protected final FragmentedArray getStructure() {
return _structure;
}
protected final int getStructurePtr() {
return _structurePtr;
}
protected final FragmentedArray getStructureStrings() {
return _structureStrings;
}
protected final int getStructureStringsPtr() {
return _structureStringsPtr;
}
protected final FragmentedArray getContentCharactersBuffer() {
return _contentCharactersBuffer;
}
protected final int getContentCharactersBufferPtr() {
return _contentCharactersBufferPtr;
}
protected final FragmentedArray getContentObjects() {
return _contentObjects;
}
protected final int getContentObjectsPtr() {
return _contentObjectsPtr;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/XMLStreamBufferException.java 0000664 0000000 0000000 00000004460 12263200227 0030132 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
public class XMLStreamBufferException extends Exception {
public XMLStreamBufferException(String message) {
super(message);
}
public XMLStreamBufferException(String message, Exception e) {
super(message, e);
}
public XMLStreamBufferException(Exception e) {
super(e);
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/XMLStreamBufferMark.java 0000664 0000000 0000000 00000007712 12263200227 0027071 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import java.util.Map;
/**
* A mark into a buffer.
*
*
* A mark can be processed in the same manner as a XMLStreamBuffer.
*
*
* A mark will share a sub set of information of the buffer that is
* marked. If the buffer is directly or indirectly associated with a
* (mutable) {@link XMLStreamBuffer} which is reset and/or re-created
* then this will invalidate the mark and processing behvaiour of the mark
* is undefined. It is the responsibility of the application to manage the
* relationship between the marked XMLStreamBuffer and one or more marks.
*/
public class XMLStreamBufferMark extends XMLStreamBuffer {
/**
* Create a mark from the buffer that is being created.
*
*
* A mark will be created from the current position of creation of the
* {@link XMLStreamBuffer} that is being created by a {@link AbstractCreator}.
*
* @param inscopeNamespaces
* The in-scope namespaces on the fragment of XML infoset that is
* to be marked.
*
* @param src
* The {@link AbstractCreator} or {@link AbstractProcessor} from which the current
* position of creation of the XMLStreamBuffer will be taken as the mark.
*/
public XMLStreamBufferMark(Map inscopeNamespaces, AbstractCreatorProcessor src) {
if(inscopeNamespaces != null) {
_inscopeNamespaces = inscopeNamespaces;
}
_structure = src._currentStructureFragment;
_structurePtr = src._structurePtr;
_structureStrings = src._currentStructureStringFragment;
_structureStringsPtr = src._structureStringsPtr;
_contentCharactersBuffer = src._currentContentCharactersBufferFragment;
_contentCharactersBufferPtr = src._contentCharactersBufferPtr;
_contentObjects = src._currentContentObjectFragment;
_contentObjectsPtr = src._contentObjectsPtr;
treeCount = 1; // TODO: define a way to create a mark over a forest
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/XMLStreamBufferResult.java 0000664 0000000 0000000 00000011204 12263200227 0027444 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import com.sun.xml.stream.buffer.sax.SAXBufferCreator;
import javax.xml.transform.sax.SAXResult;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
/**
* A JAXP Result implementation that supports the serialization to an
* {@link MutableXMLStreamBuffer} for use by applications that expect a Result.
*
*
* Reuse of a XMLStreamBufferResult more than once will require that the
* MutableXMLStreamBuffer is reset by called
* {@link #.getXMLStreamBuffer()}.reset(), or by calling
* {@link #.setXMLStreamBuffer()} with a new instance of
* {@link MutableXMLStreamBuffer}.
*
*
* The derivation of XMLStreamBufferResult from SAXResult is an implementation
* detail.
*
*
General applications shall not call the following methods:
*
* setHandler
* setLexicalHandler
* setSystemId
*
*/
public class XMLStreamBufferResult extends SAXResult {
protected MutableXMLStreamBuffer _buffer;
protected SAXBufferCreator _bufferCreator;
/**
* The default XMLStreamBufferResult constructor.
*
*
* A {@link MutableXMLStreamBuffer} is instantiated and used.
*/
public XMLStreamBufferResult() {
setXMLStreamBuffer(new MutableXMLStreamBuffer());
}
/**
* XMLStreamBufferResult constructor.
*
* @param buffer the {@link MutableXMLStreamBuffer} to use.
*/
public XMLStreamBufferResult(MutableXMLStreamBuffer buffer) {
setXMLStreamBuffer(buffer);
}
/**
* Get the {@link MutableXMLStreamBuffer} that is used.
*
* @return the {@link MutableXMLStreamBuffer}.
*/
public MutableXMLStreamBuffer getXMLStreamBuffer() {
return _buffer;
}
/**
* Set the {@link MutableXMLStreamBuffer} to use.
*
* @param buffer the {@link MutableXMLStreamBuffer}.
*/
public void setXMLStreamBuffer(MutableXMLStreamBuffer buffer) {
if (buffer == null) {
throw new NullPointerException("buffer cannot be null");
}
_buffer = buffer;
setSystemId(_buffer.getSystemId());
if (_bufferCreator != null) {
_bufferCreator.setXMLStreamBuffer(_buffer);
}
}
public ContentHandler getHandler() {
if (_bufferCreator == null) {
_bufferCreator = new SAXBufferCreator(_buffer);
setHandler(_bufferCreator);
} else if (super.getHandler() == null) {
setHandler(_bufferCreator);
}
return _bufferCreator;
}
public LexicalHandler getLexicalHandler() {
return (LexicalHandler) getHandler();
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/XMLStreamBufferSource.java 0000664 0000000 0000000 00000010522 12263200227 0027430 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import com.sun.xml.stream.buffer.sax.SAXBufferProcessor;
import java.io.ByteArrayInputStream;
import javax.xml.transform.sax.SAXSource;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
/**
* A JAXP Source implementation that supports the parsing
* of {@link XMLStreamBuffer} for use by applications that expect a Source.
*
*
* The derivation of XMLStreamBufferSource from SAXSource is an implementation
* detail.
*
*
Applications shall obey the following restrictions:
*
* The setXMLReader and setInputSource shall not be called.
* The XMLReader object obtained by the getXMLReader method shall
* be used only for parsing the InputSource object returned by
* the getInputSource method.
* The InputSource object obtained by the getInputSource method shall
* be used only for being parsed by the XMLReader object returned by
* the getXMLReader method.
*
*/
public class XMLStreamBufferSource extends SAXSource {
protected XMLStreamBuffer _buffer;
protected SAXBufferProcessor _bufferProcessor;
/**
* XMLStreamBufferSource constructor.
*
* @param buffer the {@link XMLStreamBuffer} to use.
*/
public XMLStreamBufferSource(XMLStreamBuffer buffer) {
super(new InputSource(
new ByteArrayInputStream(new byte[0])));
setXMLStreamBuffer(buffer);
}
/**
* Get the {@link XMLStreamBuffer} that is used.
*
* @return the {@link XMLStreamBuffer}.
*/
public XMLStreamBuffer getXMLStreamBuffer() {
return _buffer;
}
/**
* Set the {@link XMLStreamBuffer} to use.
*
* @param buffer the {@link XMLStreamBuffer}.
*/
public void setXMLStreamBuffer(XMLStreamBuffer buffer) {
if (buffer == null) {
throw new NullPointerException("buffer cannot be null");
}
_buffer = buffer;
if (_bufferProcessor != null) {
_bufferProcessor.setBuffer(_buffer,false);
}
}
public XMLReader getXMLReader() {
if (_bufferProcessor == null) {
_bufferProcessor = new SAXBufferProcessor(_buffer,false);
setXMLReader(_bufferProcessor);
} else if (super.getXMLReader() == null) {
setXMLReader(_bufferProcessor);
}
return _bufferProcessor;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/ 0000775 0000000 0000000 00000000000 12263200227 0023231 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/DefaultWithLexicalHandler.java 0000664 0000000 0000000 00000005255 12263200227 0031123 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.sax;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
public class DefaultWithLexicalHandler extends DefaultHandler implements LexicalHandler {
public void comment(char[] ch, int start, int length) throws SAXException { }
public void startDTD(String name, String publicId, String systemId) throws SAXException { }
public void endDTD() throws SAXException { }
public void startEntity(String name) throws SAXException { }
public void endEntity(String name) throws SAXException { }
public void startCDATA() throws SAXException { }
public void endCDATA() throws SAXException { }
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/Features.java 0000664 0000000 0000000 00000010304 12263200227 0025650 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* Fast Infoset ver. 0.1 software ("Software")
*
* Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Software is licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may
* obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations.
*
* Sun supports and benefits from the global community of open source
* developers, and thanks the community for its important contributions and
* open standards-based technology, which Sun has adopted into many of its
* products.
*
* Please note that portions of Software may be provided with notices and
* open source licenses from such communities and third parties that govern the
* use of those portions, and any licenses granted hereunder do not alter any
* rights and obligations you may have under such open source licenses,
* however, the disclaimer of warranty and limitation of liability provisions
* in this License will apply to all Software in this distribution.
*
* You acknowledge that the Software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of any nuclear
* facility.
*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
*/
package com.sun.xml.stream.buffer.sax;
public class Features {
public static final String NAMESPACES_FEATURE =
"http://xml.org/sax/features/namespaces";
public static final String NAMESPACE_PREFIXES_FEATURE =
"http://xml.org/sax/features/namespace-prefixes";
public static final String EXTERNAL_GENERAL_ENTITIES =
"http://xml.org/sax/features/external-general-entities";
public static final String EXTERNAL_PARAMETER_ENTITIES =
"http://xml.org/sax/features/external-parameter-entities";
public static final String STRING_INTERNING_FEATURE =
"http://xml.org/sax/features/string-interning";
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/Properties.java 0000664 0000000 0000000 00000007360 12263200227 0026236 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* Fast Infoset ver. 0.1 software ("Software")
*
* Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Software is licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may
* obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations.
*
* Sun supports and benefits from the global community of open source
* developers, and thanks the community for its important contributions and
* open standards-based technology, which Sun has adopted into many of its
* products.
*
* Please note that portions of Software may be provided with notices and
* open source licenses from such communities and third parties that govern the
* use of those portions, and any licenses granted hereunder do not alter any
* rights and obligations you may have under such open source licenses,
* however, the disclaimer of warranty and limitation of liability provisions
* in this License will apply to all Software in this distribution.
*
* You acknowledge that the Software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of any nuclear
* facility.
*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
*/
package com.sun.xml.stream.buffer.sax;
public class Properties {
public static final String LEXICAL_HANDLER_PROPERTY =
"http://xml.org/sax/properties/lexical-handler";
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/SAXBufferCreator.java 0000664 0000000 0000000 00000023051 12263200227 0027202 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.sax;
import com.sun.xml.stream.buffer.AbstractCreator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import java.io.IOException;
import java.io.InputStream;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
/**
* Writes into {@link MutableXMLStreamBuffer} from SAX.
*
* TODO
* Implement the marking the stream on the element when an ID
* attribute on the element is defined
*/
public class SAXBufferCreator extends AbstractCreator
implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler, LexicalHandler {
protected String[] _namespaceAttributes;
protected int _namespaceAttributesPtr;
private int depth = 0;
public SAXBufferCreator() {
_namespaceAttributes = new String[16 * 2];
}
public SAXBufferCreator(MutableXMLStreamBuffer buffer) {
this();
setBuffer(buffer);
}
public MutableXMLStreamBuffer create(XMLReader reader, InputStream in) throws IOException, SAXException {
return create(reader, in, null);
}
public MutableXMLStreamBuffer create(XMLReader reader, InputStream in, String systemId) throws IOException, SAXException {
if (_buffer == null) {
createBuffer();
}
_buffer.setSystemId(systemId);
reader.setContentHandler(this);
reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, this);
try {
setHasInternedStrings(reader.getFeature(Features.STRING_INTERNING_FEATURE));
} catch (SAXException e) {
}
if (systemId != null) {
InputSource s = new InputSource(systemId);
s.setByteStream(in);
reader.parse(s);
} else {
reader.parse(new InputSource(in));
}
return getXMLStreamBuffer();
}
public void reset() {
_buffer = null;
_namespaceAttributesPtr = 0;
depth=0;
}
public void startDocument() throws SAXException {
storeStructure(T_DOCUMENT);
}
public void endDocument() throws SAXException {
storeStructure(T_END);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
cacheNamespaceAttribute(prefix, uri);
}
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
storeQualifiedName(T_ELEMENT_LN,
uri, localName, qName);
// Has namespaces attributes
if (_namespaceAttributesPtr > 0) {
storeNamespaceAttributes();
}
// Has attributes
if (attributes.getLength() > 0) {
storeAttributes(attributes);
}
depth++;
}
public void endElement(String uri, String localName, String qName) throws SAXException {
storeStructure(T_END);
if(--depth==0)
increaseTreeCount(); // one tree processed
}
public void characters(char ch[], int start, int length) throws SAXException {
storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, ch, start, length);
}
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
characters(ch, start, length);
}
public void processingInstruction(String target, String data) throws SAXException {
storeStructure(T_PROCESSING_INSTRUCTION);
storeStructureString(target);
storeStructureString(data);
}
public void comment(char[] ch, int start, int length) throws SAXException {
storeContentCharacters(T_COMMENT_AS_CHAR_ARRAY, ch, start, length);
}
//
private void cacheNamespaceAttribute(String prefix, String uri) {
_namespaceAttributes[_namespaceAttributesPtr++] = prefix;
_namespaceAttributes[_namespaceAttributesPtr++] = uri;
if (_namespaceAttributesPtr == _namespaceAttributes.length) {
final String[] namespaceAttributes = new String[_namespaceAttributesPtr * 2];
System.arraycopy(_namespaceAttributes, 0, namespaceAttributes, 0, _namespaceAttributesPtr);
_namespaceAttributes = namespaceAttributes;
}
}
private void storeNamespaceAttributes() {
for (int i = 0; i < _namespaceAttributesPtr; i += 2) {
int item = T_NAMESPACE_ATTRIBUTE;
if (_namespaceAttributes[i].length() > 0) {
item |= FLAG_PREFIX;
storeStructureString(_namespaceAttributes[i]);
}
if (_namespaceAttributes[i + 1].length() > 0) {
item |= FLAG_URI;
storeStructureString(_namespaceAttributes[i + 1]);
}
storeStructure(item);
}
_namespaceAttributesPtr = 0;
}
private void storeAttributes(Attributes attributes) {
for (int i = 0; i < attributes.getLength(); i++) {
// Skip NS attributes. Some versions of JDK seem to send wrong local name
// Also it is not stored correctly by the following.
if (attributes.getQName(i).startsWith("xmlns"))
continue;
storeQualifiedName(T_ATTRIBUTE_LN,
attributes.getURI(i),
attributes.getLocalName(i),
attributes.getQName(i));
storeStructureString(attributes.getType(i));
storeContentString(attributes.getValue(i));
}
}
private void storeQualifiedName(int item, String uri, String localName, String qName) {
if (uri.length() > 0) {
item |= FLAG_URI;
storeStructureString(uri);
}
storeStructureString(localName);
if (qName.indexOf(':') >= 0) {
item |= FLAG_QUALIFIED_NAME;
storeStructureString(qName);
}
storeStructure(item);
}
// Empty methods for SAX handlers
// Entity resolver handler
public InputSource resolveEntity (String publicId, String systemId)
throws IOException, SAXException
{
return null;
}
// DTD handler
public void notationDecl (String name, String publicId, String systemId)
throws SAXException
{ }
public void unparsedEntityDecl (String name, String publicId,
String systemId, String notationName)
throws SAXException
{ }
// Content handler
public void setDocumentLocator (Locator locator) { }
public void endPrefixMapping (String prefix) throws SAXException { }
public void skippedEntity (String name) throws SAXException { }
// Lexical handler
public void startDTD(String name, String publicId, String systemId) throws SAXException { }
public void endDTD() throws SAXException { }
public void startEntity(String name) throws SAXException { }
public void endEntity(String name) throws SAXException { }
public void startCDATA() throws SAXException { }
public void endCDATA() throws SAXException { }
// Error handler
public void warning(SAXParseException e) throws SAXException { }
public void error(SAXParseException e) throws SAXException { }
public void fatalError(SAXParseException e) throws SAXException
{
throw e;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/sax/SAXBufferProcessor.java 0000664 0000000 0000000 00000071273 12263200227 0027573 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.sax;
import com.sun.xml.stream.buffer.AbstractProcessor;
import com.sun.xml.stream.buffer.AttributesHolder;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.LocatorImpl;
import javax.xml.XMLConstants;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* A processor of a {@link XMLStreamBuffer} that that reads the XML infoset as
* {@link XMLReader}.
*/
public class SAXBufferProcessor extends AbstractProcessor implements XMLReader {
/**
* Reference to entity resolver.
*/
protected EntityResolver _entityResolver = DEFAULT_LEXICAL_HANDLER;
/**
* Reference to dtd handler.
*/
protected DTDHandler _dtdHandler = DEFAULT_LEXICAL_HANDLER;
/**
* Reference to content handler.
*/
protected ContentHandler _contentHandler = DEFAULT_LEXICAL_HANDLER;
/**
* Reference to error handler.
*/
protected ErrorHandler _errorHandler = DEFAULT_LEXICAL_HANDLER;
/**
* Reference to lexical handler.
*/
protected LexicalHandler _lexicalHandler = DEFAULT_LEXICAL_HANDLER;
/**
* SAX Namespace attributes features
*/
protected boolean _namespacePrefixesFeature = false;
protected AttributesHolder _attributes = new AttributesHolder();
protected String[] _namespacePrefixes = new String[16];
protected int _namespacePrefixesIndex;
protected int[] _namespaceAttributesStartingStack = new int[16];
protected int[] _namespaceAttributesStack = new int[16];
protected int _namespaceAttributesStackIndex;
public SAXBufferProcessor() {
}
/**
* @deprecated
* Use {@link #SAXBufferProcessor(XMLStreamBuffer, boolean)}
*/
public SAXBufferProcessor(XMLStreamBuffer buffer) {
setXMLStreamBuffer(buffer);
}
/**
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*/
public SAXBufferProcessor(XMLStreamBuffer buffer, boolean produceFragmentEvent) {
setXMLStreamBuffer(buffer,produceFragmentEvent);
}
public boolean getFeature(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Features.NAMESPACES_FEATURE)) {
return true;
} else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
return _namespacePrefixesFeature;
} else if (name.equals(Features.EXTERNAL_GENERAL_ENTITIES)) {
return true;
} else if (name.equals(Features.EXTERNAL_PARAMETER_ENTITIES)) {
return true;
} else if (name.equals(Features.STRING_INTERNING_FEATURE)) {
return _stringInterningFeature;
} else {
throw new SAXNotRecognizedException(
"Feature not supported: " + name);
}
}
public void setFeature(String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Features.NAMESPACES_FEATURE)) {
if (!value) {
throw new SAXNotSupportedException(name + ":" + value);
}
} else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
_namespacePrefixesFeature = value;
} else if (name.equals(Features.EXTERNAL_GENERAL_ENTITIES)) {
// ignore
} else if (name.equals(Features.EXTERNAL_PARAMETER_ENTITIES)) {
// ignore
} else if (name.equals(Features.STRING_INTERNING_FEATURE)) {
if (value != _stringInterningFeature) {
throw new SAXNotSupportedException(name + ":" + value);
}
} else {
throw new SAXNotRecognizedException(
"Feature not supported: " + name);
}
}
public Object getProperty(String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
return getLexicalHandler();
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setEntityResolver(EntityResolver resolver) {
_entityResolver = resolver;
}
public EntityResolver getEntityResolver() {
return _entityResolver;
}
public void setDTDHandler(DTDHandler handler) {
_dtdHandler = handler;
}
public DTDHandler getDTDHandler() {
return _dtdHandler;
}
public void setContentHandler(ContentHandler handler) {
_contentHandler = handler;
}
public ContentHandler getContentHandler() {
return _contentHandler;
}
public void setErrorHandler(ErrorHandler handler) {
_errorHandler = handler;
}
public ErrorHandler getErrorHandler() {
return _errorHandler;
}
public void setLexicalHandler(LexicalHandler handler) {
_lexicalHandler = handler;
}
public LexicalHandler getLexicalHandler() {
return _lexicalHandler;
}
public void parse(InputSource input) throws IOException, SAXException {
// InputSource is ignored
process();
}
public void parse(String systemId) throws IOException, SAXException {
// systemId is ignored
process();
}
/**
* Short-hand for {@link #setXMLStreamBuffer(XMLStreamBuffer)} then {@link #process()}.
*
* @deprecated
* Use {@link #process(XMLStreamBuffer, boolean)}
*/
public final void process(XMLStreamBuffer buffer) throws SAXException {
setXMLStreamBuffer(buffer);
process();
}
/**
* Short-hand for {@link #setXMLStreamBuffer(XMLStreamBuffer,boolean)} then {@link #process()}.
*
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*/
public final void process(XMLStreamBuffer buffer, boolean produceFragmentEvent) throws SAXException {
setXMLStreamBuffer(buffer);
process();
}
/**
* Resets the parser to read from the beginning of the given {@link XMLStreamBuffer}.
*
* @deprecated
* Use {@link #setXMLStreamBuffer(XMLStreamBuffer, boolean)}.
*/
public void setXMLStreamBuffer(XMLStreamBuffer buffer) {
setBuffer(buffer);
}
/**
* Resets the parser to read from the beginning of the given {@link XMLStreamBuffer}.
*
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*/
public void setXMLStreamBuffer(XMLStreamBuffer buffer, boolean produceFragmentEvent) {
if(!produceFragmentEvent && _treeCount>1)
throw new IllegalStateException("Can't write a forest to a full XML infoset");
setBuffer(buffer,produceFragmentEvent);
}
/**
* Parse the sub-tree (or a whole document) that {@link XMLStreamBuffer}
* points to, and sends events to handlers.
*
*
* TODO:
* We probably need two modes for a sub-tree event generation. One for
* firing a sub-tree as if it's a whole document (in which case start/endDocument
* and appropriate additional namespace bindings are necessary), and the other
* mode for firing a subtree as a subtree, like it does today.
* A stream buffer SAX feature could be used to specify this.
*
* @throws SAXException
* Follow the same semantics as {@link XMLReader#parse(InputSource)}.
*/
public final void process() throws SAXException {
if(!_fragmentMode) {
LocatorImpl nullLocator = new LocatorImpl();
nullLocator.setSystemId(_buffer.getSystemId());
nullLocator.setLineNumber(-1);
nullLocator.setColumnNumber(-1);
_contentHandler.setDocumentLocator(nullLocator);
_contentHandler.startDocument();
// TODO: if we are writing a fragment stream buffer as a full XML document,
// we need to declare in-scope namespaces as if they are on the root element.
}
while (_treeCount>0) {
final int item = readEiiState();
switch(item) {
case STATE_DOCUMENT:
processDocument();
_treeCount--;
break;
case STATE_END:
// Empty buffer
return;
case STATE_ELEMENT_U_LN_QN:
processElement(readStructureString(), readStructureString(), readStructureString(), isInscope());
_treeCount--;
break;
case STATE_ELEMENT_P_U_LN:
{
final String prefix = readStructureString();
final String uri = readStructureString();
final String localName = readStructureString();
processElement(uri, localName, getQName(prefix, localName),isInscope());
_treeCount--;
break;
}
case STATE_ELEMENT_U_LN: {
final String uri = readStructureString();
final String localName = readStructureString();
processElement(uri, localName, localName,isInscope());
_treeCount--;
break;
}
case STATE_ELEMENT_LN:
{
final String localName = readStructureString();
processElement("", localName, localName,isInscope());
_treeCount--;
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
processCommentAsCharArraySmall();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
processCommentAsCharArrayMedium();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
processCommentAsCharArrayCopy();
break;
case STATE_COMMENT_AS_STRING:
processComment(readContentString());
break;
case STATE_PROCESSING_INSTRUCTION:
processProcessingInstruction(readStructureString(), readStructureString());
break;
default:
throw reportFatalError("Illegal state for DIIs: "+item);
}
}
if(!_fragmentMode)
_contentHandler.endDocument();
}
private void processCommentAsCharArraySmall() throws SAXException {
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
processComment(_contentCharactersBuffer, start, length);
}
/**
* Report a fatal error and abort.
*
* This is necessary to follow the SAX semantics of error handling.
*/
private SAXParseException reportFatalError(String msg) throws SAXException {
SAXParseException spe = new SAXParseException(msg, null);
if(_errorHandler!=null)
_errorHandler.fatalError(spe);
return spe;
}
private boolean isInscope() {
return _buffer.getInscopeNamespaces().size() > 0;
}
private void processDocument() throws SAXException {
while(true) {
int item = readEiiState();
switch(item) {
case STATE_ELEMENT_U_LN_QN:
processElement(readStructureString(), readStructureString(), readStructureString(),isInscope());
break;
case STATE_ELEMENT_P_U_LN:
{
final String prefix = readStructureString();
final String uri = readStructureString();
final String localName = readStructureString();
processElement(uri, localName, getQName(prefix, localName),isInscope());
break;
}
case STATE_ELEMENT_U_LN: {
final String uri = readStructureString();
final String localName = readStructureString();
processElement(uri, localName, localName,isInscope());
break;
}
case STATE_ELEMENT_LN:
{
final String localName = readStructureString();
processElement("", localName, localName,isInscope());
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
processCommentAsCharArraySmall();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
processCommentAsCharArrayMedium();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
processCommentAsCharArrayCopy();
break;
case STATE_COMMENT_AS_STRING:
processComment(readContentString());
break;
case STATE_PROCESSING_INSTRUCTION:
processProcessingInstruction(readStructureString(), readStructureString());
break;
case STATE_END:
return;
default:
throw reportFatalError("Illegal state for child of DII: "+item);
}
}
}
protected void processElement(String uri, String localName, String qName, boolean inscope) throws SAXException {
boolean hasAttributes = false;
boolean hasNamespaceAttributes = false;
int item = peekStructure();
Set prefixSet = inscope ? new HashSet() : Collections.emptySet();
if ((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE) {
cacheNamespacePrefixStartingIndex();
hasNamespaceAttributes = true;
item = processNamespaceAttributes(item, inscope, prefixSet);
}
if (inscope) {
readInscopeNamespaces(prefixSet);
}
if ((item & TYPE_MASK) == T_ATTRIBUTE) {
hasAttributes = true;
processAttributes(item);
}
_contentHandler.startElement(uri, localName, qName, _attributes);
if (hasAttributes) {
_attributes.clear();
}
do {
item = readEiiState();
switch(item) {
case STATE_ELEMENT_U_LN_QN:
processElement(readStructureString(), readStructureString(), readStructureString(), false);
break;
case STATE_ELEMENT_P_U_LN:
{
final String p = readStructureString();
final String u = readStructureString();
final String ln = readStructureString();
processElement(u, ln, getQName(p, ln),false);
break;
}
case STATE_ELEMENT_U_LN: {
final String u = readStructureString();
final String ln = readStructureString();
processElement(u, ln, ln,false);
break;
}
case STATE_ELEMENT_LN: {
final String ln = readStructureString();
processElement("", ln, ln,false);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_SMALL:
{
final int length = readStructure();
int start = readContentCharactersBuffer(length);
_contentHandler.characters(_contentCharactersBuffer, start, length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_MEDIUM:
{
final int length = readStructure16();
int start = readContentCharactersBuffer(length);
_contentHandler.characters(_contentCharactersBuffer, start, length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_COPY:
{
final char[] ch = readContentCharactersCopy();
_contentHandler.characters(ch, 0, ch.length);
break;
}
case STATE_TEXT_AS_STRING:
{
final String s = readContentString();
_contentHandler.characters(s.toCharArray(), 0, s.length());
break;
}
case STATE_TEXT_AS_OBJECT:
{
final CharSequence c = (CharSequence)readContentObject();
final String s = c.toString();
_contentHandler.characters(s.toCharArray(), 0, s.length());
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
processCommentAsCharArraySmall();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
processCommentAsCharArrayMedium();
break;
case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
processCommentAsCharArrayCopy();
break;
case T_COMMENT_AS_STRING:
processComment(readContentString());
break;
case STATE_PROCESSING_INSTRUCTION:
processProcessingInstruction(readStructureString(), readStructureString());
break;
case STATE_END:
break;
default:
throw reportFatalError("Illegal state for child of EII: "+item);
}
} while(item != STATE_END);
_contentHandler.endElement(uri, localName, qName);
if (hasNamespaceAttributes) {
processEndPrefixMapping();
}
}
private void readInscopeNamespaces(Set prefixSet) throws SAXException {
for (Map.Entry e : _buffer.getInscopeNamespaces().entrySet()) {
String key = fixNull(e.getKey());
// If the prefix is already written, do not write the prefix
if (!prefixSet.contains(key)) {
processNamespaceAttribute(key,e.getValue());
}
}
}
private static String fixNull(String s) {
if (s == null) return "";
else return s;
}
private void processCommentAsCharArrayCopy() throws SAXException {
final char[] ch = readContentCharactersCopy();
processComment(ch, 0, ch.length);
}
private void processCommentAsCharArrayMedium() throws SAXException {
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
processComment(_contentCharactersBuffer, start, length);
}
private void processEndPrefixMapping() throws SAXException {
final int end = _namespaceAttributesStack[--_namespaceAttributesStackIndex];
// final int start = (_namespaceAttributesStackIndex > 0) ? _namespaceAttributesStack[_namespaceAttributesStackIndex] : 0;
final int start = (_namespaceAttributesStackIndex >= 0) ? _namespaceAttributesStartingStack[_namespaceAttributesStackIndex] : 0;
for (int i = end - 1; i >= start; i--) {
_contentHandler.endPrefixMapping(_namespacePrefixes[i]);
}
_namespacePrefixesIndex = start;
}
private int processNamespaceAttributes(int item,boolean collectPrefixes, Set prefixSet) throws SAXException {
do {
String prefix;
switch(getNIIState(item)) {
case STATE_NAMESPACE_ATTRIBUTE:
// Undeclaration of default namespace
processNamespaceAttribute("", "");
if(collectPrefixes) {
prefixSet.add("");
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P:
// Undeclaration of namespace
prefix = readStructureString();
processNamespaceAttribute(prefix, "");
if(collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P_U:
// Declaration with prefix
prefix = readStructureString();
processNamespaceAttribute(prefix, readStructureString());
if(collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_U:
// Default declaration
processNamespaceAttribute("", readStructureString());
if(collectPrefixes) {
prefixSet.add("");
}
break;
default:
throw reportFatalError("Illegal state: "+item);
}
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE);
cacheNamespacePrefixIndex();
return item;
}
private void processAttributes(int item) throws SAXException {
do {
switch(getAIIState(item)) {
case STATE_ATTRIBUTE_U_LN_QN:
_attributes.addAttributeWithQName(readStructureString(), readStructureString(), readStructureString(), readStructureString(), readContentString());
break;
case STATE_ATTRIBUTE_P_U_LN:
{
final String p = readStructureString();
final String u = readStructureString();
final String ln = readStructureString();
_attributes.addAttributeWithQName(u, ln, getQName(p, ln), readStructureString(), readContentString());
break;
}
case STATE_ATTRIBUTE_U_LN: {
final String u = readStructureString();
final String ln = readStructureString();
_attributes.addAttributeWithQName(u, ln, ln, readStructureString(), readContentString());
break;
}
case STATE_ATTRIBUTE_LN: {
final String ln = readStructureString();
_attributes.addAttributeWithQName("", ln, ln, readStructureString(), readContentString());
break;
}
default:
throw reportFatalError("Illegal state: "+item);
}
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_ATTRIBUTE);
}
private void processNamespaceAttribute(String prefix, String uri) throws SAXException {
_contentHandler.startPrefixMapping(prefix, uri);
if (_namespacePrefixesFeature) {
// Add the namespace delcaration as an attribute
if (prefix != "") {
_attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix,
getQName(XMLConstants.XMLNS_ATTRIBUTE, prefix),
"CDATA", uri);
} else {
_attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE,
XMLConstants.XMLNS_ATTRIBUTE,
"CDATA", uri);
}
}
cacheNamespacePrefix(prefix);
}
private void cacheNamespacePrefix(String prefix) {
if (_namespacePrefixesIndex == _namespacePrefixes.length) {
final String[] namespaceAttributes = new String[_namespacePrefixesIndex * 3 / 2 + 1];
System.arraycopy(_namespacePrefixes, 0, namespaceAttributes, 0, _namespacePrefixesIndex);
_namespacePrefixes = namespaceAttributes;
}
_namespacePrefixes[_namespacePrefixesIndex++] = prefix;
}
private void cacheNamespacePrefixIndex() {
if (_namespaceAttributesStackIndex == _namespaceAttributesStack.length) {
final int[] namespaceAttributesStack = new int[_namespaceAttributesStackIndex * 3 /2 + 1];
System.arraycopy(_namespaceAttributesStack, 0, namespaceAttributesStack, 0, _namespaceAttributesStackIndex);
_namespaceAttributesStack = namespaceAttributesStack;
}
_namespaceAttributesStack[_namespaceAttributesStackIndex++] = _namespacePrefixesIndex;
}
private void cacheNamespacePrefixStartingIndex() {
if (_namespaceAttributesStackIndex == _namespaceAttributesStartingStack.length) {
final int[] namespaceAttributesStart = new int[_namespaceAttributesStackIndex * 3 /2 + 1];
System.arraycopy(_namespaceAttributesStartingStack, 0, namespaceAttributesStart, 0, _namespaceAttributesStackIndex);
_namespaceAttributesStartingStack = namespaceAttributesStart;
}
_namespaceAttributesStartingStack[_namespaceAttributesStackIndex] = _namespacePrefixesIndex;
}
private void processComment(String s) throws SAXException {
processComment(s.toCharArray(), 0, s.length());
}
private void processComment(char[] ch, int start, int length) throws SAXException {
_lexicalHandler.comment(ch, start, length);
}
private void processProcessingInstruction(String target, String data) throws SAXException {
_contentHandler.processingInstruction(target, data);
}
private static final DefaultWithLexicalHandler DEFAULT_LEXICAL_HANDLER = new DefaultWithLexicalHandler();
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/ 0000775 0000000 0000000 00000000000 12263200227 0023415 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/NamespaceContexHelper.java 0000664 0000000 0000000 00000025277 12263200227 0030512 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jvnet.staxex.NamespaceContextEx;
/**
* A helper class for managing the declaration of namespaces.
*
* A namespace is declared on a namespace context.
* Namespace contexts are pushed on and popped off the namespace context stack.
*
* A declared namespace will be in scope iff the context that it was declared on
* has not been popped off the stack.
*
* When instantiated the namespace stack consists of the root namespace context,
* which contains, by default, the "xml" and "xmlns" declarations.
* Namespaces may be declarations may be declared on the root context.
* The root context cannot be popped but can be reset to contain just the
* "xml" and "xmlns" declarations.
*
* Implementation note: determining the prefix from a namespace URI
* (or vice versa) is efficient when there are few namespace
* declarations i.e. what is considered to be the case for namespace
* declarations in 'average' XML documents. The look up of a namespace URI
* given a prefix is performed in O(n) time. The look up of a prefix given
* a namespace URI is performed in O(2n) time.
*
* The implementation does not scale when there are many namespace
* declarations. TODO: Use a hash map when there are many namespace
* declarations.
*
* @author Paul.Sandoz@Sun.Com
*/
final public class NamespaceContexHelper implements NamespaceContextEx {
private static int DEFAULT_SIZE = 8;
// The prefixes of the namespace declarations
private String[] prefixes = new String[DEFAULT_SIZE];
// The URIs of the namespace declarations
private String[] namespaceURIs = new String[DEFAULT_SIZE];
// Current position to store the next namespace declaration
private int namespacePosition;
// The namespace contexts
private int[] contexts = new int[DEFAULT_SIZE];
// Current position to store the next namespace context
private int contextPosition;
/**
* Create a new NamespaceContexHelper.
*
*/
public NamespaceContexHelper() {
// The default namespace declarations that are always in scope
prefixes[0] = "xml";
namespaceURIs[0] = "http://www.w3.org/XML/1998/namespace";
prefixes[1] = "xmlns";
namespaceURIs[1] = "http://www.w3.org/2000/xmlns/";
namespacePosition = 2;
}
// NamespaceContext interface
public String getNamespaceURI(String prefix) {
if (prefix == null) throw new IllegalArgumentException();
prefix = prefix.intern();
for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredPrefix = prefixes[i];
if (declaredPrefix == prefix) {
return namespaceURIs[i];
}
}
return "";
}
public String getPrefix(String namespaceURI) {
if (namespaceURI == null) throw new IllegalArgumentException();
for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredNamespaceURI = namespaceURIs[i];
if (declaredNamespaceURI == namespaceURI || declaredNamespaceURI.equals(namespaceURI)) {
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
for (++i; i < namespacePosition; i++)
if (declaredPrefix == prefixes[i])
return null;
return declaredPrefix;
}
}
return null;
}
public Iterator getPrefixes(String namespaceURI) {
if (namespaceURI == null) throw new IllegalArgumentException();
List l = new ArrayList();
NAMESPACE_LOOP: for (int i = namespacePosition - 1; i >= 0; i--) {
final String declaredNamespaceURI = namespaceURIs[i];
if (declaredNamespaceURI == namespaceURI || declaredNamespaceURI.equals(namespaceURI)) {
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
for (int j = i + 1; j < namespacePosition; j++)
if (declaredPrefix == prefixes[j])
continue NAMESPACE_LOOP;
l.add(declaredPrefix);
}
}
return l.iterator();
}
// NamespaceContextEx interface
public Iterator iterator() {
if (namespacePosition == 2)
return Collections.EMPTY_LIST.iterator();
final List namespaces =
new ArrayList(namespacePosition);
NAMESPACE_LOOP: for (int i = namespacePosition - 1; i >= 2; i--) {
final String declaredPrefix = prefixes[i];
// Check if prefix is out of scope
for (int j = i + 1; j < namespacePosition; j++) {
if (declaredPrefix == prefixes[j])
continue NAMESPACE_LOOP;
namespaces.add(new NamespaceBindingImpl(i));
}
}
return namespaces.iterator();
}
final private class NamespaceBindingImpl implements NamespaceContextEx.Binding {
int index;
NamespaceBindingImpl(int index) {
this.index = index;
}
public String getPrefix() {
return prefixes[index];
}
public String getNamespaceURI() {
return namespaceURIs[index];
}
}
/**
* Declare a default namespace.
*
* @param namespaceURI the namespace URI to declare, may be null.
*/
public void declareDefaultNamespace(String namespaceURI) {
declareNamespace("", namespaceURI);
}
/**
* Declare a namespace.
*
* The namespace will be declared on the current namespace context.
*
* The namespace can be removed by popping the current namespace
* context, or, if the declaration occured in the root context, by
* reseting the namespace context.
*
* A default namespace can be declared by passing ""
as
* the value of the prefix parameter.
* A namespace may be undeclared by passing null
as the
* value of the namespaceURI parameter.
*
* @param prefix the namespace prefix to declare, may not be null.
* @param namespaceURI the namespace URI to declare, may be null.
* @throws IllegalArgumentException, if the prefix is null.
*/
public void declareNamespace(String prefix, String namespaceURI) {
if (prefix == null) throw new IllegalArgumentException();
prefix = prefix.intern();
// Ignore the "xml" or "xmlns" declarations
if (prefix == "xml" || prefix == "xmlns")
return;
// Check for undeclaration
if (namespaceURI != null)
namespaceURI = namespaceURI.intern();
if (namespacePosition == namespaceURIs.length)
resizeNamespaces();
// Add new declaration
prefixes[namespacePosition] = prefix;
namespaceURIs[namespacePosition++] = namespaceURI;
}
private void resizeNamespaces() {
final int newLength = namespaceURIs.length * 3 / 2 + 1;
String[] newPrefixes = new String[newLength];
System.arraycopy(prefixes, 0, newPrefixes, 0, prefixes.length);
prefixes = newPrefixes;
String[] newNamespaceURIs = new String[newLength];
System.arraycopy(namespaceURIs, 0, newNamespaceURIs, 0, namespaceURIs.length);
namespaceURIs = newNamespaceURIs;
}
/**
* Push a namespace context on the stack.
*/
public void pushContext() {
if (contextPosition == contexts.length)
resizeContexts();
contexts[contextPosition++] = namespacePosition;
}
private void resizeContexts() {
int[] newContexts = new int[contexts.length * 3 / 2 + 1];
System.arraycopy(contexts, 0, newContexts, 0, contexts.length);
contexts = newContexts;
}
/**
* Pop the namespace context off the stack.
*
* Namespaces declared within the context (to be popped)
* will be removed and no longer be in scope.
*/
public void popContext() {
if (contextPosition > 0) {
namespacePosition = contexts[--contextPosition];
}
}
/**
* Reset namespace contexts.
*
* Pop all namespace contexts and reset the root context.
*/
public void resetContexts() {
namespacePosition = 2;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/StreamBufferCreator.java 0000664 0000000 0000000 00000011165 12263200227 0030171 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.AbstractCreator;
import java.util.ArrayList;
import java.util.List;
/**
* {@link AbstractCreator} with additional convenience code.
*
* @author Paul Sandoz
* @author Venu
* @author Kohsuke Kawaguchi
*/
abstract class StreamBufferCreator extends AbstractCreator {
private boolean checkAttributeValue = false;
protected List attributeValuePrefixes = new ArrayList();
protected void storeQualifiedName(int item, String prefix, String uri, String localName) {
if (uri != null && uri.length() > 0) {
if (prefix != null && prefix.length() > 0) {
item |= FLAG_PREFIX;
storeStructureString(prefix);
}
item |= FLAG_URI;
storeStructureString(uri);
}
storeStructureString(localName);
storeStructure(item);
}
protected final void storeNamespaceAttribute(String prefix, String uri) {
int item = T_NAMESPACE_ATTRIBUTE;
if (prefix != null && prefix.length() > 0) {
item |= FLAG_PREFIX;
storeStructureString(prefix);
}
if (uri != null && uri.length() > 0) {
item |= FLAG_URI;
storeStructureString(uri);
}
storeStructure(item);
}
protected final void storeAttribute(String prefix, String uri, String localName, String type, String value) {
storeQualifiedName(T_ATTRIBUTE_LN, prefix, uri, localName);
storeStructureString(type);
storeContentString(value);
if(checkAttributeValue && value.indexOf("://") == -1){ // the condition after && avoids looking inside URIs
int firstIndex = value.indexOf(":");
int lastIndex = value.lastIndexOf(":"); // Check last index of : as some SAML namespace have multiple ":"s
if(firstIndex != -1 && lastIndex == firstIndex){
String valuePrefix = value.substring(0, firstIndex);
if(!attributeValuePrefixes.contains(valuePrefix)){
attributeValuePrefixes.add(valuePrefix);
}
}
}
}
public final List getAttributeValuePrefixes(){
return attributeValuePrefixes;
}
protected final void storeProcessingInstruction(String target, String data) {
storeStructure(T_PROCESSING_INSTRUCTION);
storeStructureString(target);
storeStructureString(data);
}
public final boolean isCheckAttributeValue(){
return checkAttributeValue;
}
public final void setCheckAttributeValue(boolean value){
this.checkAttributeValue = value;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/StreamReaderBufferCreator.java 0000664 0000000 0000000 00000034552 12263200227 0031321 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import org.jvnet.staxex.Base64Data;
import org.jvnet.staxex.XMLStreamReaderEx;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.HashMap;
import java.util.Map;
/**
* Create a buffer using an {@link XMLStreamReader}.
*
* TODO: Implement the marking the stream on the element when an ID
* attribute on the element is defined
*/
public class StreamReaderBufferCreator extends StreamBufferCreator {
private int _eventType;
private boolean _storeInScopeNamespacesOnElementFragment;
private Map _inScopePrefixes;
/**
* Create a stream reader buffer creator.
*
* A stream buffer will be created for storing the infoset
* from a stream reader.
*/
public StreamReaderBufferCreator() {
}
/**
* Create a stream reader buffer creator using a mutable stream buffer.
*
* @param buffer the mutable stream buffer.
*/
public StreamReaderBufferCreator(MutableXMLStreamBuffer buffer) {
setBuffer(buffer);
}
/**
* Create the buffer from a stream reader.
*
* The stream reader must be positioned at the start of the document
* or the start of an element.
*
* If the stream is positioned at the start of the document then the
* whole document is stored and after storing the stream will be positioned
* at the end of the document.
*
* If the stream is positioned at the start of an element then the
* element and all its children will be stored and after storing the stream
* will be positioned at the next event after the end of the element.
*
* @return the mutable stream buffer.
* @throws XMLStreamException if the stream reader is not positioned at
* the start of the document or at an element.
*/
public MutableXMLStreamBuffer create(XMLStreamReader reader) throws XMLStreamException {
if (_buffer == null) {
createBuffer();
}
store(reader);
return getXMLStreamBuffer();
}
/**
* Creates the buffer from a stream reader that is an element fragment.
*
* The stream reader will be moved to the position of the next start of
* an element if the stream reader is not already positioned at the start
* of an element.
*
* The element and all its children will be stored and after storing the stream
* will be positioned at the next event after the end of the element.
*
* @param storeInScopeNamespaces true if in-scope namespaces of the element
* fragment should be stored.
* @return the mutable stream buffer.
* @throws XMLStreamException if the stream reader cannot be positioned at
* the start of an element.
*/
public MutableXMLStreamBuffer createElementFragment(XMLStreamReader reader,
boolean storeInScopeNamespaces) throws XMLStreamException {
if (_buffer == null) {
createBuffer();
}
if (!reader.hasNext()) {
return _buffer;
}
_storeInScopeNamespacesOnElementFragment = storeInScopeNamespaces;
_eventType = reader.getEventType();
if (_eventType != XMLStreamReader.START_ELEMENT) {
do {
_eventType = reader.next();
} while(_eventType != XMLStreamReader.START_ELEMENT && _eventType != XMLStreamReader.END_DOCUMENT);
}
if (storeInScopeNamespaces) {
_inScopePrefixes = new HashMap();
}
storeElementAndChildren(reader);
return getXMLStreamBuffer();
}
private void store(XMLStreamReader reader) throws XMLStreamException {
if (!reader.hasNext()) {
return;
}
_eventType = reader.getEventType();
switch (_eventType) {
case XMLStreamReader.START_DOCUMENT:
storeDocumentAndChildren(reader);
break;
case XMLStreamReader.START_ELEMENT:
storeElementAndChildren(reader);
break;
default:
throw new XMLStreamException("XMLStreamReader not positioned at a document or element");
}
increaseTreeCount();
}
private void storeDocumentAndChildren(XMLStreamReader reader) throws XMLStreamException {
storeStructure(T_DOCUMENT);
_eventType = reader.next();
while (_eventType != XMLStreamReader.END_DOCUMENT) {
switch (_eventType) {
case XMLStreamReader.START_ELEMENT:
storeElementAndChildren(reader);
continue;
case XMLStreamReader.COMMENT:
storeComment(reader);
break;
case XMLStreamReader.PROCESSING_INSTRUCTION:
storeProcessingInstruction(reader);
break;
}
_eventType = reader.next();
}
storeStructure(T_END);
}
private void storeElementAndChildren(XMLStreamReader reader) throws XMLStreamException {
if (reader instanceof XMLStreamReaderEx) {
storeElementAndChildrenEx((XMLStreamReaderEx)reader);
} else {
storeElementAndChildrenNoEx(reader);
}
}
private void storeElementAndChildrenEx(XMLStreamReaderEx reader) throws XMLStreamException {
int depth = 1;
if (_storeInScopeNamespacesOnElementFragment) {
storeElementWithInScopeNamespaces(reader);
} else {
storeElement(reader);
}
while(depth > 0) {
_eventType = reader.next();
switch (_eventType) {
case XMLStreamReader.START_ELEMENT:
depth++;
storeElement(reader);
break;
case XMLStreamReader.END_ELEMENT:
depth--;
storeStructure(T_END);
break;
case XMLStreamReader.NAMESPACE:
storeNamespaceAttributes(reader);
break;
case XMLStreamReader.ATTRIBUTE:
storeAttributes(reader);
break;
case XMLStreamReader.SPACE:
case XMLStreamReader.CHARACTERS:
case XMLStreamReader.CDATA: {
CharSequence c = reader.getPCDATA();
if (c instanceof Base64Data) {
storeStructure(T_TEXT_AS_OBJECT);
storeContentObject(((Base64Data)c).clone());
} else {
storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
reader.getTextCharacters(), reader.getTextStart(),
reader.getTextLength());
}
break;
}
case XMLStreamReader.COMMENT:
storeComment(reader);
break;
case XMLStreamReader.PROCESSING_INSTRUCTION:
storeProcessingInstruction(reader);
break;
}
}
/*
* Move to next item after the end of the element
* that has been stored
*/
_eventType = reader.next();
}
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException {
int depth = 1;
if (_storeInScopeNamespacesOnElementFragment) {
storeElementWithInScopeNamespaces(reader);
} else {
storeElement(reader);
}
while(depth > 0) {
_eventType = reader.next();
switch (_eventType) {
case XMLStreamReader.START_ELEMENT:
depth++;
storeElement(reader);
break;
case XMLStreamReader.END_ELEMENT:
depth--;
storeStructure(T_END);
break;
case XMLStreamReader.NAMESPACE:
storeNamespaceAttributes(reader);
break;
case XMLStreamReader.ATTRIBUTE:
storeAttributes(reader);
break;
case XMLStreamReader.SPACE:
case XMLStreamReader.CHARACTERS:
case XMLStreamReader.CDATA: {
storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
reader.getTextCharacters(), reader.getTextStart(),
reader.getTextLength());
break;
}
case XMLStreamReader.COMMENT:
storeComment(reader);
break;
case XMLStreamReader.PROCESSING_INSTRUCTION:
storeProcessingInstruction(reader);
break;
}
}
/*
* Move to next item after the end of the element
* that has been stored
*/
_eventType = reader.next();
}
private void storeElementWithInScopeNamespaces(XMLStreamReader reader) {
storeQualifiedName(T_ELEMENT_LN,
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
if (reader.getNamespaceCount() > 0) {
storeNamespaceAttributes(reader);
}
if (reader.getAttributeCount() > 0) {
storeAttributes(reader);
}
}
private void storeElement(XMLStreamReader reader) {
storeQualifiedName(T_ELEMENT_LN,
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
if (reader.getNamespaceCount() > 0) {
storeNamespaceAttributes(reader);
}
if (reader.getAttributeCount() > 0) {
storeAttributes(reader);
}
}
/**
* A low level method a create a structure element explicitly. This is useful when xsb is
* created from a fragment's XMLStreamReader and inscope namespaces can be passed using
* this method. Note that there is no way to enumerate namespaces from XMLStreamReader.
*
* For e.g: Say the SOAP message is as follows
*
* ...
*
* when xsb is to be created using a reader that is at tag, the inscope
* namespace like 'n1' can be passed using this method.
*
* WARNING: Instead of using this, try other methods(if you don't know what you are
* doing).
*
* @param ns an array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }.
*/
public void storeElement(String nsURI, String localName, String prefix, String[] ns) {
storeQualifiedName(T_ELEMENT_LN, prefix, nsURI, localName);
storeNamespaceAttributes(ns);
}
/**
* A low level method a create a structure element explicitly. This is
* required to support {@link #storeElement} method.
*
* WARNING: Instead of using this, try other methods(if you don't know what
* you are doing).
*/
public void storeEndElement() {
storeStructure(T_END);
}
private void storeNamespaceAttributes(XMLStreamReader reader) {
int count = reader.getNamespaceCount();
for (int i = 0; i < count; i++) {
storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
}
/**
* @param ns an array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }.
*/
private void storeNamespaceAttributes(String[] ns) {
for (int i = 0; i < ns.length; i=i+2) {
storeNamespaceAttribute(ns[i], ns[i+1]);
}
}
private void storeAttributes(XMLStreamReader reader) {
int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
storeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader.getAttributeLocalName(i),
reader.getAttributeType(i), reader.getAttributeValue(i));
}
}
private void storeComment(XMLStreamReader reader) {
storeContentCharacters(T_COMMENT_AS_CHAR_ARRAY,
reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
}
private void storeProcessingInstruction(XMLStreamReader reader) {
storeProcessingInstruction(reader.getPITarget(), reader.getPIData());
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/StreamReaderBufferProcessor.java 0000664 0000000 0000000 00000117225 12263200227 0031700 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.AbstractProcessor;
import com.sun.xml.stream.buffer.AttributesHolder;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import com.sun.xml.stream.buffer.XMLStreamBufferMark;
import org.jvnet.staxex.NamespaceContextEx;
import org.jvnet.staxex.XMLStreamReaderEx;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.*;
/**
* A processor of a {@link XMLStreamBuffer} that reads the XML infoset as
* {@link XMLStreamReader}.
*
*
* Because of {@link XMLStreamReader} design, this processor always produce
* a full document infoset, even if the buffer just contains a fragment.
*
*
* When {@link XMLStreamBuffer} contains a multiple tree (AKA "forest"),
* {@link XMLStreamReader} will behave as if there are multiple root elements
* (so you'll see {@link #START_ELEMENT} event where you'd normally expect
* {@link #END_DOCUMENT}.)
*
* @author Paul.Sandoz@Sun.Com
* @author K.Venugopal@sun.com
*/
public class StreamReaderBufferProcessor extends AbstractProcessor implements XMLStreamReaderEx {
private static final int CACHE_SIZE = 16;
// Stack to hold element and namespace declaration information
protected ElementStackEntry[] _stack = new ElementStackEntry[CACHE_SIZE];
/** The top-most active entry of the {@link #_stack}. */
protected ElementStackEntry _stackTop;
/** The element depth that we are in. Used to determine when we are done with a tree. */
protected int _depth;
// Arrays to hold all namespace declarations
/**
* Namespace prefixes. Can be empty but not null.
*/
protected String[] _namespaceAIIsPrefix = new String[CACHE_SIZE];
protected String[] _namespaceAIIsNamespaceName = new String[CACHE_SIZE];
protected int _namespaceAIIsEnd;
// Internal namespace context implementation
protected InternalNamespaceContext _nsCtx = new InternalNamespaceContext();
// The current event type
protected int _eventType;
/**
* Holder of the attributes.
*
* Be careful that this follows the SAX convention of using "" instead of null.
*/
protected AttributesHolder _attributeCache;
// Characters as a CharSequence
protected CharSequence _charSequence;
// Characters as a char array with offset and length
protected char[] _characters;
protected int _textOffset;
protected int _textLen;
protected String _piTarget;
protected String _piData;
//
// Represents the parser state wrt the end of parsing.
//
/**
* The parser is in the middle of parsing a document,
* with no end in sight.
*/
private static final int PARSING = 1;
/**
* The parser has already reported the {@link #END_ELEMENT},
* and we are parsing a fragment. We'll report {@link #END_DOCUMENT}
* next and be done.
*/
private static final int PENDING_END_DOCUMENT = 2;
/**
* The parser has reported the {@link #END_DOCUMENT} event,
* so we are really done parsing.
*/
private static final int COMPLETED = 3;
/**
* True if processing is complete.
*/
private int _completionState;
public StreamReaderBufferProcessor() {
for (int i=0; i < _stack.length; i++){
_stack[i] = new ElementStackEntry();
}
_attributeCache = new AttributesHolder();
}
public StreamReaderBufferProcessor(XMLStreamBuffer buffer) throws XMLStreamException {
this();
setXMLStreamBuffer(buffer);
}
public void setXMLStreamBuffer(XMLStreamBuffer buffer) throws XMLStreamException {
setBuffer(buffer,buffer.isFragment());
_completionState = PARSING;
_namespaceAIIsEnd = 0;
_characters = null;
_charSequence = null;
_eventType = START_DOCUMENT;
}
/**
* Does {@link #nextTag()} and if the parser moved to a new start tag,
* returns a {@link XMLStreamBufferMark} that captures the infoset starting
* from the newly discovered element.
*
*
* (Ideally we should have a method that works against the current position,
* but the way the data structure is read makes this somewhat difficult.)
*
* This creates a new {@link XMLStreamBufferMark} that shares the underlying
* data storage, thus it's fairly efficient.
*/
public XMLStreamBuffer nextTagAndMark() throws XMLStreamException {
while (true) {
int s = peekStructure();
if((s &TYPE_MASK)==T_ELEMENT) {
// next is start element.
Map inscope = new HashMap(_namespaceAIIsEnd);
for (int i=0 ; i<_namespaceAIIsEnd; i++)
inscope.put(_namespaceAIIsPrefix[i],_namespaceAIIsNamespaceName[i]);
XMLStreamBufferMark mark = new XMLStreamBufferMark(inscope, this);
next();
return mark;
} else if((s &TYPE_MASK)==T_DOCUMENT) {
//move the pointer to next structure.
readStructure();
//mark the next start element
XMLStreamBufferMark mark = new XMLStreamBufferMark(new HashMap(_namespaceAIIsEnd), this);
next();
return mark;
}
if(next()==END_ELEMENT)
return null;
}
}
public Object getProperty(String name) {
return null;
}
public int next() throws XMLStreamException {
switch(_completionState) {
case COMPLETED:
throw new XMLStreamException("Invalid State");
case PENDING_END_DOCUMENT:
_namespaceAIIsEnd = 0;
_completionState = COMPLETED;
return _eventType = END_DOCUMENT;
}
// Pop the stack of elements
// This is a post-processing operation
// The stack of the element should be poppoed after
// the END_ELEMENT event is returned so that the correct element name
// and namespace scope is returned
switch(_eventType) {
case END_ELEMENT:
if (_depth > 1) {
_depth--;
// _depth index is always set to the next free stack entry
// to push
popElementStack(_depth);
} else if (_depth == 1) {
_depth--;
}
}
_characters = null;
_charSequence = null;
while(true) {// loop only if we read STATE_DOCUMENT
int eiiState = readEiiState();
switch(eiiState) {
case STATE_DOCUMENT:
// we'll always produce a full document, and we've already report START_DOCUMENT event.
// so simply skil this
continue;
case STATE_ELEMENT_U_LN_QN: {
final String uri = readStructureString();
final String localName = readStructureString();
final String prefix = getPrefixFromQName(readStructureString());
processElement(prefix, uri, localName, isInscope(_depth));
return _eventType = START_ELEMENT;
}
case STATE_ELEMENT_P_U_LN:
processElement(readStructureString(), readStructureString(), readStructureString(),isInscope(_depth));
return _eventType = START_ELEMENT;
case STATE_ELEMENT_U_LN:
processElement(null, readStructureString(), readStructureString(),isInscope(_depth));
return _eventType = START_ELEMENT;
case STATE_ELEMENT_LN:
processElement(null, null, readStructureString(),isInscope(_depth));
return _eventType = START_ELEMENT;
case STATE_TEXT_AS_CHAR_ARRAY_SMALL:
_textLen = readStructure();
_textOffset = readContentCharactersBuffer(_textLen);
_characters = _contentCharactersBuffer;
return _eventType = CHARACTERS;
case STATE_TEXT_AS_CHAR_ARRAY_MEDIUM:
_textLen = readStructure16();
_textOffset = readContentCharactersBuffer(_textLen);
_characters = _contentCharactersBuffer;
return _eventType = CHARACTERS;
case STATE_TEXT_AS_CHAR_ARRAY_COPY:
_characters = readContentCharactersCopy();
_textLen = _characters.length;
_textOffset = 0;
return _eventType = CHARACTERS;
case STATE_TEXT_AS_STRING:
_eventType = CHARACTERS;
_charSequence = readContentString();
return _eventType = CHARACTERS;
case STATE_TEXT_AS_OBJECT:
_eventType = CHARACTERS;
_charSequence = (CharSequence)readContentObject();
return _eventType = CHARACTERS;
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL:
_textLen = readStructure();
_textOffset = readContentCharactersBuffer(_textLen);
_characters = _contentCharactersBuffer;
return _eventType = COMMENT;
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM:
_textLen = readStructure16();
_textOffset = readContentCharactersBuffer(_textLen);
_characters = _contentCharactersBuffer;
return _eventType = COMMENT;
case STATE_COMMENT_AS_CHAR_ARRAY_COPY:
_characters = readContentCharactersCopy();
_textLen = _characters.length;
_textOffset = 0;
return _eventType = COMMENT;
case STATE_COMMENT_AS_STRING:
_charSequence = readContentString();
return _eventType = COMMENT;
case STATE_PROCESSING_INSTRUCTION:
_piTarget = readStructureString();
_piData = readStructureString();
return _eventType = PROCESSING_INSTRUCTION;
case STATE_END:
if (_depth > 1) {
// normal case
return _eventType = END_ELEMENT;
} else if (_depth == 1) {
// this is the last end element for the current tree.
if (_fragmentMode) {
if(--_treeCount==0) // is this the last tree in the forest?
_completionState = PENDING_END_DOCUMENT;
}
return _eventType = END_ELEMENT;
} else {
// this only happens when we are processing a full document
// and we hit the "end of document" marker
_namespaceAIIsEnd = 0;
_completionState = COMPLETED;
return _eventType = END_DOCUMENT;
}
default:
throw new XMLStreamException("Internal XSB error: Invalid State="+eiiState);
}
// this should be unreachable
}
}
public final void require(int type, String namespaceURI, String localName) throws XMLStreamException {
if( type != _eventType) {
throw new XMLStreamException("");
}
if( namespaceURI != null && !namespaceURI.equals(getNamespaceURI())) {
throw new XMLStreamException("");
}
if(localName != null && !localName.equals(getLocalName())) {
throw new XMLStreamException("");
}
}
public final String getElementTextTrim() throws XMLStreamException {
// TODO getElementText* methods more efficiently
return getElementText().trim();
}
public final String getElementText() throws XMLStreamException {
if(_eventType != START_ELEMENT) {
throw new XMLStreamException("");
}
next();
return getElementText(true);
}
public final String getElementText(boolean startElementRead) throws XMLStreamException {
if (!startElementRead) {
throw new XMLStreamException("");
}
int eventType = getEventType();
StringBuilder content = new StringBuilder();
while(eventType != END_ELEMENT ) {
if(eventType == CHARACTERS
|| eventType == CDATA
|| eventType == SPACE
|| eventType == ENTITY_REFERENCE) {
content.append(getText());
} else if(eventType == PROCESSING_INSTRUCTION
|| eventType == COMMENT) {
// skipping
} else if(eventType == END_DOCUMENT) {
throw new XMLStreamException("");
} else if(eventType == START_ELEMENT) {
throw new XMLStreamException("");
} else {
throw new XMLStreamException("");
}
eventType = next();
}
return content.toString();
}
public final int nextTag() throws XMLStreamException {
next();
return nextTag(true);
}
public final int nextTag(boolean currentTagRead) throws XMLStreamException {
int eventType = getEventType();
if (!currentTagRead) {
eventType = next();
}
while((eventType == CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == CDATA && isWhiteSpace())
|| eventType == SPACE
|| eventType == PROCESSING_INSTRUCTION
|| eventType == COMMENT) {
eventType = next();
}
if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
throw new XMLStreamException("");
}
return eventType;
}
public final boolean hasNext() {
return (_eventType != END_DOCUMENT);
}
public void close() throws XMLStreamException {
}
public final boolean isStartElement() {
return (_eventType == START_ELEMENT);
}
public final boolean isEndElement() {
return (_eventType == END_ELEMENT);
}
public final boolean isCharacters() {
return (_eventType == CHARACTERS);
}
public final boolean isWhiteSpace() {
if(isCharacters() || (_eventType == CDATA)){
char [] ch = this.getTextCharacters();
int start = this.getTextStart();
int length = this.getTextLength();
for (int i = start; i < length; i++){
final char c = ch[i];
if (!(c == 0x20 || c == 0x9 || c == 0xD || c == 0xA))
return false;
}
return true;
}
return false;
}
public final String getAttributeValue(String namespaceURI, String localName) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
if (namespaceURI == null) {
// Set to the empty string to be compatible with the
// org.xml.sax.Attributes interface
namespaceURI = "";
}
return _attributeCache.getValue(namespaceURI, localName);
}
public final int getAttributeCount() {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return _attributeCache.getLength();
}
public final javax.xml.namespace.QName getAttributeName(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
final String prefix = _attributeCache.getPrefix(index);
final String localName = _attributeCache.getLocalName(index);
final String uri = _attributeCache.getURI(index);
return new QName(uri,localName,prefix);
}
public final String getAttributeNamespace(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return fixEmptyString(_attributeCache.getURI(index));
}
public final String getAttributeLocalName(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return _attributeCache.getLocalName(index);
}
public final String getAttributePrefix(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return fixEmptyString(_attributeCache.getPrefix(index));
}
public final String getAttributeType(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return _attributeCache.getType(index);
}
public final String getAttributeValue(int index) {
if (_eventType != START_ELEMENT) {
throw new IllegalStateException("");
}
return _attributeCache.getValue(index);
}
public final boolean isAttributeSpecified(int index) {
return false;
}
public final int getNamespaceCount() {
if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
return _stackTop.namespaceAIIsEnd - _stackTop.namespaceAIIsStart;
}
throw new IllegalStateException("");
}
public final String getNamespacePrefix(int index) {
if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
return _namespaceAIIsPrefix[_stackTop.namespaceAIIsStart + index];
}
throw new IllegalStateException("");
}
public final String getNamespaceURI(int index) {
if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) {
return _namespaceAIIsNamespaceName[_stackTop.namespaceAIIsStart + index];
}
throw new IllegalStateException("");
}
public final String getNamespaceURI(String prefix) {
return _nsCtx.getNamespaceURI(prefix);
}
public final NamespaceContextEx getNamespaceContext() {
return _nsCtx;
}
public final int getEventType() {
return _eventType;
}
public final String getText() {
if (_characters != null) {
String s = new String(_characters, _textOffset, _textLen);
_charSequence = s;
return s;
} else if (_charSequence != null) {
return _charSequence.toString();
} else {
throw new IllegalStateException();
}
}
public final char[] getTextCharacters() {
if (_characters != null) {
return _characters;
} else if (_charSequence != null) {
// TODO try to avoid creation of a temporary String for some
// CharSequence implementations
_characters = _charSequence.toString().toCharArray();
_textLen = _characters.length;
_textOffset = 0;
return _characters;
} else {
throw new IllegalStateException();
}
}
public final int getTextStart() {
if (_characters != null) {
return _textOffset;
} else if (_charSequence != null) {
return 0;
} else {
throw new IllegalStateException();
}
}
public final int getTextLength() {
if (_characters != null) {
return _textLen;
} else if (_charSequence != null) {
return _charSequence.length();
} else {
throw new IllegalStateException();
}
}
public final int getTextCharacters(int sourceStart, char[] target,
int targetStart, int length) throws XMLStreamException {
if (_characters != null) {
} else if (_charSequence != null) {
_characters = _charSequence.toString().toCharArray();
_textLen = _characters.length;
_textOffset = 0;
} else {
throw new IllegalStateException("");
}
try {
int remaining = _textLen - sourceStart;
int len = remaining > length ? length : remaining;
sourceStart += _textOffset;
System.arraycopy(_characters, sourceStart, target, targetStart, len);
return len;
} catch (IndexOutOfBoundsException e) {
throw new XMLStreamException(e);
}
}
private class CharSequenceImpl implements CharSequence {
private final int _offset;
private final int _length;
CharSequenceImpl(int offset, int length) {
_offset = offset;
_length = length;
}
public int length() {
return _length;
}
public char charAt(int index) {
if (index >= 0 && index < _textLen) {
return _characters[_textOffset + index];
} else {
throw new IndexOutOfBoundsException();
}
}
public CharSequence subSequence(int start, int end) {
final int length = end - start;
if (end < 0 || start < 0 || end > length || start > end) {
throw new IndexOutOfBoundsException();
}
return new CharSequenceImpl(_offset + start, length);
}
@Override
public String toString() {
return new String(_characters, _offset, _length);
}
}
public final CharSequence getPCDATA() {
if (_characters != null) {
return new CharSequenceImpl(_textOffset, _textLen);
} else if (_charSequence != null) {
return _charSequence;
} else {
throw new IllegalStateException();
}
}
public final String getEncoding() {
return "UTF-8";
}
public final boolean hasText() {
return (_characters != null || _charSequence != null);
}
public final Location getLocation() {
return new DummyLocation();
}
public final boolean hasName() {
return (_eventType == START_ELEMENT || _eventType == END_ELEMENT);
}
public final QName getName() {
return _stackTop.getQName();
}
public final String getLocalName() {
return _stackTop.localName;
}
public final String getNamespaceURI() {
return _stackTop.uri;
}
public final String getPrefix() {
return _stackTop.prefix;
}
public final String getVersion() {
return "1.0";
}
public final boolean isStandalone() {
return false;
}
public final boolean standaloneSet() {
return false;
}
public final String getCharacterEncodingScheme() {
return "UTF-8";
}
public final String getPITarget() {
if (_eventType == PROCESSING_INSTRUCTION) {
return _piTarget;
}
throw new IllegalStateException("");
}
public final String getPIData() {
if (_eventType == PROCESSING_INSTRUCTION) {
return _piData;
}
throw new IllegalStateException("");
}
protected void processElement(String prefix, String uri, String localName, boolean inscope) {
pushElementStack();
_stackTop.set(prefix, uri, localName);
_attributeCache.clear();
int item = peekStructure();
if ((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE || inscope) {
// Skip the namespace declarations on the element
// they will have been added already
item = processNamespaceAttributes(item, inscope);
}
if ((item & TYPE_MASK) == T_ATTRIBUTE) {
processAttributes(item);
}
}
private boolean isInscope(int depth) {
return _buffer.getInscopeNamespaces().size() > 0 && depth ==0;
}
private void resizeNamespaceAttributes() {
final String[] namespaceAIIsPrefix = new String[_namespaceAIIsEnd * 2];
System.arraycopy(_namespaceAIIsPrefix, 0, namespaceAIIsPrefix, 0, _namespaceAIIsEnd);
_namespaceAIIsPrefix = namespaceAIIsPrefix;
final String[] namespaceAIIsNamespaceName = new String[_namespaceAIIsEnd * 2];
System.arraycopy(_namespaceAIIsNamespaceName, 0, namespaceAIIsNamespaceName, 0, _namespaceAIIsEnd);
_namespaceAIIsNamespaceName = namespaceAIIsNamespaceName;
}
private int processNamespaceAttributes(int item, boolean inscope){
_stackTop.namespaceAIIsStart = _namespaceAIIsEnd;
Set prefixSet = inscope ? new HashSet() : Collections.emptySet();
while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE) {
if (_namespaceAIIsEnd == _namespaceAIIsPrefix.length) {
resizeNamespaceAttributes();
}
switch(getNIIState(item)){
case STATE_NAMESPACE_ATTRIBUTE:
// Undeclaration of default namespace
_namespaceAIIsPrefix[_namespaceAIIsEnd] =
_namespaceAIIsNamespaceName[_namespaceAIIsEnd++] = "";
if (inscope) {
prefixSet.add("");
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P:
// Undeclaration of namespace
_namespaceAIIsPrefix[_namespaceAIIsEnd] = readStructureString();
if (inscope) {
prefixSet.add(_namespaceAIIsPrefix[_namespaceAIIsEnd]);
}
_namespaceAIIsNamespaceName[_namespaceAIIsEnd++] = "";
break;
case STATE_NAMESPACE_ATTRIBUTE_P_U:
// Declaration with prefix
_namespaceAIIsPrefix[_namespaceAIIsEnd] = readStructureString();
if (inscope) {
prefixSet.add(_namespaceAIIsPrefix[_namespaceAIIsEnd]);
}
_namespaceAIIsNamespaceName[_namespaceAIIsEnd++] = readStructureString();
break;
case STATE_NAMESPACE_ATTRIBUTE_U:
// Default declaration
_namespaceAIIsPrefix[_namespaceAIIsEnd] = "";
if (inscope) {
prefixSet.add("");
}
_namespaceAIIsNamespaceName[_namespaceAIIsEnd++] = readStructureString();
break;
}
readStructure();
item = peekStructure();
}
if (inscope) {
for (Map.Entry e : _buffer.getInscopeNamespaces().entrySet()) {
String key = fixNull(e.getKey());
// If the prefix is already written, do not write the prefix
if (!prefixSet.contains(key)) {
if (_namespaceAIIsEnd == _namespaceAIIsPrefix.length) {
resizeNamespaceAttributes();
}
_namespaceAIIsPrefix[_namespaceAIIsEnd] = key;
_namespaceAIIsNamespaceName[_namespaceAIIsEnd++] = e.getValue();
}
}
}
_stackTop.namespaceAIIsEnd = _namespaceAIIsEnd;
return item;
}
private static String fixNull(String s) {
if (s == null) return "";
else return s;
}
private void processAttributes(int item){
do {
switch(getAIIState(item)){
case STATE_ATTRIBUTE_U_LN_QN: {
final String uri = readStructureString();
final String localName = readStructureString();
final String prefix = getPrefixFromQName(readStructureString());
_attributeCache.addAttributeWithPrefix(prefix, uri, localName, readStructureString(), readContentString());
break;
}
case STATE_ATTRIBUTE_P_U_LN:
_attributeCache.addAttributeWithPrefix(readStructureString(), readStructureString(), readStructureString(), readStructureString(), readContentString());
break;
case STATE_ATTRIBUTE_U_LN:
// _attributeCache follows SAX convention
_attributeCache.addAttributeWithPrefix("", readStructureString(), readStructureString(), readStructureString(), readContentString());
break;
case STATE_ATTRIBUTE_LN: {
_attributeCache.addAttributeWithPrefix("", "", readStructureString(), readStructureString(), readContentString());
break;
}
default :
assert false : "Internal XSB Error: wrong attribute state, Item="+item;
}
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_ATTRIBUTE);
}
private void pushElementStack() {
if (_depth == _stack.length) {
// resize stack
ElementStackEntry [] tmp = _stack;
_stack = new ElementStackEntry[_stack.length * 3 /2 + 1];
System.arraycopy(tmp, 0, _stack, 0, tmp.length);
for (int i = tmp.length; i < _stack.length; i++){
_stack[i] = new ElementStackEntry();
}
}
_stackTop = _stack[_depth++];
}
private void popElementStack(int depth) {
// _depth is checked outside this method
_stackTop = _stack[depth - 1];
// Move back the position of the namespace index
_namespaceAIIsEnd = _stack[depth].namespaceAIIsStart;
}
private final class ElementStackEntry {
/**
* Prefix.
* Just like everywhere else in StAX, this can be null but can't be empty.
*/
String prefix;
/**
* Namespace URI.
* Just like everywhere else in StAX, this can be null but can't be empty.
*/
String uri;
String localName;
QName qname;
// Start and end of namespace declarations
// in namespace declaration arrays
int namespaceAIIsStart;
int namespaceAIIsEnd;
public void set(String prefix, String uri, String localName) {
this.prefix = prefix;
this.uri = uri;
this.localName = localName;
this.qname = null;
this.namespaceAIIsStart = this.namespaceAIIsEnd = StreamReaderBufferProcessor.this._namespaceAIIsEnd;
}
public QName getQName() {
if (qname == null) {
qname = new QName(fixNull(uri), localName, fixNull(prefix));
}
return qname;
}
private String fixNull(String s) {
return (s == null) ? "" : s;
}
}
private final class InternalNamespaceContext implements NamespaceContextEx {
@SuppressWarnings({"StringEquality"})
public String getNamespaceURI(String prefix) {
if (prefix == null) {
throw new IllegalArgumentException("Prefix cannot be null");
}
/*
* If the buffer was created using string interning
* intern the prefix and check for reference equality
* rather than using String.equals();
*/
if (_stringInterningFeature) {
prefix = prefix.intern();
// Find the most recently declared prefix
for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
if (prefix == _namespaceAIIsPrefix[i]) {
return _namespaceAIIsNamespaceName[i];
}
}
} else {
// Find the most recently declared prefix
for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
if (prefix.equals(_namespaceAIIsPrefix[i])) {
return _namespaceAIIsNamespaceName[i];
}
}
}
// Check for XML-based prefixes
if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
return XMLConstants.XML_NS_URI;
} else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
}
return null;
}
public String getPrefix(String namespaceURI) {
final Iterator i = getPrefixes(namespaceURI);
if (i.hasNext()) {
return (String)i.next();
} else {
return null;
}
}
public Iterator getPrefixes(final String namespaceURI) {
if (namespaceURI == null){
throw new IllegalArgumentException("NamespaceURI cannot be null");
}
if (namespaceURI.equals(XMLConstants.XML_NS_URI)) {
return Collections.singletonList(XMLConstants.XML_NS_PREFIX).iterator();
} else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
return Collections.singletonList(XMLConstants.XMLNS_ATTRIBUTE).iterator();
}
return new Iterator() {
private int i = _namespaceAIIsEnd - 1;
private boolean requireFindNext = true;
private String p;
private String findNext() {
while(i >= 0) {
// Find the most recently declared namespace
if (namespaceURI.equals(_namespaceAIIsNamespaceName[i])) {
// Find the most recently declared prefix of the namespace
// and check if the prefix is in scope with that namespace
if (getNamespaceURI(_namespaceAIIsPrefix[i]).equals(
_namespaceAIIsNamespaceName[i])) {
return p = _namespaceAIIsPrefix[i];
}
}
i--;
}
return p = null;
}
public boolean hasNext() {
if (requireFindNext) {
findNext();
requireFindNext = false;
}
return (p != null);
}
public Object next() {
if (requireFindNext) {
findNext();
}
requireFindNext = true;
if (p == null) {
throw new NoSuchElementException();
}
return p;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
private class BindingImpl implements NamespaceContextEx.Binding {
final String _prefix;
final String _namespaceURI;
BindingImpl(String prefix, String namespaceURI) {
_prefix = prefix;
_namespaceURI = namespaceURI;
}
public String getPrefix() {
return _prefix;
}
public String getNamespaceURI() {
return _namespaceURI;
}
}
public Iterator iterator() {
return new Iterator() {
private final int end = _namespaceAIIsEnd - 1;
private int current = end;
private boolean requireFindNext = true;
private NamespaceContextEx.Binding namespace;
private NamespaceContextEx.Binding findNext() {
while(current >= 0) {
final String prefix = _namespaceAIIsPrefix[current];
// Find if the current prefix occurs more recently
// If so then it is not in scope
int i = end;
for (;i > current; i--) {
if (prefix.equals(_namespaceAIIsPrefix[i])) {
break;
}
}
if (i == current--) {
// The current prefix is in-scope
return namespace = new BindingImpl(prefix, _namespaceAIIsNamespaceName[current]);
}
}
return namespace = null;
}
public boolean hasNext() {
if (requireFindNext) {
findNext();
requireFindNext = false;
}
return (namespace != null);
}
public NamespaceContextEx.Binding next() {
if (requireFindNext) {
findNext();
}
requireFindNext = true;
if (namespace == null) {
throw new NoSuchElementException();
}
return namespace;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}
private class DummyLocation implements Location {
public int getLineNumber() {
return -1;
}
public int getColumnNumber() {
return -1;
}
public int getCharacterOffset() {
return -1;
}
public String getPublicId() {
return null;
}
public String getSystemId() {
return _buffer.getSystemId();
}
}
private static String fixEmptyString(String s) {
// s must not be null, so no need to check for that. that would be bug.
if(s.length()==0) return null;
else return s;
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/StreamWriterBufferCreator.java 0000664 0000000 0000000 00000024223 12263200227 0031365 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import org.jvnet.staxex.Base64Data;
import org.jvnet.staxex.NamespaceContextEx;
import org.jvnet.staxex.XMLStreamWriterEx;
import javax.activation.DataHandler;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
/**
* {@link XMLStreamWriter} that fills {@link MutableXMLStreamBuffer}.
*
* TODO: need to retain all attributes/namespaces and then store all namespaces
* before the attributes. Currently it is necessary for the caller to ensure
* all namespaces are written before attributes and the caller must not intermix
* calls to the writeNamespace and writeAttribute methods.
*
*/
public class StreamWriterBufferCreator extends StreamBufferCreator implements XMLStreamWriterEx {
private final NamespaceContexHelper namespaceContext = new NamespaceContexHelper();
/**
* Nesting depth of the element.
* This field is ultimately used to keep track of the # of trees we created in
* the buffer.
*/
private int depth=0;
public StreamWriterBufferCreator() {
setXMLStreamBuffer(new MutableXMLStreamBuffer());
}
public StreamWriterBufferCreator(MutableXMLStreamBuffer buffer) {
setXMLStreamBuffer(buffer);
}
// XMLStreamWriter
public Object getProperty(String str) throws IllegalArgumentException {
return null; //return null for all the property names instead of
//throwing unsupported operation exception.
}
public void close() throws XMLStreamException {
}
public void flush() throws XMLStreamException {
}
public NamespaceContextEx getNamespaceContext() {
return namespaceContext;
}
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
/*
* It is really unclear from the JavaDoc how to implement this method.
*/
throw new UnsupportedOperationException();
}
public void setDefaultNamespace(String namespaceURI) throws XMLStreamException {
setPrefix("", namespaceURI);
}
public void setPrefix(String prefix, String namespaceURI) throws XMLStreamException {
namespaceContext.declareNamespace(prefix, namespaceURI);
}
public String getPrefix(String namespaceURI) throws XMLStreamException {
return namespaceContext.getPrefix(namespaceURI);
}
public void writeStartDocument() throws XMLStreamException {
writeStartDocument("", "");
}
public void writeStartDocument(String version) throws XMLStreamException {
writeStartDocument("", "");
}
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
namespaceContext.resetContexts();
storeStructure(T_DOCUMENT);
}
public void writeEndDocument() throws XMLStreamException {
storeStructure(T_END);
}
public void writeStartElement(String localName) throws XMLStreamException {
namespaceContext.pushContext();
depth++;
final String defaultNamespaceURI = namespaceContext.getNamespaceURI("");
if (defaultNamespaceURI == null)
storeQualifiedName(T_ELEMENT_LN, null, null, localName);
else
storeQualifiedName(T_ELEMENT_LN, null, defaultNamespaceURI, localName);
}
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
namespaceContext.pushContext();
depth++;
final String prefix = namespaceContext.getPrefix(namespaceURI);
if (prefix == null) {
throw new XMLStreamException();
}
namespaceContext.pushContext();
storeQualifiedName(T_ELEMENT_LN, prefix, namespaceURI, localName);
}
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
namespaceContext.pushContext();
depth++;
storeQualifiedName(T_ELEMENT_LN, prefix, namespaceURI, localName);
}
public void writeEmptyElement(String localName) throws XMLStreamException {
writeStartElement(localName);
writeEndElement();
}
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
writeStartElement(namespaceURI, localName);
writeEndElement();
}
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
writeStartElement(prefix, localName, namespaceURI);
writeEndElement();
}
public void writeEndElement() throws XMLStreamException {
namespaceContext.popContext();
storeStructure(T_END);
if(--depth==0)
increaseTreeCount();
}
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
storeNamespaceAttribute(null, namespaceURI);
}
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
if ("xmlns".equals(prefix))
prefix = null;
storeNamespaceAttribute(prefix, namespaceURI);
}
public void writeAttribute(String localName, String value) throws XMLStreamException {
storeAttribute(null, null, localName, "CDATA", value);
}
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
final String prefix = namespaceContext.getPrefix(namespaceURI);
if (prefix == null) {
// TODO
throw new XMLStreamException();
}
writeAttribute(prefix, namespaceURI, localName, value);
}
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
storeAttribute(prefix, namespaceURI, localName, "CDATA", value);
}
public void writeCData(String data) throws XMLStreamException {
storeStructure(T_TEXT_AS_STRING);
storeContentString(data);
}
public void writeCharacters(String charData) throws XMLStreamException {
storeStructure(T_TEXT_AS_STRING);
storeContentString(charData);
}
public void writeCharacters(char[] buf, int start, int len) throws XMLStreamException {
storeContentCharacters(T_TEXT_AS_CHAR_ARRAY, buf, start, len);
}
public void writeComment(String str) throws XMLStreamException {
storeStructure(T_COMMENT_AS_STRING);
storeContentString(str);
}
public void writeDTD(String str) throws XMLStreamException {
// not support. just ignore.
}
public void writeEntityRef(String str) throws XMLStreamException {
storeStructure(T_UNEXPANDED_ENTITY_REFERENCE);
storeContentString(str);
}
public void writeProcessingInstruction(String target) throws XMLStreamException {
writeProcessingInstruction(target, "");
}
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
storeProcessingInstruction(target, data);
}
// XMLStreamWriterEx
public void writePCDATA(CharSequence charSequence) throws XMLStreamException {
if (charSequence instanceof Base64Data) {
storeStructure(T_TEXT_AS_OBJECT);
storeContentObject(((Base64Data)charSequence).clone());
} else {
writeCharacters(charSequence.toString());
}
}
public void writeBinary(byte[] bytes, int offset, int length, String endpointURL) throws XMLStreamException {
Base64Data d = new Base64Data();
byte b[] = new byte[length];
System.arraycopy(bytes, offset, b, 0, length);
d.set(b, length, null, true);
storeStructure(T_TEXT_AS_OBJECT);
storeContentObject(d);
}
public void writeBinary(DataHandler dataHandler) throws XMLStreamException {
Base64Data d = new Base64Data();
d.set(dataHandler);
storeStructure(T_TEXT_AS_OBJECT);
storeContentObject(d);
}
public OutputStream writeBinary(String endpointURL) throws XMLStreamException {
// TODO
throw new UnsupportedOperationException();
}
}
xmlstreambuffer-1.5.1/src/com/sun/xml/stream/buffer/stax/StreamWriterBufferProcessor.java 0000664 0000000 0000000 00000053402 12263200227 0031746 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.AbstractProcessor;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jvnet.staxex.Base64Data;
import org.jvnet.staxex.XMLStreamWriterEx;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
/**
* A processor of a {@link XMLStreamBuffer} that writes the XML infoset to a
* {@link XMLStreamWriter}.
*
* @author Paul.Sandoz@Sun.Com
* @author K.Venugopal@sun.com
*/
public class StreamWriterBufferProcessor extends AbstractProcessor {
public StreamWriterBufferProcessor() {
}
/**
* @deprecated
* Use {@link #StreamWriterBufferProcessor(XMLStreamBuffer, boolean)}
*/
public StreamWriterBufferProcessor(XMLStreamBuffer buffer) {
setXMLStreamBuffer(buffer,buffer.isFragment());
}
/**
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*/
public StreamWriterBufferProcessor(XMLStreamBuffer buffer,boolean produceFragmentEvent) {
setXMLStreamBuffer(buffer,produceFragmentEvent);
}
public final void process(XMLStreamBuffer buffer, XMLStreamWriter writer) throws XMLStreamException {
setXMLStreamBuffer(buffer,buffer.isFragment());
process(writer);
}
public void process(XMLStreamWriter writer) throws XMLStreamException {
if(_fragmentMode){
writeFragment(writer);
}else{
write(writer);
}
}
/**
* @deprecated
* Use {@link #setXMLStreamBuffer(XMLStreamBuffer, boolean)}
*/
public void setXMLStreamBuffer(XMLStreamBuffer buffer) {
setBuffer(buffer);
}
/**
* @param produceFragmentEvent
* True to generate fragment SAX events without start/endDocument.
* False to generate a full document SAX events.
*/
public void setXMLStreamBuffer(XMLStreamBuffer buffer, boolean produceFragmentEvent) {
setBuffer(buffer,produceFragmentEvent);
}
/**
* Writes a full XML infoset event to the given writer,
* including start/end document.
* Any inscope namespaces present will be written as namespace
* delcarations on each top-level element.
*/
public void write(XMLStreamWriter writer) throws XMLStreamException{
if(!_fragmentMode) {
if(_treeCount>1)
throw new IllegalStateException("forest cannot be written as a full infoset");
writer.writeStartDocument();
}
while(true) {
int item = getEIIState(peekStructure());
writer.flush();
switch(item) {
case STATE_DOCUMENT:
readStructure(); //skip
break;
case STATE_ELEMENT_U_LN_QN:
case STATE_ELEMENT_P_U_LN:
case STATE_ELEMENT_U_LN:
case STATE_ELEMENT_LN:
writeFragment(writer);
break;
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL: {
readStructure();
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM: {
readStructure();
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_COPY: {
readStructure();
final char[] ch = readContentCharactersCopy();
writer.writeComment(new String(ch));
break;
}
case STATE_PROCESSING_INSTRUCTION:
readStructure();
writer.writeProcessingInstruction(readStructureString(), readStructureString());
break;
case STATE_END: // done
readStructure();
writer.writeEndDocument();
return;
default:
throw new XMLStreamException("Invalid State "+item);
}
}
}
/**
* Writes the buffer as a fragment, meaning
* the writer will not receive start/endDocument events.
* Any inscope namespaces present will be written as namespace
* delcarations on each top-level element.
*
* If {@link XMLStreamBuffer} has a forest, this method will write all the forests.
*/
public void writeFragment(XMLStreamWriter writer) throws XMLStreamException {
if (writer instanceof XMLStreamWriterEx) {
writeFragmentEx((XMLStreamWriterEx)writer);
} else {
writeFragmentNoEx(writer);
}
}
public void writeFragmentEx(XMLStreamWriterEx writer) throws XMLStreamException {
int depth = 0; // used to determine when we are done with a tree.
int item = getEIIState(peekStructure());
if(item==STATE_DOCUMENT)
readStructure(); // skip STATE_DOCUMENT
do {
item = readEiiState();
switch(item) {
case STATE_DOCUMENT:
throw new AssertionError();
case STATE_ELEMENT_U_LN_QN: {
depth ++;
final String uri = readStructureString();
final String localName = readStructureString();
final String prefix = getPrefixFromQName(readStructureString());
writer.writeStartElement(prefix,localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_P_U_LN: {
depth ++;
final String prefix = readStructureString();
final String uri = readStructureString();
final String localName = readStructureString();
writer.writeStartElement(prefix,localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_U_LN: {
depth ++;
final String uri = readStructureString();
final String localName = readStructureString();
writer.writeStartElement("",localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_LN: {
depth ++;
final String localName = readStructureString();
writer.writeStartElement(localName);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_SMALL: {
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
writer.writeCharacters(_contentCharactersBuffer,start,length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_MEDIUM: {
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
writer.writeCharacters(_contentCharactersBuffer,start,length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_COPY: {
char[] c = readContentCharactersCopy();
writer.writeCharacters(c,0,c.length);
break;
}
case STATE_TEXT_AS_STRING: {
final String s = readContentString();
writer.writeCharacters(s);
break;
}
case STATE_TEXT_AS_OBJECT: {
final CharSequence c = (CharSequence)readContentObject();
writer.writePCDATA(c);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL: {
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM: {
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_COPY: {
final char[] ch = readContentCharactersCopy();
writer.writeComment(new String(ch));
break;
}
case STATE_PROCESSING_INSTRUCTION:
writer.writeProcessingInstruction(readStructureString(), readStructureString());
break;
case STATE_END:
writer.writeEndElement();
depth --;
if(depth==0)
_treeCount--;
break;
default:
throw new XMLStreamException("Invalid State "+item);
}
} while(depth>0 || _treeCount>0);
}
public void writeFragmentNoEx(XMLStreamWriter writer) throws XMLStreamException {
int depth = 0;
int item = getEIIState(peekStructure());
if(item==STATE_DOCUMENT)
readStructure(); // skip STATE_DOCUMENT
do {
item = readEiiState();
switch(item) {
case STATE_DOCUMENT:
throw new AssertionError();
case STATE_ELEMENT_U_LN_QN: {
depth ++;
final String uri = readStructureString();
final String localName = readStructureString();
final String prefix = getPrefixFromQName(readStructureString());
writer.writeStartElement(prefix,localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_P_U_LN: {
depth ++;
final String prefix = readStructureString();
final String uri = readStructureString();
final String localName = readStructureString();
writer.writeStartElement(prefix,localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_U_LN: {
depth ++;
final String uri = readStructureString();
final String localName = readStructureString();
writer.writeStartElement("",localName,uri);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_ELEMENT_LN: {
depth ++;
final String localName = readStructureString();
writer.writeStartElement(localName);
writeAttributes(writer, isInscope(depth));
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_SMALL: {
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
writer.writeCharacters(_contentCharactersBuffer,start,length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_MEDIUM: {
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
writer.writeCharacters(_contentCharactersBuffer,start,length);
break;
}
case STATE_TEXT_AS_CHAR_ARRAY_COPY: {
char[] c = readContentCharactersCopy();
writer.writeCharacters(c,0,c.length);
break;
}
case STATE_TEXT_AS_STRING: {
final String s = readContentString();
writer.writeCharacters(s);
break;
}
case STATE_TEXT_AS_OBJECT: {
final CharSequence c = (CharSequence)readContentObject();
if (c instanceof Base64Data) {
try {
Base64Data bd = (Base64Data)c;
bd.writeTo(writer);
} catch (IOException e) {
throw new XMLStreamException(e);
}
} else {
writer.writeCharacters(c.toString());
}
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_SMALL: {
final int length = readStructure();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_MEDIUM: {
final int length = readStructure16();
final int start = readContentCharactersBuffer(length);
final String comment = new String(_contentCharactersBuffer, start, length);
writer.writeComment(comment);
break;
}
case STATE_COMMENT_AS_CHAR_ARRAY_COPY: {
final char[] ch = readContentCharactersCopy();
writer.writeComment(new String(ch));
break;
}
case STATE_PROCESSING_INSTRUCTION:
writer.writeProcessingInstruction(readStructureString(), readStructureString());
break;
case STATE_END:
writer.writeEndElement();
depth --;
if(depth==0)
_treeCount--;
break;
default:
throw new XMLStreamException("Invalid State "+item);
}
} while(depth > 0 || _treeCount>0);
}
private boolean isInscope(int depth) {
return _buffer.getInscopeNamespaces().size() > 0 && depth ==1;
}
/*
* @param inscope: true means write inscope namespaces
*/
private void writeAttributes(XMLStreamWriter writer, boolean inscope) throws XMLStreamException {
// prefixSet to collect prefixes that are written before writing inscope namespaces
Set prefixSet = inscope ? new HashSet() : Collections.emptySet();
int item = peekStructure();
if ((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE) {
// Skip the namespace declarations on the element
// they will have been added already
item = writeNamespaceAttributes(item, writer, inscope, prefixSet);
}
if (inscope) {
writeInscopeNamespaces(writer, prefixSet);
}
if ((item & TYPE_MASK) == T_ATTRIBUTE) {
writeAttributes(item, writer);
}
}
private static String fixNull(String s) {
if (s == null) return "";
else return s;
}
/*
* @param prefixSet: already written prefixes
*/
private void writeInscopeNamespaces(XMLStreamWriter writer, Set prefixSet) throws XMLStreamException {
for (Map.Entry e : _buffer.getInscopeNamespaces().entrySet()) {
String key = fixNull(e.getKey());
// If the prefix is already written, do not write the prefix
if (!prefixSet.contains(key)) {
writer.writeNamespace(key, e.getValue());
}
}
}
private int writeNamespaceAttributes(int item, XMLStreamWriter writer, boolean collectPrefixes, Set prefixSet) throws XMLStreamException {
do {
switch(getNIIState(item)){
case STATE_NAMESPACE_ATTRIBUTE:
// Undeclaration of default namespace
writer.writeDefaultNamespace("");
if (collectPrefixes) {
prefixSet.add("");
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P:
// Undeclaration of namespace
// Declaration with prefix
String prefix = readStructureString();
writer.writeNamespace(prefix, "");
if (collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P_U:
// Declaration with prefix
prefix = readStructureString();
writer.writeNamespace(prefix, readStructureString());
if (collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_U:
// Default declaration
writer.writeDefaultNamespace(readStructureString());
if (collectPrefixes) {
prefixSet.add("");
}
break;
}
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE);
return item;
}
private void writeAttributes(int item, XMLStreamWriter writer) throws XMLStreamException {
do {
switch(getAIIState(item)) {
case STATE_ATTRIBUTE_U_LN_QN: {
final String uri = readStructureString();
final String localName = readStructureString();
final String prefix = getPrefixFromQName(readStructureString());
writer.writeAttribute(prefix,uri,localName,readContentString());
break;
}
case STATE_ATTRIBUTE_P_U_LN:
writer.writeAttribute(readStructureString(), readStructureString(),
readStructureString(), readContentString());
break;
case STATE_ATTRIBUTE_U_LN:
writer.writeAttribute(readStructureString(), readStructureString(), readContentString());
break;
case STATE_ATTRIBUTE_LN:
writer.writeAttribute(readStructureString(), readContentString());
break;
}
// Ignore the attribute type
readStructureString();
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_ATTRIBUTE);
}
}
xmlstreambuffer-1.5.1/test/ 0000775 0000000 0000000 00000000000 12263200227 0015677 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/ 0000775 0000000 0000000 00000000000 12263200227 0016455 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/ 0000775 0000000 0000000 00000000000 12263200227 0017262 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/ 0000775 0000000 0000000 00000000000 12263200227 0020062 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/stream/ 0000775 0000000 0000000 00000000000 12263200227 0021355 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/ 0000775 0000000 0000000 00000000000 12263200227 0022626 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/BaseBufferTestCase.java 0000664 0000000 0000000 00000014154 12263200227 0027136 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamException;
/**
* {@link TestCase} with more convenience methods for testing XMLStreamBuffer.
*
* @author Paul Sandoz
*/
public abstract class BaseBufferTestCase extends junit.framework.TestCase {
protected BaseBufferTestCase() {
}
protected BaseBufferTestCase(String name) {
super(name);
}
public int next(XMLStreamReader reader) throws XMLStreamException {
int readerEvent = reader.next();
while (readerEvent != XMLStreamReader.END_DOCUMENT) {
switch (readerEvent) {
case XMLStreamReader.START_ELEMENT:
case XMLStreamReader.END_ELEMENT:
case XMLStreamReader.CDATA:
case XMLStreamReader.CHARACTERS:
case XMLStreamReader.PROCESSING_INSTRUCTION:
return readerEvent;
default:
// falls through ignoring event
}
readerEvent = reader.next();
}
return readerEvent;
}
public int nextElementContent(XMLStreamReader reader) throws XMLStreamException {
int state = nextContent(reader);
if (state == XMLStreamReader.CHARACTERS) {
throw new XMLStreamException(
"Unexpected Character Content: " + reader.getText());
}
return state;
}
public int nextContent(XMLStreamReader reader) throws XMLStreamException {
for (;;) {
int state = next(reader);
switch (state) {
case XMLStreamReader.START_ELEMENT:
case XMLStreamReader.END_ELEMENT:
case XMLStreamReader.END_DOCUMENT:
return state;
case XMLStreamReader.CHARACTERS:
if (!reader.isWhiteSpace()) {
return XMLStreamReader.CHARACTERS;
}
}
}
}
public void verifyReaderState(XMLStreamReader reader, int expectedState) throws XMLStreamException {
int state = reader.getEventType();
if (state != expectedState) {
throw new XMLStreamException(
"Unexpected State: " + getStateName(expectedState) + " " + getStateName(state));
}
}
public static void verifyTag(XMLStreamReader reader, String namespaceURI, String localName) throws XMLStreamException {
if (localName != reader.getLocalName() || namespaceURI != reader.getNamespaceURI()) {
throw new XMLStreamException(
"Expected: " +
"{" + namespaceURI + "}" + localName + " " +
"But found: " +
"{" + reader.getNamespaceURI() + "}" + reader.getLocalName());
}
}
public static String getStateName(int state) {
switch (state) {
case XMLStreamReader.ATTRIBUTE:
return "ATTRIBUTE";
case XMLStreamReader.CDATA:
return "CDATA";
case XMLStreamReader.CHARACTERS:
return "CHARACTERS";
case XMLStreamReader.COMMENT:
return "COMMENT";
case XMLStreamReader.DTD:
return "DTD";
case XMLStreamReader.END_DOCUMENT:
return "END_DOCUMENT";
case XMLStreamReader.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamReader.ENTITY_DECLARATION:
return "ENTITY_DECLARATION";
case XMLStreamReader.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamReader.NAMESPACE:
return "NAMESPACE";
case XMLStreamReader.NOTATION_DECLARATION:
return "NOTATION_DECLARATION";
case XMLStreamReader.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamReader.SPACE:
return "SPACE";
case XMLStreamReader.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamReader.START_ELEMENT:
return "START_ELEMENT";
default :
return "UNKNOWN";
}
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/EmptyBufferTest.java 0000664 0000000 0000000 00000011053 12263200227 0026561 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import javax.xml.stream.XMLStreamReader;
/**
*
* @author Paul.Sandoz@Sun.Com
*/
public class EmptyBufferTest extends BaseBufferTestCase {
public EmptyBufferTest(String testName) {
super(testName);
}
public void testEmptyBufferUsingXMLStreamReader() throws Exception {
MutableXMLStreamBuffer b = new MutableXMLStreamBuffer();
XMLStreamReader r = b.readAsXMLStreamReader();
assertEquals(true, r.getEventType() == XMLStreamReader.START_DOCUMENT);
r.next();
assertEquals(true, r.getEventType() == XMLStreamReader.END_DOCUMENT);
}
public void testEmptyBufferUsingContentHandler() throws Exception {
MutableXMLStreamBuffer b = new MutableXMLStreamBuffer();
b.writeTo(new ContentHandler() {
boolean _startDocument = false;
public void setDocumentLocator(Locator locator) {
}
public void startDocument() throws SAXException {
_startDocument = true;
}
public void endDocument() throws SAXException {
assertEquals(true, _startDocument);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
assertEquals(false, _startDocument);
}
public void endPrefixMapping(String prefix) throws SAXException {
assertEquals(false, _startDocument);
}
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
assertEquals(false, _startDocument);
}
public void endElement(String uri, String localName, String qName) throws SAXException {
assertEquals(false, _startDocument);
}
public void characters(char[] ch, int start, int length) throws SAXException {
assertEquals(false, _startDocument);
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
assertEquals(false, _startDocument);
}
public void processingInstruction(String target, String data) throws SAXException {
assertEquals(false, _startDocument);
}
public void skippedEntity(String name) throws SAXException {
assertEquals(false, _startDocument);
}
},false);
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/MarkTest.java 0000664 0000000 0000000 00000016457 12263200227 0025240 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer;
import com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator;
import org.xml.sax.helpers.AttributesImpl;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Paul.Sandoz@Sun.Com
*/
public class MarkTest extends BaseBufferTestCase {
private static final String SOAP_MESSAGE = "data/soap-message.xml";
private static final String SOAP_NAMESPACE_URI = "http://www.w3.org/2003/05/soap-envelope";
private static final String SOAP_ENVELOPE = "Envelope";
private static final String SOAP_HEADER = "Header";
private static final String SOAP_BODY = "Body";
private URL _soapMessageURL;
public MarkTest(String testName) {
super(testName);
_soapMessageURL = this.getClass().getClassLoader().getResource(SOAP_MESSAGE);
}
public void testMark() throws Exception {
XMLStreamReader reader = XMLInputFactory.newInstance().
createXMLStreamReader(_soapMessageURL.openStream());
nextElementContent(reader);
verifyReaderState(reader,
XMLStreamReader.START_ELEMENT);
verifyTag(reader, SOAP_NAMESPACE_URI, SOAP_ENVELOPE);
// Collect namespaces on soap:Envelope
Map namespaces = new HashMap();
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
// Move to next element
nextElementContent(reader);
verifyReaderState(reader,
XMLStreamReader.START_ELEMENT);
List marks = new ArrayList();
StreamReaderBufferCreator creator = new StreamReaderBufferCreator(new MutableXMLStreamBuffer());
if (reader.getLocalName() == SOAP_HEADER
&& reader.getNamespaceURI() == SOAP_NAMESPACE_URI) {
// Collect namespaces on soap:Header
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
nextElementContent(reader);
// If SOAP header blocks are present (i.e. not )
if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
while(reader.getEventType() == XMLStreamReader.START_ELEMENT) {
Map headerBlockNamespaces = namespaces;
// Collect namespaces on SOAP header block
if (reader.getNamespaceCount() > 0) {
headerBlockNamespaces = new HashMap();
headerBlockNamespaces.putAll(namespaces);
for (int i = 0; i < reader.getNamespaceCount(); i++) {
headerBlockNamespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
}
// Mark
XMLStreamBufferMark mark = new XMLStreamBufferMark(headerBlockNamespaces, creator);
// Create Header
marks.add(mark);
creator.createElementFragment(reader, false);
}
// Move to soap:Body
nextElementContent(reader);
}
}
// Verify that is present
verifyTag(reader, SOAP_NAMESPACE_URI, SOAP_BODY);
TransformerHandler t = ((SAXTransformerFactory)TransformerFactory.newInstance()).newTransformerHandler();
t.setResult(new StreamResult(System.out));
t.startDocument();
t.startElement("","root","root",new AttributesImpl());
for (XMLStreamBufferMark mark : marks) {
XMLStreamReader markReader = mark.readAsXMLStreamReader();
processFragment(markReader);
// test subtree->SAX.
// TODO: think about the way to test the infoset correctness.
mark.writeTo(t,true);
}
t.endElement("","root","root");
t.endDocument();
}
public void processFragment(XMLStreamReader reader) throws XMLStreamException {
verifyReaderState(reader,
XMLStreamReader.START_DOCUMENT);
reader.next();
verifyReaderState(reader,
XMLStreamReader.START_ELEMENT);
int depth = 1;
while(depth > 0) {
int event = reader.next();
switch(event) {
case XMLStreamReader.START_ELEMENT:
depth++;
break;
case XMLStreamReader.END_ELEMENT:
depth--;
break;
}
}
reader.next();
verifyReaderState(reader,
XMLStreamReader.END_DOCUMENT);
boolean exceptionThrown = false;
try {
reader.next();
} catch (XMLStreamException e) {
exceptionThrown = true;
}
assertEquals(true, exceptionThrown);
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/sax/ 0000775 0000000 0000000 00000000000 12263200227 0023421 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/sax/NamespaceTest.java 0000664 0000000 0000000 00000012375 12263200227 0027030 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.sax;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import junit.framework.*;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
/**
*
* @author Paul.Sandoz@Sun.Com
*/
public class NamespaceTest extends TestCase {
public NamespaceTest(String testName) {
super(testName);
}
public void testManyNamespaceDeclarations() throws Exception {
for (int i = 0; i <= 50; i++) {
_testManyNamespaceDeclarations(i);
}
}
private void _testManyNamespaceDeclarations(int n) throws Exception {
InputStream d = createDocument(n);
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader r = spf.newSAXParser().getXMLReader();
XMLStreamBuffer b = XMLStreamBuffer.createNewBufferFromXMLReader(r, d);
}
private InputStream createDocument(int n) {
StringBuilder b = new StringBuilder();
b.append("");
b.append(" ");
return new ByteArrayInputStream(b.toString().getBytes());
}
public void testEndPrefixMappings() throws Exception {
String xml =
"" +
"" +
"e:ZZZ " +
" " +
" ";
XMLStreamReader r = getReader(xml);
do r.next(); while(!"y".equals(r.getLocalName()));
XMLStreamBuffer b = XMLStreamBuffer.createNewBufferFromXMLStreamReader(r);
SAXBufferProcessor sp = new SAXBufferProcessor(b, true);
MyContentHandler ch = new MyContentHandler();
sp.setContentHandler(ch);
sp.process();
assertEquals(3, ch.startPrefixCount);
assertEquals(3, ch.endPrefixCount);
assertTrue(ch.prefix_e_Ended);
}
static XMLStreamReader getReader(String xml) throws Exception {
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
return readerFactory.createXMLStreamReader(is);
}
static class MyContentHandler extends DefaultHandler {
int startPrefixCount = 0;
int endPrefixCount = 0;
boolean element_z_Ended = false;
boolean prefix_e_Ended = false;
public void startPrefixMapping(String prefix, String uri) throws SAXException {
startPrefixCount ++;
}
public void endPrefixMapping(String prefix) throws SAXException {
endPrefixCount ++;
if (element_z_Ended && "e".equals(prefix)) prefix_e_Ended = true;
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("z".equals(localName)) element_z_Ended = true;
}
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/stax/ 0000775 0000000 0000000 00000000000 12263200227 0023605 5 ustar 00root root 0000000 0000000 xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/stax/Base64Test.java 0000664 0000000 0000000 00000012334 12263200227 0026337 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.BaseBufferTestCase;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import javax.xml.stream.XMLStreamConstants;
import org.jvnet.staxex.Base64Data;
import org.jvnet.staxex.XMLStreamReaderEx;
import org.jvnet.staxex.XMLStreamWriterEx;
/**
*
* @author Paul.Sandoz@Sun.Com
*/
public class Base64Test extends BaseBufferTestCase {
byte[] bytes = {0, 1, 2, 3};
Base64Data data;
String base64EncodedString;
/** Creates a new instance of Base64Test */
public Base64Test() {
data = new Base64Data();
data.set(bytes, null);
base64EncodedString = data.toString();
}
MutableXMLStreamBuffer createBuffer() throws Exception {
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
XMLStreamWriterEx writer = (XMLStreamWriterEx)buffer.createFromXMLStreamWriter();
writer.writeStartDocument();
writer.writeStartElement("foo");
writer.writeBinary(bytes, 0, bytes.length, null);
writer.writeEndElement();
writer.writeEndDocument();
assertTrue(buffer.isCreated());
return buffer;
}
public void testReadingAsString() throws Exception {
MutableXMLStreamBuffer buffer = createBuffer();
XMLStreamReaderEx reader = (XMLStreamReaderEx)buffer.readAsXMLStreamReader();
assertEquals(XMLStreamConstants.START_DOCUMENT,reader.getEventType());
assertEquals(XMLStreamConstants.START_ELEMENT,reader.next());
verifyTag(reader,null,"foo");
assertEquals(XMLStreamConstants.CHARACTERS,reader.next());
assertEquals(base64EncodedString,reader.getText());
assertEquals(XMLStreamConstants.END_ELEMENT,reader.next());
verifyTag(reader,null,"foo");
}
void readPCData(XMLStreamReaderEx reader) throws Exception {
assertEquals(XMLStreamConstants.START_DOCUMENT,reader.getEventType());
assertEquals(XMLStreamConstants.START_ELEMENT,reader.next());
verifyTag(reader,null,"foo");
assertEquals(XMLStreamConstants.CHARACTERS,reader.next());
CharSequence c = reader.getPCDATA();
assertEquals(true, c instanceof Base64Data);
Base64Data d = (Base64Data)c;
byte[] b = d.getExact();
assertEquals(bytes.length, b.length);
for (int i = 0; i < bytes.length; i++) {
assertEquals(bytes[i], b[i]);
}
assertEquals(XMLStreamConstants.END_ELEMENT,reader.next());
verifyTag(reader,null,"foo");
}
public void testReadingAsPCDATA() throws Exception {
MutableXMLStreamBuffer buffer = createBuffer();
XMLStreamReaderEx reader = (XMLStreamReaderEx)buffer.readAsXMLStreamReader();
readPCData(reader);
}
public void testReadingAsPCDATAUsingCopyOfBuffer() throws Exception {
MutableXMLStreamBuffer originalBuffer = createBuffer();
XMLStreamReaderEx originalReader = (XMLStreamReaderEx)originalBuffer.readAsXMLStreamReader();
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
buffer.createFromXMLStreamReader(originalReader);
XMLStreamReaderEx reader = (XMLStreamReaderEx)buffer.readAsXMLStreamReader();
readPCData(reader);
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/stax/CharactersTest.java 0000664 0000000 0000000 00000007757 12263200227 0027407 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import junit.framework.TestCase;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.StringReader;
/**
*
* @author Jitendra.Kotamraju@Sun.Com
*/
public class CharactersTest extends TestCase {
public CharactersTest(String testName) {
super(testName);
}
public void testCharacters() throws Exception {
useReaderForTesting(0);
useReaderForTesting(1);
useReaderForTesting(512);
useReaderForTesting(1025);
useReaderForTesting(8192);
useReaderForTesting(8193);
useReaderForTesting(10000);
}
private void useReaderForTesting(int len) throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("");
for(int i=0; i < len; i++) {
builder.append('a');
}
builder.append(" ");
String str = builder.toString();
XMLStreamReader rdr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(str));
XMLStreamBuffer xsb = XMLStreamBuffer.createNewBufferFromXMLStreamReader(rdr);
XMLStreamReader xsbrdr = xsb.readAsXMLStreamReader();
rdr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(str));
rdr.next(); xsbrdr.next();
rdr.next(); xsbrdr.next();
if (rdr.hasText()) {
rdr.getTextCharacters();
compareCharacters(rdr, xsbrdr);
}
}
private void compareCharacters(XMLStreamReader rdr1, XMLStreamReader rdr2) throws Exception {
char[] buf1 = new char[1024];
char[] buf2 = new char[1024];
for (int start=0,read1=buf1.length; read1 == buf1.length; start+=buf1.length) {
read1 = rdr1.getTextCharacters(start, buf1, 0, buf1.length);
int read2 = rdr2.getTextCharacters(start, buf2, 0, buf2.length);
assertEquals(read1, read2);
assertEquals(new String(buf1), new String(buf2));
}
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/stax/InscopeNamespaceTest.java 0000664 0000000 0000000 00000031235 12263200227 0030531 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import com.sun.xml.stream.buffer.XMLStreamBufferMark;
import junit.framework.TestCase;
import javax.xml.stream.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author rama.pulavarthi@sun.com
* @author Jitendra Kotamraju
*/
public class InscopeNamespaceTest extends TestCase {
public InscopeNamespaceTest(String testName) {
super(testName);
}
public void testXMLStreamBuffer() throws Exception {
itestXMLStreamBuffer(false);
}
public void testXMLStreamBufferMark() throws Exception {
itestXMLStreamBuffer(true);
}
/**
* In this test, the namespace xmlns:user='http://foo.bar' is declared on top-level
* element and child uses it but doesn't declare it
* @throws Exception
*/
private void itestXMLStreamBuffer(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
" ";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer1() throws Exception {
itestXMLStreamBuffer1(false);
}
public void testXMLStreamBuffer1Mark() throws Exception {
itestXMLStreamBuffer1(true);
}
/**
* In this test, the namespace xmlns:user='http://foo.bar' is declared on top-level element as well as the child
* @throws Exception
*/
private void itestXMLStreamBuffer1(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
" ";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer2() throws Exception {
itestXMLStreamBuffer2(false);
}
public void testXMLStreamBuffer2Mark() throws Exception {
itestXMLStreamBuffer2(true);
}
/**
* In this test, the namespace xmlns:user='http://foo.bar' is declared
* on top-level element and child uses same prefix different ns
* @throws Exception
*/
private void itestXMLStreamBuffer2(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
" ";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo1.bar1", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer3() throws Exception {
itestXMLStreamBuffer3(false);
}
public void testXMLStreamBuffer3Mark() throws Exception {
itestXMLStreamBuffer3(true);
}
private void itestXMLStreamBuffer3(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
"";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer4() throws Exception {
itestXMLStreamBuffer4(false);
}
public void testXMLStreamBuffer4Mark() throws Exception {
itestXMLStreamBuffer4(true);
}
private void itestXMLStreamBuffer4(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
"";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo1.bar1", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer5() throws Exception {
itestXMLStreamBuffer5(false);
}
public void testXMLStreamBuffer5Mark() throws Exception {
itestXMLStreamBuffer5(true);
}
private void itestXMLStreamBuffer5(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
" ";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
assertEquals("value", reader2.getAttributeValue("http://foo1.bar1","att"));
}
public void testXMLStreamBuffer6() throws Exception {
itestXMLStreamBuffer6(false);
}
public void testXMLStreamBuffer6Mark() throws Exception {
itestXMLStreamBuffer6(true);
}
private void itestXMLStreamBuffer6(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
"";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertNull(reader2.getNamespaceURI());
}
public void testXMLStreamBuffer7() throws Exception {
itestXMLStreamBuffer7(false);
}
public void testXMLStreamBuffer7Mark() throws Exception {
itestXMLStreamBuffer7(true);
}
private void itestXMLStreamBuffer7(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
"";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
}
public void testXMLStreamBuffer8() throws Exception {
itestXMLStreamBuffer8(false);
}
public void testXMLStreamBuffer8Mark() throws Exception {
itestXMLStreamBuffer8(true);
}
private void itestXMLStreamBuffer8(boolean markReader) throws Exception {
String requestStr =
"" +
"bar " +
" ";
XMLStreamReader reader2 = markReader ? getReaderFromMark(requestStr) : getReader(requestStr);
reader2.next();// go to start element
assertEquals("http://foo.bar", reader2.getNamespaceURI());
}
// returned reader is placed at the first child
private XMLStreamReader getReader(String requestStr) throws Exception {
XMLStreamReader reader = createXMLStreamReader(new ByteArrayInputStream(requestStr.getBytes()));
reader.next();// go to start element: S:Header
// Collect namespaces on soap:Header
Map namespaces = new HashMap();
for(int i=0; i< reader.getNamespaceCount();i++){
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
while(true) {
reader.next();
if(reader.getEventType() == XMLStreamConstants.START_ELEMENT)
break;
}
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
StreamReaderBufferCreator creator = new StreamReaderBufferCreator();
creator.setXMLStreamBuffer(buffer);
// Mark
XMLStreamBuffer mark = new XMLStreamBufferMark(namespaces, creator);
// Cache the header block
// After caching Reader will be positioned at next header block or
// the end of the
creator.createElementFragment(reader, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = createXMLStreamWriter(baos);
writer.writeStartDocument();
if(mark.getInscopeNamespaces().size() > 0)
mark.writeToXMLStreamWriter(writer,true);
else
mark.writeToXMLStreamWriter(writer);
writer.writeEndDocument();
writer.flush();
//baos.writeTo(System.out);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return createXMLStreamReader(bais);
}
// returned reader is placed at the first child
private XMLStreamReader getReaderFromMark(String requestStr) throws Exception {
XMLStreamReader reader = createXMLStreamReader(new ByteArrayInputStream(requestStr.getBytes()));
reader.next();// go to start element: S:Header
// Collect namespaces on soap:Header
Map namespaces = new HashMap();
for(int i=0; i< reader.getNamespaceCount();i++){
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
while(true) {
reader.next();
if(reader.getEventType() == XMLStreamConstants.START_ELEMENT)
break;
}
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
StreamReaderBufferCreator creator = new StreamReaderBufferCreator();
creator.setXMLStreamBuffer(buffer);
// Mark
XMLStreamBuffer mark = new XMLStreamBufferMark(namespaces, creator);
creator.createElementFragment(reader, true);
return mark.readAsXMLStreamReader();
}
private XMLStreamReader createXMLStreamReader(InputStream is) throws Exception {
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
return readerFactory.createXMLStreamReader(is);
}
private XMLStreamWriter createXMLStreamWriter(OutputStream os) throws Exception {
XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
return writerFactory.createXMLStreamWriter(os);
}
}
xmlstreambuffer-1.5.1/test/com/sun/xml/stream/buffer/stax/OverrideNamespaceTest.java 0000664 0000000 0000000 00000036030 12263200227 0030706 0 ustar 00root root 0000000 0000000 /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.stream.buffer.stax;
import com.sun.xml.stream.buffer.XMLStreamBuffer;
import com.sun.xml.stream.buffer.MutableXMLStreamBuffer;
import com.sun.xml.stream.buffer.XMLStreamBufferResult;
import java.io.StringReader;
import java.util.*;
import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.parsers.SAXParserFactory;
import junit.framework.*;
import org.xml.sax.XMLReader;
/**
*
* @author Paul.Sandoz@Sun.Com
* @author Jitendra.Kotamraju@Sun.Com
*/
public class OverrideNamespaceTest extends TestCase {
public OverrideNamespaceTest(String testName) {
super(testName);
}
public void testOverrideNamespace() throws Exception {
String[] startElement = {"definitions", "types", "binding"};
String[] startElement_namespaces = {"http://wsdl", "http://types", "http://wsdl"};
String[] endElement = {"types", "binding", "definitions"};
String[] endElement_namespaces = {"http://types", "http://wsdl", "http://wsdl"};
String str = " ";
XMLStreamReader rdr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(str));
XMLStreamBuffer xsb = XMLStreamBuffer.createNewBufferFromXMLStreamReader(rdr);
XMLStreamReader xsbrdr = xsb.readAsXMLStreamReader();
int i = 0;
int j = 0;
while(xsbrdr.hasNext()) {
int event = xsbrdr.next();
if (event == XMLStreamReader.START_ELEMENT) {
assertEquals("Start of Element " + xsbrdr.getName() + " has wrong namespace",
startElement_namespaces[i], xsbrdr.getNamespaceURI("tns"));
assertEquals(startElement[i++], xsbrdr.getLocalName());
} else if (event == XMLStreamReader.END_ELEMENT) {
assertEquals("End of Element " + xsbrdr.getName() + " has wrong namespace",
endElement_namespaces[j], xsbrdr.getNamespaceURI("tns"));
assertEquals(endElement[j++], xsbrdr.getLocalName());
}
}
}
public void testOverrideNamespace1() throws Exception {
Map ns = new LinkedHashMap();
ns.put("definitions", "http://wsdl");
ns.put("types", "http://types");
ns.put("binding", "http://wsdl");
ns.put("operation", "http://operation");
ns.put("port", "http://wsdl");
String str = " ";
XMLStreamReader rdr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(str));
XMLStreamBuffer xsb = XMLStreamBuffer.createNewBufferFromXMLStreamReader(rdr);
XMLStreamReader xsbrdr = xsb.readAsXMLStreamReader();
Iterator nsItr = ns.keySet().iterator();
while(xsbrdr.hasNext()) {
int event = xsbrdr.next();
if (event == XMLStreamReader.START_ELEMENT) {
assertEquals("Wrong Start of Element", nsItr.next(), xsbrdr.getLocalName());
assertEquals("Start of Element " + xsbrdr.getName() + " has wrong namespace",
ns.get(xsbrdr.getLocalName()), xsbrdr.getNamespaceURI("tns"));
} else if (event == XMLStreamReader.END_ELEMENT) {
assertEquals("End of Element " + xsbrdr.getName() + " has wrong namespace",
ns.get(xsbrdr.getLocalName()), xsbrdr.getNamespaceURI("tns"));
}
}
}
public void testNamespaceScope1() throws Exception {
String str = "" +
"Frobnostication " +
"" +
"here. " +
" " +
" ";
useReaderForTesting(str, "html");
}
public void testNamespaceScope2() throws Exception {
String str =
""+
"Cheaper by the Dozen "+
"1568491379 "+
""+
""+
""+
"This is a funny book!"+
"
"+
" "+
" ";
useReaderForTesting(str, "", "isbn");
}
public void testNamespaceScope3() throws Exception {
String str =
""+
""+
""+
"Name Origin Description "+
""+
""+
"Huntsman "+
"Bath, UK "+
""+
"Bitter Fuggles "+
"Wonderful hop, light alcohol, good summer beer "+
"Fragile; excessive variance pub to pub "+
" "+
" "+
" "+
"
"+
" ";
useReaderForTesting(str, "");
}
public void testNamespaceScope4() throws Exception {
String str =
""+
""+
" "+
""+
"Huntsman "+
"Bath, UK "+
" "+
" "+
" "+
"
"+
" ";
useReaderForTesting(str, "", "A", "B", "P", "Q", "R");
}
public void testInscopeNamespaces() throws Exception {
String str =
"" +
"" +
"" +
"ns4:Server " +
"com.sun.istack.XMLStreamException2 " +
" " +
" " +
" ";
verifyStreamMessageCopy(str);
}
private void verifyStreamMessageCopy(String str) throws XMLStreamException {
XMLStreamReader rdr = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(str));
rdr.nextTag();
rdr.nextTag();
rdr.nextTag();
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
// preserving inscope namespaces from envelope, and body.
String[] envNs = new String[] { "S", "http://schemas.xmlsoap.org/soap/envelope/", "ns4", "A" };
c.storeElement("http://schemas.xmlsoap.org/soap/envelope/", "Envelope", "S", envNs);
String[] bodyNs = new String[] { "ns4", "http://schemas.xmlsoap.org/soap/envelope/" };
c.storeElement("http://schemas.xmlsoap.org/soap/envelope/", "Body", "S", bodyNs);
// Loop all the way for multi payload case
while(rdr.getEventType() != XMLStreamConstants.END_DOCUMENT){
String name = rdr.getLocalName();
if (name.equals("Body")) {
break;
}
c.create(rdr);
}
c.storeEndElement(); //
c.storeEndElement(); //