List of usage examples for org.dom4j Node COMMENT_NODE
short COMMENT_NODE
To view the source code for org.dom4j Node COMMENT_NODE.
Click Source Link
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeElement((Element) node); break;/*ww w. j av a2s .c o m*/ case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeNodeText(node); // write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes // write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeComment(String text) throws IOException { if (format.isNewlines()) { println();//from w w w . ja v a 2 s . c om indent(); } writer.write("<!--"); writer.write(text); writer.write("-->"); lastOutputNodeType = Node.COMMENT_NODE; }
From source file:architecture.ee.util.xml.XmlWriter.java
License:Apache License
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeElement((Element) node); break;/* w w w. j a v a2 s. com*/ case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeNodeText(node); //write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes //write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:com.christophermrossi.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack); break; case Node.TEXT_NODE: char[] text = node.getText().toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA();/*w w w. j a va 2 s . c om*/ break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() ); namespaces.put(declared.getPrefix(), declared.getURI()); //if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); //} //else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); //} break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: //System.err.println( "WARNING: Node type not supported: " + node.getNodeTypeName() ); } } }
From source file:com.cladonia.xml.XMLFormatter.java
License:Mozilla Public License
protected void writeMixedNode(Node node) throws IOException { if (DEBUG)// ww w . ja v a2 s. c o m System.out.println("XMLFormatter.writeMixedNode( " + node + ")"); int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeMixedElement((Element) node); break; case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeString(node.getText()); //write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes //write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:com.cladonia.xml.XMLFormatter.java
License:Mozilla Public License
protected void writePreservedNode(Node node) throws IOException { if (DEBUG)/* www . ja v a 2s .co m*/ System.out.println("XMLFormatter.writeMixedNode( " + node + ")"); int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writePreservedElement((Element) node); break; case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeString(node.getText()); //write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes //write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:com.flaptor.hounder.util.HtmlParser.java
License:Apache License
/** * Simple method to concatenate all readable text in the document and get the outlinks. * /* w ww . j a va 2 s . c o m*/ * @param e * the element in where to look for readable text and outlinks. * @param out * the parse output so far. For any caller except the getText itself, * should be empty. After return, it contains the readable text * of the html and the outlinks. */ protected void extractText(final Element e, final Output out, final String fieldName) { //String nodeName = e.getName(); if (!(e.getNodeType() == Node.COMMENT_NODE)) { int size = e.nodeCount(); for (int i = 0; i < size; i++) { Node node = e.node(i); if (node instanceof Element) { extractText((Element) node, out, fieldName); } else if (node instanceof Text) { String t = node.getText(); out.addFieldString(fieldName, t); } } } }
From source file:com.flaptor.util.DomUtil.java
License:Apache License
/** * Gets the entire text of an element an all its children * // ww w .j a v a 2 s .c o m * @param element * @return */ public static String getElementTextRecursively(final Element element) { String result = ""; if (!(element.getNodeType() == Node.COMMENT_NODE)) { int size = element.nodeCount(); for (int i = 0; i < size; i++) { Node node = element.node(i); if (node instanceof Element) { result += getElementTextRecursively((Element) node); } else if (node instanceof Text) { result += node.getText(); } } } return result; }
From source file:com.flaptor.util.parser.HtmlParser.java
License:Apache License
/** * Simple method to concatenate all readable text in the document and get the outlinks. * /*from ww w . j a v a 2 s . c o m*/ * @param e * the element in where to look for readable text and outlinks. * @param out * the parse output so far. For any caller except the getText itself, * should be empty. After return, it contains the readable text * of the html and the outlinks. */ protected void extractAllText(final Element e, final ParseOutput out, final String fieldName) { //String nodeName = e.getName(); if (!(e.getNodeType() == Node.COMMENT_NODE)) { int size = e.nodeCount(); for (int i = 0; i < size; i++) { Node node = e.node(i); if (node instanceof Element) { extractAllText((Element) node, out, fieldName); } else if (node instanceof Text) { String t = node.getText(); out.addFieldString(fieldName, t); } } } }
From source file:com.nokia.ant.BuildStatusDef.java
License:Open Source License
/** * If target has comment that says it is private them print warning * *//*from w ww . j a va 2s. co m*/ public void checkIfTargetPrivate(Target target, Project project) { Element targetElement = findTargetElement(target, project); if (targetElement != null) { List children = targetElement.selectNodes("preceding-sibling::node()"); if (children.size() > 0) { // Scan past the text nodes, which are most likely whitespace int index = children.size() - 1; Node child = (Node) children.get(index); while (index > 0 && child.getNodeType() == Node.TEXT_NODE) { index--; child = (Node) children.get(index); } // Check if there is a comment node String commentText = null; if (child.getNodeType() == Node.COMMENT_NODE) { Comment macroComment = (Comment) child; commentText = macroComment.getStringValue().trim(); //log(macroName + " comment: " + commentText, Project.MSG_DEBUG); } if (commentText != null) { if (commentText.contains("Private:")) { output.add( "Warning: " + target.getName() + " is private and should only be called by helium"); } if (commentText.contains("<deprecated>")) { output.add("Warning: " + target.getName() + "\n" + commentText); } } } } }