private void nodeFilter(Node node) { LinkedList<Node> currentChildNode = node.getChildNodes(); if (node.getParentNode() != null) { if (!node.getContent().equals("")) { node.setContent(StringEscapeUtils.escapeHtml(node.getContent())); } } for (int i = 0; i < currentChildNode.size(); i++) { nodeFilter(currentChildNode.get(i)); } }
private Node nodeFilter(Node currentNode) { LinkedList<Node> currentChildNode = currentNode.getChildNodes(); if (currentNode.getParentNode() != null) { if (!currentNode.getContent().equals("")) { LinkedList<Node> parentChildNodes = currentNode.getParentNode().getChildNodes(); int startPostion = parentChildNodes.indexOf(currentNode); int i = startPostion; Node parentNode = currentNode.getParentNode(); String content = currentNode.getContent(); String[] contentArray = content.split("\\r?\\n"); if (contentArray.length > 1) { currentNode.setContent(contentArray[0]); for (int j = 1; j < contentArray.length; j++) { Node nodeToAdd = new Node(); nodeToAdd.setTitle("br"); nodeToAdd.setParentNode(parentNode); parentChildNodes.add(++i, nodeToAdd); nodeToAdd = new Node(); nodeToAdd.setContent(contentArray[i]); nodeToAdd.setParentNode(parentNode); parentChildNodes.add(++i, nodeToAdd); } } } } for (int i = 0; i < currentChildNode.size(); i++) { nodeFilter(currentChildNode.get(i)); } return currentNode; }