List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE
short CDATA_SECTION_NODE
To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.
Click Source Link
CDATASection
. From source file:Main.java
/** * Generates XPath expression with the option of the Node values appended * * @param node the Node whose XPath is to be found * @param ignoreWhitespace the flag to indicate if Whitespace will be ignored * @param includeValues the flag to indicate if Node values will be included * @param noIndex the flag to indicate if Node indexes are included * @return the XPath string representation of the Node */// w w w. j a v a 2 s . com public static String generateXPath(Node node, boolean ignoreWhitespace, boolean includeValues, boolean noIndex) { boolean noValues = !includeValues; if (node == null) return ""; Node parent = node.getParentNode(); int index = noIndex ? 0 : getXPathNodeIndex(node, ignoreWhitespace); String indexStr = ""; if (index > 0) indexStr = "[" + Integer.toString(index) + "]"; //printNode(node); //printNode(parent); if (node.getNodeType() == Node.DOCUMENT_NODE) { // return only the blank String, since all the other types are preceded with / return ""; } else if (node.getNodeType() == Node.TEXT_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() + indexStr : "/TEXT(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ELEMENT_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + "/" + node.getNodeName() + indexStr; } else if (node.getNodeType() == Node.COMMENT_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() + indexStr : "/COMMENT(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() + indexStr : "/EntityReference(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() + indexStr : "/PI(" + node.getNodeValue() + ")" + indexStr); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { return generateXPath(((Attr) node).getOwnerElement(), ignoreWhitespace, noValues, noIndex) + "/'@" + node.getNodeName() + (noValues ? "" : "=" + node.getNodeValue()) + "]"; } else if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() : "/DOCTYPE(" + node.getNodeName() + ")"); } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) { return generateXPath(parent, ignoreWhitespace, noValues, noIndex) + (noValues ? node.getNodeValue() : "/CDATA(" + node.getNodeName() + ")"); } // Wont reach this far but just in case return ""; }
From source file:XMLDocumentWriter.java
/** * Output the specified DOM Node object, printing it using the specified * indentation string/*from w w w . j a va2 s.c o m*/ */ public void write(Node node, String indent) { // The output depends on the type of the node switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { // If its a Document node Document doc = (Document) node; out.println(indent + "<?xml version='1.0'?>"); // Output header Node child = doc.getFirstChild(); // Get the first node while (child != null) { // Loop 'till no more nodes write(child, indent); // Output node child = child.getNextSibling(); // Get next node } break; } case Node.DOCUMENT_TYPE_NODE: { // It is a <!DOCTYPE> tag DocumentType doctype = (DocumentType) node; // Note that the DOM Level 1 does not give us information about // the the public or system ids of the doctype, so we can't output // a complete <!DOCTYPE> tag here. We can do better with Level 2. out.println("<!DOCTYPE " + doctype.getName() + ">"); break; } case Node.ELEMENT_NODE: { // Most nodes are Elements Element elt = (Element) node; out.print(indent + "<" + elt.getTagName()); // Begin start tag NamedNodeMap attrs = elt.getAttributes(); // Get attributes for (int i = 0; i < attrs.getLength(); i++) { // Loop through them Node a = attrs.item(i); out.print(" " + a.getNodeName() + "='" + // Print attr. name fixup(a.getNodeValue()) + "'"); // Print attr. value } out.println(">"); // Finish start tag String newindent = indent + " "; // Increase indent Node child = elt.getFirstChild(); // Get child while (child != null) { // Loop write(child, newindent); // Output child child = child.getNextSibling(); // Get next child } out.println(indent + "</" + // Output end tag elt.getTagName() + ">"); break; } case Node.TEXT_NODE: { // Plain text node Text textNode = (Text) node; String text = textNode.getData().trim(); // Strip off space if ((text != null) && text.length() > 0) // If non-empty out.println(indent + fixup(text)); // print text break; } case Node.PROCESSING_INSTRUCTION_NODE: { // Handle PI nodes ProcessingInstruction pi = (ProcessingInstruction) node; out.println(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>"); break; } case Node.ENTITY_REFERENCE_NODE: { // Handle entities out.println(indent + "&" + node.getNodeName() + ";"); break; } case Node.CDATA_SECTION_NODE: { // Output CDATA sections CDATASection cdata = (CDATASection) node; // Careful! Don't put a CDATA section in the program itself! out.println(indent + "<" + "![CDATA[" + cdata.getData() + "]]" + ">"); break; } case Node.COMMENT_NODE: { // Comments Comment c = (Comment) node; out.println(indent + "<!--" + c.getData() + "-->"); break; } default: // Hopefully, this won't happen too much! System.err.println("Ignoring node: " + node.getClass().getName()); break; } }
From source file:com.apricot.eating.xml.XMLParser.java
public String getNodeCDATA(Node node) { NodeList ns = node.getChildNodes(); for (int i = 0; i < ns.getLength(); i++) { if (ns.item(i).getNodeType() == Node.CDATA_SECTION_NODE) { return ns.item(i).getNodeValue(); }/*from w w w. j a va 2 s.c o m*/ } return ""; }
From source file:fr.gouv.finances.dgfip.xemelios.utils.XmlUtils.java
public static String getXmlDataSubstituteNode(Node node, String substituteWith, String substituteInWhat) { StringBuilder sb = new StringBuilder(); switch (node.getNodeType()) { case Node.COMMENT_NODE: case Node.ENTITY_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.NOTATION_NODE: case Node.PROCESSING_INSTRUCTION_NODE: break;/*from ww w.ja v a 2 s . c o m*/ case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.ELEMENT_NODE: { String nodeName = node.getNodeName(); if (!substituteInWhat.equals(nodeName)) { sb.append("<").append(nodeName); StringBuilder attrs = new StringBuilder(); StringBuilder children = new StringBuilder(); NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { for (int i = 0; i < nnm.getLength(); i++) { Node attr = nnm.item(i); attrs.append(" ").append(getXmlDataSubstituteNode(attr, substituteWith, substituteInWhat)); } } NodeList nl = node.getChildNodes(); if (nl != null) { for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); if (child.getNodeType() == Node.ATTRIBUTE_NODE) { attrs.append(" ") .append(getXmlDataSubstituteNode(child, substituteWith, substituteInWhat)); } else { children.append(getXmlDataSubstituteNode(child, substituteWith, substituteInWhat)); } } } sb.append(attrs.toString()); if (children.length() > 0) { sb.append(">").append(children.toString()).append("</").append(nodeName).append(">"); } else { sb.append("/>"); } } else { sb.append(substituteWith); } break; } case Node.ATTRIBUTE_NODE: { sb.append(node.getNodeName()).append("=\"").append(StringEscapeUtils.escapeXml(node.getNodeValue())) .append("\""); break; } case Node.CDATA_SECTION_NODE: { sb.append("<![CDATA[").append(StringEscapeUtils.escapeXml(node.getNodeValue())).append("]]>"); } case Node.TEXT_NODE: { sb.append(StringEscapeUtils.escapeXml(node.getNodeValue())); } } return sb.toString(); }
From source file:Main.java
private static void renderNode(StringBuffer sb, Node node) { if (node == null) { sb.append("null"); return;/*from ww w . jav a 2 s. co m*/ } switch (node.getNodeType()) { case Node.DOCUMENT_NODE: sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); Node root = ((Document) node).getDocumentElement(); renderNode(sb, root); break; case Node.ELEMENT_NODE: String name = getNodeNameWithNamespace(node); NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() == 0) { sb.append("<" + name + ">"); } else { sb.append("<" + name + " "); int attrlen = attributes.getLength(); for (int i = 0; i < attrlen; i++) { Node attr = attributes.item(i); String attrName = getNodeNameWithNamespace(attr); sb.append(attrName + "=\"" + escapeChars(attr.getNodeValue())); if (i < attrlen - 1) sb.append("\" "); else sb.append("\">"); } } NodeList children = node.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { renderNode(sb, children.item(i)); } } sb.append("</" + name + ">"); break; case Node.TEXT_NODE: sb.append(escapeChars(node.getNodeValue())); break; case Node.CDATA_SECTION_NODE: sb.append("<![CDATA[" + node.getNodeValue() + "]]>"); break; case Node.PROCESSING_INSTRUCTION_NODE: sb.append("<?" + node.getNodeName() + " " + escapeChars(node.getNodeValue()) + "?>"); break; case Node.ENTITY_REFERENCE_NODE: sb.append("&" + node.getNodeName() + ";"); break; case Node.DOCUMENT_TYPE_NODE: // Ignore document type nodes break; case Node.COMMENT_NODE: sb.append("<!--" + node.getNodeValue() + "-->"); break; } return; }
From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java
private void writeNode(Writer writer, Node node) throws IOException { short type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: document(writer, (Document) node); break;/*ww w. j a v a2 s.com*/ case Node.DOCUMENT_FRAGMENT_NODE: documentFragment(writer, (DocumentFragment) node); break; case Node.DOCUMENT_TYPE_NODE: documentType(writer, (DocumentType) node); break; case Node.ELEMENT_NODE: element(writer, (Element) node); break; case Node.ATTRIBUTE_NODE: attribute(writer, (Attr) node); break; case Node.ENTITY_REFERENCE_NODE: entityReference(writer, (EntityReference) node); break; case Node.ENTITY_NODE: entity(writer, (Entity) node); break; case Node.NOTATION_NODE: notation(writer, (Notation) node); break; case Node.PROCESSING_INSTRUCTION_NODE: procInst(writer, (ProcessingInstruction) node); break; case Node.TEXT_NODE: text(writer, (Text) node); break; case Node.CDATA_SECTION_NODE: cDataSection(writer, (CDATASection) node); break; case Node.COMMENT_NODE: comment(writer, (Comment) node); break; } }
From source file:Main.java
private static void traverseNode(Node parentNode, JsonObject parentJson, JsonObject upperJson) { NodeList childList = parentNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { JsonObject childJson = new JsonObject(); Node childNode = childList.item(i); if (childNode.getNodeType() == Node.TEXT_NODE) { if (childNode.getNodeValue().trim().length() != 0) { // non empty text node reached, so add to the parent processTextNode(parentNode, upperJson, childJson, childNode); }//from w w w . ja va 2 s .c om } else if (childNode.getNodeType() == Node.ELEMENT_NODE) { if (childNode.hasAttributes()) { // attributes exist, so go thru them traverseAttributes(childJson, childNode); } if (childNode.hasChildNodes()) { // child nodes exist, so go into them traverseNode(childNode, childJson, parentJson); } if (childNode.getNodeType() != Node.TEXT_NODE) { // non text node element if (ADDED_BY_VALUE.contains(childNode)) { // already added as a value if (parentJson.has(childNode.getNodeName())) { // there is already such an element as expected JsonElement existing = parentJson.get(childNode.getNodeName()); if (existing instanceof JsonPrimitive) { // it is a primitive as expected Iterator attrs = childJson.entrySet().iterator(); if (attrs.hasNext()) { // there are attributes, so reorganize the element to include the attributes and the // value as property - #text reorganizeForAttributes(parentJson, childNode, existing, attrs); } } else if (existing instanceof JsonArray) { // already added and reorganized as an array, so take the last element of this type and // add the attributes Iterator attrs = childJson.entrySet().iterator(); if (attrs.hasNext()) { reorganizeAddAttributes(childNode, attrs); } } else if (existing instanceof JsonObject) { System.err.println("ERROR: found object, but expected primitive or array"); } } else { System.err.println("ERROR: expected element, but it does not exist"); } // remove it from the list ADDED_BY_VALUE.remove(childNode); } else { if (parentJson.has(childNode.getNodeName())) { // parent already has such an element JsonElement existing = parentJson.get(childNode.getNodeName()); if (existing instanceof JsonArray) { // and it is already an array, so just add the child to the array ((JsonArray) existing).add(childJson); } else if (existing instanceof JsonObject) { // and it not an array, so reorganize the element reorganizeElement(parentNode, parentJson, childJson, childNode, existing); } } else { // no such an element yet, so add it to the parent parentJson.add(childNode.getNodeName(), childJson); } } } } else if (childNode.getNodeType() == Node.CDATA_SECTION_NODE) { // processTextNode(parentNode, upperJson, childJson, childNode); String base64 = Base64.getEncoder().encodeToString(childNode.getNodeValue().getBytes()); parentJson.addProperty(childNode.getNodeName(), base64); } else { System.err.println("ERROR: unsupported node type: " + childNode.getNodeType()); } } }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addChildren(Element relevantElement, Node instanceNode) { Document ownerDocument = relevantElement.getOwnerDocument(); NodeList instanceChildren = instanceNode.getChildNodes(); for (int index = 0; index < instanceChildren.getLength(); index++) { Node instanceChild = (Node) instanceChildren.item(index); if (isEnabled(instanceChild)) { switch (instanceChild.getNodeType()) { case Node.TEXT_NODE: /* rather not, otherwise we cannot follow specs when * serializing to multipart/form-data for example */*from ww w . j a v a2s .c o m*/ // denormalize text for better whitespace handling during serialization List list = DOMWhitespace.denormalizeText(instanceChild.getNodeValue()); for (int item = 0; item < list.size(); item++) { relevantElement.appendChild(ownerDocument.createTextNode(list.get(item).toString())); } */ relevantElement.appendChild(ownerDocument.createTextNode(instanceChild.getNodeValue())); break; case Node.CDATA_SECTION_NODE: relevantElement.appendChild(ownerDocument.createCDATASection(instanceChild.getNodeValue())); break; case Node.ELEMENT_NODE: addElement(relevantElement, instanceChild); break; default: // ignore break; } } } }
From source file:DOM2SAX.java
/** * Writes a node using the given writer. * @param node node to serialize// w w w . j a va 2 s . c om * @throws SAXException In case of a problem while writing XML */ private void writeNode(Node node) throws SAXException { if (node == null) { return; } switch (node.getNodeType()) { case Node.ATTRIBUTE_NODE: // handled by ELEMENT_NODE case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.NOTATION_NODE: // These node types are ignored!!! break; case Node.CDATA_SECTION_NODE: final String cdata = node.getNodeValue(); if (lexicalHandler != null) { lexicalHandler.startCDATA(); contentHandler.characters(cdata.toCharArray(), 0, cdata.length()); lexicalHandler.endCDATA(); } else { // in the case where there is no lex handler, we still // want the text of the cdate to make its way through. contentHandler.characters(cdata.toCharArray(), 0, cdata.length()); } break; case Node.COMMENT_NODE: // should be handled!!! if (lexicalHandler != null) { final String value = node.getNodeValue(); lexicalHandler.comment(value.toCharArray(), 0, value.length()); } break; case Node.DOCUMENT_NODE: contentHandler.startDocument(); Node next = node.getFirstChild(); while (next != null) { writeNode(next); next = next.getNextSibling(); } contentHandler.endDocument(); break; case Node.ELEMENT_NODE: String prefix; List pushedPrefixes = new java.util.ArrayList(); final AttributesImpl attrs = new AttributesImpl(); final NamedNodeMap map = node.getAttributes(); final int length = map.getLength(); // Process all namespace declarations for (int i = 0; i < length; i++) { final Node attr = map.item(i); final String qnameAttr = attr.getNodeName(); // Ignore everything but NS declarations here if (qnameAttr.startsWith(XMLNS_PREFIX)) { final String uriAttr = attr.getNodeValue(); final int colon = qnameAttr.lastIndexOf(':'); prefix = (colon > 0) ? qnameAttr.substring(colon + 1) : EMPTYSTRING; if (startPrefixMapping(prefix, uriAttr)) { pushedPrefixes.add(prefix); } } } // Process all other attributes for (int i = 0; i < length; i++) { final Node attr = map.item(i); final String qnameAttr = attr.getNodeName(); // Ignore NS declarations here if (!qnameAttr.startsWith(XMLNS_PREFIX)) { final String uriAttr = attr.getNamespaceURI(); // Uri may be implicitly declared if (uriAttr != null) { final int colon = qnameAttr.lastIndexOf(':'); prefix = (colon > 0) ? qnameAttr.substring(0, colon) : EMPTYSTRING; if (startPrefixMapping(prefix, uriAttr)) { pushedPrefixes.add(prefix); } } // Add attribute to list attrs.addAttribute(attr.getNamespaceURI(), getLocalName(attr), qnameAttr, "CDATA", attr.getNodeValue()); } } // Now process the element itself final String qname = node.getNodeName(); final String uri = node.getNamespaceURI(); final String localName = getLocalName(node); // Uri may be implicitly declared if (uri != null) { final int colon = qname.lastIndexOf(':'); prefix = (colon > 0) ? qname.substring(0, colon) : EMPTYSTRING; if (startPrefixMapping(prefix, uri)) { pushedPrefixes.add(prefix); } } // Generate SAX event to start element contentHandler.startElement(uri, localName, qname, attrs); // Traverse all child nodes of the element (if any) next = node.getFirstChild(); while (next != null) { writeNode(next); next = next.getNextSibling(); } // Generate SAX event to close element contentHandler.endElement(uri, localName, qname); // Generate endPrefixMapping() for all pushed prefixes final int nPushedPrefixes = pushedPrefixes.size(); for (int i = 0; i < nPushedPrefixes; i++) { endPrefixMapping((String) pushedPrefixes.get(i)); } break; case Node.PROCESSING_INSTRUCTION_NODE: contentHandler.processingInstruction(node.getNodeName(), node.getNodeValue()); break; case Node.TEXT_NODE: final String data = node.getNodeValue(); contentHandler.characters(data.toCharArray(), 0, data.length()); break; default: //nop } }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processChildNodes(ArrayList<Node> nodeList, StringBuffer sb, int indentLevel, boolean doText, boolean withFormatting, boolean trim, String appendToCRLF, String contextPath, int projectId) { Iterator nodeI = nodeList.iterator(); while (nodeI.hasNext()) { Node n = (Node) nodeI.next(); if (n != null) { if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { if (doText) { String value = n.getNodeValue(); // Escaped characters value = StringUtils.replace(value, "*", "\\*"); value = StringUtils.replace(value, "#", "\\#"); value = StringUtils.replace(value, "=", "\\="); value = StringUtils.replace(value, "|", "\\|"); value = StringUtils.replace(value, "[", "\\{"); value = StringUtils.replace(value, "]", "\\}"); if (trim && !nodeI.hasNext()) { // If within a cell, make sure returns include the cell value // String value = (appendToCRLF.length() > 0 ? StringUtils.replace(n.getNodeValue(), CRLF, CRLF + appendToCRLF) : n.getNodeValue()); LOG.trace(" <text:trim>"); // Output the value, trim is required sb.append(StringUtils.fromHtmlValue(value.trim())); } else { // If within a cell, make sure returns include the cell value if (appendToCRLF.length() > 0 && (hasParentNodeType(n, "th") || hasParentNodeType(n, "td")) && value.trim().length() == 0) { // This is an empty value... check to see if the previous line has content or not before appending a new line } else { LOG.trace(" <text>"); sb.append(StringUtils.fromHtmlValue((appendToCRLF.length() > 0 ? StringUtils.replace(value, CRLF, CRLF + appendToCRLF) : value))); }/*from w w w. ja v a 2 s . c o m*/ } } } else if (n.getNodeType() == Node.ELEMENT_NODE) { Element element = ((Element) n); String tag = element.getTagName(); LOG.trace(tag); if ("h1".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("= ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =").append(CRLF + appendToCRLF); } else if ("h2".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ==").append(CRLF + appendToCRLF); } else if ("h3".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("=== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ===").append(CRLF + appendToCRLF); } else if ("h4".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("==== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ====").append(CRLF + appendToCRLF); } else if ("h5".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("===== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" =====").append(CRLF + appendToCRLF); } else if ("h6".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("====== ").append(StringUtils.fromHtmlValue(element.getTextContent().trim())) .append(" ======").append(CRLF + appendToCRLF); } else if ("p".equals(tag) || "div".equals(tag)) { if (n.getChildNodes().getLength() > 0 && (hasTextContent(n) || hasImageNodes(n.getChildNodes()))) { // If this contains a Table, UL, OL, or object skip everything else to get there ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "table", "ul", "ol", "object" }, false); if (subNodes.size() > 0) { LOG.trace(" nonTextNodes - yes"); processChildNodes(subNodes, sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } else { LOG.trace(" nonTextNodes - no"); startOnNewLine(sb, appendToCRLF); processChildNodes(getNodeList(n), sb, indentLevel, true, true, false, appendToCRLF, contextPath, projectId); } } } else if ("strong".equals(tag) || "b".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, false, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("'''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, false, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("'''"); } } } } } else if ("em".equals(tag) || "i".equals(tag)) { if (n.getChildNodes().getLength() > 0) { if ("".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); } else { if (hasNonTextNodes(n.getChildNodes())) { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } else { if (withFormatting) { sb.append("''"); } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { sb.append("''"); } } } } } else if ("span".equals(tag)) { if (n.getChildNodes().getLength() > 0 && !"".equals(StringUtils.fromHtmlValue(n.getTextContent()).trim())) { if (element.hasAttribute("style")) { String value = element.getAttribute("style"); if (withFormatting) { if (value.contains("underline")) { sb.append("__"); } if (value.contains("line-through")) { sb.append("<s>"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("italic")) { sb.append("''"); } } processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); if (withFormatting) { if (value.contains("italic")) { sb.append("''"); } if (value.contains("bold")) { sb.append("'''"); } if (value.contains("line-through")) { sb.append("</s>"); } if (value.contains("underline")) { sb.append("__"); } } } else { processChildNodes(getNodeList(n), sb, indentLevel, true, withFormatting, trim, appendToCRLF, contextPath, projectId); } } } else if ("ul".equals(tag) || "ol".equals(tag) || "dl".equals(tag)) { ++indentLevel; if (indentLevel == 1) { if (appendToCRLF.length() == 0) { startOnNewLine(sb, appendToCRLF); } else { // Something\n // ! // !* Item 1 // !* Item 2 if (!sb.toString().endsWith("|") && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul newline CRLF"); sb.append(CRLF + appendToCRLF); } } } if (indentLevel > 1 && !sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("ul indent CRLF"); sb.append(CRLF + appendToCRLF); } processChildNodes(getNodeList(n), sb, indentLevel, false, false, trim, appendToCRLF, contextPath, projectId); --indentLevel; } else if ("li".equals(tag)) { String parentTag = ((Element) element.getParentNode()).getTagName(); for (int counter = 0; counter < indentLevel; counter++) { if ("ul".equals(parentTag)) { sb.append("*"); } else if ("ol".equals(parentTag)) { sb.append("#"); } } sb.append(" "); processChildNodes(getNodeList(n), sb, indentLevel, true, false, true, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("li CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("dt".equals(tag) || "dd".equals(tag)) { processChildNodes(getNodeList(n), sb, indentLevel, true, false, trim, appendToCRLF, contextPath, projectId); if (!sb.toString().endsWith(CRLF + appendToCRLF)) { LOG.trace("dt CRLF"); sb.append(CRLF + appendToCRLF); } } else if ("pre".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<pre>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</pre>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("code".equals(tag)) { startOnNewLine(sb, appendToCRLF); sb.append("<code>"); processChildNodes(getNodeList(n), sb, indentLevel, true, true, trim, appendToCRLF, contextPath, projectId); sb.append("</code>"); if (nodeI.hasNext()) { sb.append(CRLF + appendToCRLF); sb.append(CRLF + appendToCRLF); } } else if ("br".equals(tag)) { LOG.trace("br CRLF"); sb.append(CRLF + appendToCRLF); } else if ("table".equals(tag)) { // Always start a table on a new line startOnNewLine(sb, appendToCRLF); processTable(n.getChildNodes(), sb, 0, false, false, contextPath, projectId, 0); //if (nodeI.hasNext()) { // sb.append(CRLF); //} } else if ("form".equals(tag)) { // Always start a form on a new line startOnNewLine(sb, appendToCRLF); CustomForm form = processForm(n); convertFormToWiki(form, sb); } else if ("a".equals(tag)) { // Determine if the link is around text or around an image if (n.getChildNodes().getLength() > 0 && hasImageNodes(n.getChildNodes())) { // The link is around an image LOG.debug("Processing link as an image"); // Get the img tag and pass to processImage... ArrayList<Node> subNodes = new ArrayList<Node>(); getNodes(n.getChildNodes(), subNodes, new String[] { "img" }, false); processImage(sb, subNodes.get(0), (Element) subNodes.get(0), appendToCRLF, contextPath, projectId); } else { // The link is around text processLink(sb, element, appendToCRLF, contextPath, projectId); } } else if ("img".equals(tag)) { processImage(sb, n, element, appendToCRLF, contextPath, projectId); } else if ("object".equals(tag)) { startOnNewLine(sb, appendToCRLF); processVideo(sb, n, element, appendToCRLF, contextPath); } else { processChildNodes(getNodeList(n), sb, indentLevel, false, true, trim, appendToCRLF, contextPath, projectId); } } } } }