You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2022/11/01 23:14:52 UTC
[ws-axiom] branch master updated: [AXIOM-506] Remove legacy classes depending on DataHandlerProvider
This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new b0a5f7d41 [AXIOM-506] Remove legacy classes depending on DataHandlerProvider
b0a5f7d41 is described below
commit b0a5f7d418ceda783e85b9f65a6b43699d3fe1ee
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Tue Nov 1 23:14:43 2022 +0000
[AXIOM-506] Remove legacy classes depending on DataHandlerProvider
DataHandlerProvider will be removed, so those classes will need to be
deleted from axiom-compat.
---
.../om/impl/serialize/StreamingOMSerializer.java | 656 ------------------
.../axiom/om/impl/util/OMSerializerUtil.java | 741 ---------------------
.../util/jaxb/AttachmentUnmarshallerImpl.java | 55 --
.../java/org/apache/axiom/util/jaxb/JAXBUtils.java | 65 --
.../axiom/util/stax/xop/OptimizationPolicy.java | 101 ---
.../util/stax/xop/XOPDecodingStreamReader.java | 514 --------------
.../util/stax/xop/XOPDecodingStreamWriter.java | 156 -----
.../util/stax/xop/XOPEncodingStreamReader.java | 581 ----------------
.../util/stax/xop/XOPEncodingStreamWrapper.java | 96 ---
.../util/stax/xop/XOPEncodingStreamWriter.java | 263 --------
.../org/apache/axiom/util/stax/xop/XOPUtils.java | 134 ----
.../impl/serialize/StreamingOMSerializerTest.java | 82 ---
.../util/stax/xop/XOPDecodingStreamReaderTest.java | 68 --
.../util/stax/xop/XOPEncodingStreamReaderTest.java | 58 --
.../apache/axiom/util/stax/xop/XOPUtilsTest.java | 35 -
15 files changed, 3605 deletions(-)
diff --git a/axiom-compat/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java b/axiom-compat/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
deleted file mode 100644
index dcb96bc9d..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
+++ /dev/null
@@ -1,656 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.om.impl.serialize;
-
-import org.apache.axiom.ext.stax.DTDReader;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMDataSource;
-import org.apache.axiom.om.OMDocument;
-import org.apache.axiom.om.OMSerializer;
-import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.impl.OMXMLStreamReaderEx;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
-import org.apache.axiom.util.stax.XMLStreamReaderUtils;
-import org.apache.axiom.util.stax.XMLStreamWriterUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-/**
- * @deprecated To copy events from an {@link XMLStreamReader} to an {@link XMLStreamWriter}, use
- * {@link OMXMLBuilderFactory#createStAXOMBuilder(XMLStreamReader)} to create an
- * {@link OMDocument}, then serialize it using
- * {@link OMContainer#serializeAndConsume(XMLStreamWriter)}.
- */
-public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {
-
- private static final Log log = LogFactory.getLog(StreamingOMSerializer.class);
-
- private static int namespaceSuffix = 0;
- public static final String NAMESPACE_PREFIX = "ns";
-
- private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
- private static final String XSI_LOCAL_NAME = "type";
- /*
- * The behavior of the serializer is such that it returns when it encounters the
- * starting element for the second time. The depth variable tracks the depth of the
- * serilizer and tells it when to return.
- * Note that it is assumed that this serialization starts on an Element.
- */
-
- /** Field depth */
- private int depth = 0;
-
- private DataHandlerReader dataHandlerReader;
- private DataHandlerWriter dataHandlerWriter;
-
- /**
- * Method serialize.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- @Override
- public void serialize(XMLStreamReader reader, XMLStreamWriter writer)
- throws XMLStreamException {
- serialize(reader, writer, true);
- }
-
- /**
- * @param reader
- * @param writer
- * @param startAtNext indicate if reading should start at next event or current event
- * @throws XMLStreamException
- */
- public void serialize(XMLStreamReader reader, XMLStreamWriter writer, boolean startAtNext)
- throws XMLStreamException {
-
- dataHandlerReader = XMLStreamReaderUtils.getDataHandlerReader(reader);
- dataHandlerWriter = XMLStreamWriterUtils.getDataHandlerWriter(writer);
-
- if (reader instanceof OMXMLStreamReaderEx) {
- int event = reader.getEventType();
- if (event <= 0 ||
- event == XMLStreamReader.PROCESSING_INSTRUCTION ||
- event == XMLStreamReader.START_DOCUMENT) {
- // Since we are serializing an entire document,
- // enable the the optimized DataSource events.
- // This will allow OMDataSource elements to be serialized
- // directly without expansion.
- if (log.isDebugEnabled()) {
- log.debug("Enable OMDataSource events while serializing this document");
- }
- ((OMXMLStreamReaderEx) reader).enableDataSourceEvents(true);
- }
- }
- try {
- serializeNode(reader, writer, startAtNext);
- } finally {
- if (reader instanceof OMXMLStreamReaderEx) {
- ((OMXMLStreamReaderEx) reader).enableDataSourceEvents(false);
- }
- }
-
- }
-
- /**
- * Method serializeNode.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer)
- throws XMLStreamException {
- serializeNode(reader, writer, true);
- }
- protected void serializeNode(XMLStreamReader reader,
- XMLStreamWriter writer,
- boolean startAtNext)
- throws XMLStreamException {
- // TODO We get the StAXWriter at this point and uses it hereafter
- // assuming that this is the only entry point to this class.
- // If there can be other classes calling methodes of this we might
- // need to change methode signatures to OMOutputer
-
- // If not startAtNext, then seed the processing with the current element.
- boolean useCurrentEvent = !startAtNext;
-
- while (reader.hasNext() || useCurrentEvent) {
- int event = 0;
- OMDataSource ds = null;
- if (useCurrentEvent) {
- event = reader.getEventType();
- useCurrentEvent = false;
- } else {
- event = reader.next();
- }
-
- // If the reader is exposing a DataSourc
- // for this event, then simply serialize the
- // DataSource
- if (reader instanceof OMXMLStreamReaderEx) {
- ds = ((OMXMLStreamReaderEx) reader).getDataSource();
- }
- if (ds != null) {
- ds.serialize(writer);
- } else {
- switch (event) {
- case START_ELEMENT:
- serializeElement(reader, writer);
- depth++;
- break;
- case ATTRIBUTE:
- serializeAttributes(reader, writer);
- break;
- case CHARACTERS:
- if (dataHandlerReader != null && dataHandlerReader.isBinary()) {
- serializeDataHandler();
- break;
- }
- // Fall through
- case SPACE:
- serializeText(reader, writer);
- break;
- case COMMENT:
- serializeComment(reader, writer);
- break;
- case CDATA:
- serializeCData(reader, writer);
- break;
- case PROCESSING_INSTRUCTION:
- serializeProcessingInstruction(reader, writer);
- break;
- case END_ELEMENT:
- serializeEndElement(writer);
- depth--;
- break;
- case START_DOCUMENT:
- depth++; //if a start document is found then increment the depth
- break;
- case END_DOCUMENT:
- if (depth != 0) depth--; //for the end document - reduce the depth
- try {
- serializeEndElement(writer);
- } catch (Exception e) {
- //TODO: log exceptions
- }
- break;
- case DTD:
- serializeDTD(reader, writer);
- break;
- case ENTITY_REFERENCE:
- writer.writeEntityRef(reader.getLocalName());
- }
- }
- if (depth == 0) {
- break;
- }
- }
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeElement(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
-
-
- // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
- // Please keep this code in sync with the code in OMSerializerUtil.serializeStartpart
-
- // The algorithm is:
- // ... generate writeStartElement
- //
- // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
- // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
- // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
- //
- // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
- // ... generate writeAttribute for each attribute
-
- ArrayList<String> writePrefixList = null;
- ArrayList<String> writeNSList = null;
-
- // Get the prefix and namespace of the element. "" and null are identical.
- String ePrefix = reader.getPrefix();
- ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
- String eNamespace = reader.getNamespaceURI();
- eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
-
- // Write the startElement if required
- if (eNamespace != null) {
- if (ePrefix == null) {
- if (!OMSerializerUtil.isAssociated("", eNamespace, writer)) {
-
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- writePrefixList.add("");
- writeNSList.add(eNamespace);
- }
-
- writer.writeStartElement("", reader.getLocalName(), eNamespace);
- } else {
-
- if (!OMSerializerUtil.isAssociated(ePrefix, eNamespace, writer)) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- writePrefixList.add(ePrefix);
- writeNSList.add(eNamespace);
- }
-
- writer.writeStartElement(ePrefix, reader.getLocalName(), eNamespace);
- }
- } else {
- writer.writeStartElement(reader.getLocalName());
- }
-
- // Generate setPrefix for the namespace declarations
- int count = reader.getNamespaceCount();
- for (int i = 0; i < count; i++) {
- String prefix = reader.getNamespacePrefix(i);
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- String namespace = reader.getNamespaceURI(i);
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
- String newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
- }
-
- // Generate setPrefix for the element
- // If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- String newPrefix = OMSerializerUtil.generateSetPrefix(ePrefix, eNamespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(eNamespace);
- }
- }
-
- // Now Generate setPrefix for each attribute
- count = reader.getAttributeCount();
- for (int i = 0; i < count; i++) {
- String prefix = reader.getAttributePrefix(i);
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- String namespace = reader.getAttributeNamespace(i);
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
- // Default prefix referencing is not allowed on an attribute
- if (prefix == null && namespace != null) {
- String writerPrefix = writer.getPrefix(namespace);
- writerPrefix =
- (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
- prefix = (writerPrefix != null) ?
- writerPrefix :
- generateUniquePrefix(writer.getNamespaceContext());
- }
- newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, writer, true);
- // If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
- }
-
- // Now Generate setPrefix for each prefix referenced in an xsi:type
- // For example xsi:type="p:dataType"
- // The following code will make sure that setPrefix is called for "p".
- count = reader.getAttributeCount();
- for (int i = 0; i < count; i++) {
- String prefix = reader.getAttributePrefix(i);
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- String namespace = reader.getAttributeNamespace(i);
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
- String localName = reader.getAttributeLocalName(i);
-
- if (XSI_URI.equals(namespace) &&
- XSI_LOCAL_NAME.equals(localName)) {
- String value = reader.getAttributeValue(i);
- if (log.isDebugEnabled()) {
- log.debug("The value of xsi:type is " + value);
- }
- if (value != null) {
- value = value.trim();
- if (value.indexOf(":") > 0) {
- String refPrefix = value.substring(0, value.indexOf(":"));
- String refNamespace = reader.getNamespaceURI(refPrefix);
- if (refNamespace != null && refNamespace.length() > 0) {
-
- newPrefix = OMSerializerUtil.generateSetPrefix(refPrefix,
- refNamespace,
- writer,
- true);
- // If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- if (newPrefix != null) {
- if (log.isDebugEnabled()) {
- log.debug("An xmlns:" + newPrefix +"=\"" + refNamespace +"\" will be written");
- }
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(refNamespace);
- }
- }
- }
-
- }
- }
- }
- }
-
- // Now write out the list of namespace declarations in this list that we constructed
- // while doing the "set" processing.
- if (writePrefixList != null) {
- for (int i = 0; i < writePrefixList.size(); i++) {
- String prefix = writePrefixList.get(i);
- String namespace = writeNSList.get(i);
- if (prefix != null) {
- if (namespace == null) {
- writer.writeNamespace(prefix, "");
- } else {
- writer.writeNamespace(prefix, namespace);
- }
- } else {
- writer.writeDefaultNamespace(namespace);
- }
- }
- }
-
- // Now write the attributes
- count = reader.getAttributeCount();
- for (int i = 0; i < count; i++) {
- String prefix = reader.getAttributePrefix(i);
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- String namespace = reader.getAttributeNamespace(i);
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
-
- if (prefix == null && namespace != null) {
- // Default namespaces are not allowed on an attribute reference.
- // Earlier in this code, a unique prefix was added for this case...now obtain and use it
- prefix = writer.getPrefix(namespace);
- //XMLStreamWriter doesn't allow for getPrefix to know whether you're asking for the prefix
- //for an attribute or an element. So if the namespace matches the default namespace getPrefix will return
- //the empty string, as if it were an element, in all cases (even for attributes, and even if
- //there was a prefix specifically set up for this), which is not the desired behavior.
- //Since the interface is base java, we can't fix it where we need to (by adding an attr boolean to
- //XMLStreamWriter.getPrefix), so we hack it in here...
- if (prefix == null || "".equals(prefix)) {
- for (int j = 0; j < writePrefixList.size(); j++) {
- if (namespace.equals(writeNSList.get(j))) {
- prefix = writePrefixList.get(j);
- }
- }
- }
- } else if (namespace != null && !prefix.equals("xml")) {
- // Use the writer's prefix if it is different, but if the writers
- // prefix is empty then do not replace because attributes do not
- // default to the default namespace like elements do.
- String writerPrefix = writer.getPrefix(namespace);
- if (!prefix.equals(writerPrefix) && !"".equals(writerPrefix)) {
- prefix = writerPrefix;
- }
- }
- if (namespace != null) {
- // Qualified attribute
- writer.writeAttribute(prefix, namespace,
- reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- } else {
- // Unqualified attribute
- writer.writeAttribute(reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- }
- }
- }
-
- /**
- * Method serializeEndElement.
- *
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeEndElement(XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeEndElement();
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeText(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeCharacters(reader.getText());
- }
-
- /**
- * Method serializeCData.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeCData(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeCData(reader.getText());
- }
-
- /**
- * Method serializeComment.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeComment(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeComment(reader.getText());
- }
-
- /**
- * Method serializeProcessingInstruction.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeProcessingInstruction(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
- }
-
- /**
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- protected void serializeAttributes(XMLStreamReader reader,
- XMLStreamWriter writer)
- throws XMLStreamException {
- int count = reader.getAttributeCount();
- String prefix = null;
- String namespaceName = null;
- String writerPrefix = null;
- for (int i = 0; i < count; i++) {
- prefix = reader.getAttributePrefix(i);
- namespaceName = reader.getAttributeNamespace(i);
- /*
- Some parser implementations return null for the unqualified namespace.
- But getPrefix(null) will throw an exception (according to the XMLStreamWriter
- javadoc. We guard against this by using "" for the unqualified namespace.
- */
- namespaceName =(namespaceName == null) ? "" : namespaceName;
-
- // Using getNamespaceContext should be avoided when not necessary.
- // Some parser implementations construct a new NamespaceContext each time it is invoked.
- // writerPrefix = writer.getNamespaceContext().getPrefix(namespaceName);
- writerPrefix = writer.getPrefix(namespaceName);
-
- if (!"".equals(namespaceName)) {
- //prefix has already being declared but this particular attrib has a
- //no prefix attached. So use the prefix provided by the writer
- if (writerPrefix != null && (prefix == null || prefix.equals(""))) {
- writer.writeAttribute(writerPrefix, namespaceName,
- reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
-
- //writer prefix is available but different from the current
- //prefix of the attrib. We should be decalring the new prefix
- //as a namespace declaration
- } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
- writer.writeNamespace(prefix, namespaceName);
- writer.writeAttribute(prefix, namespaceName,
- reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
-
- //prefix is null (or empty), but the namespace name is valid! it has not
- //being written previously also. So we need to generate a prefix
- //here
- } else {
- prefix = generateUniquePrefix(writer.getNamespaceContext());
- writer.writeNamespace(prefix, namespaceName);
- writer.writeAttribute(prefix, namespaceName,
- reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- }
- } else {
- //empty namespace is equal to no namespace!
- writer.writeAttribute(reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- }
-
-
- }
- }
-
- /**
- * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
- *
- * @param nsCtxt
- * @return string
- */
- private String generateUniquePrefix(NamespaceContext nsCtxt) {
- String prefix = NAMESPACE_PREFIX + namespaceSuffix++;
- //null should be returned if the prefix is not bound!
- while (nsCtxt.getNamespaceURI(prefix) != null) {
- prefix = NAMESPACE_PREFIX + namespaceSuffix++;
- }
-
- return prefix;
- }
-
- /**
- * Method serializeNamespace.
- *
- * @param prefix
- * @param URI
- * @param writer
- * @throws XMLStreamException
- */
- private void serializeNamespace(String prefix,
- String URI,
- XMLStreamWriter writer)
- throws XMLStreamException {
- String prefix1 = writer.getPrefix(URI);
- if (prefix1 == null) {
- writer.writeNamespace(prefix, URI);
- writer.setPrefix(prefix, URI);
- }
- }
-
- private void serializeDataHandler() throws XMLStreamException {
- try {
- if (dataHandlerReader.isDeferred()) {
- dataHandlerWriter.writeDataHandler(dataHandlerReader.getDataHandlerProvider(),
- dataHandlerReader.getContentID(), dataHandlerReader.isOptimized());
- } else {
- dataHandlerWriter.writeDataHandler(dataHandlerReader.getDataHandler(),
- dataHandlerReader.getContentID(), dataHandlerReader.isOptimized());
- }
- } catch (IOException ex) {
- throw new XMLStreamException("Error while reading data handler", ex);
- }
- }
-
- private void serializeDTD(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- DTDReader dtdReader;
- try {
- dtdReader = (DTDReader)reader.getProperty(DTDReader.PROPERTY);
- } catch (IllegalArgumentException ex) {
- dtdReader = null;
- }
- if (dtdReader == null) {
- throw new XMLStreamException("Cannot serialize the DTD because the XMLStreamReader doesn't support the DTDReader extension");
- }
- XMLStreamWriterUtils.writeDTD(writer, dtdReader.getRootName(), dtdReader.getPublicId(),
- dtdReader.getSystemId(), reader.getText());
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java b/axiom-compat/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
deleted file mode 100644
index 1e3224a77..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
+++ /dev/null
@@ -1,741 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.om.impl.util;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMConstants;
-import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
-import org.apache.axiom.om.util.CommonUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-/**
- * @deprecated
- */
-public class OMSerializerUtil {
- private static final Log log = LogFactory.getLog(OMSerializerUtil.class);
- private static boolean ADV_DEBUG_ENABLED = true;
-
- static long nsCounter = 0;
-
- private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
- private static final String XSI_LOCAL_NAME = "type";
- /**
- * Method serializeEndpart.
- *
- * @param writer
- * @throws javax.xml.stream.XMLStreamException
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeEndpart(XMLStreamWriter writer)
- throws XMLStreamException {
- writer.writeEndElement();
- }
-
- /**
- * Method serializeAttribute.
- *
- * @param attr
- * @param writer
- * @throws XMLStreamException
- * @deprecated use serializeStartpart instead
- */
- public static void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
- throws XMLStreamException {
-
- // first check whether the attribute is associated with a namespace
- OMNamespace ns = attr.getNamespace();
- String prefix = null;
- String namespaceName = null;
- if (ns != null) {
-
- // add the prefix if it's availble
- prefix = ns.getPrefix();
- namespaceName = ns.getNamespaceURI();
- if (prefix != null) {
- writer.writeAttribute(prefix, namespaceName,
- attr.getLocalName(), attr.getAttributeValue());
- } else {
- writer.writeAttribute(namespaceName, attr.getLocalName(),
- attr.getAttributeValue());
- }
- } else {
- String localName = attr.getLocalName();
- String attributeValue = attr.getAttributeValue();
- writer.writeAttribute(localName, attributeValue);
- }
- }
-
- /**
- * Method serializeNamespace.
- *
- * @param namespace
- * @param writer
- * @throws XMLStreamException
- * @deprecated Use serializeStartpart instead
- */
- public static void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer)
- throws XMLStreamException {
- if (namespace == null) {
- return;
- }
- String uri = namespace.getNamespaceURI();
- String prefix = namespace.getPrefix();
-
- if (uri != null && !"".equals(uri)) {
- String prefixFromWriter = writer.getPrefix(uri);
-
- // Handling Default Namespaces First
- // Case 1 :
- // here we are trying define a default namespace. But has this been defined in the current context.
- // yes, there can be a default namespace, but it may have a different URI. If its a different URI
- // then explicitly define the default namespace here.
- // Case 2 :
- // The passed in namespace is a default ns, but there is a non-default ns declared
- // in the current scope.
- if (("".equals(prefix) && "".equals(prefixFromWriter) &&
- !uri.equals(writer.getNamespaceContext().getNamespaceURI(""))) ||
- (prefix != null && "".equals(prefix) &&
- (prefixFromWriter == null || !prefix.equals(prefixFromWriter)))) {
- // this has not been declared earlier
- writer.writeDefaultNamespace(uri);
- writer.setDefaultNamespace(uri);
- } else {
- prefix = prefix == null ? getNextNSPrefix(writer) : prefix;
- if (prefix != null && !prefix.equals(prefixFromWriter) &&
- !checkForPrefixInTheCurrentContext(writer, uri, prefix)) {
- writer.writeNamespace(prefix, uri);
- writer.setPrefix(prefix, uri);
- }
- }
- } else {
- // now the nsURI passed is "" or null. Meaning we gonna work with defaultNS.
- // check whether there is a defaultNS already declared. If yes, is it the same as this ?
- String currentDefaultNSURI = writer.getNamespaceContext().getNamespaceURI("");
- if ((currentDefaultNSURI != null && !currentDefaultNSURI.equals(uri)) ||
- uri != null && !uri.equals(currentDefaultNSURI)) {
- // this has not been declared earlier
- writer.writeDefaultNamespace(uri);
- writer.setDefaultNamespace(uri);
- }
- }
- }
-
- /**
- * @deprecated This method was used to work around a StAX conformance issue in early versions
- * of the XL XP-J parser. This is now handled by
- * {@link org.apache.axiom.util.stax.dialect.StAXDialect}, and this method always returns
- * <code>false</code>.
- */
- public static boolean isSetPrefixBeforeStartElement(XMLStreamWriter writer) {
- return false;
- }
-
- /**
- * Method serializeStartpart. Serialize the start tag of an element.
- *
- * @param element
- * @param writer
- * @throws XMLStreamException
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeStartpart(OMElement element,
- XMLStreamWriter writer) throws XMLStreamException {
- serializeStartpart(element, element.getLocalName(), writer);
- }
-
- /**
- * Method serializeStartpart. Serialize the start tag of an element.
- *
- * @param element
- * @param localName (in some cases, the caller wants to force a different localName)
- * @param writer
- * @throws XMLStreamException
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeStartpart(OMElement element, String localName,
- XMLStreamWriter writer)
- throws XMLStreamException {
-
- // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
- // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
-
- // The algorithm is:
- // ... generate writeStartElement
- //
- // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
- // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
- // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
- //
- // ... generate writeNamespace/writerDefaultNamespace for the new namespace declarations determine during the "set" processing
- // ... generate writeAttribute for each attribute
-
- ArrayList<String> writePrefixList = null;
- ArrayList<String> writeNSList = null;
-
- // Get the namespace and prefix of the element
- OMNamespace eOMNamespace = element.getNamespace();
- String ePrefix = null;
- String eNamespace = null;
- if (eOMNamespace != null) {
- ePrefix = eOMNamespace.getPrefix();
- eNamespace = eOMNamespace.getNamespaceURI();
- }
- ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
- eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
-
- if (eNamespace != null) {
- if (ePrefix == null) {
- if (!isAssociated("", eNamespace, writer)) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (! writePrefixList.contains("")) {
- writePrefixList.add("");
- writeNSList.add(eNamespace);
- }
- }
- writer.writeStartElement("", localName, eNamespace);
- } else {
- /*
- * If XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) associates
- * the prefix with the namespace ..
- */
- if (!isAssociated(ePrefix, eNamespace, writer)) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (! writePrefixList.contains(ePrefix)) {
- writePrefixList.add(ePrefix);
- writeNSList.add(eNamespace);
- }
- }
-
- writer.writeStartElement(ePrefix, localName, eNamespace);
- }
- } else {
- writer.writeStartElement(localName);
- }
-
- // Generate setPrefix for the namespace declarations
- Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
- while (it != null && it.hasNext()) {
- OMNamespace omNamespace = it.next();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
-
- String newPrefix = generateSetPrefix(prefix, namespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
- }
-
- // Generate setPrefix for the element
- // Get the prefix and namespace of the element. "" and null are identical.
- String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, false);
- // If this is a new association, remember it so that it can written out later
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(eNamespace);
- }
- }
-
- // Now Generate setPrefix for each attribute
- Iterator<OMAttribute> attrs = element.getAllAttributes();
- while (attrs != null && attrs.hasNext()) {
- OMAttribute attr = attrs.next();
- OMNamespace omNamespace = attr.getNamespace();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
- // Default prefix referencing is not allowed on an attribute
- if (prefix == null && namespace != null) {
- String writerPrefix = writer.getPrefix(namespace);
- writerPrefix =
- (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
- prefix = (writerPrefix != null) ?
- writerPrefix : getNextNSPrefix();
- }
- newPrefix = generateSetPrefix(prefix, namespace, writer, true);
- // If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- if (newPrefix != null) {
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(namespace);
- }
- }
- }
-
- // Now Generate setPrefix for each prefix referenced in an xsi:type
- // For example xsi:type="p:dataType"
- // The following code will make sure that setPrefix is called for "p".
- attrs = element.getAllAttributes();
- while (attrs != null && attrs.hasNext()) {
- OMAttribute attr = attrs.next();
- OMNamespace omNamespace = attr.getNamespace();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
- String local = attr.getLocalName();
-
- if (XSI_URI.equals(namespace) &&
- XSI_LOCAL_NAME.equals(local)) {
- String value = attr.getAttributeValue();
- if (log.isDebugEnabled()) {
- log.debug("The value of xsi:type is " + value);
- }
- if (value != null) {
- value = value.trim();
- if (value.indexOf(":") > 0) {
- String refPrefix = value.substring(0, value.indexOf(":"));
- OMNamespace omNS = element.findNamespaceURI(refPrefix);
- String refNamespace = (omNS == null) ? null : omNS.getNamespaceURI();
- if (refNamespace != null && refNamespace.length() > 0) {
-
- newPrefix = generateSetPrefix(refPrefix,
- refNamespace,
- writer,
- true);
- // If the prefix is not associated with a namespace yet, remember it so that we can
- // write out a namespace declaration
- if (newPrefix != null) {
- if (log.isDebugEnabled()) {
- log.debug("An xmlns:" + newPrefix +"=\"" + refNamespace +"\" will be written");
- }
- if (writePrefixList == null) {
- writePrefixList = new ArrayList<String>();
- writeNSList = new ArrayList<String>();
- }
- if (!writePrefixList.contains(newPrefix)) {
- writePrefixList.add(newPrefix);
- writeNSList.add(refNamespace);
- }
- }
- }
- }
- }
- }
- }
-
- // Now write out the list of namespace declarations in this list that we constructed
- // while doing the "set" processing.
- if (writePrefixList != null) {
- for (int i = 0; i < writePrefixList.size(); i++) {
- String prefix = writePrefixList.get(i);
- String namespace = writeNSList.get(i);
- if (prefix != null) {
- if (namespace == null) {
- writer.writeNamespace(prefix, "");
- } else {
- writer.writeNamespace(prefix, namespace);
- }
- } else {
- writer.writeDefaultNamespace(namespace);
- }
- }
- }
-
- // Now write the attributes
- attrs = element.getAllAttributes();
- while (attrs != null && attrs.hasNext()) {
- OMAttribute attr = attrs.next();
- OMNamespace omNamespace = attr.getNamespace();
- String prefix = null;
- String namespace = null;
- if (omNamespace != null) {
- prefix = omNamespace.getPrefix();
- namespace = omNamespace.getNamespaceURI();
- }
- prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
- namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-
- if (prefix == null && namespace != null) {
- // Default namespaces are not allowed on an attribute reference.
- // Earlier in this code, a unique prefix was added for this case...now obtain and use it
- prefix = writer.getPrefix(namespace);
- //XMLStreamWriter doesn't allow for getPrefix to know whether you're asking for the prefix
- //for an attribute or an element. So if the namespace matches the default namespace getPrefix will return
- //the empty string, as if it were an element, in all cases (even for attributes, and even if
- //there was a prefix specifically set up for this), which is not the desired behavior.
- //Since the interface is base java, we can't fix it where we need to (by adding an attr boolean to
- //XMLStreamWriter.getPrefix), so we hack it in here...
- if (prefix == null || "".equals(prefix)) {
- for (int i = 0; i < writePrefixList.size(); i++) {
- if (namespace.equals(writeNSList.get(i))) {
- prefix = writePrefixList.get(i);
- }
- }
- }
- } else if (namespace != null) {
- // Use the writer's prefix if it is different, but if the writers
- // prefix is empty then do not replace because attributes do not
- // default to the default namespace like elements do.
- String writerPrefix = writer.getPrefix(namespace);
- if (!prefix.equals(writerPrefix) && writerPrefix != null && !"".equals(writerPrefix)) {
- prefix = writerPrefix;
- }
- }
- if (namespace != null) {
- if(prefix == null && OMConstants.XMLNS_URI.equals(namespace)){
- prefix = OMConstants.XMLNS_PREFIX;
- }
- // Qualified attribute
- writer.writeAttribute(prefix, namespace,
- attr.getLocalName(),
- attr.getAttributeValue());
- } else {
- // Unqualified attribute
- writer.writeAttribute(attr.getLocalName(),
- attr.getAttributeValue());
- }
- }
- }
-
- /**
- * @deprecated This is an internal method that is no longer used.
- */
- private static boolean checkForPrefixInTheCurrentContext(XMLStreamWriter writer,
- String nameSpaceName, String prefix)
- throws XMLStreamException {
- Iterator<?> prefixesIter = writer.getNamespaceContext().getPrefixes(nameSpaceName);
- while (prefixesIter.hasNext()) {
- String prefix_w = (String) prefixesIter.next();
- if (prefix_w.equals(prefix)) {
- // if found do not declare the ns
- return true;
- }
- }
- return false;
- }
-
- /**
- * serializeNamespaces
- *
- * @param element
- * @param writer
- * @throws XMLStreamException
- * @deprecated Use serializeStartpart instead
- */
- public static void serializeNamespaces
- (OMElement
- element,
- XMLStreamWriter writer) throws XMLStreamException {
- Iterator<OMNamespace> namespaces = element.getAllDeclaredNamespaces();
- if (namespaces != null) {
- while (namespaces.hasNext()) {
- serializeNamespace(namespaces.next(), writer);
- }
- }
- }
-
- /**
- * Serialize attributes
- *
- * @param element
- * @param writer
- * @throws XMLStreamException
- * @deprecated Consider using serializeStartpart instead
- */
- public static void serializeAttributes
- (OMElement
- element,
- XMLStreamWriter writer) throws XMLStreamException {
- Iterator<OMAttribute> attributes = element.getAllAttributes();
- if (attributes != null && attributes.hasNext()) {
- while (attributes.hasNext()) {
- serializeAttribute(attributes.next(), writer);
- }
- }
- }
-
- /**
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeNormal
- (OMElement
- element, XMLStreamWriter writer, boolean cache)
- throws XMLStreamException {
-
- if (cache) {
- element.build();
- }
-
- serializeStartpart(element, writer);
- OMNode firstChild = element.getFirstOMChild();
- if (firstChild != null) {
- if (cache) {
- (firstChild).serialize(writer);
- } else {
- (firstChild).serializeAndConsume(writer);
- }
- }
- serializeEndpart(writer);
- }
-
- /**
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeByPullStream
- (OMElement
- element, XMLStreamWriter writer) throws XMLStreamException {
- serializeByPullStream(element, writer, false);
- }
-
- /**
- * @deprecated This is an internal method that is no longer used.
- */
- public static void serializeByPullStream
- (OMElement
- element, XMLStreamWriter writer, boolean cache) throws XMLStreamException {
- XMLStreamReader reader = element.getXMLStreamReader(cache);
- try {
- new StreamingOMSerializer().serialize(reader, writer);
- } finally {
- reader.close();
- }
- }
-
- /**
- * Get the next prefix name
- * @return next prefix name
- * @deprecated
- */
- public static String getNextNSPrefix() {
-
- String prefix = "axis2ns" + ++nsCounter % Long.MAX_VALUE;
-
- /**
- * Calling getNextNSPrefix is "a last gasp" approach
- * for obtaining a prefix. In almost all cases, the
- * OM element should be provided a prefix by the source parser
- * or programatically by the user. We only get to this
- * spot if one was not supplied.
- *
- * The debug information is two-fold.
- * (1) It helps users determine at what point in the code this default
- * prefix is getting built. This will help them identify
- * where to change their code if they don't want a default
- * prefix.
- *
- * (2) It identifies this place in the code as suspect.
- * Do we really want to keep generating new prefixes (?).
- * This could result in lots of symbol table entries for the
- * subsequent parser that reads this data. This could hamper
- * extremely long run usages.
- * This could be a point where we want a plugin so that users can
- * decide their own strategy. Examples from other products
- * include generating a prefix number from the namespace
- * string.
- *
- */
- if (log.isDebugEnabled()) {
- log.debug("Obtained next prefix:" + prefix);
- if (ADV_DEBUG_ENABLED && log.isTraceEnabled()) {
- log.trace(CommonUtils.callStackToString());
- }
- }
- return prefix;
- }
-
- /**
- * @deprecated This is an internal method that is no longer used.
- */
- public static String getNextNSPrefix(XMLStreamWriter writer) {
- String prefix = getNextNSPrefix();
- while (writer.getNamespaceContext().getNamespaceURI(prefix) != null) {
- prefix = getNextNSPrefix();
- }
-
- return prefix;
- }
-
- /**
- * Generate setPrefix/setDefaultNamespace if the prefix is not associated
- *
- * @param prefix
- * @param namespace
- * @param writer
- * @param attr
- * @return prefix name if a setPrefix/setDefaultNamespace is performed
- */
- public static String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer,
- boolean attr) throws XMLStreamException {
- prefix = (prefix == null) ? "" : prefix;
-
-
- // If the prefix and namespace are already associated, no generation is needed
- if (isAssociated(prefix, namespace, writer)) {
- return null;
- }
-
- // Attributes without a prefix always are associated with the unqualified namespace
- // according to the schema specification. No generation is needed.
- if (prefix.length() == 0 && namespace == null && attr) {
- return null;
- }
-
- // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
- String newPrefix = null;
- if (namespace != null) {
- // Qualified Namespace
- if (prefix.length() == 0) {
- writer.setDefaultNamespace(namespace);
- newPrefix = "";
- } else {
- writer.setPrefix(prefix, namespace);
- newPrefix = prefix;
- }
- } else {
- // Unqualified Namespace
- // Disable the default namespace
- writer.setDefaultNamespace("");
- newPrefix = "";
- }
- return newPrefix;
- }
- /**
- * @param prefix
- * @param namespace
- * @param writer
- * @return true if the prefix is associated with the namespace in the current context
- */
- public static boolean isAssociated(String prefix, String namespace, XMLStreamWriter writer)
- throws XMLStreamException {
-
- // The "xml" prefix is always (implicitly) associated. Returning true here makes sure that
- // we never write a declaration for the xml namespace. See AXIOM-37 for a discussion
- // of this issue.
- if ("xml".equals(prefix)) {
- return true;
- }
-
- // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
- // Please use other writer methods first.
-
- // For consistency, convert null arguments.
- // This helps get around the parser implementation differences.
- // In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
- prefix = (prefix == null) ? "" : prefix;
- namespace = (namespace == null) ? "" : namespace;
-
- if (namespace.length() > 0) {
- // QUALIFIED NAMESPACE
- // Get the namespace associated with the prefix
- String writerPrefix = writer.getPrefix(namespace);
- if (prefix.equals(writerPrefix)) {
- return true;
- }
-
- // It is possible that the namespace is associated with multiple prefixes,
- // So try getting the namespace as a second step.
- if (writerPrefix != null) {
- NamespaceContext nsContext = writer.getNamespaceContext();
- if(nsContext != null) {
- String writerNS = nsContext.getNamespaceURI(prefix);
- return namespace.equals(writerNS);
- }
- }
- return false;
- } else {
- // UNQUALIFIED NAMESPACE
-
- // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
- if (prefix.length() > 0) {
- throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");
- }
-
- // Get the namespace associated with the prefix.
- // It is illegal to call getPrefix with null, but the specification is not
- // clear on what happens if called with "". So the following code is
- // protected
- try {
- String writerPrefix = writer.getPrefix("");
- if (writerPrefix != null && writerPrefix.length() == 0) {
- return true;
- }
- } catch (Throwable t) {
- if (log.isDebugEnabled()) {
- log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
- }
- }
-
-
-
- // Fallback to using the namespace context
- NamespaceContext nsContext = writer.getNamespaceContext();
- if (nsContext != null) {
- String writerNS = nsContext.getNamespaceURI("");
- if (writerNS != null && writerNS.length() > 0) {
- return false;
- }
- }
- return true;
- }
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/AttachmentUnmarshallerImpl.java b/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/AttachmentUnmarshallerImpl.java
deleted file mode 100644
index a6b74802f..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/AttachmentUnmarshallerImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.jaxb;
-
-import java.io.IOException;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-
-import org.apache.axiom.util.stax.xop.MimePartProvider;
-import org.apache.axiom.util.stax.xop.XOPUtils;
-
-final class AttachmentUnmarshallerImpl extends AttachmentUnmarshaller {
- private final MimePartProvider mimePartProvider;
-
- AttachmentUnmarshallerImpl(MimePartProvider mimePartProvider) {
- this.mimePartProvider = mimePartProvider;
- }
-
- @Override
- public byte[] getAttachmentAsByteArray(String cid) {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- @Override
- public DataHandler getAttachmentAsDataHandler(String cid) {
- try {
- return mimePartProvider.getDataHandler(XOPUtils.getContentIDFromURL(cid));
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public boolean isXOPPackage() {
- return true;
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/JAXBUtils.java b/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/JAXBUtils.java
deleted file mode 100644
index f3c2f8caa..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/jaxb/JAXBUtils.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.jaxb;
-
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-import org.apache.axiom.util.stax.xop.XOPEncodedStream;
-import org.apache.axiom.util.stax.xop.XOPUtils;
-
-/**
- * Contains low level utility methods that integrate JAXB with some of the Axiom specific StAX
- * extensions.
- *
- * @deprecated
- */
-public final class JAXBUtils {
- private JAXBUtils() {}
-
- /**
- * Create an adapter that enables an {@link Unmarshaller} to perform XOP/MTOM processing on an
- * {@link XMLStreamReader} that exposes the {@link DataHandlerReader} extension. This method
- * should be used in the following way:
- * <ol>
- * <li>Create the {@link Unmarshaller}.
- * <li>Call this method with the {@link XMLStreamReader} to be unmarshalled.
- * <li>Configure the {@link Unmarshaller} with the {@link AttachmentUnmarshaller} returned by
- * {@link UnmarshallerAdapter#getAttachmentUnmarshaller()}.
- * <li>Call {@link Unmarshaller#unmarshal(XMLStreamReader)} or
- * {@link Unmarshaller#unmarshal(XMLStreamReader, Class)}, passing the {@link XMLStreamReader}
- * returned by {@link UnmarshallerAdapter#getReader()} as parameter.
- * </ol>
- *
- * @param reader
- * an {@link XMLStreamReader} that may expose the {@link DataHandlerReader} extension
- * @return the adapter
- */
- public static UnmarshallerAdapter getUnmarshallerAdapter(XMLStreamReader reader) {
- XOPEncodedStream stream = XOPUtils.getXOPEncodedStream(reader);
- XMLStreamReader xopEncodedReader = stream.getReader();
- if (xopEncodedReader == reader) {
- return new UnmarshallerAdapter(reader, null);
- } else {
- return new UnmarshallerAdapter(xopEncodedReader, new AttachmentUnmarshallerImpl(stream.getMimePartProvider()));
- }
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/OptimizationPolicy.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/OptimizationPolicy.java
deleted file mode 100644
index 52f4707a3..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/OptimizationPolicy.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-
-import javax.activation.DataHandler;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-
-/**
- * Encapsulates an algorithm that decides whether base64 encoded binary data should be optimized
- * using XOP. The implementation takes the decision based on the submitted binary content and the
- * "eligible for optimization" flag. Depending on the context of use, this flag is provided by the
- * return value of {@link org.apache.axiom.ext.stax.datahandler.DataHandlerReader#isOptimized()} or
- * the <code>optimize</code> argument of
- * {@link org.apache.axiom.ext.stax.datahandler.DataHandlerWriter#writeDataHandler(DataHandler, String, boolean)}
- * or
- * {@link org.apache.axiom.ext.stax.datahandler.DataHandlerWriter#writeDataHandler(DataHandlerProvider, String, boolean)}.
- */
-public interface OptimizationPolicy {
- /**
- * Policy implementation that optimizes all binary content marked as eligible for optimization.
- */
- OptimizationPolicy DEFAULT = new OptimizationPolicy() {
- @Override
- public boolean isOptimized(DataHandler dataHandler, boolean optimize) {
- return optimize;
- }
-
- @Override
- public boolean isOptimized(DataHandlerProvider dataHandlerProvider, boolean optimize) {
- return optimize;
- }
- };
-
- /**
- * Policy implementation that optimizes all binary content, regardless of whether is has been
- * marked as eligible for optimization.
- */
- OptimizationPolicy ALL = new OptimizationPolicy() {
- @Override
- public boolean isOptimized(DataHandler dataHandler, boolean optimize) {
- return true;
- }
-
- @Override
- public boolean isOptimized(DataHandlerProvider dataHandlerProvider, boolean optimize) {
- return true;
- }
- };
-
- /**
- * Determine whether the binary content supplied by a given {@link DataHandler} should be
- * optimized.
- *
- * @param dataHandler
- * the binary content
- * @param optimize
- * indicates whether the binary content was initially marked as eligible for
- * optimization (see above)
- * @return <code>true</code> if the binary content should be optimized using XOP, i.e. encoded
- * using {@code xop:Include}
- * @throws IOException
- * if an error occurs while reading the data handler
- */
- boolean isOptimized(DataHandler dataHandler, boolean optimize) throws IOException;
-
- /**
- * Determine whether the binary content supplied by a given {@link DataHandlerProvider} should
- * be optimized.
- *
- * @param dataHandlerProvider
- * the binary content
- * @param optimize
- * indicates whether the binary content was initially marked as eligible for
- * optimization (see above)
- * @return <code>true</code> if the binary content should be optimized using XOP, i.e. encoded
- * using {@code xop:Include}
- * @throws IOException
- * if an error occurs while reading the data handler
- */
- boolean isOptimized(DataHandlerProvider dataHandlerProvider, boolean optimize) throws IOException;
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java
deleted file mode 100644
index d58b845f5..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.java
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-import javax.activation.DataHandler;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-import org.apache.axiom.util.base64.Base64Utils;
-import org.apache.axiom.util.stax.XMLEventUtils;
-import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * {@link XMLStreamReader} wrapper that decodes XOP. It uses the extension defined by
- * {@link DataHandlerReader} to expose the {@link DataHandler} objects referenced by
- * {@code xop:Include} elements encountered in the underlying stream. If the consumer uses
- * {@link #getText()}, {@link #getTextCharacters()},
- * {@link #getTextCharacters(int, char[], int, int)} or {@link #getElementText()} when an
- * {@code xop:Include} element is present in the underlying stream, then the decoder will produce
- * a base64 representation of the data.
- * <p>
- * Note that this class only implements infoset transformation, but doesn't handle MIME processing.
- * A {@link MimePartProvider} implementation must be provided to the constructor of this class. This
- * object will be used to load MIME parts referenced by {@code xop:Include} elements encountered
- * in the underlying stream.
- * <p>
- * This class supports deferred loading of MIME parts: If the consumer uses
- * {@link DataHandlerReader#getDataHandlerProvider()}, then the {@link MimePartProvider} will only
- * be invoked when {@link DataHandlerProvider#getDataHandler()} is called.
- */
-public class XOPDecodingStreamReader extends XMLStreamReaderWrapper implements DataHandlerReader {
- private static final String SOLE_CHILD_MSG =
- "Expected xop:Include as the sole child of an element information item (see section " +
- "3.2 of http://www.w3.org/TR/xop10/)";
-
- private static class DataHandlerProviderImpl implements DataHandlerProvider {
- private final MimePartProvider mimePartProvider;
- private final String contentID;
-
- public DataHandlerProviderImpl(MimePartProvider mimePartProvider, String contentID) {
- this.mimePartProvider = mimePartProvider;
- this.contentID = contentID;
- }
-
- public String getContentID() {
- return contentID;
- }
-
- @Override
- public DataHandler getDataHandler() throws IOException {
- return mimePartProvider.getDataHandler(contentID);
- }
- }
-
- private static final Log log = LogFactory.getLog(XOPDecodingStreamReader.class);
-
- private final MimePartProvider mimePartProvider;
- private DataHandlerProviderImpl dh;
- private String base64;
-
- /**
- * Constructor.
- *
- * @param parent
- * the XML stream to decode
- * @param mimePartProvider
- * An implementation of the {@link MimePartProvider} interface that will be used to
- * load the {@link DataHandler} objects for MIME parts referenced by
- * {@code xop:Include} element information items encountered in the underlying
- * stream.
- */
- public XOPDecodingStreamReader(XMLStreamReader parent, MimePartProvider mimePartProvider) {
- super(parent);
- this.mimePartProvider = mimePartProvider;
- }
-
- private void resetDataHandler() {
- dh = null;
- base64 = null;
- }
-
- /**
- * Process an {@code xop:Include} event and return the content ID.
- * <p>
- * Precondition: The parent reader is on the START_ELEMENT event for the {@code xop:Include}
- * element. Note that the method doesn't check this condition.
- * <p>
- * Postcondition: The parent reader is on the event following the END_ELEMENT event for the
- * {@code xop:Include} element, i.e. the parent reader is on the END_ELEMENT event of the
- * element enclosing the {@code xop:Include} element.
- *
- * @return the content ID the {@code xop:Include} refers to
- *
- * @throws XMLStreamException
- */
- private String processXopInclude() throws XMLStreamException {
- if (super.getAttributeCount() != 1 ||
- !super.getAttributeLocalName(0).equals(XOPConstants.HREF)) {
- throw new XMLStreamException("Expected xop:Include element information item with " +
- "a (single) href attribute");
- }
- String href = super.getAttributeValue(0);
- if(log.isDebugEnabled()){
- log.debug("processXopInclude - found href : " + href);
- }
- if (!href.startsWith("cid:")) {
- throw new XMLStreamException("Expected href attribute containing a URL in the " +
- "cid scheme");
- }
- String contentID;
- try {
- // URIs should always be decoded using UTF-8. On the other hand, since non ASCII
- // characters are not allowed in content IDs, we can simply decode using ASCII
- // (which is a subset of UTF-8)
- contentID = URLDecoder.decode(href.substring(4), "ascii");
- if(log.isDebugEnabled()){
- log.debug("processXopInclude - decoded contentID : " + contentID);
- }
- } catch (UnsupportedEncodingException ex) {
- // We should never get here
- throw new XMLStreamException(ex);
- }
- if (super.next() != END_ELEMENT) {
- throw new XMLStreamException(
- "Expected xop:Include element information item to be empty");
- }
- // Also consume the END_ELEMENT event of the xop:Include element. There are
- // two reasons for this:
- // - It allows us to validate that the message conforms to the XOP specs.
- // - It makes it easier to implement the getNamespaceContext method.
- if (super.next() != END_ELEMENT) {
- throw new XMLStreamException(SOLE_CHILD_MSG);
- }
- if (log.isDebugEnabled()) {
- log.debug("Encountered xop:Include for content ID '" + contentID + "'");
- }
- return contentID;
- }
-
- @Override
- public int next() throws XMLStreamException {
- boolean wasStartElement;
- int event;
- if (dh != null) {
- resetDataHandler();
- // We already advanced to the next event after the xop:Include (see below), so there
- // is no call to parent.next() here
- event = END_ELEMENT;
- wasStartElement = false;
- } else {
- wasStartElement = super.getEventType() == START_ELEMENT;
- event = super.next();
- }
- if (event == START_ELEMENT
- && super.getLocalName().equals(XOPConstants.INCLUDE)
- && super.getNamespaceURI().equals(XOPConstants.NAMESPACE_URI)) {
- if (!wasStartElement) {
- throw new XMLStreamException(SOLE_CHILD_MSG);
- }
- dh = new DataHandlerProviderImpl(mimePartProvider, processXopInclude());
- return CHARACTERS;
- } else {
- return event;
- }
- }
-
- @Override
- public int getEventType() {
- return dh == null ? super.getEventType() : CHARACTERS;
- }
-
- @Override
- public int nextTag() throws XMLStreamException {
- if (dh != null) {
- resetDataHandler();
- // We already advanced to the next event after the xop:Include (see the implementation
- // of the next() method) and we now that it is an END_ELEMENT event.
- return END_ELEMENT;
- } else {
- return super.nextTag();
- }
- }
-
- @Override
- public Object getProperty(String name) throws IllegalArgumentException {
- if (DataHandlerReader.PROPERTY.equals(name)) {
- return this;
- } else {
- return super.getProperty(name);
- }
- }
-
- @Override
- public String getElementText() throws XMLStreamException {
- if (super.getEventType() != START_ELEMENT) {
- throw new XMLStreamException("The current event is not a START_ELEMENT event");
- }
- int event = super.next();
- // Note that an xop:Include must be the first child of the element
- if (event == START_ELEMENT
- && super.getLocalName().equals(XOPConstants.INCLUDE)
- && super.getNamespaceURI().equals(XOPConstants.NAMESPACE_URI)) {
- String contentID = processXopInclude();
- try {
- return toBase64(mimePartProvider.getDataHandler(contentID));
- } catch (IOException ex) {
- throw new XMLStreamException("Failed to load MIME part '" + contentID + "'", ex);
- }
- } else {
- String text = null;
- StringBuffer buffer = null;
- while (event != END_ELEMENT) {
- switch (event) {
- case CHARACTERS:
- case CDATA:
- case SPACE:
- case ENTITY_REFERENCE:
- if (text == null && buffer == null) {
- text = super.getText();
- } else {
- String thisText = super.getText();
- if (buffer == null) {
- buffer = new StringBuffer(text.length() + thisText.length());
- buffer.append(text);
- }
- buffer.append(thisText);
- }
- break;
- case PROCESSING_INSTRUCTION:
- case COMMENT:
- // Skip this event
- break;
- default:
- throw new XMLStreamException("Unexpected event " +
- XMLEventUtils.getEventTypeString(event) +
- " while reading element text");
- }
- event = super.next();
- }
- if (buffer != null) {
- return buffer.toString();
- } else if (text != null) {
- return text;
- } else {
- return "";
- }
- }
- }
-
- @Override
- public String getPrefix() {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getPrefix();
- }
- }
-
- @Override
- public String getNamespaceURI() {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getNamespaceURI();
- }
- }
-
- @Override
- public String getLocalName() {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getLocalName();
- }
- }
-
- @Override
- public QName getName() {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getName();
- }
- }
-
- @Override
- public Location getLocation() {
- return super.getLocation();
- }
-
- @Override
- public String getNamespaceURI(String prefix) {
- String uri = super.getNamespaceURI(prefix);
- if ("xop".equals(prefix) && uri != null) {
- System.out.println(prefix + " -> " + uri);
- }
- return uri;
- }
-
- @Override
- public int getNamespaceCount() {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getNamespaceCount();
- }
- }
-
- @Override
- public String getNamespacePrefix(int index) {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getNamespacePrefix(index);
- }
- }
-
- @Override
- public String getNamespaceURI(int index) {
- if (dh != null) {
- throw new IllegalStateException();
- } else {
- return super.getNamespaceURI(index);
- }
- }
-
- private static String toBase64(DataHandler dh) throws XMLStreamException {
- try {
- return Base64Utils.encode(dh);
- } catch (IOException ex) {
- throw new XMLStreamException("Exception when encoding data handler as base64", ex);
- }
- }
-
- private String toBase64() throws XMLStreamException {
- if (base64 == null) {
- try {
- base64 = toBase64(dh.getDataHandler());
- } catch (IOException ex) {
- throw new XMLStreamException("Failed to load MIME part '" + dh.getContentID() + "'", ex);
- }
- }
- return base64;
- }
-
- @Override
- public String getText() {
- if (dh != null) {
- try {
- return toBase64();
- } catch (XMLStreamException ex) {
- throw new RuntimeException(ex);
- }
- } else {
- return super.getText();
- }
- }
-
- @Override
- public char[] getTextCharacters() {
- if (dh != null) {
- try {
- return toBase64().toCharArray();
- } catch (XMLStreamException ex) {
- throw new RuntimeException(ex);
- }
- } else {
- return super.getTextCharacters();
- }
- }
-
- @Override
- public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
- throws XMLStreamException {
- if (dh != null) {
- String text = toBase64();
- int copied = Math.min(length, text.length()-sourceStart);
- text.getChars(sourceStart, sourceStart + copied, target, targetStart);
- return copied;
- } else {
- return super.getTextCharacters(sourceStart, target, targetStart, length);
- }
- }
-
- @Override
- public int getTextLength() {
- if (dh != null) {
- try {
- return toBase64().length();
- } catch (XMLStreamException ex) {
- throw new RuntimeException(ex);
- }
- } else {
- return super.getTextLength();
- }
- }
-
- @Override
- public int getTextStart() {
- if (dh != null) {
- return 0;
- } else {
- return super.getTextStart();
- }
- }
-
- @Override
- public boolean hasText() {
- return dh != null || super.hasText();
- }
-
- @Override
- public boolean isCharacters() {
- return dh != null || super.isCharacters();
- }
-
- @Override
- public boolean isStartElement() {
- return dh == null && super.isStartElement();
- }
-
- @Override
- public boolean isEndElement() {
- return dh == null && super.isEndElement();
- }
-
- @Override
- public boolean hasName() {
- return dh == null && super.hasName();
- }
-
- @Override
- public boolean isWhiteSpace() {
- return dh == null && super.isWhiteSpace();
- }
-
- @Override
- public void require(int type, String namespaceURI, String localName)
- throws XMLStreamException {
- if (dh != null) {
- if (type != CHARACTERS) {
- throw new XMLStreamException("Expected CHARACTERS event");
- }
- } else {
- super.require(type, namespaceURI, localName);
- }
- }
-
- @Override
- public boolean isBinary() {
- return dh != null;
- }
-
- @Override
- public boolean isOptimized() {
- // xop:Include implies optimized
- return true;
- }
-
- @Override
- public boolean isDeferred() {
- return true;
- }
-
- @Override
- public String getContentID() {
- return dh.getContentID();
- }
-
- @Override
- public DataHandler getDataHandler() throws XMLStreamException{
- try {
- return dh.getDataHandler();
- } catch (IOException ex) {
- throw new XMLStreamException("Failed to load MIME part '" + dh.getContentID() + "'");
- }
- }
-
- @Override
- public DataHandlerProvider getDataHandlerProvider() {
- return dh;
- }
-
- XOPEncodedStream getXOPEncodedStream() {
- return new XOPEncodedStream(getParent(), mimePartProvider);
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamWriter.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamWriter.java
deleted file mode 100644
index 32f7f3d2a..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamWriter.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-import org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper;
-
-/**
- * {@link XMLStreamWriter} wrapper that decodes XOP. It assumes that the underlying stream
- * implements the {@link DataHandlerWriter} extension and translates calls that write
- * {@code xop:Include} elements into calls to the appropriate methods defined by
- * {@link DataHandlerWriter}.
- */
-public class XOPDecodingStreamWriter extends XMLStreamWriterWrapper {
- private final MimePartProvider mimePartProvider;
- private final DataHandlerWriter dataHandlerWriter;
- private boolean inXOPInclude;
- private String contentID;
-
- /**
- * Constructor.
- *
- * @param parent
- * the {@link XMLStreamWriter} to write the decoded stream to; the instance must
- * implement the {@link DataHandlerWriter} extension
- * @param mimePartProvider
- * an implementation of the {@link MimePartProvider} interface that will be used to
- * load the {@link DataHandler} objects for MIME parts referenced by
- * {@code xop:Include} element information items written to this wrapper
- */
- public XOPDecodingStreamWriter(XMLStreamWriter parent, MimePartProvider mimePartProvider) {
- super(parent);
- this.mimePartProvider = mimePartProvider;
- dataHandlerWriter = (DataHandlerWriter)parent.getProperty(DataHandlerWriter.PROPERTY);
- }
-
- @Override
- public void writeStartElement(String prefix, String localName, String namespaceURI)
- throws XMLStreamException {
- if (localName.equals(XOPConstants.INCLUDE)
- && namespaceURI.equals(XOPConstants.NAMESPACE_URI)) {
- inXOPInclude = true;
- } else {
- super.writeStartElement(prefix, localName, namespaceURI);
- }
- }
-
- @Override
- public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
- if (localName.equals(XOPConstants.INCLUDE)
- && namespaceURI.equals(XOPConstants.NAMESPACE_URI)) {
- inXOPInclude = true;
- } else {
- super.writeStartElement(namespaceURI, localName);
- }
- }
-
- @Override
- public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
- throws XMLStreamException {
- if (inXOPInclude) {
- processAttribute(namespaceURI, localName, value);
- } else {
- super.writeAttribute(prefix, namespaceURI, localName, value);
- }
- }
-
- @Override
- public void writeAttribute(String namespaceURI, String localName, String value)
- throws XMLStreamException {
- if (inXOPInclude) {
- processAttribute(namespaceURI, localName, value);
- } else {
- super.writeAttribute(namespaceURI, localName, value);
- }
- }
-
- @Override
- public void writeAttribute(String localName, String value) throws XMLStreamException {
- if (inXOPInclude) {
- processAttribute(null, localName, value);
- } else {
- super.writeAttribute(localName, value);
- }
- }
-
- private void processAttribute(String namespaceURI, String localName, String value)
- throws XMLStreamException {
- if ((namespaceURI == null || namespaceURI.length() == 0)
- && localName.equals(XOPConstants.HREF)) {
- if (!value.startsWith("cid:")) {
- throw new XMLStreamException("Expected href attribute containing a URL in the " +
- "cid scheme");
- }
- try {
- contentID = URLDecoder.decode(value.substring(4), "ascii");
- } catch (UnsupportedEncodingException ex) {
- // We should never get here
- throw new XMLStreamException(ex);
- }
- } else {
- throw new XMLStreamException("Expected xop:Include element information item with " +
- "a (single) href attribute");
- }
- }
-
- @Override
- public void writeEndElement() throws XMLStreamException {
- if (inXOPInclude) {
- if (contentID == null) {
- throw new XMLStreamException("Encountered an xop:Include element without " +
- "href attribute");
- }
- // TODO: we should create a DataHandlerProvider if isLoaded returns false for the given contentID
- DataHandler dh;
- try {
- dh = mimePartProvider.getDataHandler(contentID);
- } catch (IOException ex) {
- throw new XMLStreamException("Error while fetching data handler", ex);
- }
- try {
- dataHandlerWriter.writeDataHandler(dh, contentID, true);
- } catch (IOException ex) {
- throw new XMLStreamException("Error while writing data handler", ex);
- }
- inXOPInclude = false;
- contentID = null;
- } else {
- super.writeEndElement();
- }
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java
deleted file mode 100644
index 9a4773ddc..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReader.java
+++ /dev/null
@@ -1,581 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.activation.DataHandler;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
-
-/**
- * {@link XMLStreamReader} wrapper that encodes XOP. It assumes that the underlying reader
- * implements the extension defined by {@link DataHandlerReader} so that it can identify the
- * information items to optimize (by looking for
- * {@link javax.xml.stream.XMLStreamConstants#CHARACTERS} events for which
- * {@link DataHandlerReader#isBinary()} returns <code>true</code>). The {@link DataHandler}
- * objects for the parts referenced by {@code xop:Include} element information items produced by
- * an instance of this class can be retrieved using the {@link #getDataHandler(String)} method.
- * <p>
- * Note that the primary purpose of this class is not to serialize an XML infoset to an XOP package
- * (this is better done using {@link XOPEncodingStreamWriter}), but rather to optimize interaction
- * (by exchanging {@link DataHandler} objects instead of base64 encoded representations) with
- * databinding frameworks that understand XOP, but that are not aware of the
- * {@link DataHandlerReader} extension.
- * <p>
- * This class defers loading of {@link DataHandler} objects until {@link #getDataHandler(String)} is
- * called, except if this is not supported by the underlying stream.
- */
-public class XOPEncodingStreamReader extends XOPEncodingStreamWrapper implements XMLStreamReader {
- /**
- * Wrapper that adds the XOP namespace to another namespace context.
- */
- private static class NamespaceContextWrapper implements NamespaceContext {
- private static final List<String> xopPrefixList = Arrays.asList(new String[] {
- XOPConstants.DEFAULT_PREFIX });
-
- private final NamespaceContext parent;
-
- public NamespaceContextWrapper(NamespaceContext parent) {
- this.parent = parent;
- }
-
- @Override
- public String getNamespaceURI(String prefix) {
- return XOPConstants.DEFAULT_PREFIX.equals(prefix)
- ? XOPConstants.NAMESPACE_URI
- : parent.getNamespaceURI(prefix);
- }
-
- @Override
- public String getPrefix(String namespaceURI) {
- return XOPConstants.NAMESPACE_URI.equals(namespaceURI)
- ? XOPConstants.DEFAULT_PREFIX
- : parent.getPrefix(namespaceURI);
- }
-
- @Override
- public Iterator<String> getPrefixes(String namespaceURI) {
- Iterator<String> prefixes = parent.getPrefixes(namespaceURI);
- if (XOPConstants.NAMESPACE_URI.equals(namespaceURI)) {
- if (!prefixes.hasNext()) {
- return xopPrefixList.iterator();
- } else {
- // This case is very unusual
- List<String> prefixList = new ArrayList<String>();
- do {
- prefixList.add((String)prefixes.next());
- } while (prefixes.hasNext());
- prefixList.add(XOPConstants.DEFAULT_PREFIX);
- return prefixList.iterator();
- }
- } else {
- return prefixes;
- }
- }
- }
-
- private static final int STATE_PASS_THROUGH = 0;
- private static final int STATE_XOP_INCLUDE_START_ELEMENT = 1;
- private static final int STATE_XOP_INCLUDE_END_ELEMENT = 2;
-
- private final XMLStreamReader parent;
- private final DataHandlerReader dataHandlerReader;
- private int state = STATE_PASS_THROUGH;
- private String currentContentID;
-
- /**
- * Constructor.
- *
- * @param parent
- * The XML stream to encode. The reader must implement the extension defined by
- * {@link DataHandlerReader}.
- * @param contentIDGenerator
- * used to generate content IDs for the binary content exposed as
- * {@code xop:Include} element information items
- * @param optimizationPolicy
- * the policy to apply to decide which binary content to optimize
- *
- * @throws IllegalArgumentException
- * if the provided {@link XMLStreamReader} doesn't implement the extension defined
- * by {@link DataHandlerReader}
- */
- public XOPEncodingStreamReader(XMLStreamReader parent, ContentIDGenerator contentIDGenerator,
- OptimizationPolicy optimizationPolicy) {
- super(contentIDGenerator, optimizationPolicy);
- this.parent = parent;
- DataHandlerReader dataHandlerReader;
- try {
- dataHandlerReader = (DataHandlerReader)parent.getProperty(DataHandlerReader.PROPERTY);
- } catch (IllegalArgumentException ex) {
- dataHandlerReader = null;
- }
- if (dataHandlerReader == null) {
- throw new IllegalArgumentException("The supplied XMLStreamReader doesn't implement the DataHandlerReader extension");
- }
- this.dataHandlerReader = dataHandlerReader;
- }
-
- @Override
- public int next() throws XMLStreamException {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- state = STATE_XOP_INCLUDE_END_ELEMENT;
- return END_ELEMENT;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- state = STATE_PASS_THROUGH;
- currentContentID = null;
- // Fall through
- default:
- int event = parent.next();
- if (event == CHARACTERS && dataHandlerReader.isBinary()) {
- String contentID;
- try {
- if (dataHandlerReader.isDeferred()) {
- contentID = processDataHandler(
- dataHandlerReader.getDataHandlerProvider(),
- dataHandlerReader.getContentID(),
- dataHandlerReader.isOptimized());
- } else {
- contentID = processDataHandler(
- dataHandlerReader.getDataHandler(),
- dataHandlerReader.getContentID(),
- dataHandlerReader.isOptimized());
- }
- } catch (IOException ex) {
- throw new XMLStreamException("Error while processing data handler", ex);
- }
- if (contentID != null) {
- currentContentID = contentID;
- state = STATE_XOP_INCLUDE_START_ELEMENT;
- return START_ELEMENT;
- } else {
- return CHARACTERS;
- }
- } else {
- return event;
- }
- }
- }
-
- @Override
- public boolean hasNext() throws XMLStreamException {
- return state == STATE_PASS_THROUGH ? parent.hasNext() : true;
- }
-
- @Override
- public int nextTag() throws XMLStreamException {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- state = STATE_XOP_INCLUDE_END_ELEMENT;
- return END_ELEMENT;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- currentContentID = null;
- // Fall through
- default:
- return parent.nextTag();
- }
- }
-
- @Override
- public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
- if (state == STATE_PASS_THROUGH) {
- parent.require(type, namespaceURI, localName);
- } else {
- if (state == STATE_XOP_INCLUDE_START_ELEMENT && type != START_ELEMENT
- || state == STATE_XOP_INCLUDE_END_ELEMENT && type != END_ELEMENT
- || namespaceURI != null && !namespaceURI.equals(XOPConstants.NAMESPACE_URI)
- || localName != null && !localName.equals(XOPConstants.INCLUDE)) {
- throw new XMLStreamException();
- }
- }
- }
-
- @Override
- public Location getLocation() {
- return parent.getLocation();
- }
-
- @Override
- public void close() throws XMLStreamException {
- parent.close();
- }
-
- @Override
- public Object getProperty(String name) throws IllegalArgumentException {
- return parent.getProperty(name);
- }
-
- @Override
- public String getEncoding() {
- return parent.getEncoding();
- }
-
- @Override
- public String getCharacterEncodingScheme() {
- return parent.getCharacterEncodingScheme();
- }
-
- @Override
- public String getVersion() {
- return parent.getVersion();
- }
-
- @Override
- public boolean isStandalone() {
- return parent.isStandalone();
- }
-
- @Override
- public boolean standaloneSet() {
- return parent.standaloneSet();
- }
-
- @Override
- public String getPIData() {
- return parent.getPIData();
- }
-
- @Override
- public String getPITarget() {
- return parent.getPITarget();
- }
-
- @Override
- public int getAttributeCount() {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- return 1;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeCount();
- }
- }
-
- @Override
- public String getAttributeLocalName(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return XOPConstants.HREF;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeLocalName(index);
- }
- }
-
- @Override
- public QName getAttributeName(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return new QName(XOPConstants.HREF);
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeName(index);
- }
- }
-
- @Override
- public String getAttributeNamespace(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return null;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeNamespace(index);
- }
- }
-
- @Override
- public String getAttributePrefix(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return null;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributePrefix(index);
- }
- }
-
- @Override
- public String getAttributeType(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return "CDATA";
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeType(index);
- }
- }
-
- @Override
- public String getAttributeValue(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- // We don't use full URL encoding here, because this might cause
- // interoperability issues. The specs (RFC 2111 and 2392) are not very clear
- // on which characters should be URL encoded, but one can consider that '%'
- // is the only really unsafe character.
- return "cid:" + currentContentID.replaceAll("%", "%25");
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeValue(index);
- }
- }
-
- @Override
- public boolean isAttributeSpecified(int index) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if (index != 0) {
- throw new IllegalArgumentException();
- }
- return true;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.isAttributeSpecified(index);
- }
- }
-
- @Override
- public String getAttributeValue(String namespaceURI, String localName) {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- if ((namespaceURI == null || namespaceURI.length() == 0)
- && localName.equals(XOPConstants.HREF)) {
- return "cid:" + currentContentID;
- } else {
- return null;
- }
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getAttributeValue(namespaceURI, localName);
- }
- }
-
- @Override
- public String getElementText() throws XMLStreamException {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- state = STATE_XOP_INCLUDE_END_ELEMENT;
- return "";
- case STATE_XOP_INCLUDE_END_ELEMENT:
- throw new IllegalStateException();
- default:
- return parent.getElementText();
- }
- }
-
- @Override
- public int getEventType() {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT:
- return START_ELEMENT;
- case STATE_XOP_INCLUDE_END_ELEMENT:
- return END_ELEMENT;
- default:
- return parent.getEventType();
- }
- }
-
- @Override
- public String getNamespaceURI() {
- return state == STATE_PASS_THROUGH ? parent.getNamespaceURI() : XOPConstants.NAMESPACE_URI;
- }
-
- @Override
- public String getLocalName() {
- return state == STATE_PASS_THROUGH ? parent.getLocalName() : XOPConstants.INCLUDE;
- }
-
- @Override
- public String getPrefix() {
- return state == STATE_PASS_THROUGH ? parent.getPrefix() : XOPConstants.DEFAULT_PREFIX;
- }
-
- @Override
- public QName getName() {
- return state == STATE_PASS_THROUGH ? parent.getName() : XOPConstants.INCLUDE_QNAME;
- }
-
- @Override
- public NamespaceContext getNamespaceContext() {
- NamespaceContext ctx = parent.getNamespaceContext();
- if (state != STATE_PASS_THROUGH) {
- ctx = new NamespaceContextWrapper(ctx);
- }
- return ctx;
- }
-
- @Override
- public String getNamespaceURI(String prefix) {
- if (state != STATE_PASS_THROUGH && XOPConstants.DEFAULT_PREFIX.equals(prefix)) {
- return XOPConstants.NAMESPACE_URI;
- } else {
- return parent.getNamespaceURI(prefix);
- }
- }
-
- @Override
- public int getNamespaceCount() {
- return state == STATE_PASS_THROUGH ? parent.getNamespaceCount() : 1;
- }
-
- @Override
- public String getNamespacePrefix(int index) {
- if (state == STATE_PASS_THROUGH) {
- return parent.getNamespacePrefix(index);
- } else if (index != 0) {
- throw new IllegalArgumentException();
- } else {
- return XOPConstants.DEFAULT_PREFIX;
- }
- }
-
- @Override
- public String getNamespaceURI(int index) {
- if (state == STATE_PASS_THROUGH) {
- return parent.getNamespaceURI(index);
- } else if (index != 0) {
- throw new IllegalArgumentException();
- } else {
- return XOPConstants.NAMESPACE_URI;
- }
- }
-
- @Override
- public String getText() {
- if (state == STATE_PASS_THROUGH) {
- return parent.getText();
- } else {
- throw new IllegalStateException();
- }
- }
-
- @Override
- public int getTextStart() {
- if (state == STATE_PASS_THROUGH) {
- return parent.getTextStart();
- } else {
- throw new IllegalStateException();
- }
- }
-
- @Override
- public int getTextLength() {
- if (state == STATE_PASS_THROUGH) {
- return parent.getTextLength();
- } else {
- throw new IllegalStateException();
- }
- }
-
- @Override
- public char[] getTextCharacters() {
- if (state == STATE_PASS_THROUGH) {
- return parent.getTextCharacters();
- } else {
- throw new IllegalStateException();
- }
- }
-
- @Override
- public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
- throws XMLStreamException {
- if (state == STATE_PASS_THROUGH) {
- return parent.getTextCharacters(sourceStart, target, targetStart, length);
- } else {
- throw new IllegalStateException();
- }
- }
-
- @Override
- public boolean hasName() {
- return state == STATE_PASS_THROUGH ? parent.hasName() : true;
- }
-
- @Override
- public boolean hasText() {
- return state == STATE_PASS_THROUGH ? parent.hasText() : false;
- }
-
- @Override
- public boolean isCharacters() {
- return state == STATE_PASS_THROUGH ? parent.isCharacters() : false;
- }
-
- @Override
- public boolean isWhiteSpace() {
- return state == STATE_PASS_THROUGH ? parent.isWhiteSpace() : false;
- }
-
- @Override
- public boolean isStartElement() {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT: return true;
- case STATE_XOP_INCLUDE_END_ELEMENT: return false;
- default: return parent.isStartElement();
- }
- }
-
- @Override
- public boolean isEndElement() {
- switch (state) {
- case STATE_XOP_INCLUDE_START_ELEMENT: return false;
- case STATE_XOP_INCLUDE_END_ELEMENT: return true;
- default: return parent.isEndElement();
- }
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java
deleted file mode 100644
index 48bf81533..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWrapper.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.activation.DataHandler;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-
-/**
- * Base class for {@link XOPEncodingStreamReader} and {@link XOPEncodingStreamWriter}.
- */
-public abstract class XOPEncodingStreamWrapper implements MimePartProvider {
- private final Map<String,Object> dataHandlerObjects = new LinkedHashMap<String,Object>();
- private final ContentIDGenerator contentIDGenerator;
- private final OptimizationPolicy optimizationPolicy;
-
- public XOPEncodingStreamWrapper(ContentIDGenerator contentIDGenerator,
- OptimizationPolicy optimizationPolicy) {
- this.contentIDGenerator = contentIDGenerator;
- this.optimizationPolicy = optimizationPolicy;
- }
-
- private String addDataHandler(Object dataHandlerObject, String existingContentID) {
- String contentID = contentIDGenerator.generateContentID(existingContentID);
- dataHandlerObjects.put(contentID, dataHandlerObject);
- return contentID;
- }
-
- protected String processDataHandler(DataHandler dataHandler,
- String existingContentID,
- boolean optimize) throws IOException {
- if (optimizationPolicy.isOptimized(dataHandler, optimize)) {
- return addDataHandler(dataHandler, existingContentID);
- } else {
- return null;
- }
- }
-
- protected String processDataHandler(DataHandlerProvider dataHandlerProvider,
- String existingContentID,
- boolean optimize) throws IOException {
- if (optimizationPolicy.isOptimized(dataHandlerProvider, optimize)) {
- return addDataHandler(dataHandlerProvider, existingContentID);
- } else {
- return null;
- }
- }
-
- /**
- * Get the set of content IDs referenced in {@code xop:Include} element information items
- * produced by this wrapper.
- *
- * @return The set of content IDs in their order of appearance in the infoset. If no
- * {@code xop:Include} element information items have been produced yet, an empty
- * set will be returned.
- */
- public Set<String> getContentIDs() {
- return Collections.unmodifiableSet(dataHandlerObjects.keySet());
- }
-
- @Override
- public DataHandler getDataHandler(String contentID) throws IOException {
- Object dataHandlerObject = dataHandlerObjects.get(contentID);
- if (dataHandlerObject == null) {
- throw new IllegalArgumentException("No DataHandler object found for content ID '" +
- contentID + "'");
- } else if (dataHandlerObject instanceof DataHandler) {
- return (DataHandler)dataHandlerObject;
- } else {
- return ((DataHandlerProvider)dataHandlerObject).getDataHandler();
- }
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java
deleted file mode 100644
index 877c0d252..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-
-import javax.activation.DataHandler;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-import org.apache.axiom.util.stax.XMLStreamWriterUtils;
-
-/**
- * {@link XMLStreamWriter} wrapper that encodes XOP. It implements the extension
- * defined by {@link DataHandlerWriter}. The {@link DataHandler}
- * objects for the parts referenced by {@code xop:Include} element information items produced by
- * an instance of this class can be retrieved using the {@link #getDataHandler(String)} method.
- */
-public class XOPEncodingStreamWriter extends XOPEncodingStreamWrapper
- implements XMLStreamWriter, DataHandlerWriter {
- private final XMLStreamWriter parent;
-
- /**
- * Constructor.
- *
- * @param parent
- * the XML stream to write the encoded infoset to
- * @param contentIDGenerator
- * used to generate content IDs for the binary content encoded as
- * {@code xop:Include} element information items
- * @param optimizationPolicy
- * the policy to apply to decide which binary content to optimize
- */
- public XOPEncodingStreamWriter(XMLStreamWriter parent, ContentIDGenerator contentIDGenerator,
- OptimizationPolicy optimizationPolicy) {
- super(contentIDGenerator, optimizationPolicy);
- this.parent = parent;
- }
-
- @Override
- public Object getProperty(String name) throws IllegalArgumentException {
- if (DataHandlerWriter.PROPERTY.equals(name)) {
- return this;
- } else {
- return parent.getProperty(name);
- }
- }
-
- private void writeXOPInclude(String contentID) throws XMLStreamException {
- String writerPrefix = parent.getPrefix(XOPConstants.NAMESPACE_URI);
- if (writerPrefix != null) {
- parent.writeStartElement(XOPConstants.NAMESPACE_URI, "Include");
- } else {
- parent.writeStartElement(XOPConstants.DEFAULT_PREFIX, XOPConstants.INCLUDE,
- XOPConstants.NAMESPACE_URI);
- parent.setPrefix(XOPConstants.DEFAULT_PREFIX, XOPConstants.NAMESPACE_URI);
- parent.writeNamespace(XOPConstants.DEFAULT_PREFIX, XOPConstants.NAMESPACE_URI);
- }
- parent.writeAttribute(XOPConstants.HREF, XOPUtils.getURLForContentID(contentID));
- parent.writeEndElement();
- }
-
- @Override
- public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize)
- throws IOException, XMLStreamException {
- contentID = processDataHandler(dataHandler, contentID, optimize);
- if (contentID != null) {
- writeXOPInclude(contentID);
- } else {
- XMLStreamWriterUtils.writeBase64(parent, dataHandler);
- }
- }
-
- @Override
- public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID,
- boolean optimize) throws IOException, XMLStreamException {
- contentID = processDataHandler(dataHandlerProvider, contentID, optimize);
- if (contentID != null) {
- writeXOPInclude(contentID);
- } else {
- XMLStreamWriterUtils.writeBase64(parent, dataHandlerProvider.getDataHandler());
- }
- }
-
- @Override
- public void close() throws XMLStreamException {
- parent.close();
- }
-
- @Override
- public void flush() throws XMLStreamException {
- parent.flush();
- }
-
- @Override
- public NamespaceContext getNamespaceContext() {
- return parent.getNamespaceContext();
- }
-
- @Override
- public String getPrefix(String uri) throws XMLStreamException {
- return parent.getPrefix(uri);
- }
-
- @Override
- public void setDefaultNamespace(String uri) throws XMLStreamException {
- parent.setDefaultNamespace(uri);
- }
-
- @Override
- public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
- parent.setNamespaceContext(context);
- }
-
- @Override
- public void setPrefix(String prefix, String uri) throws XMLStreamException {
- parent.setPrefix(prefix, uri);
- }
-
- @Override
- public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
- throws XMLStreamException {
- parent.writeAttribute(prefix, namespaceURI, localName, value);
- }
-
- @Override
- public void writeAttribute(String namespaceURI, String localName, String value)
- throws XMLStreamException {
- parent.writeAttribute(namespaceURI, localName, value);
- }
-
- @Override
- public void writeAttribute(String localName, String value) throws XMLStreamException {
- parent.writeAttribute(localName, value);
- }
-
- @Override
- public void writeCData(String data) throws XMLStreamException {
- parent.writeCData(data);
- }
-
- @Override
- public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
- parent.writeCharacters(text, start, len);
- }
-
- @Override
- public void writeCharacters(String text) throws XMLStreamException {
- parent.writeCharacters(text);
- }
-
- @Override
- public void writeComment(String data) throws XMLStreamException {
- parent.writeComment(data);
- }
-
- @Override
- public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
- parent.writeDefaultNamespace(namespaceURI);
- }
-
- @Override
- public void writeDTD(String dtd) throws XMLStreamException {
- parent.writeDTD(dtd);
- }
-
- @Override
- public void writeEmptyElement(String prefix, String localName, String namespaceURI)
- throws XMLStreamException {
- parent.writeEmptyElement(prefix, localName, namespaceURI);
- }
-
- @Override
- public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
- parent.writeEmptyElement(namespaceURI, localName);
- }
-
- @Override
- public void writeEmptyElement(String localName) throws XMLStreamException {
- parent.writeEmptyElement(localName);
- }
-
- @Override
- public void writeEndDocument() throws XMLStreamException {
- parent.writeEndDocument();
- }
-
- @Override
- public void writeEndElement() throws XMLStreamException {
- parent.writeEndElement();
- }
-
- @Override
- public void writeEntityRef(String name) throws XMLStreamException {
- parent.writeEntityRef(name);
- }
-
- @Override
- public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
- parent.writeNamespace(prefix, namespaceURI);
- }
-
- @Override
- public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
- parent.writeProcessingInstruction(target, data);
- }
-
- @Override
- public void writeProcessingInstruction(String target) throws XMLStreamException {
- parent.writeProcessingInstruction(target);
- }
-
- @Override
- public void writeStartDocument() throws XMLStreamException {
- parent.writeStartDocument();
- }
-
- @Override
- public void writeStartDocument(String encoding, String version) throws XMLStreamException {
- parent.writeStartDocument(encoding, version);
- }
-
- @Override
- public void writeStartDocument(String version) throws XMLStreamException {
- parent.writeStartDocument(version);
- }
-
- @Override
- public void writeStartElement(String prefix, String localName, String namespaceURI)
- throws XMLStreamException {
- parent.writeStartElement(prefix, localName, namespaceURI);
- }
-
- @Override
- public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
- parent.writeStartElement(namespaceURI, localName);
- }
-
- @Override
- public void writeStartElement(String localName) throws XMLStreamException {
- parent.writeStartElement(localName);
- }
-}
diff --git a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java b/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java
deleted file mode 100644
index a764583bc..000000000
--- a/axiom-compat/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.util.stax.XMLStreamReaderUtils;
-
-/**
- * Contains utility methods related to XOP.
- */
-public class XOPUtils {
- private static final MimePartProvider nullMimePartProvider = new MimePartProvider() {
- @Override
- public DataHandler getDataHandler(String contentID) throws IOException {
- throw new IllegalArgumentException("There are no MIME parts!");
- }
- };
-
- private XOPUtils() {}
-
- /**
- * Extract the content ID from a URL following the cid scheme defined by RFC2392.
- *
- * @param url the URL
- * @return the corresponding content ID
- * @throws IllegalArgumentException if the URL doesn't use the cid scheme
- */
- public static String getContentIDFromURL(String url) {
- if (url.startsWith("cid:")) {
- try {
- // URIs should always be decoded using UTF-8 (see AXIOM-129). On the
- // other hand, since non ASCII characters are not allowed in content IDs,
- // we can simply decode using ASCII (which is a subset of UTF-8)
- return URLDecoder.decode(url.substring(4), "ascii");
- } catch (UnsupportedEncodingException ex) {
- // We should never get here
- throw new Error(ex);
- }
- } else {
- throw new IllegalArgumentException("The URL doesn't use the cid scheme");
- }
- }
-
- /**
- * Build a cid URL from the given content ID as described in RFC2392.
- * <p>
- * Note that this implementation only encodes the percent character (replacing it by "%25"). The
- * reason is given by the following quotes from RFC3986:
- * <blockquote>
- * If a reserved character is
- * found in a URI component and no delimiting role is known for that character, then it must be
- * interpreted as representing the data octet corresponding to that character's encoding in
- * US-ASCII. [...]
- * <p>
- * Under normal circumstances, the only time when octets within a URI are percent-encoded is
- * during the process of producing the URI from its component parts. This is when an
- * implementation determines which of the reserved characters are to be used as subcomponent
- * delimiters and which can be safely used as data. [...]
- * <p>
- * Because the percent ("%") character serves as the indicator for percent-encoded octets, it
- * must be percent-encoded as "%25" for that octet to be used as data within a URI.
- * </blockquote>
- * <p>
- * Since RFC2392 doesn't define any subcomponents for the cid scheme and since RFC2045 specifies
- * that only US-ASCII characters are allowed in content IDs, the percent character (which is
- * specifically allowed by RFC2045) is the only character that needs URL encoding.
- * <p>
- * Another reason to strictly limit the set of characters to be encoded is that some
- * applications fail to decode cid URLs correctly if they contain percent encoded octets.
- *
- * @param contentID the content ID (without enclosing angle brackets)
- * @return the corresponding URL in the cid scheme
- */
- public static String getURLForContentID(String contentID) {
- return "cid:" + contentID.replaceAll("%", "%25");
- }
-
- /**
- * Get an XOP encoded stream for a given stream reader. Depending on its
- * type and characteristics, this method may wrap or unwrap the stream
- * reader:
- * <ol>
- * <li>If the original reader is an {@link XOPEncodingStreamReader} it will
- * be preserved, since it is already XOP encoded.
- * <li>If the original reader is an {@link XOPDecodingStreamReader}, it will
- * be unwrapped to give access to the underlying XOP encoded reader.
- * <li>If the original reader is a plain XML stream reader implementing the
- * {@link org.apache.axiom.ext.stax.datahandler.DataHandlerReader}
- * extension, it will be wrapped in an {@link XOPEncodingStreamReader} so
- * that optimized binary data can be transferred using XOP.
- * <li>In all other cases, the original reader is simply preserved.
- * </ol>
- *
- * @param reader
- * the original reader
- * @return the XOP encoded stream
- */
- public static XOPEncodedStream getXOPEncodedStream(XMLStreamReader reader) {
- if (reader instanceof XOPEncodingStreamReader) {
- return new XOPEncodedStream(reader, (MimePartProvider)reader);
- } else if (reader instanceof XOPDecodingStreamReader) {
- return ((XOPDecodingStreamReader)reader).getXOPEncodedStream();
- } else if (XMLStreamReaderUtils.getDataHandlerReader(reader) != null) {
- XOPEncodingStreamReader wrapper = new XOPEncodingStreamReader(reader,
- ContentIDGenerator.DEFAULT, OptimizationPolicy.ALL);
- return new XOPEncodedStream(wrapper, wrapper);
- } else {
- return new XOPEncodedStream(reader, nullMimePartProvider);
- }
- }
-}
diff --git a/axiom-compat/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java b/axiom-compat/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java
deleted file mode 100644
index d9ceb2f4a..000000000
--- a/axiom-compat/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.om.impl.serialize;
-
-import static com.google.common.truth.Truth.assertAbout;
-import static org.apache.axiom.truth.xml.XMLTruth.xml;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.axiom.testing.multiton.Multiton;
-import org.apache.axiom.ts.xml.XMLSample;
-import org.apache.axiom.util.stax.dialect.StAXDialect;
-import org.apache.axiom.util.stax.dialect.StAXDialectDetector;
-import org.xml.sax.InputSource;
-
-public class StreamingOMSerializerTest extends TestCase {
- private final XMLSample file;
-
- public StreamingOMSerializerTest(String name, XMLSample file) {
- super(name);
- this.file = file;
- }
-
- @Override
- protected void runTest() throws Throwable {
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- StAXDialect dialect = StAXDialectDetector.getDialect(inputFactory.getClass());
- inputFactory = dialect.normalize(inputFactory);
- // Allow CDATA events
- inputFactory = dialect.enableCDataReporting(inputFactory);
- inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
- XMLOutputFactory outputFactory = dialect.normalize(XMLOutputFactory.newInstance());
- StreamingOMSerializer serializer = new StreamingOMSerializer();
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- XMLStreamReader reader = inputFactory.createXMLStreamReader(new StreamSource(file.getUrl().toString()));
- String encoding = reader.getEncoding();
- XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
- writer.writeStartDocument(encoding, reader.getVersion());
- serializer.serialize(reader, writer, false);
- writer.writeEndDocument();
- writer.flush();
- InputSource actual = new InputSource();
- actual.setByteStream(new ByteArrayInputStream(out.toByteArray()));
- actual.setSystemId(file.getUrl().toString());
- assertAbout(xml()).that(actual).hasSameContentAs(file.getUrl());
- }
-
- public static TestSuite suite() throws Exception {
- TestSuite suite = new TestSuite();
- for (XMLSample file : Multiton.getInstances(XMLSample.class)) {
- suite.addTest(new StreamingOMSerializerTest(file.getName(), file));
- }
- return suite;
- }
-}
diff --git a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java b/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
deleted file mode 100644
index 235c7b03b..000000000
--- a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPDecodingStreamReaderTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import java.io.ByteArrayInputStream;
-
-import javax.imageio.ImageIO;
-import javax.xml.stream.XMLStreamReader;
-
-import junit.framework.TestCase;
-
-import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
-import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.testutils.stax.XMLStreamReaderComparator;
-import org.apache.axiom.ts.soap.MTOMSample;
-import org.apache.commons.codec.binary.Base64;
-
-public class XOPDecodingStreamReaderTest extends TestCase {
- private XMLStreamReader getXOPDecodingStreamReader() throws Exception {
- Attachments attachments = new Attachments(MTOMSample.SAMPLE1.getInputStream(),
- MTOMSample.SAMPLE1.getContentType());
- return new XOPDecodingStreamReader(
- StAXUtils.createXMLStreamReader(attachments.getRootPartInputStream()),
- new AttachmentsMimePartProvider(attachments));
- }
-
- public void testCompareToInlined() throws Exception {
- XMLStreamReader expected = StAXUtils.createXMLStreamReader(
- MTOMSample.SAMPLE1.getInlinedMessage());
- XMLStreamReader actual = getXOPDecodingStreamReader();
- XMLStreamReaderComparator comparator = new XMLStreamReaderComparator(expected, actual);
- comparator.addPrefix("xop");
- comparator.compare();
- expected.close();
- actual.close();
- }
-
- public void testGetElementText() throws Exception {
- XMLStreamReader reader = getXOPDecodingStreamReader();
- while (!reader.isStartElement() || !reader.getLocalName().equals("image1")) {
- reader.next();
- }
- String base64 = reader.getElementText();
- byte[] data = Base64.decodeBase64(base64);
- // The data is actually a JPEG image. Try to decode it to check that the data is not
- // corrupted.
- ImageIO.read(new ByteArrayInputStream(data));
- reader.close();
- }
-}
diff --git a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java b/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
deleted file mode 100644
index 0214a11b4..000000000
--- a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamReaderTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import javax.xml.stream.XMLStreamReader;
-
-import junit.framework.TestCase;
-
-import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.impl.builder.AttachmentsMimePartProvider;
-import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.testutils.stax.XMLStreamReaderComparator;
-import org.apache.axiom.ts.soap.MTOMSample;
-
-public class XOPEncodingStreamReaderTest extends TestCase {
- private static ContentIDGenerator contentIDGenerator = new ContentIDGenerator() {
- @Override
- public String generateContentID(String existingContentID) {
- if (existingContentID == null) {
- fail();
- }
- return existingContentID;
- }
- };
-
- public void test() throws Exception {
- Attachments[] attachments = new Attachments[2];
- XMLStreamReader[] soapPartReader = new XMLStreamReader[2];
- for (int i=0; i<2; i++) {
- attachments[i] = new Attachments(MTOMSample.SAMPLE1.getInputStream(),
- MTOMSample.SAMPLE1.getContentType());
- soapPartReader[i] = StAXUtils.createXMLStreamReader(attachments[i].getRootPartInputStream());
- }
- XMLStreamReader actual = new XOPEncodingStreamReader(new XOPDecodingStreamReader(soapPartReader[1], new AttachmentsMimePartProvider(attachments[1])), contentIDGenerator, OptimizationPolicy.DEFAULT);
- new XMLStreamReaderComparator(soapPartReader[0], actual).compare();
- for (int i=0; i<2; i++) {
- soapPartReader[i].close();
- }
- }
-
-}
diff --git a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java b/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java
deleted file mode 100644
index 73d878f31..000000000
--- a/axiom-compat/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.axiom.util.stax.xop;
-
-import junit.framework.TestCase;
-
-public class XOPUtilsTest extends TestCase {
- public void testGetURLForContentID() {
- // We should not unnecessarily encode characters such as '@', because some implementations
- // don't decode cid URLs correctly
- assertEquals("cid:test@apache.org", XOPUtils.getURLForContentID("test@apache.org"));
- }
-
- public void testGetURLForContentIDWithPercent() {
- // '%' is the only character that really needs encoding
- assertEquals("cid:xxx%25xxx@apache.org", XOPUtils.getURLForContentID("xxx%xxx@apache.org"));
- }
-}