Skip to content

Commit aa14469

Browse files
committed
scripting: assume XMLBeans 5.x, replace call to getXmlObject with toXMLString
1 parent 1afcdae commit aa14469

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,29 @@ public OMElement fromScript(Object o) {
8787
// If we have an XMLObject but not a wrapped XmlObject, try the old approach
8888
if (xmlObject == null && o instanceof XMLObject) {
8989
// TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
90-
Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
91-
90+
XMLObject jsXML = (XMLObject) ScriptableObject.callMethod((XMLObject) o, "copy", new Object[0]);
91+
92+
// get proper XML representation from toXMLString()
93+
String xmlString;
9294
try {
93-
// Try the old API first (getXmlObject)
94-
Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
95-
xmlObject = (XmlObject)wrapper.unwrap();
96-
} catch (Exception e) {
97-
// Fallback for XMLBeans 5.x: use toXMLString() to get proper XML representation
98-
String xmlString = null;
99-
try {
100-
// Try toXMLString() method first
101-
xmlString = (String) ScriptableObject.callMethod((XMLObject)jsXML, "toXMLString", new Object[0]);
102-
} catch (Exception toXMLException) {
103-
// If toXMLString() doesn't work, try toString()
104-
xmlString = ((XMLObject) jsXML).toString();
105-
}
106-
107-
// Remove extra whitespace to match expected format
108-
String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
109-
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
110-
new java.io.StringReader(normalizedXML));
111-
OMElement omElement = builder.getDocumentElement();
112-
return omElement;
95+
// Try toXMLString() method first
96+
xmlString = (String) ScriptableObject.callMethod(jsXML, "toXMLString", new Object[0]);
97+
} catch (Exception toXMLException) {
98+
// If toXMLString() doesn't work, try toString()
99+
xmlString = jsXML.toString();
113100
}
101+
102+
// Remove extra whitespace to match expected format
103+
String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
104+
return OMXMLBuilderFactory
105+
.createOMBuilder(new java.io.StringReader(normalizedXML))
106+
.getDocumentElement();
114107
}
115108

116109
if (xmlObject != null) {
117-
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(xmlObject.newInputStream());
118-
OMElement omElement = builder.getDocumentElement();
119-
return omElement;
110+
return OMXMLBuilderFactory
111+
.createOMBuilder(xmlObject.newInputStream())
112+
.getDocumentElement();
120113
} else {
121114
throw new RuntimeException("Unable to extract XmlObject from JavaScript object");
122115
}
@@ -125,5 +118,4 @@ public OMElement fromScript(Object o) {
125118
throw new RuntimeException("Failed to convert JavaScript XML to OMElement: " + e.getMessage(), e);
126119
}
127120
}
128-
129121
}

0 commit comments

Comments
 (0)