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 2011/04/03 23:30:51 UTC
svn commit: r1088419 [1/2] - in
/webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/impl/
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-api/src/mai...
Author: veithen
Date: Sun Apr 3 21:30:50 2011
New Revision: 1088419
URL: http://svn.apache.org/viewvc?rev=1088419&view=rev
Log:
Attempt to resolve the inconsistencies related to charset encoding in XML declaration vs. charset encoding used when parsing the document.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDocument.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLFragmentStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/mtom/MTOMAttachmentStream_inlined.xml
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/CharacterEncoding2Test.java
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDocument.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDocument.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDocument.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDocument.java Sun Apr 3 21:30:50 2011
@@ -46,6 +46,23 @@ public interface OMDocument extends OMCo
void setOMDocumentElement(OMElement rootElement);
/**
+ * Get the character set encoding scheme. This is the encoding that was used used for this
+ * document at the time of the parsing. This is <code>null</code> when it is not known, such as
+ * when the document was created in memory or from a character stream.
+ *
+ * @return the charset encoding for this document, or <code>null</code> if the encoding is not
+ * known
+ */
+ String getCharsetEncoding();
+
+ /**
+ * Sets the character set encoding scheme to be used.
+ *
+ * @param charsetEncoding
+ */
+ void setCharsetEncoding(String charsetEncoding);
+
+ /**
* Returns the XML version.
*
* @return Returns String.
@@ -62,19 +79,22 @@ public interface OMDocument extends OMCo
void setXMLVersion(String version);
/**
- * Returns the character set encoding scheme.
- *
- * @return Returns String.
+ * Get the charset encoding of this document as specified in the XML declaration.
+ *
+ * @return the charset encoding specified in the XML declaration, or <code>null</code> if the
+ * document didn't have an XML declaration or if the <code>encoding</code> attribute was
+ * not specified in the XML declaration
*/
- String getCharsetEncoding();
+ String getXMLEncoding();
/**
- * Sets the character set encoding scheme to be used.
- *
- * @param charsetEncoding
+ * Set the charset encoding for the XML declaration of this document.
+ *
+ * @param encoding
+ * the value of the <code>encoding</code> attribute of the XML declaration
*/
- void setCharsetEncoding(String charsetEncoding);
-
+ void setXMLEncoding(String encoding);
+
/**
* XML standalone value. This will be yes, no or null (if not available)
*
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java Sun Apr 3 21:30:50 2011
@@ -1187,7 +1187,19 @@ class SwitchingWrapper extends AbstractX
* @return Returns String.
*/
public String getEncoding() {
- return null;
+ if (parser != null) {
+ return parser.getEncoding();
+ } else {
+ if (currentEvent == START_DOCUMENT) {
+ if (lastNode instanceof OMDocument) {
+ return ((OMDocument)lastNode).getCharsetEncoding();
+ } else {
+ return null;
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
}
/**
@@ -1232,10 +1244,19 @@ class SwitchingWrapper extends AbstractX
* @return Returns String.
*/
public String getCharacterEncodingScheme() {
- if(builder != null) {
- return builder.getCharacterEncoding();
+ if (parser != null) {
+ return parser.getCharacterEncodingScheme();
+ } else {
+ if (currentEvent == START_DOCUMENT) {
+ if (lastNode instanceof OMDocument) {
+ return ((OMDocument)lastNode).getXMLEncoding();
+ } else {
+ return null;
+ }
+ } else {
+ throw new IllegalStateException();
+ }
}
- return "utf-8";
}
/**
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Sun Apr 3 21:30:50 2011
@@ -121,12 +121,8 @@ public abstract class StAXBuilder implem
protected StAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {
omfactory = ombuilderFactory;
- // The getCharacterEncodingScheme and getEncoding information are
- // only available at the START_DOCUMENT event.
- charEncoding = parser.getCharacterEncodingScheme();
- if(charEncoding == null){
- charEncoding = parser.getEncoding();
- }
+ // The getEncoding information is only available at the START_DOCUMENT event.
+ charEncoding = parser.getEncoding();
initParser(parser);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Sun Apr 3 21:30:50 2011
@@ -187,6 +187,7 @@ public class StAXOMBuilder extends StAXB
}
if (parser.getEventType() == XMLStreamConstants.START_DOCUMENT) {
document.setXMLVersion(parser.getVersion());
+ document.setXMLEncoding(parser.getCharacterEncodingScheme());
document.setStandalone(parser.isStandalone() ? "yes" : "no");
} else {
// We allow creating a StAXOMWrapper from a parser in state START_ELEMENT. In that
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilder.java Sun Apr 3 21:30:50 2011
@@ -326,6 +326,10 @@ public class StAXSOAPModelBuilder extend
// create a SOAPMessage to hold the SOAP envelope and assign the SOAP envelope in that.
soapMessage = soapFactory.createSOAPMessage(this);
+ // TODO: this needs to be reviewed; why do we create an OMDocument in StAXOMBuilder and
+ // then replace it here
+ OMDocument orgDocument = this.document;
+ soapMessage.setXMLEncoding(orgDocument.getXMLEncoding());
this.document = soapMessage;
if (charEncoding != null) {
document.setCharsetEncoding(charEncoding);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLFragmentStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLFragmentStreamReader.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLFragmentStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLFragmentStreamReader.java Sun Apr 3 21:30:50 2011
@@ -160,11 +160,19 @@ public class XMLFragmentStreamReader imp
}
public String getCharacterEncodingScheme() {
- return "UTF-8";
+ if (state == STATE_START_DOCUMENT) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
}
public String getEncoding() {
- return "UTF-8";
+ if (state == STATE_START_DOCUMENT) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
}
public String getVersion() {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java?rev=1088419&r1=1088418&r2=1088419&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java Sun Apr 3 21:30:50 2011
@@ -29,12 +29,29 @@ import org.apache.axiom.util.stax.wrappe
* root level information items other than elements.
*/
public class DocumentElementExtractor extends XMLStreamReaderWrapper {
+ private int event = START_DOCUMENT;
private int depth;
public DocumentElementExtractor(XMLStreamReader parent) {
super(parent);
}
+ public String getCharacterEncodingScheme() {
+ if (event == START_DOCUMENT) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getEncoding() {
+ if (event == START_DOCUMENT) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
public int next() throws XMLStreamException {
int event;
loop: while (true) {