public short getNodeType(Object node) { if ( node instanceof Node ) { return ((Node) node).getNodeType(); } return 0; }
@Override String getType(Object node) { switch(((Node) node).getNodeType()) { case Node.ATTRIBUTE_NODE: { return "attribute";
public boolean matches(Node node) { return node.getNodeType() == nodeType; }
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE:
/** * DOCUMENT ME! * * @param content * DOCUMENT ME! * * @return the text value of the given content object as text which returns * the text value of CDATA, Entity or Text nodes */ protected String getContentAsText(Object content) { if (content instanceof Node) { Node node = (Node) content; switch (node.getNodeType()) { case CDATA_SECTION_NODE: // case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case TEXT_NODE: return node.getText(); default: break; } } else if (content instanceof String) { return (String) content; } return ""; }
/** * DOCUMENT ME! * * @param content * DOCUMENT ME! * * @return the XPath defined string-value of the given content object */ protected String getContentAsStringValue(Object content) { if (content instanceof Node) { Node node = (Node) content; switch (node.getNodeType()) { case CDATA_SECTION_NODE: // case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case TEXT_NODE: case ELEMENT_NODE: return node.getStringValue(); default: break; } } else if (content instanceof String) { return (String) content; } return ""; }
public void setText(String text) { /* remove all text nodes */ List<Node> allContent = contentList(); if (allContent != null) { Iterator<Node> it = allContent.iterator(); while (it.hasNext()) { Node node = it.next(); switch (node.getNodeType()) { case CDATA_SECTION_NODE: // case ENTITY_NODE: case ENTITY_REFERENCE_NODE: case TEXT_NODE: it.remove(); default: break; } } } addText(text); }
public boolean remove(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: return remove((Element) node); case COMMENT_NODE: return remove((Comment) node); case PROCESSING_INSTRUCTION_NODE: return remove((ProcessingInstruction) node); default: invalidNodeTypeAddException(node); return false; } }
public void add(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: add((Element) node); break; case COMMENT_NODE: add((Comment) node); break; case PROCESSING_INSTRUCTION_NODE: add((ProcessingInstruction) node); break; default: invalidNodeTypeAddException(node); } }
int matchType = node.getNodeType();
public int compare(Node n1, Node n2) { int nodeType1 = n1.getNodeType(); int nodeType2 = n2.getNodeType(); int answer = nodeType1 - nodeType2;
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType();
public boolean remove(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: return remove((Element) node); case ATTRIBUTE_NODE: return remove((Attribute) node); case TEXT_NODE: return remove((Text) node); case CDATA_SECTION_NODE: return remove((CDATA) node); case ENTITY_REFERENCE_NODE: return remove((Entity) node); case PROCESSING_INSTRUCTION_NODE: return remove((ProcessingInstruction) node); case COMMENT_NODE: return remove((Comment) node); /* * case DOCUMENT_TYPE_NODE: return remove((DocumentType) node); */ case NAMESPACE_NODE: return remove((Namespace) node); default: return false; } }
switch (n.getNodeType()) { case Node.ELEMENT_NODE: writeElement((Element) n);
int nodeType = node.getNodeType();
public void add(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: add((Element) node);
public static boolean hasNonTextChilds(Element element) { for (Object node : element.content()) { Node e1 = (Node) node; if (e1.getNodeType() != Node.TEXT_NODE) { return true; } } return false; }
public void testBug926713() throws Exception { Document doc = getDocument("/xml/test/cdata.xml"); Element foo = doc.getRootElement(); Element bar = foo.element("bar"); List content = bar.content(); assertEquals(3, content.size()); assertEquals(Node.TEXT_NODE, ((Node) content.get(0)).getNodeType()); assertEquals(Node.CDATA_SECTION_NODE, ((Node) content.get(1)) .getNodeType()); assertEquals(Node.TEXT_NODE, ((Node) content.get(2)).getNodeType()); } }
public boolean remove(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: return remove((Element) node); case COMMENT_NODE: return remove((Comment) node); case PROCESSING_INSTRUCTION_NODE: return remove((ProcessingInstruction) node); default: invalidNodeTypeAddException(node); return false; } }
public boolean remove(Node node) { switch (node.getNodeType()) { case ELEMENT_NODE: return remove((Element) node); case COMMENT_NODE: return remove((Comment) node); case PROCESSING_INSTRUCTION_NODE: return remove((ProcessingInstruction) node); default: invalidNodeTypeAddException(node); return false; } }