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 2012/08/20 22:47:10 UTC
svn commit: r1375212 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/
Author: veithen
Date: Mon Aug 20 20:47:10 2012
New Revision: 1375212
URL: http://svn.apache.org/viewvc?rev=1375212&view=rev
Log:
AXIOM-435: Correctly support entity references that have a replacement value containing markup.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1375212&r1=1375211&r2=1375212&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Mon Aug 20 20:47:10 2012
@@ -275,10 +275,12 @@ public class SAXOMBuilder extends Defaul
*/
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
- if (nextElem == null) {
- nextElem = createNextElement("DUMMY");
+ if (!inEntityReference) {
+ if (nextElem == null) {
+ nextElem = createNextElement("DUMMY");
+ }
+ ((OMElementEx)nextElem).addNamespaceDeclaration(uri, prefix);
}
- ((OMElementEx)nextElem).addNamespaceDeclaration(uri, prefix);
}
public void endPrefixMapping(String prefix) throws SAXException {
@@ -292,49 +294,51 @@ public class SAXOMBuilder extends Defaul
*/
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
- if (localName == null || localName.trim().equals(""))
- localName = qName.substring(qName.indexOf(':') + 1);
- if (nextElem == null)
- nextElem = createNextElement(localName);
- else
- nextElem.setLocalName(localName);
-
- int idx = qName.indexOf(':');
- String prefix = idx == -1 ? "" : qName.substring(0, idx);
- BuilderUtil.setNamespace(nextElem, namespaceURI, prefix, false);
-
- int j = atts.getLength();
- for (int i = 0; i < j; i++) {
- // Note that some SAX parsers report namespace declarations as attributes in addition
- // to calling start/endPrefixMapping.
- // NOTE: This filter was introduced to make SAXOMBuilder work with some versions of
- // XMLBeans (2.3.0). It is not clear whether this is a bug in XMLBeans or not.
- // See http://forum.springframework.org/showthread.php?t=43958 for a discussion.
- // If this test causes problems with other parsers, don't hesitate to remove it.
- if (!atts.getQName(i).startsWith("xmlns")) {
- String attrNamespaceURI = atts.getURI(i);
- OMNamespace ns;
- if (attrNamespaceURI.length() > 0) {
- ns = nextElem.findNamespace(atts.getURI(i), null);
- if (ns == null) {
- // The "xml" prefix is not necessarily declared explicitly; in this case,
- // create a new OMNamespace instance.
- if (attrNamespaceURI.equals(XMLConstants.XML_NS_URI)) {
- ns = factory.createOMNamespace(XMLConstants.XML_NS_URI, XMLConstants.XML_NS_PREFIX);
- } else {
- throw new SAXException("Unbound namespace " + attrNamespaceURI);
+ if (!inEntityReference) {
+ if (localName == null || localName.trim().equals(""))
+ localName = qName.substring(qName.indexOf(':') + 1);
+ if (nextElem == null)
+ nextElem = createNextElement(localName);
+ else
+ nextElem.setLocalName(localName);
+
+ int idx = qName.indexOf(':');
+ String prefix = idx == -1 ? "" : qName.substring(0, idx);
+ BuilderUtil.setNamespace(nextElem, namespaceURI, prefix, false);
+
+ int j = atts.getLength();
+ for (int i = 0; i < j; i++) {
+ // Note that some SAX parsers report namespace declarations as attributes in addition
+ // to calling start/endPrefixMapping.
+ // NOTE: This filter was introduced to make SAXOMBuilder work with some versions of
+ // XMLBeans (2.3.0). It is not clear whether this is a bug in XMLBeans or not.
+ // See http://forum.springframework.org/showthread.php?t=43958 for a discussion.
+ // If this test causes problems with other parsers, don't hesitate to remove it.
+ if (!atts.getQName(i).startsWith("xmlns")) {
+ String attrNamespaceURI = atts.getURI(i);
+ OMNamespace ns;
+ if (attrNamespaceURI.length() > 0) {
+ ns = nextElem.findNamespace(atts.getURI(i), null);
+ if (ns == null) {
+ // The "xml" prefix is not necessarily declared explicitly; in this case,
+ // create a new OMNamespace instance.
+ if (attrNamespaceURI.equals(XMLConstants.XML_NS_URI)) {
+ ns = factory.createOMNamespace(XMLConstants.XML_NS_URI, XMLConstants.XML_NS_PREFIX);
+ } else {
+ throw new SAXException("Unbound namespace " + attrNamespaceURI);
+ }
}
+ } else {
+ ns = null;
}
- } else {
- ns = null;
+ OMAttribute attr = nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i), ns);
+ attr.setAttributeType(atts.getType(i));
}
- OMAttribute attr = nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i), ns);
- attr.setAttributeType(atts.getType(i));
}
+
+ lastNode = nextElem;
+ nextElem = null;
}
-
- lastNode = nextElem;
- nextElem = null;
}
/*
@@ -345,27 +349,35 @@ public class SAXOMBuilder extends Defaul
*/
public void endElement(String uri, String localName, String qName)
throws SAXException {
- if (lastNode.isComplete()) {
- OMContainer parent = lastNode.getParent();
- ((OMNodeEx) parent).setComplete(true);
- lastNode = (OMNode) parent;
- } else {
- OMElement e = (OMElement) lastNode;
- ((OMNodeEx) e).setComplete(true);
+ if (!inEntityReference) {
+ if (lastNode.isComplete()) {
+ OMContainer parent = lastNode.getParent();
+ ((OMNodeEx) parent).setComplete(true);
+ lastNode = (OMNode) parent;
+ } else {
+ OMElement e = (OMElement) lastNode;
+ ((OMNodeEx) e).setComplete(true);
+ }
}
}
public void startCDATA() throws SAXException {
- textNodeType = OMNode.CDATA_SECTION_NODE;
+ if (!inEntityReference) {
+ textNodeType = OMNode.CDATA_SECTION_NODE;
+ }
}
public void endCDATA() throws SAXException {
- textNodeType = OMNode.TEXT_NODE;
+ if (!inEntityReference) {
+ textNodeType = OMNode.TEXT_NODE;
+ }
}
public void characterData(char[] ch, int start, int length, int nodeType)
throws SAXException {
- addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType, true));
+ if (!inEntityReference) {
+ addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType, true));
+ }
}
public void characters(char[] ch, int start, int length)
@@ -377,20 +389,26 @@ public class SAXOMBuilder extends Defaul
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
- characterData(ch, start, length, OMNode.SPACE_NODE);
+ if (!inEntityReference) {
+ characterData(ch, start, length, OMNode.SPACE_NODE);
+ }
}
public void processingInstruction(String target, String data)
throws SAXException {
- addNode(factory.createOMProcessingInstruction(getContainer(), target, data, true));
+ if (!inEntityReference) {
+ addNode(factory.createOMProcessingInstruction(getContainer(), target, data, true));
+ }
}
public void comment(char[] ch, int start, int length) throws SAXException {
- if (lastNode == null) {
- // Do nothing: the comment appears before the root element.
- return;
- }
- addNode(factory.createOMComment(getContainer(), new String(ch, start, length), true));
+ if (!inEntityReference) {
+ if (lastNode == null) {
+ // Do nothing: the comment appears before the root element.
+ return;
+ }
+ addNode(factory.createOMComment(getContainer(), new String(ch, start, length), true));
+ }
}
public void skippedEntity(String name) throws SAXException {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml?rev=1375212&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml Mon Aug 20 20:47:10 2012
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!DOCTYPE root [
+ <!ENTITY testentref "<child><!--comment--><?pi test?></child>">
+ <!ELEMENT root (child)>
+ <!ELEMENT child (#PCDATA)>
+]>
+<root>
+ &testentref;
+</root>
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/resources/org/apache/axiom/testutils/conformance/entity-reference-with-markup.xml
------------------------------------------------------------------------------
svn:eol-style = native