本文整理汇总了Java中org.w3c.dom.ls.LSParserFilter类的典型用法代码示例。如果您正苦于以下问题:Java LSParserFilter类的具体用法?Java LSParserFilter怎么用?Java LSParserFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LSParserFilter类属于org.w3c.dom.ls包,在下文中一共展示了LSParserFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: endDocument
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void endDocument()
throws SAXException
{
if (interrupted)
{
return;
}
super.endDocument();
switch (getDecision(ctx, false))
{
case LSParserFilter.FILTER_REJECT:
ctx = null;
doc = null;
break;
}
nodes = null;
decisions = null;
}
示例2: startElement
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void startElement(String uri, String localName, String qName,
Attributes atts)
throws SAXException
{
if (rejecting || interrupted)
{
return;
}
Element element = createElement(uri, localName, qName, atts);
ctx = element;
short decision = getDecision(element, true);
nodes.addLast(element);
decisions.addLast(new Short(decision));
switch (decision)
{
case LSParserFilter.FILTER_REJECT:
rejecting = true;
break;
case LSParserFilter.FILTER_INTERRUPT:
interrupted = true;
break;
}
}
示例3: characters
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void characters(char[] c, int off, int len)
throws SAXException
{
if (rejecting || interrupted)
{
return;
}
Text text = createText(c, off, len);
short decision = getDecision(text, false);
switch (decision)
{
case LSParserFilter.FILTER_ACCEPT:
ctx.appendChild(text);
break;
case LSParserFilter.FILTER_INTERRUPT:
interrupted = true;
break;
}
}
示例4: processingInstruction
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void processingInstruction(String target, String data)
throws SAXException
{
if (rejecting || interrupted || inDTD)
{
return;
}
Node pi = createProcessingInstruction(target, data);
short decision = getDecision(pi, false);
switch (decision)
{
case LSParserFilter.FILTER_ACCEPT:
ctx.appendChild(pi);
break;
case LSParserFilter.FILTER_INTERRUPT:
interrupted = true;
break;
}
}
示例5: endDTD
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void endDTD()
throws SAXException
{
if (interrupted)
{
return;
}
Node doctype = (Node) nodes.removeLast();
decisions.removeLast();
inDTD = false;
ctx = doc;
short decision = getDecision(doctype, false);
switch (decision)
{
case LSParserFilter.FILTER_ACCEPT:
ctx.appendChild(doctype);
break;
case LSParserFilter.FILTER_INTERRUPT:
interrupted = true;
break;
}
}
示例6: endDocument
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void endDocument()
throws SAXException
{
if (interrupted)
{
return;
}
super.endDocument();
switch (getDecision(ctx, false))
{
case LSParserFilter.FILTER_REJECT:
ctx = null;
doc = null;
break;
}
nodes = null;
decisions = null;
}
示例7: startElement
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
public void startElement(String uri, String localName, String qName,
Attributes atts)
throws SAXException
{
if (rejecting || interrupted)
{
return;
}
Element element = createElement(uri, localName, qName, atts);
ctx = element;
short decision = getDecision(element, true);
nodes.addLast(element);
decisions.addLast(new Short(decision));
switch (decision)
{
case LSParserFilter.FILTER_REJECT:
rejecting = true;
break;
case LSParserFilter.FILTER_INTERRUPT:
interrupted = true;
break;
}
}
示例8: testfilter0001
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning
* with state, input and output values orientation
* for public Document parse(LSInput is),
* <br><b>pre-conditions</b>: set filter that REJECTs any CHILD* node,
* <br><b>is</b>: xml1
* <br><b>output</b>: XML document with ELEMNENT1 and ELEMENT2 only.
*/
@Test
public void testfilter0001() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
if (enode.getNodeName().startsWith("CHILD")) {
return FILTER_REJECT;
}
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<?xml version=\"1.0\"?><ROOT><ELEMENT1></ELEMENT1><ELEMENT2>test1</ELEMENT2></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}
示例9: testFilter0002
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that SKIPs ELEMENT1 node, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: XML document with CHILD1 and ELEMENT2 only.
*/
@Test
public void testFilter0002() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
if (enode.getNodeName().startsWith("ELEMENT1")) {
return FILTER_SKIP;
}
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<?xml version=\"1.0\"?><ROOT><CHILD1/><CHILD1><COC1/></CHILD1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}
示例10: testFilter0003
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that SKIPs ELEMENT1 node, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: XML document with ELEMENT1 only.
*/
@Test
public void testFilter0003() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
if (enode.getNodeName().startsWith("ELEMENT2")) {
return FILTER_INTERRUPT;
}
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<ROOT><ELEMENT1><CHILD1/><CHILD1><COC1/></CHILD1></ELEMENT1></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}
示例11: testFilter0004
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that accepts all, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: full XML document.
*/
@Test
public void testFilter0004() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<ROOT><ELEMENT1><CHILD1/><CHILD1><COC1/></CHILD1></ELEMENT1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}
示例12: testFilter0005
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that REJECTs all, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: empty XML document.
*/
@Test
public void testFilter0005() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
return FILTER_REJECT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
Document doc = parser.parse(getXmlSource(xml1));
NodeList children = doc.getDocumentElement().getChildNodes();
if (children.getLength() != 0) {
Assert.fail("Not all children skipped");
}
System.out.println("OKAY");
}
示例13: testFilter0006
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that SKIPs all, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: empty XML document.
*/
@Test
public void testFilter0006() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
return FILTER_SKIP;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
Document doc = parser.parse(getXmlSource(xml1));
NodeList children = doc.getDocumentElement().getChildNodes();
if (children.getLength() != 0) {
Assert.fail("Not all children skipped");
}
System.out.println("OKAY");
}
示例14: testFilter0007
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that REJECTs any CHILD* start element, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: XML document with ELEMENT1 and ELEMENT2 only.
*/
@Test
public void testFilter0007() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
if (elt.getTagName().startsWith("CHILD")) {
return FILTER_REJECT;
}
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<?xml version=\"1.0\"?><ROOT><ELEMENT1></ELEMENT1><ELEMENT2>test1</ELEMENT2></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}
示例15: testFilter0008
import org.w3c.dom.ls.LSParserFilter; //导入依赖的package包/类
/**
* Equivalence class partitioning with state, input and output values
* orientation for public Document parse(LSInput is), <br>
* <b>pre-conditions</b>: set filter that SKIPs ELEMENT1 start element, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: XML document with CHILD1 and ELEMENT2 only.
*/
@Test
public void testFilter0008() {
LSParser parser = createLSParser();
if (parser == null) {
Assert.fail("Unable to create LSParser!");
}
// set filter
parser.setFilter(new LSParserFilter() {
public short startElement(Element elt) {
if (elt.getTagName().equals("ELEMENT1")) {
return FILTER_SKIP;
}
return FILTER_ACCEPT;
}
public short acceptNode(Node enode) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
String expected = "<?xml version=\"1.0\"?><ROOT><CHILD1/><CHILD1><COC1/></CHILD1><ELEMENT2>test1<CHILD2/></ELEMENT2></ROOT>";
Document doc = parser.parse(getXmlSource(xml1));
if (!match(expected, doc)) {
Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed");
}
System.out.println("OKAY");
}