All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.util.xml.StaxSource Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
/*
 * Copyright 2002-2009 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.util.xml;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.sax.SAXSource;

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(XMLReader)} or {@link #setInputSource(InputSource)} will result in * UnsupportedOperationExceptions. * * @author Arjen Poutsma * @see XMLEventReader * @see XMLStreamReader * @see javax.xml.transform.Transformer * @since 3.0 */ 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 */ 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 */ 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) */ 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) */ 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"); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy