SWS-434
This commit is contained in:
@@ -147,13 +147,20 @@ class AxiomHandler implements ContentHandler, LexicalHandler {
|
||||
}
|
||||
|
||||
public void startEntity(String name) throws SAXException {
|
||||
charactersType = XMLStreamConstants.ENTITY_REFERENCE;
|
||||
if (!isPredefinedEntityReference(name)) {
|
||||
charactersType = XMLStreamConstants.ENTITY_REFERENCE;
|
||||
}
|
||||
}
|
||||
|
||||
public void endEntity(String name) throws SAXException {
|
||||
charactersType = XMLStreamConstants.CHARACTERS;
|
||||
}
|
||||
|
||||
private boolean isPredefinedEntityReference(String name) {
|
||||
return "lt".equals(name) || "gt".equals(name) || "amp".equals(name) || "quot".equals(name) ||
|
||||
"apos".equals(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unsupported
|
||||
*/
|
||||
|
||||
@@ -31,17 +31,21 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
public class AxiomHandlerTest extends XMLTestCase {
|
||||
|
||||
private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" +
|
||||
"<root xmlns='namespace'>" +
|
||||
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
|
||||
"</root>";
|
||||
private static final String XML_1 =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" + "<root xmlns='namespace'>" +
|
||||
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
|
||||
"</root>";
|
||||
|
||||
private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" +
|
||||
"<child xmlns='namespace2' />" + "</root>";
|
||||
private static final String XML_2_EXPECTED =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" + "<child xmlns='namespace2' />" +
|
||||
"</root>";
|
||||
|
||||
private static final String XML_2_SNIPPET =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
|
||||
|
||||
private static final String XML_3_ENTITY =
|
||||
"<predefined-entity-reference><>&"'</predefined-entity-reference>";
|
||||
|
||||
private AxiomHandler handler;
|
||||
|
||||
private OMDocument result;
|
||||
@@ -87,4 +91,14 @@ public class AxiomHandlerTest extends XMLTestCase {
|
||||
result.serialize(bos);
|
||||
assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
public void testContentHandlerPredefinedEntityReference() throws Exception {
|
||||
handler = new AxiomHandler(result, factory);
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_3_ENTITY)));
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
result.serialize(bos);
|
||||
assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user