List of usage examples for org.dom4j Node CDATA_SECTION_NODE
short CDATA_SECTION_NODE
To view the source code for org.dom4j Node CDATA_SECTION_NODE.
Click Source Link
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeCDATA(String text) throws IOException { writer.write("<![CDATA["); if (text != null) { writer.write(text);/*ww w. j a v a 2s . com*/ } writer.write("]]>"); lastOutputNodeType = Node.CDATA_SECTION_NODE; }
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;/*from w w w. j a v a 2 s . c om*/ 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.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 av a2 s . co 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: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 ww .j av a 2 s . com 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)/*from w w w.j a va2s . co 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)//from w w w.j a va2 s.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.devoteam.srit.xmlloader.core.utils.XMLElementTextOnlyParser.java
License:Open Source License
public List<Element> replace(Element element, ParameterPool variables) throws Exception { List<Element> result = new LinkedList(); result.add(element.createCopy());/*from ww w . j a v a2 s . com*/ element = result.get(0); Iterator nodesIterator = element.nodeIterator(); HashMap<Node, Node> nodesToReplace = new HashMap<Node, Node>(); boolean alreadyNext = false; while (nodesIterator.hasNext()) { Node node = null; if (!alreadyNext) { node = (Node) nodesIterator.next(); } Node lastTextNode = null; String lastTextNodeText = ""; alreadyNext = false; // // We put all successive TEXT Nodes into one node ( there is some fragmentation i don't understand ) // while (null != node && node.getNodeType() == Node.TEXT_NODE) { alreadyNext = true; lastTextNode = (Text) node; lastTextNodeText += lastTextNode.getText(); // this node will be deleted later ... if not overwritten in this hashmap nodesToReplace.put(lastTextNode, null); if (nodesIterator.hasNext()) { node = (Node) nodesIterator.next(); } else { node = null; } } // // We process normally the CDATA Nodes // if (null != node && node.getNodeType() == Node.CDATA_SECTION_NODE) { lastTextNode = (Node) node; lastTextNodeText = lastTextNode.getText(); } // // We do nothing for the other type Nodes // if (null == lastTextNode) { continue; } lastTextNode.setText(lastTextNodeText); // // Now that we have only one, complete, TEXT node or one CDATA node to proceed // Node textNode = (Node) lastTextNode; String text = textNode.getText(); String out = ""; int endOfLine; String line; // // Transform all \r\n, in \n // //text = Utils.replaceNoRegex(text, "\r", ""); while (text.length() > 0) { // // Read a line // endOfLine = text.indexOf("\n"); if (endOfLine == -1) { line = text; text = ""; } else { line = text.substring(0, endOfLine + 1); text = text.substring(endOfLine + 1); } // // Replace line if it contains at least a variable // if (Parameter.containsParameter(line)) { List<String> results = variables.parse(line); for (String s : results) { out += s; } } else { out += line; } } // // Set new text into new AVP // Text newTextNode = new DefaultText(out); nodesToReplace.put(textNode, newTextNode); } for (Node key : nodesToReplace.keySet()) { DefaultElementInterface.replaceNode((DefaultElement) element, key, nodesToReplace.get(key)); } if (result.size() != 1) { throw new ExecutionException("Size of result for XMLElementTextOnlyParser should be 1"); } return result; }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack<Map<String, Slot>> 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 = Expression.evaluateText(node.getText().toString(), beanShell).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();/*from w ww . j a va2 s. c o m*/ 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:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
private void parseSqlTag(AbstractTag parent, Element el, String namesp) throws Exception { AbstractTag prevTag = null;//from www.j av a2s . c o m List<Node> list = el.content(); Iterator<Node> it = list.iterator(); while (it.hasNext()) { Node node = it.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element childEl = (Element) node; prevTag = parseElementTag(parent, node, childEl, namesp, prevTag); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String text = node.getText().replaceAll("\n|\t", " ").trim(); if (!"".equals(text)) { TextTag tag = new TextTag(text, prevTag); parent.addChild(tag); prevTag = tag; } break; } } }
From source file:freemarker.ext.xml._Dom4jNavigator.java
License:Apache License
String getType(Object node) { switch (((Node) node).getNodeType()) { case Node.ATTRIBUTE_NODE: { return "attribute"; }// ww w. j a v a 2 s .c o m case Node.CDATA_SECTION_NODE: { return "cdata"; } case Node.COMMENT_NODE: { return "comment"; } case Node.DOCUMENT_NODE: { return "document"; } case Node.DOCUMENT_TYPE_NODE: { return "documentType"; } case Node.ELEMENT_NODE: { return "element"; } case Node.ENTITY_REFERENCE_NODE: { return "entityReference"; } case Node.NAMESPACE_NODE: { return "namespace"; } case Node.PROCESSING_INSTRUCTION_NODE: { return "processingInstruction"; } case Node.TEXT_NODE: { return "text"; } } return "unknown"; }