Author: veithen
Date: Fri Aug 7 21:46:30 2009
New Revision: 802234
URL: http://svn.apache.org/viewvc?rev=802234&view=rev
Log:
Changed the normalization for the createXMLStreamWriter and writeStartDocument
methods so that they throw an exception when a null encoding is passed as
argument.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java
(with props)
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPStreamWriterWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxDialect.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXDialectTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
Fri Aug 7 21:46:30 2009
@@ -48,7 +48,11 @@
if (version == null) {
version = "1.0";
}
- writer.getXmlStreamWriter().writeStartDocument(encoding, version);
+ if (encoding == null) {
+ writer.getXmlStreamWriter().writeStartDocument(version);
+ } else {
+ writer.getXmlStreamWriter().writeStartDocument(encoding,
version);
+ }
}
Iterator children = document.getChildren();
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
Fri Aug 7 21:46:30 2009
@@ -52,7 +52,10 @@
}
public XMLStreamWriter normalize(XMLStreamWriter writer) {
- return new BEAStreamWriterWrapper(writer);
+ // The stream writer implementation of the reference implementation
doesn't handle masked
+ // namespace bindings correctly. We wrap the writer in a
+ // NamespaceContextCorrectingXMLStreamWriterWrapper to work around
this problem.
+ return new NamespaceContextCorrectingXMLStreamWriterWrapper(writer);
}
public XMLInputFactory normalize(XMLInputFactory factory) {
@@ -60,6 +63,6 @@
}
public XMLOutputFactory normalize(XMLOutputFactory factory) {
- return new BEAOutputFactoryWrapper(factory, this);
+ return new NormalizingXMLOutputFactoryWrapper(factory, this);
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPDialect.java
Fri Aug 7 21:46:30 2009
@@ -60,6 +60,6 @@
}
public XMLOutputFactory normalize(XMLOutputFactory factory) {
- return new NormalizingXMLOutputFactoryWrapper(factory, this);
+ return new SJSXPOutputFactoryWrapper(factory, this);
}
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java?rev=802234&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java
Fri Aug 7 21:46:30 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.dialect;
+
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+class SJSXPOutputFactoryWrapper extends NormalizingXMLOutputFactoryWrapper {
+ public SJSXPOutputFactoryWrapper(XMLOutputFactory parent,
AbstractStAXDialect dialect) {
+ super(parent, dialect);
+ }
+
+ public XMLEventWriter createXMLEventWriter(OutputStream stream, String
encoding)
+ throws XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ return super.createXMLEventWriter(stream, encoding);
+ }
+ }
+
+ public XMLStreamWriter createXMLStreamWriter(OutputStream stream, String
encoding)
+ throws XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ return super.createXMLStreamWriter(stream, encoding);
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPOutputFactoryWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPStreamWriterWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPStreamWriterWrapper.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPStreamWriterWrapper.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/SJSXPStreamWriterWrapper.java
Fri Aug 7 21:46:30 2009
@@ -19,6 +19,7 @@
package org.apache.axiom.util.stax.dialect;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper;
@@ -28,6 +29,14 @@
super(parent);
}
+ public void writeStartDocument(String encoding, String version) throws
XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ super.writeStartDocument(encoding, version);
+ }
+ }
+
public Object getProperty(String name) throws IllegalArgumentException {
// When no properties have been set on the writer, getProperty throws a
// NullPointerException; see
https://sjsxp.dev.java.net/issues/show_bug.cgi?id=28
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
Fri Aug 7 21:46:30 2009
@@ -36,13 +36,14 @@
* for the charset encoding parameter in the following methods:
* <ul>
* <li>{...@link
XMLOutputFactory#createXMLEventWriter(java.io.OutputStream, String)}</li>
+ * <li>{...@link
XMLOutputFactory#createXMLStreamWriter(java.io.OutputStream, String)}</li>
* <li>{...@link
javax.xml.stream.XMLStreamWriter#writeStartDocument(String, String)}</li>
* </ul>
- * Most implementations accept <code>null</code> values, but some throw a
- * {...@link NullPointerException}. To avoid portability issues, the
dialect implementation
- * normalizes the behavior of these methods so that they accept
<code>null</code> values
- * (in which case the methods will delegate to the corresponding
variants without
- * charset encoding parameter).</li>
+ * Some implementations accept <code>null</code> values, while others
throw an exception.
+ * To make sure that code written to run with a normalized {...@link
XMLOutputFactory} remains
+ * portable, the dialect implementation normalizes the behavior of these
methods so that they
+ * consistently throw an exception when called with a <code>null</code>
encoding. Note that
+ * the type of exception to be thrown remains unspecified.</li>
* <li>The StAX specifications require that {...@link
javax.xml.stream.XMLStreamReader#getEncoding()}
* returns the "input encoding if known or <code>null</code> if
unknown". This requirement
* is not precise enough to guarantee consistent behavior across
different implementations.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxDialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxDialect.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxDialect.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxDialect.java
Fri Aug 7 21:46:30 2009
@@ -51,7 +51,7 @@
}
public XMLStreamWriter normalize(XMLStreamWriter writer) {
- return writer;
+ return new WoodstoxStreamWriterWrapper(writer);
}
public XMLInputFactory normalize(XMLInputFactory factory) {
@@ -59,6 +59,6 @@
}
public XMLOutputFactory normalize(XMLOutputFactory factory) {
- return factory;
+ return new WoodstoxOutputFactoryWrapper(factory, this);
}
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java?rev=802234&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java
Fri Aug 7 21:46:30 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.dialect;
+
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+class WoodstoxOutputFactoryWrapper extends NormalizingXMLOutputFactoryWrapper {
+ public WoodstoxOutputFactoryWrapper(XMLOutputFactory parent,
AbstractStAXDialect dialect) {
+ super(parent, dialect);
+ }
+
+ public XMLEventWriter createXMLEventWriter(OutputStream stream, String
encoding)
+ throws XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ return super.createXMLEventWriter(stream, encoding);
+ }
+ }
+
+ public XMLStreamWriter createXMLStreamWriter(OutputStream stream, String
encoding)
+ throws XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ return super.createXMLStreamWriter(stream, encoding);
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxOutputFactoryWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java?rev=802234&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java
Fri Aug 7 21:46:30 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.dialect;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper;
+
+class WoodstoxStreamWriterWrapper extends XMLStreamWriterWrapper {
+ public WoodstoxStreamWriterWrapper(XMLStreamWriter parent) {
+ super(parent);
+ }
+
+ public void writeStartDocument(String encoding, String version) throws
XMLStreamException {
+ if (encoding == null) {
+ throw new IllegalArgumentException();
+ } else {
+ super.writeStartDocument(encoding, version);
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/WoodstoxStreamWriterWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
Fri Aug 7 21:46:30 2009
@@ -106,13 +106,6 @@
});
}
- public void testCreateXMLStreamWriterWithNullEncoding() throws Exception {
- // This should not cause a NullPointerException
- XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(System.out,
null);
- writer.writeEmptyElement("root");
- writer.close();
- }
-
public void testInputFactoryIsImmutable() throws Exception {
try {
StAXUtils.getXMLInputFactory().setProperty("javax.xml.stream.isValidating",
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXDialectTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXDialectTest.java?rev=802234&r1=802233&r2=802234&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXDialectTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXDialectTest.java
Fri Aug 7 21:46:30 2009
@@ -23,12 +23,37 @@
import java.io.StringReader;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
import junit.framework.TestCase;
import org.apache.axiom.om.util.StAXUtils;
public class StAXDialectTest extends TestCase {
+ public void testCreateXMLStreamWriterWithNullEncoding() {
+ // This should cause an exception
+ try {
+ StAXUtils.createXMLStreamWriter(System.out, null);
+ } catch (Throwable ex) {
+ // Expected
+ return;
+ }
+ // Attention here: since the fail method works by throwing an
exception and we
+ // catch Throwable, it must be invoked outside of the catch block!
+ fail("Expected createXMLStreamWriter to throw an exception");
+ }
+
+ public void testWriteStartDocumentWithNullEncoding() throws Exception {
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(System.out,
"UTF-8");
+ try {
+ writer.writeStartDocument(null, "1.0");
+ } catch (Throwable ex) {
+ // Expected
+ return;
+ }
+ fail("Expected writeStartDocument to throw an exception");
+ }
+
public void testGetEncoding() throws Exception {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new
ByteArrayInputStream(
"<?xml version='1.0'
encoding='iso-8859-15'?><root/>".getBytes("iso-8859-15")));