diff --git a/core/src/test/java/org/springframework/ws/server/endpoint/support/PayloadRootUtilsTest.java b/core/src/test/java/org/springframework/ws/server/endpoint/support/PayloadRootUtilsTest.java
index 9194325a..a0dfdc6e 100644
--- a/core/src/test/java/org/springframework/ws/server/endpoint/support/PayloadRootUtilsTest.java
+++ b/core/src/test/java/org/springframework/ws/server/endpoint/support/PayloadRootUtilsTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2005-2010 the original author or authors.
+ * Copyright 2005-2012 the original author or authors.
*
* 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
+ * 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,
@@ -29,7 +29,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
-import org.springframework.xml.transform.StaxSource;
+import org.springframework.util.xml.StaxUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -59,7 +59,7 @@ public class PayloadRootUtilsTest {
String contents = "true if the current JAXP version is at least JAXP 1.3
- * @see #getJaxpVersion()
- * @see #JAXP_13
- * @deprecated as of Spring-WS 2.0 which requires Java 1.5+
- */
- @Deprecated
- public static boolean isAtLeastJaxp13() {
- return getJaxpVersion() >= JAXP_13;
- }
-
/**
* Convenience method to determine if the current JAXP version is at least 1.4 (packaged with JDK 1.6).
*
diff --git a/xml/src/main/java/org/springframework/xml/stream/AbstractStaxContentHandler.java b/xml/src/main/java/org/springframework/xml/stream/AbstractStaxContentHandler.java
deleted file mode 100644
index ec609c67..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/AbstractStaxContentHandler.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-
-import org.springframework.xml.namespace.QNameUtils;
-import org.springframework.xml.namespace.SimpleNamespaceContext;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * Abstract base class for SAX ContentHandler implementations that use StAX as a basis. All methods
- * delegate to internal template methods, capable of throwing a XMLStreamException. Additionally, an
- * namespace context is used to keep track of declared namespaces.
- *
- * @author Arjen Poutsma
- * @since 1.0.0
- * @deprecated With no concrete replacement
- */
-@Deprecated
-public abstract class AbstractStaxContentHandler implements ContentHandler {
-
- private SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
-
- /**
- * @throws SAXException
- */
- public final void startDocument() throws SAXException {
- namespaceContext.clear();
- try {
- startDocumentInternal();
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle startDocument: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void startDocumentInternal() throws XMLStreamException;
-
- public final void endDocument() throws SAXException {
- namespaceContext.clear();
- try {
- endDocumentInternal();
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle startDocument: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void endDocumentInternal() throws XMLStreamException;
-
- /**
- * Binds the given prefix to the given namespaces.
- *
- * @see SimpleNamespaceContext#bindNamespaceUri(String,String)
- */
- public final void startPrefixMapping(String prefix, String uri) {
- namespaceContext.bindNamespaceUri(prefix, uri);
- }
-
- /**
- * Removes the binding for the given prefix.
- *
- * @see SimpleNamespaceContext#removeBinding(String)
- */
- public final void endPrefixMapping(String prefix) {
- namespaceContext.removeBinding(prefix);
- }
-
- public final void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
- try {
- startElementInternal(QNameUtils.toQName(uri, qName), atts, namespaceContext);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle startElement: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void startElementInternal(QName name, Attributes atts, SimpleNamespaceContext namespaceContext)
- throws XMLStreamException;
-
- public final void endElement(String uri, String localName, String qName) throws SAXException {
- try {
- endElementInternal(QNameUtils.toQName(uri, qName), namespaceContext);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle endElement: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void endElementInternal(QName name, SimpleNamespaceContext namespaceContext)
- throws XMLStreamException;
-
- public final void characters(char ch[], int start, int length) throws SAXException {
- try {
- charactersInternal(ch, start, length);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle characters: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void charactersInternal(char[] ch, int start, int length) throws XMLStreamException;
-
- public final void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
- try {
- ignorableWhitespaceInternal(ch, start, length);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle ignorableWhitespace:" + ex.getMessage(), ex);
- }
- }
-
- protected abstract void ignorableWhitespaceInternal(char[] ch, int start, int length) throws XMLStreamException;
-
- public final void processingInstruction(String target, String data) throws SAXException {
- try {
- processingInstructionInternal(target, data);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle processingInstruction: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void processingInstructionInternal(String target, String data) throws XMLStreamException;
-
- public final void skippedEntity(String name) throws SAXException {
- try {
- skippedEntityInternal(name);
- }
- catch (XMLStreamException ex) {
- throw new SAXException("Could not handle skippedEntity: " + ex.getMessage(), ex);
- }
- }
-
- protected abstract void skippedEntityInternal(String name) throws XMLStreamException;
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/AbstractStaxXmlReader.java b/xml/src/main/java/org/springframework/xml/stream/AbstractStaxXmlReader.java
deleted file mode 100644
index 96af3618..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/AbstractStaxXmlReader.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLStreamException;
-
-import org.springframework.xml.sax.AbstractXmlReader;
-
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Abstract base class for SAX XMLReader implementations that use StAX as a basis.
- *
- * @author Arjen Poutsma
- * @see #setContentHandler(org.xml.sax.ContentHandler)
- * @see #setDTDHandler(org.xml.sax.DTDHandler)
- * @see #setEntityResolver(org.xml.sax.EntityResolver)
- * @see #setErrorHandler(org.xml.sax.ErrorHandler)
- * @since 1.0.0
- * @deprecated With no concrete replacement
- */
-@Deprecated
-public abstract class AbstractStaxXmlReader extends AbstractXmlReader {
-
- private static final String NAMESPACES_FEATURE_NAME = "http://xml.org/sax/features/namespaces";
-
- private static final String NAMESPACE_PREFIXES_FEATURE_NAME = "http://xml.org/sax/features/namespace-prefixes";
-
- private static final String IS_STANDALONE_FEATURE_NAME = "http://xml.org/sax/features/is-standalone";
-
- private boolean namespacesFeature = true;
-
- private boolean namespacePrefixesFeature = false;
-
- private Boolean isStandalone;
-
- @Override
- public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
- if (NAMESPACES_FEATURE_NAME.equals(name)) {
- return namespacesFeature;
- }
- else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
- return namespacePrefixesFeature;
- }
- else if (IS_STANDALONE_FEATURE_NAME.equals(name)) {
- if (isStandalone != null) {
- return isStandalone;
- }
- else {
- throw new SAXNotSupportedException("startDocument() callback not completed yet");
- }
- }
- else {
- return super.getFeature(name);
- }
- }
-
- @Override
- public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
- if (NAMESPACES_FEATURE_NAME.equals(name)) {
- this.namespacesFeature = value;
- }
- else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
- this.namespacePrefixesFeature = value;
- }
- else {
- super.setFeature(name, value);
- }
- }
-
- /** Indicates whether the SAX feature http://xml.org/sax/features/namespaces is turned on. */
- protected boolean hasNamespacesFeature() {
- return namespacesFeature;
- }
-
- /** Indicates whether the SAX feature http://xml.org/sax/features/namespaces-prefixes is turned on. */
- protected boolean hasNamespacePrefixesFeature() {
- return namespacePrefixesFeature;
- }
-
- protected void setStandalone(boolean standalone) {
- isStandalone = (standalone) ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Parses the StAX XML reader passed at construction-time.
- *
InputSource is not read, but ignored.
- *
- * @param ignored is ignored
- * @throws SAXException A SAX exception, possibly wrapping a XMLStreamException
- */
- public final void parse(InputSource ignored) throws SAXException {
- parse();
- }
-
- /**
- * Parses the StAX XML reader passed at construction-time.
- *
- * Note that the given system identifier is not read, but ignored.
- *
- * @param ignored is ignored
- * @throws SAXException A SAX exception, possibly wrapping a XMLStreamException
- */
- public final void parse(String ignored) throws SAXException {
- parse();
- }
-
- private void parse() throws SAXException {
- try {
- parseInternal();
- }
- catch (XMLStreamException ex) {
- Locator locator = null;
- if (ex.getLocation() != null) {
- locator = new StaxLocator(ex.getLocation());
- }
- SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
- if (getErrorHandler() != null) {
- getErrorHandler().fatalError(saxException);
- }
- else {
- throw saxException;
- }
- }
- }
-
- /**
- * Sets the SAX Locator based on the given StAX Location.
- *
- * @param location the location
- * @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
- */
- protected void setLocator(Location location) {
- if (getContentHandler() != null) {
- getContentHandler().setDocumentLocator(new StaxLocator(location));
- }
- }
-
- /** Template-method that parses the StAX reader passed at construction-time. */
- protected abstract void parseInternal() throws SAXException, XMLStreamException;
-
- /**
- * Implementation of the Locator interface that is based on a StAX Location.
- *
- * @see Locator
- * @see Location
- */
- private static class StaxLocator implements Locator {
-
- private Location location;
-
- protected StaxLocator(Location location) {
- this.location = location;
- }
-
- public String getPublicId() {
- return location.getPublicId();
- }
-
- public String getSystemId() {
- return location.getSystemId();
- }
-
- public int getLineNumber() {
- return location.getLineNumber();
- }
-
- public int getColumnNumber() {
- return location.getColumnNumber();
- }
- }
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/AbstractXmlStreamReader.java b/xml/src/main/java/org/springframework/xml/stream/AbstractXmlStreamReader.java
deleted file mode 100644
index c617bff5..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/AbstractXmlStreamReader.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.springframework.util.Assert;
-
-/**
- * Abstract base class for XMLStreamReaders.
- *
- * @author Arjen Poutsma
- * @since 1.0.0
- * @deprecated With no concrete replacement
- */
-@Deprecated
-public abstract class AbstractXmlStreamReader implements XMLStreamReader {
-
- public String getElementText() throws XMLStreamException {
- if (getEventType() != XMLStreamConstants.START_ELEMENT) {
- throw new XMLStreamException("parser must be on START_ELEMENT to read next text", getLocation());
- }
- int eventType = next();
- StringBuilder builder = new StringBuilder();
- while (eventType != XMLStreamConstants.END_ELEMENT) {
- if (eventType == XMLStreamConstants.CHARACTERS || eventType == XMLStreamConstants.CDATA ||
- eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
- builder.append(getText());
- }
- else
- if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) {
- // skipping
- }
- else if (eventType == XMLStreamConstants.END_DOCUMENT) {
- throw new XMLStreamException("unexpected end of document when reading element text content",
- getLocation());
- }
- else if (eventType == XMLStreamConstants.START_ELEMENT) {
- throw new XMLStreamException("element text content may not contain START_ELEMENT", getLocation());
- }
- else {
- throw new XMLStreamException("Unexpected event type " + eventType, getLocation());
- }
- eventType = next();
- }
- return builder.toString();
- }
-
- public String getAttributeLocalName(int index) {
- return getAttributeName(index).getLocalPart();
- }
-
- public String getAttributeNamespace(int index) {
- return getAttributeName(index).getNamespaceURI();
- }
-
- public String getAttributePrefix(int index) {
- return getAttributeName(index).getPrefix();
- }
-
- public String getNamespaceURI() {
- int eventType = getEventType();
- if (eventType == XMLStreamConstants.START_ELEMENT || eventType == XMLStreamConstants.END_ELEMENT) {
- return getName().getNamespaceURI();
- }
- else {
- throw new IllegalStateException("parser must be on START_ELEMENT or END_ELEMENT state");
- }
- }
-
- public String getNamespaceURI(String prefix) {
- Assert.notNull(prefix, "No prefix given");
- return getNamespaceContext().getNamespaceURI(prefix);
- }
-
- public boolean hasText() {
- int eventType = getEventType();
- return eventType == XMLStreamConstants.SPACE || eventType == XMLStreamConstants.CHARACTERS ||
- eventType == XMLStreamConstants.COMMENT || eventType == XMLStreamConstants.CDATA ||
- eventType == XMLStreamConstants.ENTITY_REFERENCE;
- }
-
- public String getPrefix() {
- int eventType = getEventType();
- if (eventType == XMLStreamConstants.START_ELEMENT || eventType == XMLStreamConstants.END_ELEMENT) {
- return getName().getPrefix();
- }
- else {
- throw new IllegalStateException("parser must be on START_ELEMENT or END_ELEMENT state");
- }
- }
-
- public boolean hasName() {
- int eventType = getEventType();
- return eventType == XMLStreamConstants.START_ELEMENT || eventType == XMLStreamConstants.END_ELEMENT;
- }
-
- public boolean isWhiteSpace() {
- return getEventType() == XMLStreamConstants.SPACE;
- }
-
- public boolean isStartElement() {
- return getEventType() == XMLStreamConstants.START_ELEMENT;
- }
-
- public boolean isEndElement() {
- return getEventType() == XMLStreamConstants.END_ELEMENT;
- }
-
- public boolean isCharacters() {
- return getEventType() == XMLStreamConstants.CHARACTERS;
- }
-
- public int nextTag() throws XMLStreamException {
- int eventType = next();
- while (eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace() ||
- eventType == XMLStreamConstants.CDATA && isWhiteSpace() || eventType == XMLStreamConstants.SPACE ||
- eventType == XMLStreamConstants.PROCESSING_INSTRUCTION || eventType == XMLStreamConstants.COMMENT) {
- eventType = next();
- }
- if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
- throw new XMLStreamException("expected start or end tag", getLocation());
- }
- return eventType;
- }
-
- public void require(int expectedType, String namespaceURI, String localName) throws XMLStreamException {
- int eventType = getEventType();
- if (eventType != expectedType) {
- throw new XMLStreamException("Expected [" + expectedType + "] but read [" + eventType + "]");
- }
- }
-
- public String getAttributeValue(String namespaceURI, String localName) {
- for (int i = 0; i < getAttributeCount(); i++) {
- QName name = getAttributeName(i);
- if (name.getLocalPart().equals(localName) &&
- (namespaceURI == null || name.getNamespaceURI().equals(namespaceURI))) {
- return getAttributeValue(i);
- }
- }
- return null;
- }
-
- public boolean hasNext() throws XMLStreamException {
- return getEventType() != END_DOCUMENT;
- }
-
- public String getLocalName() {
- return getName().getLocalPart();
- }
-
- public char[] getTextCharacters() {
- return getText().toCharArray();
- }
-
- public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
- throws XMLStreamException {
- char[] source = getTextCharacters();
- length = Math.min(length, source.length);
- System.arraycopy(source, sourceStart, target, targetStart, length);
- return length;
- }
-
- public int getTextLength() {
- return getText().length();
- }
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/StaxEventContentHandler.java b/xml/src/main/java/org/springframework/xml/stream/StaxEventContentHandler.java
deleted file mode 100644
index 08a4154f..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/StaxEventContentHandler.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLEventFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.Namespace;
-import javax.xml.stream.events.XMLEvent;
-import javax.xml.stream.util.XMLEventConsumer;
-
-import org.springframework.util.StringUtils;
-import org.springframework.xml.namespace.QNameUtils;
-import org.springframework.xml.namespace.SimpleNamespaceContext;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-
-/**
- * SAX ContentHandler that transforms callback calls to XMLEvents and writes them to a
- * XMLEventConsumer.
- *
- * @author Arjen Poutsma
- * @see XMLEvent
- * @see XMLEventConsumer
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createContentHandler(javax.xml.stream.XMLEventWriter)}.
- */
-@Deprecated
-public class StaxEventContentHandler extends AbstractStaxContentHandler {
-
- private final XMLEventFactory eventFactory;
-
- private final XMLEventConsumer eventConsumer;
-
- private Locator locator;
-
- /**
- * Constructs a new instance of the StaxEventContentHandler that writes to the given
- * XMLEventConsumer. A default XMLEventFactory will be created.
- *
- * @param consumer the consumer to write events to
- */
- public StaxEventContentHandler(XMLEventConsumer consumer) {
- eventFactory = XMLEventFactory.newInstance();
- eventConsumer = consumer;
- }
-
- /**
- * Constructs a new instance of the StaxEventContentHandler that uses the given event factory to create
- * events and writes to the given XMLEventConsumer.
- *
- * @param consumer the consumer to write events to
- * @param factory the factory used to create events
- */
- public StaxEventContentHandler(XMLEventConsumer consumer, XMLEventFactory factory) {
- eventFactory = factory;
- eventConsumer = consumer;
- }
-
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- @Override
- protected void startDocumentInternal() throws XMLStreamException {
- consumeEvent(eventFactory.createStartDocument());
- }
-
- @Override
- protected void endDocumentInternal() throws XMLStreamException {
- consumeEvent(eventFactory.createEndDocument());
- }
-
- @Override
- protected void startElementInternal(QName name, Attributes atts, SimpleNamespaceContext namespaceContext)
- throws XMLStreamException {
- ListNameSpace objects from the NamespaceContext. */
- private ListXMLReader that reads from a StAX XMLEventReader. Consumes XMLEvents from
- * an XMLEventReader, and calls the corresponding methods on the SAX callback interfaces.
- *
- * @author Arjen Poutsma
- * @see XMLEventReader
- * @see #setContentHandler(org.xml.sax.ContentHandler)
- * @see #setDTDHandler(org.xml.sax.DTDHandler)
- * @see #setEntityResolver(org.xml.sax.EntityResolver)
- * @see #setErrorHandler(org.xml.sax.ErrorHandler)
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createXMLReader(javax.xml.stream.XMLEventReader)}
- */
-@Deprecated
-public class StaxEventXmlReader extends AbstractStaxXmlReader {
-
- private final XMLEventReader reader;
-
- /**
- * Constructs a new instance of the StaxEventXmlReader that reads from the given
- * XMLEventReader. The supplied event reader must be in XMLStreamConstants.START_DOCUMENT
- * or XMLStreamConstants.START_ELEMENT state.
- *
- * @param reader the XMLEventReader to read from
- * @throws IllegalStateException if the reader is not at the start of a document or element
- */
- public StaxEventXmlReader(XMLEventReader reader) {
- try {
- XMLEvent event = reader.peek();
- if (event == null || !(event.isStartDocument() || event.isStartElement())) {
- throw new IllegalStateException("XMLEventReader not at start of document or element");
- }
- }
- catch (XMLStreamException ex) {
- throw new IllegalStateException("Could not read first element: " + ex.getMessage());
- }
-
- this.reader = reader;
- }
-
- @Override
- protected void parseInternal() throws SAXException, XMLStreamException {
- boolean documentStarted = false;
- boolean documentEnded = false;
- int elementDepth = 0;
- while (reader.hasNext() && elementDepth >= 0) {
- XMLEvent event = reader.nextEvent();
- if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
- handleStartDocument();
- documentStarted = true;
- }
- switch (event.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- elementDepth++;
- handleStartElement(event.asStartElement());
- break;
- case XMLStreamConstants.END_ELEMENT:
- elementDepth--;
- if (elementDepth >= 0) {
- handleEndElement(event.asEndElement());
- }
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- handleProcessingInstruction((ProcessingInstruction) event);
- break;
- case XMLStreamConstants.CHARACTERS:
- case XMLStreamConstants.SPACE:
- case XMLStreamConstants.CDATA:
- handleCharacters(event.asCharacters());
- break;
- case XMLStreamConstants.START_DOCUMENT:
- setLocator(event.getLocation());
- handleStartDocument();
- documentStarted = true;
- break;
- case XMLStreamConstants.END_DOCUMENT:
- handleEndDocument();
- documentEnded = true;
- break;
- case XMLStreamConstants.NOTATION_DECLARATION:
- handleNotationDeclaration((NotationDeclaration) event);
- break;
- case XMLStreamConstants.ENTITY_DECLARATION:
- handleEntityDeclaration((EntityDeclaration) event);
- break;
- case XMLStreamConstants.COMMENT:
- handleComment((Comment) event);
- break;
- case XMLStreamConstants.DTD:
- handleDtd((DTD) event);
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- handleEntityReference((EntityReference) event);
- break;
- }
- }
- if (!documentEnded) {
- handleEndDocument();
- }
-
- }
-
- private void handleStartElement(StartElement startElement) throws SAXException {
- if (getContentHandler() != null) {
- QName qName = startElement.getName();
- if (hasNamespacesFeature()) {
- for (Iterator> i = startElement.getNamespaces(); i.hasNext();) {
- Namespace namespace = (Namespace) i.next();
- getContentHandler().startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
- }
- getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(),
- QNameUtils.toQualifiedName(qName), getAttributes(startElement));
- }
- else {
- getContentHandler()
- .startElement("", "", QNameUtils.toQualifiedName(qName), getAttributes(startElement));
- }
- }
- }
-
- private void handleCharacters(Characters characters) throws SAXException {
- char[] data = characters.getData().toCharArray();
- if (getContentHandler() != null && characters.isIgnorableWhiteSpace()) {
- getContentHandler().ignorableWhitespace(data, 0, data.length);
- return;
- }
- if (characters.isCData() && getLexicalHandler() != null) {
- getLexicalHandler().startCDATA();
- }
- if (getContentHandler() != null) {
- getContentHandler().characters(data, 0, data.length);
- }
- if (characters.isCData() && getLexicalHandler() != null) {
- getLexicalHandler().endCDATA();
- }
- }
-
- private void handleEndDocument() throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().endDocument();
- }
- }
-
- private void handleEndElement(EndElement endElement) throws SAXException {
- if (getContentHandler() != null) {
- QName qName = endElement.getName();
- if (hasNamespacesFeature()) {
- getContentHandler()
- .endElement(qName.getNamespaceURI(), qName.getLocalPart(), QNameUtils.toQualifiedName(qName));
- for (Iterator> i = endElement.getNamespaces(); i.hasNext();) {
- Namespace namespace = (Namespace) i.next();
- getContentHandler().endPrefixMapping(namespace.getPrefix());
- }
- }
- else {
- getContentHandler().endElement("", "", QNameUtils.toQualifiedName(qName));
- }
-
- }
- }
-
- private void handleNotationDeclaration(NotationDeclaration declaration) throws SAXException {
- if (getDTDHandler() != null) {
- getDTDHandler().notationDecl(declaration.getName(), declaration.getPublicId(), declaration.getSystemId());
- }
- }
-
- private void handleEntityDeclaration(EntityDeclaration entityDeclaration) throws SAXException {
- if (getDTDHandler() != null) {
- getDTDHandler().unparsedEntityDecl(entityDeclaration.getName(), entityDeclaration.getPublicId(),
- entityDeclaration.getSystemId(), entityDeclaration.getNotationName());
- }
- }
-
- private void handleProcessingInstruction(ProcessingInstruction pi) throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().processingInstruction(pi.getTarget(), pi.getData());
- }
- }
-
- private void handleStartDocument() throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().startDocument();
- }
- }
-
- private void handleComment(Comment comment) throws SAXException {
- if (getLexicalHandler() != null) {
- char[] ch = comment.getText().toCharArray();
- getLexicalHandler().comment(ch, 0, ch.length);
- }
- }
-
- private void handleDtd(DTD dtd) throws SAXException {
- if (getLexicalHandler() != null) {
- javax.xml.stream.Location location = dtd.getLocation();
- getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
- }
- if (getLexicalHandler() != null) {
- getLexicalHandler().endDTD();
- }
-
- }
-
- private void handleEntityReference(EntityReference reference) throws SAXException {
- if (getLexicalHandler() != null) {
- getLexicalHandler().startEntity(reference.getName());
- }
- if (getLexicalHandler() != null) {
- getLexicalHandler().endEntity(reference.getName());
- }
-
- }
-
- private Attributes getAttributes(StartElement event) {
- AttributesImpl attributes = new AttributesImpl();
-
- for (Iterator> i = event.getAttributes(); i.hasNext();) {
- Attribute attribute = (Attribute) i.next();
- QName qName = attribute.getName();
- String namespace = qName.getNamespaceURI();
- if (namespace == null || !hasNamespacesFeature()) {
- namespace = "";
- }
- String type = attribute.getDTDType();
- if (type == null) {
- type = "CDATA";
- }
- attributes.addAttribute(namespace, qName.getLocalPart(), QNameUtils.toQualifiedName(qName), type,
- attribute.getValue());
- }
- if (hasNamespacePrefixesFeature()) {
- for (Iterator> i = event.getNamespaces(); i.hasNext();) {
- Namespace namespace = (Namespace) i.next();
- String prefix = namespace.getPrefix();
- String namespaceUri = namespace.getNamespaceURI();
- String qName;
- if (StringUtils.hasLength(prefix)) {
- qName = "xmlns:" + prefix;
- }
- else {
- qName = "xmlns";
- }
- attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
- }
- }
-
- return attributes;
- }
-
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/StaxStreamContentHandler.java b/xml/src/main/java/org/springframework/xml/stream/StaxStreamContentHandler.java
deleted file mode 100644
index dc2f4c99..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/StaxStreamContentHandler.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import java.util.Iterator;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.springframework.util.StringUtils;
-import org.springframework.xml.namespace.QNameUtils;
-import org.springframework.xml.namespace.SimpleNamespaceContext;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-
-/**
- * SAX ContentHandler that writes to a XMLStreamWriter.
- *
- * @author Arjen Poutsma
- * @see XMLStreamWriter
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createContentHandler(javax.xml.stream.XMLStreamWriter)}
- */
-@Deprecated
-public class StaxStreamContentHandler extends AbstractStaxContentHandler {
-
- private final XMLStreamWriter streamWriter;
-
- /**
- * Constructs a new instance of the StaxStreamContentHandler that writes to the given
- * XMLStreamWriter.
- *
- * @param streamWriter the stream writer to write to
- */
- public StaxStreamContentHandler(XMLStreamWriter streamWriter) {
- this.streamWriter = streamWriter;
- }
-
- public void setDocumentLocator(Locator locator) {
- }
-
- @Override
- protected void charactersInternal(char[] ch, int start, int length) throws XMLStreamException {
- streamWriter.writeCharacters(ch, start, length);
- }
-
- @Override
- protected void endDocumentInternal() throws XMLStreamException {
- streamWriter.writeEndDocument();
- }
-
- @Override
- protected void endElementInternal(QName name, SimpleNamespaceContext namespaceContext) throws XMLStreamException {
- streamWriter.writeEndElement();
- }
-
- @Override
- protected void ignorableWhitespaceInternal(char[] ch, int start, int length) throws XMLStreamException {
- streamWriter.writeCharacters(ch, start, length);
- }
-
- @Override
- protected void processingInstructionInternal(String target, String data) throws XMLStreamException {
- streamWriter.writeProcessingInstruction(target, data);
- }
-
- @Override
- protected void skippedEntityInternal(String name) {
- }
-
- @Override
- protected void startDocumentInternal() throws XMLStreamException {
- streamWriter.writeStartDocument();
- }
-
- @Override
- protected void startElementInternal(QName name, Attributes attributes, SimpleNamespaceContext namespaceContext)
- throws XMLStreamException {
- streamWriter.writeStartElement(QNameUtils.getPrefix(name), name.getLocalPart(), name.getNamespaceURI());
- String defaultNamespaceUri = namespaceContext.getNamespaceURI("");
- if (StringUtils.hasLength(defaultNamespaceUri)) {
- streamWriter.writeNamespace("", defaultNamespaceUri);
- streamWriter.setDefaultNamespace(defaultNamespaceUri);
- }
- for (IteratorXMLReader that reads from a StAX XMLStreamReader. Reads from an
- * XMLStreamReader, and calls the corresponding methods on the SAX callback interfaces.
- *
- * @author Arjen Poutsma
- * @see XMLStreamReader
- * @see #setContentHandler(org.xml.sax.ContentHandler)
- * @see #setDTDHandler(org.xml.sax.DTDHandler)
- * @see #setEntityResolver(org.xml.sax.EntityResolver)
- * @see #setErrorHandler(org.xml.sax.ErrorHandler)
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createXMLReader(javax.xml.stream.XMLStreamReader)}
- */
-@Deprecated
-public class StaxStreamXmlReader extends AbstractStaxXmlReader {
-
- private final XMLStreamReader reader;
-
- private final SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
-
- /**
- * Constructs a new instance of the StaxStreamXmlReader that reads from the given
- * XMLStreamReader. The supplied stream reader must be in XMLStreamConstants.START_DOCUMENT
- * or XMLStreamConstants.START_ELEMENT state.
- *
- * @param reader the XMLEventReader to read from
- * @throws IllegalStateException if the reader is not at the start of a document or element
- */
- public StaxStreamXmlReader(XMLStreamReader reader) {
- int event = reader.getEventType();
- if (!(event == XMLStreamConstants.START_DOCUMENT || event == XMLStreamConstants.START_ELEMENT)) {
- throw new IllegalStateException("XMLEventReader not at start of document or element");
- }
- this.reader = reader;
- }
-
- @Override
- protected void parseInternal() throws SAXException, XMLStreamException {
- boolean documentStarted = false;
- boolean documentEnded = false;
- int elementDepth = 0;
- int eventType = reader.getEventType();
- while (true) {
- if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.END_DOCUMENT &&
- !documentStarted) {
- handleStartDocument();
- documentStarted = true;
- }
- switch (eventType) {
- case XMLStreamConstants.START_ELEMENT:
- elementDepth++;
- handleStartElement();
- break;
- case XMLStreamConstants.END_ELEMENT:
- elementDepth--;
- if (elementDepth >= 0) {
- handleEndElement();
- }
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- handleProcessingInstruction();
- break;
- case XMLStreamConstants.CHARACTERS:
- case XMLStreamConstants.SPACE:
- case XMLStreamConstants.CDATA:
- handleCharacters();
- break;
- case XMLStreamConstants.START_DOCUMENT:
- setLocator(reader.getLocation());
- handleStartDocument();
- documentStarted = true;
- break;
- case XMLStreamConstants.END_DOCUMENT:
- handleEndDocument();
- documentEnded = true;
- break;
- case XMLStreamConstants.COMMENT:
- handleComment();
- break;
- case XMLStreamConstants.DTD:
- handleDtd();
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- handleEntityReference();
- break;
- }
- if (reader.hasNext() && elementDepth >= 0) {
- eventType = reader.next();
- }
- else {
- break;
- }
- }
- if (!documentEnded) {
- handleEndDocument();
- }
- }
-
- private void handleStartDocument() throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().startDocument();
- if (reader.standaloneSet()) {
- setStandalone(reader.isStandalone());
- }
- }
- }
-
- private void handleStartElement() throws SAXException {
- if (getContentHandler() != null) {
- QName qName = reader.getName();
- if (hasNamespacesFeature()) {
- for (int i = 0; i < reader.getNamespaceCount(); i++) {
- String prefix = reader.getNamespacePrefix(i);
- if (prefix == null) {
- prefix = "";
- }
- startPrefixMapping(prefix, reader.getNamespaceURI(i));
- }
- for (int i = 0; i < reader.getAttributeCount(); i++) {
- String prefix = reader.getAttributePrefix(i);
- if (prefix == null) {
- prefix = "";
- }
- String namespace = reader.getAttributeNamespace(i);
- if (namespace == null) {
- continue;
- }
- startPrefixMapping(prefix, namespace);
- }
- getContentHandler()
- .startElement(qName.getNamespaceURI(), qName.getLocalPart(), QNameUtils.toQualifiedName(qName),
- getAttributes());
- }
- else {
- getContentHandler().startElement("", "", QNameUtils.toQualifiedName(qName), getAttributes());
- }
- }
- }
-
- private void startPrefixMapping(String prefix, String namespace) throws SAXException {
- if (!namespaceContext.getNamespaceURI(prefix).equals(namespace)) {
- getContentHandler().startPrefixMapping(prefix, namespace);
- namespaceContext.bindNamespaceUri(prefix, namespace);
- }
- }
-
- private void handleEndElement() throws SAXException {
- if (getContentHandler() != null) {
- QName qName = reader.getName();
- if (hasNamespacesFeature()) {
- getContentHandler()
- .endElement(qName.getNamespaceURI(), qName.getLocalPart(), QNameUtils.toQualifiedName(qName));
- for (int i = 0; i < reader.getNamespaceCount(); i++) {
- String prefix = reader.getNamespacePrefix(i);
- if (prefix == null) {
- prefix = "";
- }
- endPrefixMapping(prefix);
- }
- }
- else {
- getContentHandler().endElement("", "", QNameUtils.toQualifiedName(qName));
- }
- }
- }
-
- private void endPrefixMapping(String prefix) throws SAXException {
- if (namespaceContext.hasBinding(prefix)) {
- getContentHandler().endPrefixMapping(prefix);
- namespaceContext.removeBinding(prefix);
- }
- }
-
- private void handleCharacters() throws SAXException {
- if (getContentHandler() != null && reader.isWhiteSpace()) {
- getContentHandler()
- .ignorableWhitespace(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
- return;
- }
- if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) {
- getLexicalHandler().startCDATA();
- }
- if (getContentHandler() != null) {
- getContentHandler().characters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
- }
- if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) {
- getLexicalHandler().endCDATA();
- }
- }
-
- private void handleComment() throws SAXException {
- if (getLexicalHandler() != null) {
- getLexicalHandler().comment(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
- }
- }
-
- private void handleDtd() throws SAXException {
- if (getLexicalHandler() != null) {
- javax.xml.stream.Location location = reader.getLocation();
- getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
- }
- if (getLexicalHandler() != null) {
- getLexicalHandler().endDTD();
- }
- }
-
- private void handleEntityReference() throws SAXException {
- if (getLexicalHandler() != null) {
- getLexicalHandler().startEntity(reader.getLocalName());
- }
- if (getLexicalHandler() != null) {
- getLexicalHandler().endEntity(reader.getLocalName());
- }
- }
-
- private void handleEndDocument() throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().endDocument();
- }
- }
-
- private void handleProcessingInstruction() throws SAXException {
- if (getContentHandler() != null) {
- getContentHandler().processingInstruction(reader.getPITarget(), reader.getPIData());
- }
- }
-
- private Attributes getAttributes() {
- AttributesImpl attributes = new AttributesImpl();
-
- for (int i = 0; i < reader.getAttributeCount(); i++) {
- String namespace = reader.getAttributeNamespace(i);
- if (namespace == null || !hasNamespacesFeature()) {
- namespace = "";
- }
- String type = reader.getAttributeType(i);
- if (type == null) {
- type = "CDATA";
- }
- attributes.addAttribute(namespace, reader.getAttributeLocalName(i),
- QNameUtils.toQualifiedName(reader.getAttributeName(i)), type, reader.getAttributeValue(i));
- }
- if (hasNamespacePrefixesFeature()) {
- for (int i = 0; i < reader.getNamespaceCount(); i++) {
- String prefix = reader.getNamespacePrefix(i);
- String namespaceUri = reader.getNamespaceURI(i);
- String qName;
- if (StringUtils.hasLength(prefix)) {
- qName = "xmlns:" + prefix;
- }
- else {
- qName = "xmlns";
- }
- attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
- }
- }
-
- return attributes;
- }
-
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/XmlEventStreamReader.java b/xml/src/main/java/org/springframework/xml/stream/XmlEventStreamReader.java
deleted file mode 100644
index 06571e6e..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/XmlEventStreamReader.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import java.util.Iterator;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.Namespace;
-import javax.xml.stream.events.ProcessingInstruction;
-import javax.xml.stream.events.StartDocument;
-import javax.xml.stream.events.XMLEvent;
-
-/**
- * Implementation of the XMLStreamReader interface that wraps a XMLEventReader. Useful,
- * because the StAX XMLInputFactory allows one to create a event reader from a stream reader, but not
- * vice-versa.
- *
- * @author Arjen Poutsma
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createEventStreamReader(XMLEventReader)}
- */
-@Deprecated
-public class XmlEventStreamReader extends AbstractXmlStreamReader {
-
- private XMLEvent event;
-
- private final XMLEventReader eventReader;
-
- public XmlEventStreamReader(XMLEventReader eventReader) throws XMLStreamException {
- this.eventReader = eventReader;
- event = eventReader.nextEvent();
- }
-
- public boolean isStandalone() {
- if (event.isStartDocument()) {
- return ((StartDocument) event).isStandalone();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public String getVersion() {
- if (event.isStartDocument()) {
- return ((StartDocument) event).getVersion();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public int getTextStart() {
- return 0;
- }
-
- public String getText() {
- if (event.isCharacters()) {
- return event.asCharacters().getData();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public String getPITarget() {
- if (event.isProcessingInstruction()) {
- return ((ProcessingInstruction) event).getTarget();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public String getPIData() {
- if (event.isProcessingInstruction()) {
- return ((ProcessingInstruction) event).getData();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public int getNamespaceCount() {
- Iterator> namespaces;
- if (event.isStartElement()) {
- namespaces = event.asStartElement().getNamespaces();
- }
- else if (event.isEndElement()) {
- namespaces = event.asEndElement().getNamespaces();
- }
- else {
- throw new IllegalStateException();
- }
- return countIterator(namespaces);
- }
-
- public NamespaceContext getNamespaceContext() {
- if (event.isStartElement()) {
- return event.asStartElement().getNamespaceContext();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public QName getName() {
- if (event.isStartElement()) {
- return event.asStartElement().getName();
- }
- else if (event.isEndElement()) {
- return event.asEndElement().getName();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- public Location getLocation() {
- return event.getLocation();
- }
-
- public int getEventType() {
- return event.getEventType();
- }
-
- public String getEncoding() {
- return null;
- }
-
- public String getCharacterEncodingScheme() {
- return null;
- }
-
- public int getAttributeCount() {
- if (!event.isStartElement()) {
- throw new IllegalStateException();
- }
- Iterator> attributes = event.asStartElement().getAttributes();
- return countIterator(attributes);
- }
-
- public void close() throws XMLStreamException {
- eventReader.close();
- }
-
- public QName getAttributeName(int index) {
- return getAttribute(index).getName();
- }
-
- public String getAttributeType(int index) {
- return getAttribute(index).getDTDType();
- }
-
- public String getAttributeValue(int index) {
- return getAttribute(index).getValue();
- }
-
- public String getNamespacePrefix(int index) {
- return getNamespace(index).getPrefix();
- }
-
- public String getNamespaceURI(int index) {
- return getNamespace(index).getNamespaceURI();
- }
-
- public Object getProperty(String name) throws IllegalArgumentException {
- return eventReader.getProperty(name);
- }
-
- public boolean isAttributeSpecified(int index) {
- return getAttribute(index).isSpecified();
- }
-
- public int next() throws XMLStreamException {
- event = eventReader.nextEvent();
- return event.getEventType();
- }
-
- public boolean standaloneSet() {
- if (event.isStartDocument()) {
- return ((StartDocument) event).standaloneSet();
- }
- else {
- throw new IllegalStateException();
- }
- }
-
- private int countIterator(Iterator> iterator) {
- int count = 0;
- while (iterator.hasNext()) {
- iterator.next();
- count++;
- }
- return count;
- }
-
- private Attribute getAttribute(int index) {
- if (!event.isStartElement()) {
- throw new IllegalStateException();
- }
- int count = 0;
- Iterator> attributes = event.asStartElement().getAttributes();
- while (attributes.hasNext()) {
- Attribute attribute = (Attribute) attributes.next();
- if (count == index) {
- return attribute;
- }
- else {
- count++;
- }
- }
- throw new IllegalArgumentException();
- }
-
- private Namespace getNamespace(int index) {
- Iterator> namespaces;
- if (event.isStartElement()) {
- namespaces = event.asStartElement().getNamespaces();
- }
- else if (event.isEndElement()) {
- namespaces = event.asEndElement().getNamespaces();
- }
- else {
- throw new IllegalStateException();
- }
- int count = 0;
- while (namespaces.hasNext()) {
- Namespace namespace = (Namespace) namespaces.next();
- if (count == index) {
- return namespace;
- }
- else {
- count++;
- }
- }
- throw new IllegalArgumentException();
- }
-}
diff --git a/xml/src/main/java/org/springframework/xml/stream/package.html b/xml/src/main/java/org/springframework/xml/stream/package.html
deleted file mode 100644
index 14298b80..00000000
--- a/xml/src/main/java/org/springframework/xml/stream/package.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-Provides classes that help with StAX: the Streaming API for XML. Mostly for internal use by the framework.
-
-
diff --git a/xml/src/main/java/org/springframework/xml/transform/StaxResult.java b/xml/src/main/java/org/springframework/xml/transform/StaxResult.java
deleted file mode 100644
index 77f42b25..00000000
--- a/xml/src/main/java/org/springframework/xml/transform/StaxResult.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.transform;
-
-import javax.xml.stream.XMLEventFactory;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.sax.SAXResult;
-
-import org.springframework.xml.stream.StaxEventContentHandler;
-import org.springframework.xml.stream.StaxStreamContentHandler;
-
-import org.xml.sax.ContentHandler;
-
-/**
- * Implementation of the Result tagging interface for StAX writers. Can be constructed with a
- * XMLEventConsumer or a XMLStreamWriter.
- *
- * This class is necessary because there is no implementation of Source for StaxReaders in JAXP 1.3. There
- * is a StAXResult in JAXP 1.4 (JDK 1.6), but this class is kept around for back-ward compatibility
- * reasons.
- *
- * Even though StaxResult extends from SAXResult, calling the methods of
- * SAXResult is not supported. In general, the only supported operation on this class is
- * to use the ContentHandler obtained via {@link #getHandler()} to parse an input source using an
- * XMLReader. Calling {@link #setHandler(org.xml.sax.ContentHandler)} will result in
- * UnsupportedOperationExceptions.
- *
- * @author Arjen Poutsma
- * @see XMLEventWriter
- * @see XMLStreamWriter
- * @see javax.xml.transform.Transformer
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createStaxResult(XMLEventWriter)} and {@link
- * org.springframework.util.xml.StaxUtils#createStaxResult(XMLStreamWriter)}
- */
-@Deprecated
-public class StaxResult extends SAXResult {
-
- private XMLEventWriter eventWriter;
-
- private XMLStreamWriter streamWriter;
-
- /**
- * Constructs a new instance of the StaxResult with the specified XMLStreamWriter.
- *
- * @param streamWriter the XMLStreamWriter to write to
- */
- public StaxResult(XMLStreamWriter streamWriter) {
- super.setHandler(new StaxStreamContentHandler(streamWriter));
- this.streamWriter = streamWriter;
- }
-
- /**
- * Constructs a new instance of the StaxResult with the specified XMLEventWriter.
- *
- * @param eventWriter the XMLEventWriter to write to
- */
- public StaxResult(XMLEventWriter eventWriter) {
- super.setHandler(new StaxEventContentHandler(eventWriter));
- this.eventWriter = eventWriter;
- }
-
- /**
- * Constructs a new instance of the StaxResult with the specified XMLEventWriter and
- * XMLEventFactory.
- *
- * @param eventWriter the XMLEventWriter to write to
- * @param eventFactory the XMLEventFactory to use for creating events
- */
- public StaxResult(XMLEventWriter eventWriter, XMLEventFactory eventFactory) {
- super.setHandler(new StaxEventContentHandler(eventWriter, eventFactory));
- this.eventWriter = eventWriter;
- }
-
- /**
- * Returns the XMLEventWriter used by this StaxResult. If this StaxResult was
- * created with an XMLStreamWriter, the result will be null.
- *
- * @return the StAX event writer used by this result
- * @see #StaxResult(javax.xml.stream.XMLEventWriter)
- */
- public XMLEventWriter getXMLEventWriter() {
- return eventWriter;
- }
-
- /**
- * Returns the XMLStreamWriter used by this StaxResult. If this StaxResult
- * was created with an XMLEventConsumer, the result will be null.
- *
- * @return the StAX stream writer used by this result
- * @see #StaxResult(javax.xml.stream.XMLStreamWriter)
- */
- public XMLStreamWriter getXMLStreamWriter() {
- return streamWriter;
- }
-
- /**
- * Throws a UnsupportedOperationException.
- *
- * @throws UnsupportedOperationException always
- */
- @Override
- public void setHandler(ContentHandler handler) {
- throw new UnsupportedOperationException("setHandler is not supported");
- }
-}
diff --git a/xml/src/main/java/org/springframework/xml/transform/StaxSource.java b/xml/src/main/java/org/springframework/xml/transform/StaxSource.java
deleted file mode 100644
index 043c3fcc..00000000
--- a/xml/src/main/java/org/springframework/xml/transform/StaxSource.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.transform;
-
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.sax.SAXSource;
-
-import org.springframework.xml.stream.StaxEventXmlReader;
-import org.springframework.xml.stream.StaxStreamXmlReader;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-/**
- * Implementation of the Source tagging interface for StAX readers. Can be constructed with a
- * XMLEventReader or a XMLStreamReader.
- *
- * This class is necessary because there is no implementation of Source for StAX Readers in JAXP 1.3. There
- * is a StAXSource in JAXP 1.4 (JDK 1.6), but this class is kept around for back-ward compatibility
- * reasons.
- *
- * Even though StaxSource extends from SAXSource, calling the methods of
- * SAXSource is not supported. In general, the only supported operation on this class is
- * to use the XMLReader obtained via {@link #getXMLReader()} to parse the input source obtained via {@link
- * #getInputSource()}. Calling {@link #setXMLReader(org.xml.sax.XMLReader)} or {@link
- * #setInputSource(org.xml.sax.InputSource)} will result in UnsupportedOperationExceptions.
- *
- * @author Arjen Poutsma
- * @see XMLEventReader
- * @see XMLStreamReader
- * @see javax.xml.transform.Transformer
- * @since 1.0.0
- * @deprecated In favor of {@link org.springframework.util.xml.StaxUtils#createStaxSource(XMLEventReader)} and {@link
- * org.springframework.util.xml.StaxUtils#createStaxSource(XMLStreamReader)}
- */
-@Deprecated
-public class StaxSource extends SAXSource {
-
- private XMLEventReader eventReader;
-
- private XMLStreamReader streamReader;
-
- /**
- * Constructs a new instance of the StaxSource with the specified XMLStreamReader. The
- * supplied stream reader must be in XMLStreamConstants.START_DOCUMENT or
- * XMLStreamConstants.START_ELEMENT state.
- *
- * @param streamReader the XMLStreamReader to read from
- * @throws IllegalStateException if the reader is not at the start of a document or element
- */
- public StaxSource(XMLStreamReader streamReader) {
- super(new StaxStreamXmlReader(streamReader), new InputSource());
- this.streamReader = streamReader;
- }
-
- /**
- * Constructs a new instance of the StaxSource with the specified XMLEventReader. The
- * supplied event reader must be in XMLStreamConstants.START_DOCUMENT or
- * XMLStreamConstants.START_ELEMENT state.
- *
- * @param eventReader the XMLEventReader to read from
- * @throws IllegalStateException if the reader is not at the start of a document or element
- */
- public StaxSource(XMLEventReader eventReader) {
- super(new StaxEventXmlReader(eventReader), new InputSource());
- this.eventReader = eventReader;
- }
-
- /**
- * Returns the XMLEventReader used by this StaxSource. If this StaxSource was
- * created with an XMLStreamReader, the result will be null.
- *
- * @return the StAX event reader used by this source
- * @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader)
- */
- public XMLEventReader getXMLEventReader() {
- return eventReader;
- }
-
- /**
- * Returns the XMLStreamReader used by this StaxSource. If this StaxSource
- * was created with an XMLEventReader, the result will be null.
- *
- * @return the StAX event reader used by this source
- * @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader)
- */
- public XMLStreamReader getXMLStreamReader() {
- return streamReader;
- }
-
- /**
- * Throws a UnsupportedOperationException.
- *
- * @throws UnsupportedOperationException always
- */
- @Override
- public void setInputSource(InputSource inputSource) {
- throw new UnsupportedOperationException("setInputSource is not supported");
- }
-
- /**
- * Throws a UnsupportedOperationException.
- *
- * @throws UnsupportedOperationException always
- */
- @Override
- public void setXMLReader(XMLReader reader) {
- throw new UnsupportedOperationException("setXMLReader is not supported");
- }
-}
diff --git a/xml/src/main/java/org/springframework/xml/transform/TraxUtils.java b/xml/src/main/java/org/springframework/xml/transform/TraxUtils.java
index 4569d5cd..b7f0195f 100644
--- a/xml/src/main/java/org/springframework/xml/transform/TraxUtils.java
+++ b/xml/src/main/java/org/springframework/xml/transform/TraxUtils.java
@@ -22,7 +22,6 @@ import java.io.Reader;
import java.io.Writer;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
@@ -54,131 +53,6 @@ import org.xml.sax.ext.LexicalHandler;
*/
public abstract class TraxUtils {
- /**
- * Indicates whether the given {@link Source} is a StAX Source.
- *
- * @return true if source is a Spring-WS {@link StaxSource} or JAXP 1.4 {@link
- * StAXSource}; false otherwise.
- * @deprecated In favor of {@link StaxUtils#isStaxSource(Source)}
- */
- @Deprecated
- public static boolean isStaxSource(Source source) {
- if (source instanceof StaxSource) {
- return true;
- }
- return StaxUtils.isStaxSource(source);
- }
-
- /**
- * Indicates whether the given {@link Result} is a StAX Result.
- *
- * @return true if result is a Spring-WS {@link StaxResult} or JAXP 1.4 {@link
- * StAXResult}; false otherwise.
- * @deprecated In favor of {@link StaxUtils#isStaxResult(Result)}
- */
- @Deprecated
- public static boolean isStaxResult(Result result) {
- if (result instanceof StaxResult) {
- return true;
- }
- return StaxUtils.isStaxResult(result);
- }
-
- /**
- * Returns the {@link XMLStreamReader} for the given StAX Source.
- *
- * @param source a Spring-WS {@link StaxSource} or {@link StAXSource}
- * @return the {@link XMLStreamReader}
- * @throws IllegalArgumentException if source is neither a Spring-WS {@link StaxSource} or {@link
- * StAXSource}
- * @deprecated In favor of {@link StaxUtils#getXMLStreamReader(Source)}
- */
- @Deprecated
- public static XMLStreamReader getXMLStreamReader(Source source) {
- if (source instanceof StaxSource) {
- return ((StaxSource) source).getXMLStreamReader();
- }
- return StaxUtils.getXMLStreamReader(source);
- }
-
- /**
- * Returns the {@link XMLEventReader} for the given StAX Source.
- *
- * @param source a Spring-WS {@link StaxSource} or {@link StAXSource}
- * @return the {@link XMLEventReader}
- * @throws IllegalArgumentException if source is neither a Spring-WS {@link StaxSource} or {@link
- * StAXSource}
- * @deprecated In favor of {@link StaxUtils#getXMLEventReader(Source)}
- */
- @Deprecated
- public static XMLEventReader getXMLEventReader(Source source) {
- if (source instanceof StaxSource) {
- return ((StaxSource) source).getXMLEventReader();
- }
- return StaxUtils.getXMLEventReader(source);
- }
-
- /**
- * Returns the {@link XMLStreamWriter} for the given StAX Result.
- *
- * @param result a Spring-WS {@link StaxResult} or {@link StAXResult}
- * @return the {@link XMLStreamReader}
- * @throws IllegalArgumentException if source is neither a Spring-WS {@link StaxResult} or {@link
- * StAXResult}
- * @deprecated In favor of {@link StaxUtils#getXMLStreamWriter(Result)}
- */
- @Deprecated
- public static XMLStreamWriter getXMLStreamWriter(Result result) {
- if (result instanceof StaxResult) {
- return ((StaxResult) result).getXMLStreamWriter();
- }
- return StaxUtils.getXMLStreamWriter(result);
- }
-
- /**
- * Returns the {@link XMLEventWriter} for the given StAX Result.
- *
- * @param result a Spring-WS {@link StaxResult} or {@link StAXResult}
- * @return the {@link XMLStreamReader}
- * @throws IllegalArgumentException if source is neither a Spring-WS {@link StaxResult} or {@link
- * StAXResult}
- * @deprecated In favor of {@link StaxUtils#getXMLEventWriter(Result)}
- */
- @Deprecated
- public static XMLEventWriter getXMLEventWriter(Result result) {
- if (result instanceof StaxResult) {
- return ((StaxResult) result).getXMLEventWriter();
- }
- return StaxUtils.getXMLEventWriter(result);
- }
-
- /**
- * Creates a StAX {@link Source} for the given {@link XMLStreamReader}. Returns a {@link StAXSource} under JAXP 1.4
- * or higher, or a {@link StaxSource} otherwise.
- *
- * @param streamReader the StAX stream reader
- * @return a source wrapping streamReader
- * @deprecated In favor of {@link StaxUtils#createStaxSource(XMLStreamReader)}
- */
- @Deprecated
- public static Source createStaxSource(XMLStreamReader streamReader) {
- return StaxUtils.createStaxSource(streamReader);
- }
-
- /**
- * Creates a StAX {@link Source} for the given {@link XMLEventReader}. Returns a {@link StAXSource} under JAXP 1.4
- * or higher, or a {@link StaxSource} otherwise.
- *
- * @param eventReader the StAX event reader
- * @return a source wrapping eventReader
- * @throws XMLStreamException in case of StAX errors
- * @deprecated In favor of {@link StaxUtils#createStaxSource(XMLEventReader)}
- */
- @Deprecated
- public static Source createStaxSource(XMLEventReader eventReader) throws XMLStreamException {
- return StaxUtils.createStaxSource(eventReader);
- }
-
/**
* Returns the {@link Document} of the given {@link DOMSource}.
*
@@ -210,14 +84,14 @@ public abstract class TraxUtils {
callback.domSource(((DOMSource) source).getNode());
return;
}
- else if (isStaxSource(source)) {
- XMLStreamReader streamReader = getXMLStreamReader(source);
+ else if (StaxUtils.isStaxSource(source)) {
+ XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
if (streamReader != null) {
callback.staxSource(streamReader);
return;
}
else {
- XMLEventReader eventReader = getXMLEventReader(source);
+ XMLEventReader eventReader = StaxUtils.getXMLEventReader(source);
if (eventReader != null) {
callback.staxSource(eventReader);
return;
@@ -261,14 +135,14 @@ public abstract class TraxUtils {
callback.domResult(((DOMResult) result).getNode());
return;
}
- else if (isStaxResult(result)) {
- XMLStreamWriter streamWriter = getXMLStreamWriter(result);
+ else if (StaxUtils.isStaxResult(result)) {
+ XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(result);
if (streamWriter != null) {
callback.staxResult(streamWriter);
return;
}
else {
- XMLEventWriter eventWriter = getXMLEventWriter(result);
+ XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(result);
if (eventWriter != null) {
callback.staxResult(eventWriter);
return;
@@ -324,7 +198,7 @@ public abstract class TraxUtils {
/**
* Perform an operation on the {@code XMLEventReader} contained in a JAXP 1.4 {@link StAXSource} or Spring
- * {@link StaxSource}.
+ * {@link StaxUtils#createStaxSource StaxSource}.
*
* @param eventReader the reader
*/
@@ -332,7 +206,7 @@ public abstract class TraxUtils {
/**
* Perform an operation on the {@code XMLStreamReader} contained in a JAXP 1.4 {@link StAXSource} or Spring
- * {@link StaxSource}.
+ * {@link StaxUtils#createStaxSource StaxSource}.
*
* @param streamReader the reader
*/
@@ -387,7 +261,7 @@ public abstract class TraxUtils {
/**
* Perform an operation on the {@code XMLEventWriter} contained in a JAXP 1.4 {@link StAXResult} or Spring
- * {@link StaxResult}.
+ * {@link StaxUtils#createStaxResult StaxResult}.
*
* @param eventWriter the writer
*/
@@ -395,7 +269,7 @@ public abstract class TraxUtils {
/**
* Perform an operation on the {@code XMLStreamWriter} contained in a JAXP 1.4 {@link StAXResult} or Spring
- * {@link StaxResult}.
+ * {@link StaxUtils#createStaxResult StaxResult}.
*
* @param streamWriter the writer
*/
diff --git a/xml/src/main/java/org/springframework/xml/validation/Jaxp10ValidatorFactory.java b/xml/src/main/java/org/springframework/xml/validation/Jaxp10ValidatorFactory.java
deleted file mode 100644
index 699de203..00000000
--- a/xml/src/main/java/org/springframework/xml/validation/Jaxp10ValidatorFactory.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2005-2011 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.validation;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.springframework.core.io.Resource;
-import org.springframework.xml.sax.SaxUtils;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Internal class that uses JAXP 1.0 features to create XmlValidator instances.
- *
- * @author Arjen Poutsma
- * @since 1.0.0
- * @deprecated in favor of {@link Jaxp13ValidatorFactory}
- */
-@Deprecated
-abstract class Jaxp10ValidatorFactory {
-
- private static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
-
- private static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
-
- static XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
- InputSource[] inputSources = new InputSource[schemaResources.length];
- for (int i = 0; i < schemaResources.length; i++) {
- inputSources[i] = SaxUtils.createInputSource(schemaResources[i]);
- }
- return new Jaxp10Validator(inputSources, schemaLanguage);
- }
-
- private static class Jaxp10Validator implements XmlValidator {
-
- private SAXParserFactory parserFactory;
-
- private TransformerFactory transformerFactory;
-
- private InputSource[] schemaInputSources;
-
- private String schemaLanguage;
-
- private Jaxp10Validator(InputSource[] schemaInputSources, String schemaLanguage) {
- this.schemaInputSources = schemaInputSources;
- this.schemaLanguage = schemaLanguage;
- transformerFactory = TransformerFactory.newInstance();
- parserFactory = SAXParserFactory.newInstance();
- parserFactory.setNamespaceAware(true);
- parserFactory.setValidating(true);
- }
-
- public SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler)
- throws IOException {
- return validate(source);
- }
-
- public SAXParseException[] validate(Source source) throws IOException {
- SAXParser parser = createSAXParser();
- DefaultValidationErrorHandler errorHandler = new DefaultValidationErrorHandler();
- try {
- if (source instanceof SAXSource) {
- validateSAXSource((SAXSource) source, parser, errorHandler);
- }
- else if (source instanceof StreamSource) {
- validateStreamSource((StreamSource) source, parser, errorHandler);
- }
- else if (source instanceof DOMSource) {
- validateDOMSource((DOMSource) source, parser, errorHandler);
- }
- else {
- throw new IllegalArgumentException("Source [" + source.getClass().getName() +
- "] is neither SAXSource, DOMSource, nor StreamSource");
- }
- return errorHandler.getErrors();
- }
- catch (SAXException ex) {
- throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex);
- }
- }
-
- private void validateDOMSource(DOMSource domSource, SAXParser parser, DefaultValidationErrorHandler errorHandler)
- throws IOException, SAXException {
- try {
- // Sadly, JAXP 1.0 DOM doesn't implement DOM level 3, so we cannot use Document.normalizeDocument()
- // Instead, we write the Document to a Stream, and validate that
- Transformer transformer = transformerFactory.newTransformer();
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- transformer.transform(domSource, new StreamResult(outputStream));
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
- validateStreamSource(new StreamSource(inputStream), parser, errorHandler);
- }
- catch (TransformerException ex) {
- throw new XmlValidationException("Could not validate DOM source: " + ex.getMessage(), ex);
- }
-
- }
-
- private void validateStreamSource(StreamSource streamSource,
- SAXParser parser,
- DefaultValidationErrorHandler errorHandler) throws SAXException, IOException {
- if (streamSource.getInputStream() != null) {
- parser.parse(streamSource.getInputStream(), errorHandler);
- }
- else if (streamSource.getReader() != null) {
- parser.parse(new InputSource(streamSource.getReader()), errorHandler);
- }
- else {
- throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader");
- }
- }
-
- private void validateSAXSource(SAXSource source, SAXParser parser, DefaultValidationErrorHandler errorHandler)
- throws SAXException, IOException {
- parser.parse(source.getInputSource(), errorHandler);
- }
-
- private SAXParser createSAXParser() {
- try {
- SAXParser parser = parserFactory.newSAXParser();
- parser.setProperty(SCHEMA_LANGUAGE, schemaLanguage);
- parser.setProperty(SCHEMA_SOURCE, schemaInputSources);
- return parser;
- }
- catch (ParserConfigurationException ex) {
- throw new XmlValidationException("Could not create SAXParser: " + ex.getMessage(), ex);
- }
- catch (SAXException ex) {
- throw new XmlValidationException("Could not create SAXParser: " + ex.getMessage(), ex);
- }
- }
- }
-
- /** DefaultHandler extension that stores errors and fatal errors in a list. */
- private static class DefaultValidationErrorHandler extends DefaultHandler {
-
- private ListArgumentMatcher implementation that matches SAX arguments. */
- protected static class SaxArgumentMatcher extends AbstractMatcher {
-
- @Override
- public boolean matches(Object[] expected, Object[] actual) {
- if (expected == actual) {
- return true;
- }
- if (expected == null || actual == null) {
- return false;
- }
- if (expected.length != actual.length) {
- throw new IllegalArgumentException("Expected and actual arguments must have the same size");
- }
- if (expected.length == 3 && expected[0] instanceof char[] && expected[1] instanceof Integer &&
- expected[2] instanceof Integer) {
- // handling of the character(char[], int, int) methods
- String expectedString = new String((char[]) expected[0], (Integer) expected[1],
- (Integer) expected[2]);
- String actualString = new String((char[]) actual[0], (Integer) actual[1],
- (Integer) actual[2]);
- return expectedString.equals(actualString);
- }
- else if (expected.length == 1 && (expected[0] instanceof Locator)) {
- return true;
- }
- else {
- return super.matches(expected, actual);
- }
- }
-
- @Override
- protected boolean argumentMatches(Object expected, Object actual) {
- if (expected instanceof char[]) {
- return Arrays.equals((char[]) expected, (char[]) actual);
- }
- else if (expected instanceof Attributes) {
- Attributes expectedAttributes = (Attributes) expected;
- Attributes actualAttributes = (Attributes) actual;
- if (expectedAttributes.getLength() != actualAttributes.getLength()) {
- return false;
- }
- for (int i = 0; i < expectedAttributes.getLength(); i++) {
- boolean found = false;
- for (int j = 0; j < actualAttributes.getLength(); j++) {
- if (expectedAttributes.getURI(i).equals(actualAttributes.getURI(j)) &&
- expectedAttributes.getQName(i).equals(actualAttributes.getQName(j)) &&
- expectedAttributes.getType(i).equals(actualAttributes.getType(j)) &&
- expectedAttributes.getValue(i).equals(actualAttributes.getValue(j))) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
- return true;
- }
- else {
- return super.argumentMatches(expected, actual);
- }
- }
-
- @Override
- public String toString(Object[] arguments) {
- if (arguments != null && arguments.length == 3 && arguments[0] instanceof char[] &&
- arguments[1] instanceof Integer && arguments[2] instanceof Integer) {
- return new String((char[]) arguments[0], (Integer) arguments[1],
- (Integer) arguments[2]);
- }
- else {
- return super.toString(arguments);
- }
- }
-
- @Override
- protected String argumentToString(Object argument) {
- if (argument instanceof char[]) {
- char[] array = (char[]) argument;
- StringBuilder builder = new StringBuilder();
- for (char anArray : array) {
- builder.append(anArray);
- }
- return builder.toString();
- }
- else if (argument instanceof Attributes) {
- Attributes attributes = (Attributes) argument;
- StringBuilder builder = new StringBuilder("[");
- for (int i = 0; i < attributes.getLength(); i++) {
- if (attributes.getURI(i).length() != 0) {
- builder.append('{');
- builder.append(attributes.getURI(i));
- builder.append('}');
- }
-// if (attributes.getLocalName(i).length() != 0) {
-// buffer.append('[');
-// buffer.append(attributes.getLocalName(i));
-// buffer.append(']');
-// }
- if (attributes.getQName(i).length() != 0) {
- builder.append(attributes.getQName(i));
- }
- builder.append('=');
- builder.append(attributes.getValue(i));
- if (i < attributes.getLength() - 1) {
- builder.append(", ");
- }
- }
- builder.append(']');
- return builder.toString();
- }
- else if (argument instanceof Locator) {
- Locator locator = (Locator) argument;
- StringBuilder builder = new StringBuilder("[");
- builder.append(locator.getLineNumber());
- builder.append(',');
- builder.append(locator.getColumnNumber());
- builder.append(']');
- return builder.toString();
- }
- else {
- return super.argumentToString(argument);
- }
- }
- }
-
- private static class CopyingContentHandler implements ContentHandler {
-
- private final ContentHandler wrappee;
-
- private CopyingContentHandler(ContentHandler wrappee) {
- this.wrappee = wrappee;
- }
-
- public void setDocumentLocator(Locator locator) {
- wrappee.setDocumentLocator(locator);
- }
-
- public void startDocument() throws SAXException {
- wrappee.startDocument();
- }
-
- public void endDocument() throws SAXException {
- wrappee.endDocument();
- }
-
- public void startPrefixMapping(String prefix, String uri) throws SAXException {
- wrappee.startPrefixMapping(prefix, uri);
- }
-
- public void endPrefixMapping(String prefix) throws SAXException {
- wrappee.endPrefixMapping(prefix);
- }
-
- public void startElement(String uri, String localName, String qName, Attributes attributes)
- throws SAXException {
- wrappee.startElement(uri, localName, qName, new AttributesImpl(attributes));
- }
-
- public void endElement(String uri, String localName, String qName) throws SAXException {
- wrappee.endElement(uri, localName, qName);
- }
-
- public void characters(char ch[], int start, int length) throws SAXException {
- wrappee.characters(copy(ch), start, length);
- }
-
- public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
- }
-
- public void processingInstruction(String target, String data) throws SAXException {
- wrappee.processingInstruction(target, data);
- }
-
- public void skippedEntity(String name) throws SAXException {
- wrappee.skippedEntity(name);
- }
- }
-
- private static class CopyingLexicalHandler implements LexicalHandler {
-
- private final LexicalHandler wrappee;
-
- private CopyingLexicalHandler(LexicalHandler wrappee) {
- this.wrappee = wrappee;
- }
-
- public void startDTD(String name, String publicId, String systemId) throws SAXException {
- wrappee.startDTD("element", publicId, systemId);
- }
-
- public void endDTD() throws SAXException {
- wrappee.endDTD();
- }
-
- public void startEntity(String name) throws SAXException {
- wrappee.startEntity(name);
- }
-
- public void endEntity(String name) throws SAXException {
- wrappee.endEntity(name);
- }
-
- public void startCDATA() throws SAXException {
- wrappee.startCDATA();
- }
-
- public void endCDATA() throws SAXException {
- wrappee.endCDATA();
- }
-
- public void comment(char ch[], int start, int length) throws SAXException {
- wrappee.comment(copy(ch), start, length);
- }
- }
-
- private static char[] copy(char[] ch) {
- char[] copy = new char[ch.length];
- System.arraycopy(ch, 0, copy, 0, ch.length);
- return copy;
- }
-
-}
diff --git a/xml/src/test/java/org/springframework/xml/stream/StaxEventContentHandlerTest.java b/xml/src/test/java/org/springframework/xml/stream/StaxEventContentHandlerTest.java
deleted file mode 100644
index 1f20429e..00000000
--- a/xml/src/test/java/org/springframework/xml/stream/StaxEventContentHandlerTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import java.io.Writer;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-
-@SuppressWarnings("Since15")
-public class StaxEventContentHandlerTest extends AbstractStaxContentHandlerTestCase {
-
- @Override
- protected AbstractStaxContentHandler createStaxContentHandler(Writer writer) throws XMLStreamException {
- XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- return new StaxEventContentHandler(outputFactory.createXMLEventWriter(writer));
- }
-}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java b/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java
deleted file mode 100644
index 39f4df98..00000000
--- a/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2005-2010 the original author or authors.
- *
- * 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 under the License.
- */
-
-package org.springframework.xml.stream;
-
-import java.io.InputStream;
-import java.io.StringReader;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-
-import org.easymock.MockControl;
-import org.junit.Test;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.AttributesImpl;
-
-@SuppressWarnings("Since15")
-public class StaxEventXmlReaderTest extends AbstractStaxXmlReaderTestCase {
-
- public static final String CONTENT = "