diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..7644b64 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,37 @@ +# +# Copyright (c) 2021 Contributors to the Eclipse Foundation +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, +# or the Eclipse Distribution License v. 1.0 which is available at +# http://www.eclipse.org/org/documents/edl-v10.php. +# +# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause +# + +name: JAXB stax-ex + +on: + pull_request: + push: + +jobs: + build: + name: Test on JDK ${{ matrix.java_version }} + runs-on: ubuntu-latest + + strategy: + matrix: + java_version: [ 11, 17-ea ] + + steps: + - name: Checkout for build + uses: actions/checkout@v2.3.4 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + distribution: 'zulu' + java-version: ${{ matrix.java_version }} + - name: Verify + run: mvn -B -V -U -C -Poss-release clean verify org.glassfish.copyright:glassfish-copyright-maven-plugin:check -Dgpg.skip=true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b3faefd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Distribution License v. 1.0, which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: BSD-3-Clause -# - -language: java - -dist: bionic - -jdk: - - oraclejdk11 - - openjdk-ea - -cache: - directories: - - .autoconf - - $HOME/.m2 - -script: - - mvn -B -V -U -C -Pstaging,oss-release clean verify org.glassfish.copyright:glassfish-copyright-maven-plugin:check -Dgpg.skip=true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a030d2d..93c9551 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -[//]: # " Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. " +[//]: # " Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. " [//]: # " " [//]: # " This program and the accompanying materials are made available under the " [//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at " diff --git a/NOTICE.md b/NOTICE.md index ddfd0d1..85e808f 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -1,4 +1,4 @@ -[//]: # " Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. " +[//]: # " Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. " [//]: # " " [//]: # " This program and the accompanying materials are made available under the " [//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at " diff --git a/README.md b/README.md index 2c69eea..a365c6d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[//]: # " Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. " +[//]: # " Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. " [//]: # " " [//]: # " This program and the accompanying materials are made available under the " [//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at " @@ -6,8 +6,6 @@ [//]: # " " [//]: # " SPDX-License-Identifier: BSD-3-Clause " -[![Build Status](https://travis-ci.com/eclipse-ee4j/jaxb-stax-ex.svg?branch=master)](https://travis-ci.com/eclipse-ee4j/jaxb-stax-ex) - # Extended StAX API This project contains a few extensions to complement JSR-173 StAX API in the following areas: diff --git a/pom.xml b/pom.xml index 4648b7b..eb96889 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ false Low - 4.2.0 + 4.3.0 2.0.1 3.0.1 4.13.2 @@ -148,7 +148,7 @@ maven-javadoc-plugin - 3.2.0 + 3.3.0 maven-enforcer-plugin @@ -247,6 +247,8 @@ -Xlint:all + true + true @@ -379,7 +381,7 @@ org.jacoco jacoco-maven-plugin - 0.8.6 + 0.8.7 diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 0a93ff3..e6607cb 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at diff --git a/src/main/java/org/jvnet/staxex/Base64Data.java b/src/main/java/org/jvnet/staxex/Base64Data.java index c1b73f6..8540523 100644 --- a/src/main/java/org/jvnet/staxex/Base64Data.java +++ b/src/main/java/org/jvnet/staxex/Base64Data.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -186,10 +186,12 @@ private final class Base64StreamingDataHandler extends StreamingDataHandler { super(source); } + @Override public InputStream readOnce() throws IOException { return getDataSource().getInputStream(); } + @Override public void moveTo(File dst) throws IOException { FileOutputStream fout = new FileOutputStream(dst); try { @@ -199,6 +201,7 @@ public void moveTo(File dst) throws IOException { } } + @Override public void close() throws IOException { // nothing to do } @@ -210,10 +213,12 @@ private static final class FilterDataHandler extends StreamingDataHandler { super(dh.getDataSource()); } + @Override public InputStream readOnce() throws IOException { return getDataSource().getInputStream(); } + @Override public void moveTo(File dst) throws IOException { byte[] buf = new byte[8192]; InputStream in = null; @@ -246,6 +251,7 @@ public void moveTo(File dst) throws IOException { } } + @Override public void close() throws IOException { // nothing to do } @@ -339,6 +345,7 @@ public String getMimeType() { * Gets the number of characters needed to represent * this binary data in the base64 encoding. */ + @Override public int length() { // for each 3 bytes you use 4 chars // if the remainder is 1 or 2 there will be 4 more @@ -350,6 +357,7 @@ public int length() { * Encode this binary data in the base64 encoding * and returns the character at the specified position. */ + @Override public char charAt(int index) { // we assume that the length() method is called before this method // (otherwise how would the caller know that the index is valid?) @@ -403,6 +411,7 @@ public char charAt(int index) { * which doesn't happen that much for base64. * So this method should be smaller than faster. */ + @Override public CharSequence subSequence(int start, int end) { StringBuilder buf = new StringBuilder(); get(); // fill in the buffer if we haven't done so @@ -492,7 +501,8 @@ static String getProperty(final String propName) { return System.getProperty(propName); } else { return (String) java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { + new java.security.PrivilegedAction() { + @Override public java.lang.Object run() { return System.getProperty(propName); } diff --git a/src/main/java/org/jvnet/staxex/Base64Encoder.java b/src/main/java/org/jvnet/staxex/Base64Encoder.java index 912c156..2b3c25c 100644 --- a/src/main/java/org/jvnet/staxex/Base64Encoder.java +++ b/src/main/java/org/jvnet/staxex/Base64Encoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at diff --git a/src/main/java/org/jvnet/staxex/Base64EncoderStream.java b/src/main/java/org/jvnet/staxex/Base64EncoderStream.java index 9a09373..4a383f0 100644 --- a/src/main/java/org/jvnet/staxex/Base64EncoderStream.java +++ b/src/main/java/org/jvnet/staxex/Base64EncoderStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -43,6 +43,7 @@ public Base64EncoderStream(OutputStream out) { /** * Create a BASE64 encoder that encodes the specified input stream + * @param out */ public Base64EncoderStream(XMLStreamWriter outWriter, OutputStream out) { super(out); diff --git a/src/main/java/org/jvnet/staxex/BinaryText.java b/src/main/java/org/jvnet/staxex/BinaryText.java index ffef023..9800679 100644 --- a/src/main/java/org/jvnet/staxex/BinaryText.java +++ b/src/main/java/org/jvnet/staxex/BinaryText.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -14,7 +14,7 @@ /** * BinaryText represents a MTOM attachment. - * + * * @author shih-chang.chen@oracle.com */ public interface BinaryText { diff --git a/src/main/java/org/jvnet/staxex/ByteArrayOutputStreamEx.java b/src/main/java/org/jvnet/staxex/ByteArrayOutputStreamEx.java index d8ad5a7..9e1fc59 100644 --- a/src/main/java/org/jvnet/staxex/ByteArrayOutputStreamEx.java +++ b/src/main/java/org/jvnet/staxex/ByteArrayOutputStreamEx.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at diff --git a/src/main/java/org/jvnet/staxex/MtomEnabled.java b/src/main/java/org/jvnet/staxex/MtomEnabled.java index 8d61723..58df0d1 100644 --- a/src/main/java/org/jvnet/staxex/MtomEnabled.java +++ b/src/main/java/org/jvnet/staxex/MtomEnabled.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -14,7 +14,7 @@ /** * A SOAPElement implementation may support this interface to allow MTOM attachments. - * + * * @author shih-chang.chen@oracle.com */ public interface MtomEnabled { diff --git a/src/main/java/org/jvnet/staxex/NamespaceContextEx.java b/src/main/java/org/jvnet/staxex/NamespaceContextEx.java index 24ec57f..a1fb726 100644 --- a/src/main/java/org/jvnet/staxex/NamespaceContextEx.java +++ b/src/main/java/org/jvnet/staxex/NamespaceContextEx.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -47,6 +47,7 @@ public interface NamespaceContextEx extends NamespaceContext, Iterable iterator(); /** diff --git a/src/main/java/org/jvnet/staxex/StAxSOAPBody.java b/src/main/java/org/jvnet/staxex/StAxSOAPBody.java index 5b31422..f9faa6f 100644 --- a/src/main/java/org/jvnet/staxex/StAxSOAPBody.java +++ b/src/main/java/org/jvnet/staxex/StAxSOAPBody.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -7,7 +7,6 @@ * * SPDX-License-Identifier: BSD-3-Clause */ - package org.jvnet.staxex; import javax.xml.namespace.QName; @@ -16,50 +15,53 @@ import javax.xml.stream.XMLStreamWriter; /** - * A StAxSOAPBody is a SOAPBody that allows to be loaded from a StAX style payload. - * + * A StAxSOAPBody is a SOAPBody that allows to be loaded from a StAX style + * payload. + * * @author shih-chang.chen@oracle.com */ public interface StAxSOAPBody { - + /** * The StAxSOAPBody represents the StAX source of SOAPBody payload. */ public static interface Payload { - + /** * Retrieve payload qname without materializing its contents - * @return + * + * @return qname */ - public QName getPayloadQName(); - - public XMLStreamReader readPayload() throws XMLStreamException; - - public void writePayloadTo(XMLStreamWriter writer)throws XMLStreamException; + public QName getPayloadQName(); - /** - * Retrieve payload attribute value without materializing its contents - * @param localName - * @return - * @throws XMLStreamException - */ - public String getPayloadAttributeValue(String localName) throws XMLStreamException; + public XMLStreamReader readPayload() throws XMLStreamException; + + public void writePayloadTo(XMLStreamWriter writer) throws XMLStreamException; + + /** + * Retrieve payload attribute value without materializing its contents + * + * @param localName attribute local name + * @return payload attribute value + * @throws XMLStreamException for errors + */ + public String getPayloadAttributeValue(String localName) throws XMLStreamException; - /** - * Retrieve payload attribute value without materializing its contents - * @param qName - * @return - * @throws XMLStreamException - */ - public String getPayloadAttributeValue(QName qName) throws XMLStreamException; - - public void materialize() throws XMLStreamException; + /** + * Retrieve payload attribute value without materializing its contents + * + * @param qName attribute QName + * @return payload attribute value + * @throws XMLStreamException for errors + */ + public String getPayloadAttributeValue(QName qName) throws XMLStreamException; + + public void materialize() throws XMLStreamException; } - + public void setPayload(Payload src) throws XMLStreamException; - - public Payload getPayload()throws XMLStreamException; - - public boolean hasStaxPayload(); - } + public Payload getPayload() throws XMLStreamException; + + public boolean hasStaxPayload(); +} diff --git a/src/main/java/org/jvnet/staxex/StreamingDataHandler.java b/src/main/java/org/jvnet/staxex/StreamingDataHandler.java index 9a022f8..b10680c 100644 --- a/src/main/java/org/jvnet/staxex/StreamingDataHandler.java +++ b/src/main/java/org/jvnet/staxex/StreamingDataHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -118,6 +118,8 @@ public StreamingDataHandler(DataSource dataSource) { * behave in undefined fashion. For a simliar reason, * calling this method multiple times will cause * undefined behavior. + * @param dst + * @throws IOException for errors */ public abstract void moveTo(File dst) throws IOException; @@ -126,7 +128,9 @@ public StreamingDataHandler(DataSource dataSource) { * (such as an attachment in a web service read from a temp * file will be deleted.) After calling this method, it is * illegal to call any other methods. + * @throws IOException for errors */ + @Override public abstract void close() throws IOException; public String getHrefCid() { diff --git a/src/main/java/org/jvnet/staxex/XMLStreamReaderEx.java b/src/main/java/org/jvnet/staxex/XMLStreamReaderEx.java index fd76f98..02d4560 100644 --- a/src/main/java/org/jvnet/staxex/XMLStreamReaderEx.java +++ b/src/main/java/org/jvnet/staxex/XMLStreamReaderEx.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -145,6 +145,8 @@ public interface XMLStreamReaderEx extends XMLStreamReader { * * @throws IllegalStateException * if the parser is not pointing at characters infoset item. + * @throws XMLStreamException + * for other errors. * * TODO: * fix the dependency to JAXB internal class. @@ -154,6 +156,7 @@ public interface XMLStreamReaderEx extends XMLStreamReader { /** * {@inheritDoc} */ + @Override NamespaceContextEx getNamespaceContext(); /** @@ -164,6 +167,8 @@ public interface XMLStreamReaderEx extends XMLStreamReader { * The parser can often do this more efficiently than * {@code getElementText().trim()}. * + * @throws XMLStreamException for errors + * @return * @see #getElementText() */ String getElementTextTrim() throws XMLStreamException; diff --git a/src/main/java/org/jvnet/staxex/XMLStreamWriterEx.java b/src/main/java/org/jvnet/staxex/XMLStreamWriterEx.java index 3541b42..728eaea 100644 --- a/src/main/java/org/jvnet/staxex/XMLStreamWriterEx.java +++ b/src/main/java/org/jvnet/staxex/XMLStreamWriterEx.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -75,6 +75,7 @@ public interface XMLStreamWriterEx extends XMLStreamWriter { * this mandatory parameter identifies the MIME type of the binary data. * If the MIME type isn't known by the caller, "application/octet-stream" can * be always used to indicate "I don't know." Never null. + * @throws XMLStreamException for errors */ void writeBinary(byte[] data, int start, int len, String contentType) throws XMLStreamException; @@ -89,6 +90,7 @@ public interface XMLStreamWriterEx extends XMLStreamWriter { * * @param data * always non-null. After this method call, the callee owns the data handler. + * @throws XMLStreamException for errors */ void writeBinary(DataHandler data) throws XMLStreamException; @@ -110,6 +112,7 @@ public interface XMLStreamWriterEx extends XMLStreamWriter { * * @return * always return a non-null {@link OutputStream}. + * @throws XMLStreamException for errors */ OutputStream writeBinary(String contentType) throws XMLStreamException; @@ -128,6 +131,7 @@ public interface XMLStreamWriterEx extends XMLStreamWriter { * recommended (so that the consumer interested in seeing it * as binary data may take advantage of mor efficient * data representation.) + * @throws XMLStreamException for errors * */ void writePCDATA(CharSequence data) throws XMLStreamException; @@ -135,5 +139,6 @@ public interface XMLStreamWriterEx extends XMLStreamWriter { /** * {@inheritDoc} */ + @Override NamespaceContextEx getNamespaceContext(); } diff --git a/src/main/java/org/jvnet/staxex/util/DOMStreamReader.java b/src/main/java/org/jvnet/staxex/util/DOMStreamReader.java index a00ad86..3518a7e 100644 --- a/src/main/java/org/jvnet/staxex/util/DOMStreamReader.java +++ b/src/main/java/org/jvnet/staxex/util/DOMStreamReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -78,7 +78,7 @@ public class DOMStreamReader implements XMLStreamReader, NamespaceContext { /** * List of attributes extracted from _namedNodeMap. */ - private final FinalArrayList _currentAttributes = new FinalArrayList(); + private final FinalArrayList _currentAttributes = new FinalArrayList<>(); /** * {@link Scope} buffer. @@ -111,7 +111,7 @@ protected static final class Scope { /** * List of namespace declarations extracted from _namedNodeMap */ - final FinalArrayList currentNamespaces = new FinalArrayList(); + final FinalArrayList currentNamespaces = new FinalArrayList<>(); /** * Additional namespace declarations obtained as a result of "fixing" DOM tree, @@ -119,7 +119,7 @@ protected static final class Scope { * * One entry occupies two spaces (prefix followed by URI.) */ - final FinalArrayList additionalNamespaces = new FinalArrayList(); + final FinalArrayList additionalNamespaces = new FinalArrayList<>(); Scope(Scope parent) { this.parent = parent; @@ -216,6 +216,7 @@ public void setCurrentNode(Node node) { // displayDOM(node, System.out); } + @Override public void close() throws XMLStreamException { } @@ -307,6 +308,7 @@ private Scope allocateScope() { return scope; } + @Override public int getAttributeCount() { if (_state == START_ELEMENT) return _currentAttributes.size(); @@ -314,8 +316,10 @@ public int getAttributeCount() { } /** - * Return an attribute's local name. Handle the case of DOM level 1 nodes. + * Return an attribute's local name.Handle the case of DOM level 1 nodes. + * @return */ + @Override public String getAttributeLocalName(int index) { if (_state == START_ELEMENT) { String localName = _currentAttributes.get(index).getLocalName(); @@ -328,6 +332,7 @@ public String getAttributeLocalName(int index) { /** * Return an attribute's qname. Handle the case of DOM level 1 nodes. */ + @Override public QName getAttributeName(int index) { if (_state == START_ELEMENT) { Node attr = _currentAttributes.get(index); @@ -344,6 +349,7 @@ public QName getAttributeName(int index) { throw new IllegalStateException("DOMStreamReader: getAttributeName() called in illegal state"); } + @Override public String getAttributeNamespace(int index) { if (_state == START_ELEMENT) { String uri = _currentAttributes.get(index).getNamespaceURI(); @@ -352,6 +358,7 @@ public String getAttributeNamespace(int index) { throw new IllegalStateException("DOMStreamReader: getAttributeNamespace() called in illegal state"); } + @Override public String getAttributePrefix(int index) { if (_state == START_ELEMENT) { String prefix = _currentAttributes.get(index).getPrefix(); @@ -360,6 +367,7 @@ public String getAttributePrefix(int index) { throw new IllegalStateException("DOMStreamReader: getAttributePrefix() called in illegal state"); } + @Override public String getAttributeType(int index) { if (_state == START_ELEMENT) { return "CDATA"; @@ -367,6 +375,7 @@ public String getAttributeType(int index) { throw new IllegalStateException("DOMStreamReader: getAttributeType() called in illegal state"); } + @Override public String getAttributeValue(int index) { if (_state == START_ELEMENT) { return _currentAttributes.get(index).getNodeValue(); @@ -374,6 +383,7 @@ public String getAttributeValue(int index) { throw new IllegalStateException("DOMStreamReader: getAttributeValue() called in illegal state"); } + @Override public String getAttributeValue(String namespaceURI, String localName) { if (_state == START_ELEMENT) { if (_namedNodeMap != null) { @@ -385,25 +395,31 @@ public String getAttributeValue(String namespaceURI, String localName) { throw new IllegalStateException("DOMStreamReader: getAttributeValue() called in illegal state"); } + @Override public String getCharacterEncodingScheme() { return null; } + @Override public String getElementText() throws javax.xml.stream.XMLStreamException { throw new RuntimeException("DOMStreamReader: getElementText() not implemented"); } + @Override public String getEncoding() { return null; } + @Override public int getEventType() { return _state; } /** - * Return an element's local name. Handle the case of DOM level 1 nodes. + * Return an element's local name.Handle the case of DOM level 1 nodes. + * @return */ + @Override public String getLocalName() { if (_state == START_ELEMENT || _state == END_ELEMENT) { String localName = _current.getLocalName(); @@ -416,6 +432,7 @@ else if (_state == ENTITY_REFERENCE) { throw new IllegalStateException("DOMStreamReader: getAttributeValue() called in illegal state"); } + @Override public Location getLocation() { return DummyLocation.INSTANCE; } @@ -423,6 +440,7 @@ public Location getLocation() { /** * Return an element's qname. Handle the case of DOM level 1 nodes. */ + @Override public javax.xml.namespace.QName getName() { if (_state == START_ELEMENT || _state == END_ELEMENT) { String localName = _current.getLocalName(); @@ -438,6 +456,7 @@ public javax.xml.namespace.QName getName() { throw new IllegalStateException("DOMStreamReader: getName() called in illegal state"); } + @Override public NamespaceContext getNamespaceContext() { return this; } @@ -455,18 +474,22 @@ private Scope getCheckedScope() { throw new IllegalStateException("DOMStreamReader: neither on START_ELEMENT nor END_ELEMENT"); } + @Override public int getNamespaceCount() { return getCheckedScope().getNamespaceCount(); } + @Override public String getNamespacePrefix(int index) { return getCheckedScope().getNamespacePrefix(index); } + @Override public String getNamespaceURI(int index) { return getCheckedScope().getNamespaceURI(index); } + @Override public String getNamespaceURI() { if (_state == START_ELEMENT || _state == END_ELEMENT) { String uri = _current.getNamespaceURI(); @@ -477,9 +500,12 @@ public String getNamespaceURI() { /** * This method is not particularly fast, but shouldn't be called very - * often. If we start to use it more, we should keep track of the - * NS declarations using a NamespaceContext implementation instead. + * often.If we start to use it more, we should keep track of the + NS declarations using a NamespaceContext implementation instead. + * @param prefix + * @return */ + @Override public String getNamespaceURI(String prefix) { if (prefix == null) { throw new IllegalArgumentException("DOMStreamReader: getNamespaceURI(String) call with a null prefix"); @@ -509,6 +535,7 @@ else if (prefix.equals("xmlns")) { return null; } + @Override public String getPrefix(String nsUri) { if (nsUri == null) { throw new IllegalArgumentException("DOMStreamReader: getPrefix(String) call with a null namespace URI"); @@ -575,14 +602,16 @@ private static String getPrefixForAttr(Attr attr, String nsUri) { return null; } - public Iterator getPrefixes(String nsUri) { + @Override + public Iterator getPrefixes(String nsUri) { // This is an incorrect implementation, // but AFAIK it's not used in the JAX-WS runtime String prefix = getPrefix(nsUri); - if(prefix==null) return Collections.emptyList().iterator(); + if(prefix==null) return Collections.emptyList().iterator(); else return Collections.singletonList(prefix).iterator(); } + @Override public String getPIData() { if (_state == PROCESSING_INSTRUCTION) { return ((ProcessingInstruction) _current).getData(); @@ -590,6 +619,7 @@ public String getPIData() { return null; } + @Override public String getPITarget() { if (_state == PROCESSING_INSTRUCTION) { return ((ProcessingInstruction) _current).getTarget(); @@ -597,6 +627,7 @@ public String getPITarget() { return null; } + @Override public String getPrefix() { if (_state == START_ELEMENT || _state == END_ELEMENT) { String prefix = _current.getPrefix(); @@ -605,10 +636,12 @@ public String getPrefix() { return null; } + @Override public Object getProperty(String str) throws IllegalArgumentException { return null; } + @Override public String getText() { if (_state == CHARACTERS) return wholeText; @@ -617,10 +650,12 @@ public String getText() { throw new IllegalStateException("DOMStreamReader: getTextLength() called in illegal state"); } + @Override public char[] getTextCharacters() { return getText().toCharArray(); } + @Override public int getTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength) throws XMLStreamException { String text = getText(); @@ -630,10 +665,12 @@ public int getTextCharacters(int sourceStart, char[] target, int targetStart, return copiedSize; } + @Override public int getTextLength() { return getText().length(); } + @Override public int getTextStart() { if (_state == CHARACTERS || _state == CDATA || _state == COMMENT || _state == ENTITY_REFERENCE) { return 0; @@ -641,18 +678,22 @@ public int getTextStart() { throw new IllegalStateException("DOMStreamReader: getTextStart() called in illegal state"); } + @Override public String getVersion() { return null; } + @Override public boolean hasName() { return (_state == START_ELEMENT || _state == END_ELEMENT); } + @Override public boolean hasNext() throws javax.xml.stream.XMLStreamException { return (_state != END_DOCUMENT); } + @Override public boolean hasText() { if (_state == CHARACTERS || _state == CDATA || _state == COMMENT || _state == ENTITY_REFERENCE) { return getText().trim().length() > 0; @@ -660,26 +701,32 @@ public boolean hasText() { return false; } + @Override public boolean isAttributeSpecified(int param) { return false; } + @Override public boolean isCharacters() { return (_state == CHARACTERS); } + @Override public boolean isEndElement() { return (_state == END_ELEMENT); } + @Override public boolean isStandalone() { return true; } + @Override public boolean isStartElement() { return (_state == START_ELEMENT); } + @Override public boolean isWhiteSpace() { if (_state == CHARACTERS || _state == CDATA) return getText().trim().length()==0; @@ -709,6 +756,7 @@ private static int mapNodeTypeToState(int nodetype) { } } + @Override public int next() throws XMLStreamException { while(true) { int r = _next(); @@ -794,6 +842,7 @@ protected int _next() throws XMLStreamException { } } + @Override public int nextTag() throws javax.xml.stream.XMLStreamException { int eventType = next(); while (eventType == CHARACTERS && isWhiteSpace() @@ -810,6 +859,7 @@ public int nextTag() throws javax.xml.stream.XMLStreamException { return eventType; } + @Override public void require(int type, String namespaceURI, String localName) throws javax.xml.stream.XMLStreamException { @@ -824,6 +874,7 @@ public void require(int type, String namespaceURI, String localName) } } + @Override public boolean standaloneSet() { return true; } diff --git a/src/main/java/org/jvnet/staxex/util/DummyLocation.java b/src/main/java/org/jvnet/staxex/util/DummyLocation.java index 417a041..05b0b07 100644 --- a/src/main/java/org/jvnet/staxex/util/DummyLocation.java +++ b/src/main/java/org/jvnet/staxex/util/DummyLocation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -22,18 +22,23 @@ private DummyLocation() {} public static final Location INSTANCE = new DummyLocation(); + @Override public int getCharacterOffset() { return -1; } + @Override public int getColumnNumber() { return -1; } + @Override public int getLineNumber() { return -1; } + @Override public String getPublicId() { return null; } + @Override public String getSystemId() { return null; } diff --git a/src/main/java/org/jvnet/staxex/util/FinalArrayList.java b/src/main/java/org/jvnet/staxex/util/FinalArrayList.java index d41c6a5..75551b9 100644 --- a/src/main/java/org/jvnet/staxex/util/FinalArrayList.java +++ b/src/main/java/org/jvnet/staxex/util/FinalArrayList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -16,6 +16,7 @@ /** * {@link ArrayList} with a final marker to help JIT. * @author Kohsuke Kawaguchi + * @param element type */ public final class FinalArrayList extends ArrayList { public FinalArrayList(int initialCapacity) { @@ -25,7 +26,7 @@ public FinalArrayList(int initialCapacity) { public FinalArrayList() { } - public FinalArrayList(Collection collection) { + public FinalArrayList(Collection collection) { super(collection); } } diff --git a/src/main/java/org/jvnet/staxex/util/MtomStreamWriter.java b/src/main/java/org/jvnet/staxex/util/MtomStreamWriter.java index 0952e40..d199e53 100644 --- a/src/main/java/org/jvnet/staxex/util/MtomStreamWriter.java +++ b/src/main/java/org/jvnet/staxex/util/MtomStreamWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at diff --git a/src/main/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriter.java b/src/main/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriter.java index c870e07..7c36a54 100644 --- a/src/main/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriter.java +++ b/src/main/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -34,13 +34,13 @@ * @author Ryan Shoemaker */ public class XMLStreamReaderToXMLStreamWriter { - + static public class Breakpoint { protected XMLStreamReader reader; protected XMLStreamWriter writer; - - public Breakpoint(XMLStreamReader r, XMLStreamWriter w) { reader = r; writer = w; } - + + public Breakpoint(XMLStreamReader r, XMLStreamWriter w) { reader = r; writer = w; } + public XMLStreamReader reader() { return reader; } public XMLStreamWriter writer() { return writer; } public boolean proceedBeforeStartElement() { return true; } @@ -55,15 +55,20 @@ static public class Breakpoint { private char[] buf; boolean optimizeBase64Data = false; - + AttachmentMarshaller mtomAttachmentMarshaller; - + + public XMLStreamReaderToXMLStreamWriter() { + super(); + } + /** * Reads one subtree and writes it out. * *

* The {@link XMLStreamWriter} never receives a start/end document event. * Those need to be written separately by the caller. + * @throws javax.xml.stream.XMLStreamException */ public void bridge(XMLStreamReader in, XMLStreamWriter out) throws XMLStreamException { bridge(in, out, null); @@ -72,14 +77,14 @@ public void bridge(XMLStreamReader in, XMLStreamWriter out) throws XMLStreamExce public void bridge(Breakpoint breakPoint) throws XMLStreamException { bridge(breakPoint.reader(), breakPoint.writer(), breakPoint); } - + private void bridge(XMLStreamReader in, XMLStreamWriter out, Breakpoint breakPoint) throws XMLStreamException { assert in!=null && out!=null; this.in = in; this.out = out; optimizeBase64Data = (in instanceof XMLStreamReaderEx); - + if (out instanceof XMLStreamWriterEx && out instanceof MtomStreamWriter) { mtomAttachmentMarshaller = ((MtomStreamWriter) out).getAttachmentMarshaller(); } @@ -150,13 +155,13 @@ protected void handlePI() throws XMLStreamException { protected void handleCharacters() throws XMLStreamException { - + CharSequence c = null; - + if (optimizeBase64Data) { c = ((XMLStreamReaderEx)in).getPCDATA(); } - + if ((c != null) && (c instanceof Base64Data)) { if (mtomAttachmentMarshaller != null) { Base64Data b64d = (Base64Data) c; @@ -211,6 +216,7 @@ protected void handleStartElement() throws XMLStreamException { * *

* Used from {@link #handleStartElement()}. + * @throws javax.xml.stream.XMLStreamException */ protected void handleAttribute(int i) throws XMLStreamException { String nsUri = in.getAttributeNamespace(i); @@ -261,7 +267,7 @@ private static String fixNull(String s) { } private int getEventType() throws XMLStreamException { - int event = in.getEventType(); + int event = in.getEventType(); // if the parser is at the start tag, proceed to the first element //Note - need to do this every time because we could be using a composite reader if(event == XMLStreamConstants.START_DOCUMENT) { diff --git a/src/test/java/org/jvnet/staxex/util/ByteCodeVersionTest.java b/src/test/java/org/jvnet/staxex/util/ByteCodeVersionTest.java deleted file mode 100644 index 8d605e5..0000000 --- a/src/test/java/org/jvnet/staxex/util/ByteCodeVersionTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0, which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.jvnet.staxex.util; - -import java.io.DataInputStream; -import java.io.InputStream; -import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; - -/** - * - * @author lukas - */ -public class ByteCodeVersionTest { - - public ByteCodeVersionTest() { - } - - @Test - public void testModuleInfoByteCodeVersion() { - // module-info for JDK 9 - verifyClassFileFormat("/module-info.class", 0x35); - } - - @Test - public void testClassByteCodeVersion() { - // class files for JDK 7 - verifyClassFileFormat("/org/jvnet/staxex/MtomEnabled.class", 0x34); - } - - private static void verifyClassFileFormat(String resource, int expectedClassVersion) { - try (InputStream in = ByteCodeVersionTest.class.getModule().getResourceAsStream(resource); - DataInputStream data = new DataInputStream(in)) { - if (0xCAFEBABE != data.readInt()) { - Assert.fail("invalid header"); - } - // minor - int i = data.readUnsignedShort(); - // major - i = data.readUnsignedShort(); - Assert.assertEquals("Class Files compiled for wrong java runtime version", expectedClassVersion, i); - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - } -} diff --git a/src/test/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriterTest.java b/src/test/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriterTest.java index 2f4eacc..d4eda9b 100644 --- a/src/test/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriterTest.java +++ b/src/test/java/org/jvnet/staxex/util/XMLStreamReaderToXMLStreamWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -7,7 +7,6 @@ * * SPDX-License-Identifier: BSD-3-Clause */ - package org.jvnet.staxex.util; import java.io.StringReader; @@ -25,368 +24,457 @@ import org.junit.Test; public class XMLStreamReaderToXMLStreamWriterTest { - - @Test - /** Tests that XMLStreamReaderToXMLStreamWriter.bridge does - * not send null namespace prefixes to the XMLStreamWriter because - * some writers used by us cannot handle the null prefix - * @throws XMLStreamException - */ - public void testNullNamespacePrefix() throws XMLStreamException { - XMLInputFactory infact = XMLInputFactory.newInstance(); - String xmlString = "" + - "" + - ""; - XMLStreamReader in = new XMLStreamReaderNullPrefix(infact.createXMLStreamReader(new StringReader(xmlString))); - StringWriter sw = new StringWriter(); - XMLStreamWriter out = new XMLStreamWriterNoNullPrefixes(XMLOutputFactory.newInstance().createXMLStreamWriter(sw)); - XMLStreamReaderToXMLStreamWriter readerToWriter = new XMLStreamReaderToXMLStreamWriter(); - readerToWriter.bridge(in, out); - } - - //Define a delegating XMLStreamReader that always returns null for empty prefix - //and a delegating XMLStreamWriter that chokes on null prefix - private static class XMLStreamWriterNoNullPrefixes implements XMLStreamWriter { - private XMLStreamWriter delegate; - - public XMLStreamWriterNoNullPrefixes(XMLStreamWriter delegate) { - this.delegate = delegate; - } - - public void close() throws XMLStreamException { - delegate.close(); - } - - public void flush() throws XMLStreamException { - delegate.flush(); - } - - public NamespaceContext getNamespaceContext() { - return delegate.getNamespaceContext(); - } - - public String getPrefix(String arg0) throws XMLStreamException { - return delegate.getPrefix(arg0); - } - - public Object getProperty(String arg0) throws IllegalArgumentException { - return delegate.getProperty(arg0); - } - - public void setDefaultNamespace(String arg0) throws XMLStreamException { - delegate.setDefaultNamespace(arg0); - } - - public void setNamespaceContext(NamespaceContext arg0) - throws XMLStreamException { - delegate.setNamespaceContext(arg0); - } - - public void setPrefix(String arg0, String arg1) - throws XMLStreamException { - delegate.setPrefix(arg0, arg1); - } - - public void writeAttribute(String arg0, String arg1, String arg2, - String arg3) throws XMLStreamException { - delegate.writeAttribute(arg0, arg1, arg2, arg3); - } - - public void writeAttribute(String arg0, String arg1, String arg2) - throws XMLStreamException { - delegate.writeAttribute(arg0, arg1, arg2); - } - - public void writeAttribute(String arg0, String arg1) - throws XMLStreamException { - delegate.writeAttribute(arg0, arg1); - } - - public void writeCData(String arg0) throws XMLStreamException { - delegate.writeCData(arg0); - } - - public void writeCharacters(char[] arg0, int arg1, int arg2) - throws XMLStreamException { - delegate.writeCharacters(arg0, arg1, arg2); - } - - public void writeCharacters(String arg0) throws XMLStreamException { - delegate.writeCharacters(arg0); - } - - public void writeComment(String arg0) throws XMLStreamException { - delegate.writeComment(arg0); - } - - public void writeDTD(String arg0) throws XMLStreamException { - delegate.writeDTD(arg0); - } - - public void writeDefaultNamespace(String arg0) - throws XMLStreamException { - delegate.writeDefaultNamespace(arg0); - } - - public void writeEmptyElement(String arg0, String arg1, String arg2) - throws XMLStreamException { - delegate.writeEmptyElement(arg0, arg1, arg2); - } - - public void writeEmptyElement(String arg0, String arg1) - throws XMLStreamException { - delegate.writeEmptyElement(arg0, arg1); - } - - public void writeEmptyElement(String arg0) throws XMLStreamException { - delegate.writeEmptyElement(arg0); - } - - public void writeEndDocument() throws XMLStreamException { - delegate.writeEndDocument(); - } - - public void writeEndElement() throws XMLStreamException { - delegate.writeEndElement(); - } - - public void writeEntityRef(String arg0) throws XMLStreamException { - delegate.writeEntityRef(arg0); - } - - public void writeNamespace(String prefix, String ns) - throws XMLStreamException { - if (prefix == null) throw new XMLStreamException("NS Prefix from XMLStreamReaderToXMLStreamWriter cannot be null!"); - delegate.writeNamespace(prefix, ns); - } - - public void writeProcessingInstruction(String arg0, String arg1) - throws XMLStreamException { - delegate.writeProcessingInstruction(arg0, arg1); - } - - public void writeProcessingInstruction(String arg0) - throws XMLStreamException { - delegate.writeProcessingInstruction(arg0); - } - - public void writeStartDocument() throws XMLStreamException { - delegate.writeStartDocument(); - } - - public void writeStartDocument(String arg0, String arg1) - throws XMLStreamException { - delegate.writeStartDocument(arg0, arg1); - } - - public void writeStartDocument(String arg0) throws XMLStreamException { - delegate.writeStartDocument(arg0); - } - - public void writeStartElement(String arg0, String arg1, String arg2) - throws XMLStreamException { - delegate.writeStartElement(arg0, arg1, arg2); - } - - public void writeStartElement(String arg0, String arg1) - throws XMLStreamException { - delegate.writeStartElement(arg0, arg1); - } - - public void writeStartElement(String arg0) throws XMLStreamException { - delegate.writeStartElement(arg0); - } - } - private static class XMLStreamReaderNullPrefix implements XMLStreamReader { - private XMLStreamReader delegate; - - public XMLStreamReaderNullPrefix(XMLStreamReader reader) { - delegate = reader; - } - - public void close() throws XMLStreamException { - delegate.close(); - } - - public int getAttributeCount() { - return delegate.getAttributeCount(); - } - - public String getAttributeLocalName(int arg0) { - return delegate.getAttributeLocalName(arg0); - } - - public QName getAttributeName(int arg0) { - return delegate.getAttributeName(arg0); - } - - public String getAttributeNamespace(int arg0) { - return delegate.getAttributeNamespace(arg0); - } - - public String getAttributePrefix(int arg0) { - return delegate.getAttributePrefix(arg0); - } - - public String getAttributeType(int arg0) { - return delegate.getAttributeType(arg0); - } - - public String getAttributeValue(int arg0) { - return delegate.getAttributeValue(arg0); - } - - public String getAttributeValue(String arg0, String arg1) { - return delegate.getAttributeValue(arg0, arg1); - } - - public String getCharacterEncodingScheme() { - return delegate.getCharacterEncodingScheme(); - } - - public String getElementText() throws XMLStreamException { - return delegate.getElementText(); - } - - public String getEncoding() { - return delegate.getEncoding(); - } - - public int getEventType() { - return delegate.getEventType(); - } - - public String getLocalName() { - return delegate.getLocalName(); - } - - public Location getLocation() { - return delegate.getLocation(); - } - - public QName getName() { - return delegate.getName(); - } - - public NamespaceContext getNamespaceContext() { - return delegate.getNamespaceContext(); - } - - public int getNamespaceCount() { - return delegate.getNamespaceCount(); - } - - public String getNamespacePrefix(int arg0) { - String prefix = delegate.getNamespacePrefix(arg0); - if ("".equals(prefix)) return null; - return prefix; - } - - public String getNamespaceURI() { - return delegate.getNamespaceURI(); - } - - public String getNamespaceURI(int arg0) { - return delegate.getNamespaceURI(arg0); - } - - public String getNamespaceURI(String arg0) { - return delegate.getNamespaceURI(arg0); - } - - public String getPIData() { - return delegate.getPIData(); - } - - public String getPITarget() { - return delegate.getPITarget(); - } - - public String getPrefix() { - return delegate.getPrefix(); - } - - public Object getProperty(String arg0) throws IllegalArgumentException { - return delegate.getProperty(arg0); - } - - public String getText() { - return delegate.getText(); - } - - public char[] getTextCharacters() { - return delegate.getTextCharacters(); - } - - public int getTextCharacters(int arg0, char[] arg1, int arg2, int arg3) - throws XMLStreamException { - return delegate.getTextCharacters(arg0, arg1, arg2, arg3); - } - - public int getTextLength() { - return delegate.getTextLength(); - } - - public int getTextStart() { - return delegate.getTextStart(); - } - - public String getVersion() { - return delegate.getVersion(); - } - - public boolean hasName() { - return delegate.hasName(); - } - - public boolean hasNext() throws XMLStreamException { - return delegate.hasNext(); - } - - public boolean hasText() { - return delegate.hasText(); - } - - public boolean isAttributeSpecified(int arg0) { - return delegate.isAttributeSpecified(arg0); - } - - public boolean isCharacters() { - return delegate.isCharacters(); - } - - public boolean isEndElement() { - return delegate.isEndElement(); - } - - public boolean isStandalone() { - return delegate.isStandalone(); - } - - public boolean isStartElement() { - return delegate.isStartElement(); - } - - public boolean isWhiteSpace() { - return delegate.isWhiteSpace(); - } - - public int next() throws XMLStreamException { - return delegate.next(); - } - - public int nextTag() throws XMLStreamException { - return delegate.nextTag(); - } - - public void require(int arg0, String arg1, String arg2) - throws XMLStreamException { - delegate.require(arg0, arg1, arg2); - } - - public boolean standaloneSet() { - return delegate.standaloneSet(); - } - } - + + public XMLStreamReaderToXMLStreamWriterTest() { + } + + /** + * Tests that XMLStreamReaderToXMLStreamWriter.bridge does not send null + * namespace prefixes to the XMLStreamWriter because some writers used by us + * cannot handle the null prefix + * + * @throws XMLStreamException + */ + @Test + public void testNullNamespacePrefix() throws XMLStreamException { + XMLInputFactory infact = XMLInputFactory.newInstance(); + String xmlString = "" + + "" + + ""; + XMLStreamReader in = new XMLStreamReaderNullPrefix(infact.createXMLStreamReader(new StringReader(xmlString))); + StringWriter sw = new StringWriter(); + XMLStreamWriter out = new XMLStreamWriterNoNullPrefixes(XMLOutputFactory.newInstance().createXMLStreamWriter(sw)); + XMLStreamReaderToXMLStreamWriter readerToWriter = new XMLStreamReaderToXMLStreamWriter(); + readerToWriter.bridge(in, out); + } + + //Define a delegating XMLStreamReader that always returns null for empty prefix + //and a delegating XMLStreamWriter that chokes on null prefix + private static class XMLStreamWriterNoNullPrefixes implements XMLStreamWriter { + + private XMLStreamWriter delegate; + + public XMLStreamWriterNoNullPrefixes(XMLStreamWriter delegate) { + this.delegate = delegate; + } + + @Override + public void close() throws XMLStreamException { + delegate.close(); + } + + @Override + public void flush() throws XMLStreamException { + delegate.flush(); + } + + @Override + public NamespaceContext getNamespaceContext() { + return delegate.getNamespaceContext(); + } + + @Override + public String getPrefix(String arg0) throws XMLStreamException { + return delegate.getPrefix(arg0); + } + + @Override + public Object getProperty(String arg0) throws IllegalArgumentException { + return delegate.getProperty(arg0); + } + + @Override + public void setDefaultNamespace(String arg0) throws XMLStreamException { + delegate.setDefaultNamespace(arg0); + } + + @Override + public void setNamespaceContext(NamespaceContext arg0) + throws XMLStreamException { + delegate.setNamespaceContext(arg0); + } + + @Override + public void setPrefix(String arg0, String arg1) + throws XMLStreamException { + delegate.setPrefix(arg0, arg1); + } + + @Override + public void writeAttribute(String arg0, String arg1, String arg2, + String arg3) throws XMLStreamException { + delegate.writeAttribute(arg0, arg1, arg2, arg3); + } + + @Override + public void writeAttribute(String arg0, String arg1, String arg2) + throws XMLStreamException { + delegate.writeAttribute(arg0, arg1, arg2); + } + + @Override + public void writeAttribute(String arg0, String arg1) + throws XMLStreamException { + delegate.writeAttribute(arg0, arg1); + } + + @Override + public void writeCData(String arg0) throws XMLStreamException { + delegate.writeCData(arg0); + } + + @Override + public void writeCharacters(char[] arg0, int arg1, int arg2) + throws XMLStreamException { + delegate.writeCharacters(arg0, arg1, arg2); + } + + @Override + public void writeCharacters(String arg0) throws XMLStreamException { + delegate.writeCharacters(arg0); + } + + @Override + public void writeComment(String arg0) throws XMLStreamException { + delegate.writeComment(arg0); + } + + @Override + public void writeDTD(String arg0) throws XMLStreamException { + delegate.writeDTD(arg0); + } + + @Override + public void writeDefaultNamespace(String arg0) + throws XMLStreamException { + delegate.writeDefaultNamespace(arg0); + } + + @Override + public void writeEmptyElement(String arg0, String arg1, String arg2) + throws XMLStreamException { + delegate.writeEmptyElement(arg0, arg1, arg2); + } + + @Override + public void writeEmptyElement(String arg0, String arg1) + throws XMLStreamException { + delegate.writeEmptyElement(arg0, arg1); + } + + @Override + public void writeEmptyElement(String arg0) throws XMLStreamException { + delegate.writeEmptyElement(arg0); + } + + @Override + public void writeEndDocument() throws XMLStreamException { + delegate.writeEndDocument(); + } + + @Override + public void writeEndElement() throws XMLStreamException { + delegate.writeEndElement(); + } + + @Override + public void writeEntityRef(String arg0) throws XMLStreamException { + delegate.writeEntityRef(arg0); + } + + @Override + public void writeNamespace(String prefix, String ns) + throws XMLStreamException { + if (prefix == null) { + throw new XMLStreamException("NS Prefix from XMLStreamReaderToXMLStreamWriter cannot be null!"); + } + delegate.writeNamespace(prefix, ns); + } + + @Override + public void writeProcessingInstruction(String arg0, String arg1) + throws XMLStreamException { + delegate.writeProcessingInstruction(arg0, arg1); + } + + @Override + public void writeProcessingInstruction(String arg0) + throws XMLStreamException { + delegate.writeProcessingInstruction(arg0); + } + + @Override + public void writeStartDocument() throws XMLStreamException { + delegate.writeStartDocument(); + } + + @Override + public void writeStartDocument(String arg0, String arg1) + throws XMLStreamException { + delegate.writeStartDocument(arg0, arg1); + } + + @Override + public void writeStartDocument(String arg0) throws XMLStreamException { + delegate.writeStartDocument(arg0); + } + + @Override + public void writeStartElement(String arg0, String arg1, String arg2) + throws XMLStreamException { + delegate.writeStartElement(arg0, arg1, arg2); + } + + @Override + public void writeStartElement(String arg0, String arg1) + throws XMLStreamException { + delegate.writeStartElement(arg0, arg1); + } + + @Override + public void writeStartElement(String arg0) throws XMLStreamException { + delegate.writeStartElement(arg0); + } + } + + private static class XMLStreamReaderNullPrefix implements XMLStreamReader { + + private XMLStreamReader delegate; + + public XMLStreamReaderNullPrefix(XMLStreamReader reader) { + delegate = reader; + } + + @Override + public void close() throws XMLStreamException { + delegate.close(); + } + + @Override + public int getAttributeCount() { + return delegate.getAttributeCount(); + } + + @Override + public String getAttributeLocalName(int arg0) { + return delegate.getAttributeLocalName(arg0); + } + + @Override + public QName getAttributeName(int arg0) { + return delegate.getAttributeName(arg0); + } + + @Override + public String getAttributeNamespace(int arg0) { + return delegate.getAttributeNamespace(arg0); + } + + @Override + public String getAttributePrefix(int arg0) { + return delegate.getAttributePrefix(arg0); + } + + @Override + public String getAttributeType(int arg0) { + return delegate.getAttributeType(arg0); + } + + @Override + public String getAttributeValue(int arg0) { + return delegate.getAttributeValue(arg0); + } + + @Override + public String getAttributeValue(String arg0, String arg1) { + return delegate.getAttributeValue(arg0, arg1); + } + + @Override + public String getCharacterEncodingScheme() { + return delegate.getCharacterEncodingScheme(); + } + + @Override + public String getElementText() throws XMLStreamException { + return delegate.getElementText(); + } + + @Override + public String getEncoding() { + return delegate.getEncoding(); + } + + @Override + public int getEventType() { + return delegate.getEventType(); + } + + @Override + public String getLocalName() { + return delegate.getLocalName(); + } + + @Override + public Location getLocation() { + return delegate.getLocation(); + } + + @Override + public QName getName() { + return delegate.getName(); + } + + @Override + public NamespaceContext getNamespaceContext() { + return delegate.getNamespaceContext(); + } + + @Override + public int getNamespaceCount() { + return delegate.getNamespaceCount(); + } + + @Override + public String getNamespacePrefix(int arg0) { + String prefix = delegate.getNamespacePrefix(arg0); + if ("".equals(prefix)) { + return null; + } + return prefix; + } + + @Override + public String getNamespaceURI() { + return delegate.getNamespaceURI(); + } + + @Override + public String getNamespaceURI(int arg0) { + return delegate.getNamespaceURI(arg0); + } + + @Override + public String getNamespaceURI(String arg0) { + return delegate.getNamespaceURI(arg0); + } + + @Override + public String getPIData() { + return delegate.getPIData(); + } + + @Override + public String getPITarget() { + return delegate.getPITarget(); + } + + @Override + public String getPrefix() { + return delegate.getPrefix(); + } + + @Override + public Object getProperty(String arg0) throws IllegalArgumentException { + return delegate.getProperty(arg0); + } + + @Override + public String getText() { + return delegate.getText(); + } + + @Override + public char[] getTextCharacters() { + return delegate.getTextCharacters(); + } + + @Override + public int getTextCharacters(int arg0, char[] arg1, int arg2, int arg3) + throws XMLStreamException { + return delegate.getTextCharacters(arg0, arg1, arg2, arg3); + } + + @Override + public int getTextLength() { + return delegate.getTextLength(); + } + + @Override + public int getTextStart() { + return delegate.getTextStart(); + } + + @Override + public String getVersion() { + return delegate.getVersion(); + } + + @Override + public boolean hasName() { + return delegate.hasName(); + } + + @Override + public boolean hasNext() throws XMLStreamException { + return delegate.hasNext(); + } + + @Override + public boolean hasText() { + return delegate.hasText(); + } + + @Override + public boolean isAttributeSpecified(int arg0) { + return delegate.isAttributeSpecified(arg0); + } + + @Override + public boolean isCharacters() { + return delegate.isCharacters(); + } + + @Override + public boolean isEndElement() { + return delegate.isEndElement(); + } + + @Override + public boolean isStandalone() { + return delegate.isStandalone(); + } + + @Override + public boolean isStartElement() { + return delegate.isStartElement(); + } + + @Override + public boolean isWhiteSpace() { + return delegate.isWhiteSpace(); + } + + @Override + public int next() throws XMLStreamException { + return delegate.next(); + } + + @Override + public int nextTag() throws XMLStreamException { + return delegate.nextTag(); + } + + @Override + public void require(int arg0, String arg1, String arg2) + throws XMLStreamException { + delegate.require(arg0, arg1, arg2); + } + + @Override + public boolean standaloneSet() { + return delegate.standaloneSet(); + } + } + }