use of org.xml.sax.ext.LexicalHandler in project spring-framework by spring-projects.
the class AbstractStaxXMLReaderTestCase method lexicalHandler.
@Test
public void lexicalHandler() throws Exception {
Resource testLexicalHandlerXml = new ClassPathResource("testLexicalHandler.xml", getClass());
LexicalHandler expectedLexicalHandler = mockLexicalHandler();
standardReader.setContentHandler(null);
standardReader.setProperty("http://xml.org/sax/properties/lexical-handler", expectedLexicalHandler);
standardReader.parse(new InputSource(testLexicalHandlerXml.getInputStream()));
inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.FALSE);
inputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE);
inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
LexicalHandler actualLexicalHandler = mockLexicalHandler();
willAnswer(invocation -> invocation.getArguments()[0] = "element").given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString());
AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream());
staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler);
staxXmlReader.parse(new InputSource());
// TODO: broken comparison since Mockito 2.2 upgrade
// verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler);
}
use of org.xml.sax.ext.LexicalHandler in project j2objc by google.
the class DOM3TreeWalker method traverse.
/**
* Perform a pre-order traversal non-recursive style.
*
* Note that TreeWalker assumes that the subtree is intended to represent
* a complete (though not necessarily well-formed) document and, during a
* traversal, startDocument and endDocument will always be issued to the
* SAX listener.
*
* @param pos Node in the tree where to start traversal
*
* @throws TransformerException
*/
public void traverse(Node pos) throws org.xml.sax.SAXException {
this.fSerializer.startDocument();
// Determine if the Node is a DOM Level 3 Core Node.
if (pos.getNodeType() != Node.DOCUMENT_NODE) {
Document ownerDoc = pos.getOwnerDocument();
if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
fIsLevel3DOM = true;
}
} else {
if (((Document) pos).getImplementation().hasFeature("Core", "3.0")) {
fIsLevel3DOM = true;
}
}
if (fSerializer instanceof LexicalHandler) {
fLexicalHandler = ((LexicalHandler) this.fSerializer);
}
if (fFilter != null)
fWhatToShowFilter = fFilter.getWhatToShow();
Node top = pos;
while (null != pos) {
startNode(pos);
Node nextNode = null;
nextNode = pos.getFirstChild();
while (null == nextNode) {
endNode(pos);
if (top.equals(pos))
break;
nextNode = pos.getNextSibling();
if (null == nextNode) {
pos = pos.getParentNode();
if ((null == pos) || (top.equals(pos))) {
if (null != pos)
endNode(pos);
nextNode = null;
break;
}
}
}
pos = nextNode;
}
this.fSerializer.endDocument();
}
use of org.xml.sax.ext.LexicalHandler in project robovm by robovm.
the class DOM3TreeWalker method traverse.
/**
* Perform a pre-order traversal non-recursive style.
*
* Note that TreeWalker assumes that the subtree is intended to represent
* a complete (though not necessarily well-formed) document and, during a
* traversal, startDocument and endDocument will always be issued to the
* SAX listener.
*
* @param pos Node in the tree where to start traversal
*
* @throws TransformerException
*/
public void traverse(Node pos) throws org.xml.sax.SAXException {
this.fSerializer.startDocument();
// Determine if the Node is a DOM Level 3 Core Node.
if (pos.getNodeType() != Node.DOCUMENT_NODE) {
Document ownerDoc = pos.getOwnerDocument();
if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
fIsLevel3DOM = true;
}
} else {
if (((Document) pos).getImplementation().hasFeature("Core", "3.0")) {
fIsLevel3DOM = true;
}
}
if (fSerializer instanceof LexicalHandler) {
fLexicalHandler = ((LexicalHandler) this.fSerializer);
}
if (fFilter != null)
fWhatToShowFilter = fFilter.getWhatToShow();
Node top = pos;
while (null != pos) {
startNode(pos);
Node nextNode = null;
nextNode = pos.getFirstChild();
while (null == nextNode) {
endNode(pos);
if (top.equals(pos))
break;
nextNode = pos.getNextSibling();
if (null == nextNode) {
pos = pos.getParentNode();
if ((null == pos) || (top.equals(pos))) {
if (null != pos)
endNode(pos);
nextNode = null;
break;
}
}
}
pos = nextNode;
}
this.fSerializer.endDocument();
}
use of org.xml.sax.ext.LexicalHandler in project sling by apache.
the class HtmlParserImpl method parse.
/**
* @see org.apache.sling.commons.html.HtmlParser#parse(java.io.InputStream, java.lang.String, org.xml.sax.ContentHandler)
*/
public void parse(InputStream stream, String encoding, ContentHandler ch) throws SAXException {
final Parser parser = new Parser();
if (ch instanceof LexicalHandler) {
parser.setProperty("http://xml.org/sax/properties/lexical-handler", ch);
}
for (String feature : features.keySet()) {
parser.setProperty(feature, features.get(feature));
}
parser.setContentHandler(ch);
final InputSource source = new InputSource(stream);
source.setEncoding(encoding);
try {
parser.parse(source);
} catch (IOException ioe) {
throw new SAXException(ioe);
}
}
Aggregations