下面列出了怎么用org.w3c.dom.ls.LSParserFilter的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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");
}
/**
* 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 ELEMENT1 only.
*/
@Test
public void testFilter0009() {
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("ELEMENT2")) {
return FILTER_INTERRUPT;
}
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></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");
}
/**
* 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 start element, <br>
* <b>is</b>: xml1 <br>
* <b>output</b>: empty XML document.
*/
@Test
public void testFilter0010() {
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_REJECT;
}
public short acceptNode(Node enode) {
return FILTER_ACCEPT;
}
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");
}
/**
* 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 testFilter0011() {
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_SKIP;
}
public short acceptNode(Node enode) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return NodeFilter.SHOW_ALL;
}
});
Document doc = parser.parse(getXmlSource(xml1));
NodeList children = doc.getDocumentElement().getChildNodes();
if (children.getLength() != 1) {
Assert.fail("Not all Element nodes skipped");
}
System.out.println("OKAY");
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
@SuppressWarnings("fallthrough") // by design at case LSParserFilter.FILTER_REJECT
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
@SuppressWarnings("fallthrough") // by design at case LSParserFilter.FILTER_REJECT
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}
protected void setCharacterData (boolean sawChars){
// handle character data
fFirstChunk = sawChars;
// if we have data in the buffer we must have created
// a text node already.
Node child = fCurrentNode.getLastChild ();
if (child != null) {
if (fStringBuilder.length () > 0) {
// REVISIT: should this check be performed?
if (child.getNodeType () == Node.TEXT_NODE) {
if (fDocumentImpl != null) {
((TextImpl)child).replaceData (fStringBuilder.toString ());
}
else {
((Text)child).setData (fStringBuilder.toString ());
}
}
// reset string buffer
fStringBuilder.setLength (0);
}
if (fDOMFilter !=null && !fInEntityRef) {
if ( (child.getNodeType () == Node.TEXT_NODE ) &&
((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
short code = fDOMFilter.acceptNode (child);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since Comment has no children.
}
case LSParserFilter.FILTER_SKIP: {
fCurrentNode.removeChild (child);
return;
}
default: {
// accept node -- do nothing
}
}
}
} // end-if fDOMFilter !=null
} // end-if child !=null
}
/**
* The end of a CDATA section.
* @param augs Additional information that may include infoset augmentations
*
* @throws XNIException Thrown by handler to signal an error.
*/
public void endCDATA (Augmentations augs) throws XNIException {
fInCDATASection = false;
if (!fDeferNodeExpansion) {
if (fFilterReject) {
return;
}
if (fCurrentCDATASection !=null) {
if (fDOMFilter !=null && !fInEntityRef &&
(fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
short code = fDOMFilter.acceptNode (fCurrentCDATASection);
switch (code) {
case LSParserFilter.FILTER_INTERRUPT:{
throw Abort.INSTANCE;
}
case LSParserFilter.FILTER_REJECT:{
// fall through to SKIP since CDATA section has no children.
}
case LSParserFilter.FILTER_SKIP: {
Node parent = fCurrentNode.getParentNode ();
parent.removeChild (fCurrentCDATASection);
fCurrentNode = parent;
return;
}
default: {
// accept node
}
}
}
fCurrentNode = fCurrentNode.getParentNode ();
fCurrentCDATASection = null;
}
}
else {
if (fCurrentCDATASectionIndex !=-1) {
fCurrentNodeIndex =
fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
fCurrentCDATASectionIndex = -1;
}
}
}