List of usage examples for org.dom4j Node TEXT_NODE
short TEXT_NODE
To view the source code for org.dom4j Node TEXT_NODE.
Click Source Link
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (ch == null || ch.length == 0 || length <= 0) { return;//from www.j a v a 2 s.c o m } try { /* * we can't use the writeString method here because it's possible we * don't receive all characters at once and calling writeString * would cause unwanted spaces to be added in between these chunks * of character arrays. */ String string = new String(ch, start, length); if (escapeText) { string = escapeElementEntities(string); } if (format.isTrimText()) { if ((lastOutputNodeType == Node.TEXT_NODE) && !charactersAdded) { writer.write(" "); } else if (charactersAdded && Character.isWhitespace(lastChar)) { writer.write(lastChar); } String delim = ""; StringTokenizer tokens = new StringTokenizer(string); while (tokens.hasMoreTokens()) { writer.write(delim); writer.write(tokens.nextToken()); delim = " "; } } else { writer.write(string); } charactersAdded = true; lastChar = ch[start + length - 1]; lastOutputNodeType = Node.TEXT_NODE; super.characters(ch, start, length); } catch (IOException e) { handleException(e); } }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeString(String text) throws IOException { if (text != null && text.length() > 0) { if (escapeText) { text = escapeElementEntities(text); }//from w w w . j a va2 s . c o m // if (format.isPadText()) { // if (lastOutputNodeType == Node.ELEMENT_NODE) { // writer.write(PAD_TEXT); // } // } if (format.isTrimText()) { boolean first = true; StringTokenizer tokenizer = new StringTokenizer(text); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (first) { first = false; if (lastOutputNodeType == Node.TEXT_NODE) { writer.write(" "); } } else { writer.write(" "); } writer.write(token); lastOutputNodeType = Node.TEXT_NODE; } } else { lastOutputNodeType = Node.TEXT_NODE; writer.write(text); } } }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
/** * This method is used to write out Nodes that contain text and still allow * for xml:space to be handled properly. * *//*from w w w . j a va 2s . co m*/ protected void writeNodeText(Node node) throws IOException { String text = node.getText(); if (text != null && text.length() > 0) { if (escapeText) { text = escapeElementEntities(text); } lastOutputNodeType = Node.TEXT_NODE; writer.write(text); } }
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;// w w w . j a v a2 s . 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.ee.util.xml.XmlWriter.java
License:Apache License
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (ch == null || ch.length == 0 || length <= 0) { return;/* w ww .j a v a 2 s .c om*/ } try { /* * we can't use the writeString method here because it's possible * we don't receive all characters at once and calling writeString * would cause unwanted spaces to be added in between these chunks * of character arrays. */ String string = new String(ch, start, length); if (escapeText) { string = escapeElementEntities(string); } if (format.isTrimText()) { if ((lastOutputNodeType == Node.TEXT_NODE) && !charactersAdded) { writer.write(" "); } else if (charactersAdded && Character.isWhitespace(lastChar)) { writer.write(lastChar); } String delim = ""; StringTokenizer tokens = new StringTokenizer(string); while (tokens.hasMoreTokens()) { writer.write(delim); writer.write(tokens.nextToken()); delim = " "; } } else { writer.write(string); } charactersAdded = true; lastChar = ch[start + length - 1]; lastOutputNodeType = Node.TEXT_NODE; super.characters(ch, start, length); } catch (IOException e) { handleException(e); } }
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;//from w w w . j ava2 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:architecture.ee.util.xml.XmlWriter.java
License:Apache License
protected void writeString(String text) throws IOException { if (text != null && text.length() > 0) { if (escapeText) { text = escapeElementEntities(text); }// w ww. j a va 2 s. c om // if (format.isPadText()) { // if (lastOutputNodeType == Node.ELEMENT_NODE) { // writer.write(PAD_TEXT); // } // } if (format.isTrimText()) { boolean first = true; StringTokenizer tokenizer = new StringTokenizer(text); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (first) { first = false; if (lastOutputNodeType == Node.TEXT_NODE) { writer.write(" "); } } else { writer.write(" "); } writer.write(token); lastOutputNodeType = Node.TEXT_NODE; } } else { lastOutputNodeType = Node.TEXT_NODE; writer.write(text); } } }
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();/* ww w .ja v 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 writeString(String text) throws IOException { if (text != null && text.length() > 0) { if (format.isTrimText()) { boolean first = true; StringTokenizer tokenizer = new StringTokenizer(text); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (wrapText && lineLength != -1 && ((((LineWriter) writer).getColumn() + token.length()) > lineLength)) { indentLevel++;//from w ww . j a va 2 s . c o m writePrintln(); indent(); indentLevel--; if (first) { first = false; } } else if (first) { first = false; if (lastOutputNodeType == Node.TEXT_NODE) { writer.write(" "); } else if (format.isPadText() && lastOutputNodeType == Node.ELEMENT_NODE) { writer.write(" "); } } else { writer.write(" "); } writer.write(token); lastOutputNodeType = Node.TEXT_NODE; } } else { lastOutputNodeType = Node.TEXT_NODE; writer.write(text); } } }
From source file:com.cladonia.xml.XMLFormatter.java
License:Mozilla Public License
protected void writeMixedNode(Node node) throws IOException { if (DEBUG)/*from ww w . j av 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); } }