private Node[] processIndexNode( final Node theNode, final Document theTargetDocument, final IndexEntryFoundListener theIndexEntryFoundListener) { theNode.normalize(); boolean ditastyle = false; String textNode = null; final NodeList childNodes = theNode.getChildNodes(); final StringBuilder textBuf = new StringBuilder(); final List<Node> contents = new ArrayList<Node>(); for (int i = 0; i < childNodes.getLength(); i++) { final Node child = childNodes.item(i); if (checkElementName(child)) { ditastyle = true; break; } else if (child.getNodeType() == Node.ELEMENT_NODE) { textBuf.append(XMLUtils.getStringValue((Element) child)); contents.add(child); } else if (child.getNodeType() == Node.TEXT_NODE) { textBuf.append(child.getNodeValue()); contents.add(child); } } textNode = IndexStringProcessor.normalizeTextValue(textBuf.toString()); if (textNode.length() == 0) { textNode = null; } if (theNode.getAttributes().getNamedItem(elIndexRangeStartName) != null || theNode.getAttributes().getNamedItem(elIndexRangeEndName) != null) { ditastyle = true; } final ArrayList<Node> res = new ArrayList<Node>(); if ((ditastyle)) { final IndexEntry[] indexEntries = indexDitaProcessor.processIndexDitaNode(theNode, ""); for (final IndexEntry indexEntrie : indexEntries) { theIndexEntryFoundListener.foundEntry(indexEntrie); } final Node[] nodes = transformToNodes(indexEntries, theTargetDocument, null); for (final Node node : nodes) { res.add(node); } } else if (textNode != null) { final Node[] nodes = processIndexString(textNode, contents, theTargetDocument, theIndexEntryFoundListener); for (final Node node : nodes) { res.add(node); } } else { return new Node[0]; } return (Node[]) res.toArray(new Node[res.size()]); }
/** * Processes curr node. Copies node to the target document if its is not a text node of index * entry element. Otherwise it process it and creates nodes with "prefix" in given "namespace_url" * from the parsed index entry text. * * @param theNode node to process * @param theTargetDocument target document used to import and create nodes * @param theIndexEntryFoundListener listener to notify that new index entry was found * @return the array of nodes after processing input node */ private Node[] processCurrNode( final Node theNode, final Document theTargetDocument, final IndexEntryFoundListener theIndexEntryFoundListener) { final NodeList childNodes = theNode.getChildNodes(); if (checkElementName(theNode)) { return processIndexNode(theNode, theTargetDocument, theIndexEntryFoundListener); } else { final Node result = theTargetDocument.importNode(theNode, false); for (int i = 0; i < childNodes.getLength(); i++) { final Node[] processedNodes = processCurrNode(childNodes.item(i), theTargetDocument, theIndexEntryFoundListener); for (final Node node : processedNodes) { result.appendChild(node); } } return new Node[] {result}; } }