/** Constructor. */
  public ConrefPushReader() {
    pushtable = new Hashtable<>();
    try {
      reader = XMLUtils.getXMLReader();
      reader.setFeature(FEATURE_NAMESPACE_PREFIX, false);
      reader.setFeature(FEATURE_NAMESPACE, true);
      reader.setContentHandler(this);
    } catch (final Exception e) {
      throw new RuntimeException("Failed to initialize XML parser: " + e.getMessage(), e);
    }

    final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder();
    pushDocument = documentBuilder.newDocument();
  }
Beispiel #2
0
  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()]);
  }
 private Document readMap(final File file) throws DITAOTException {
   InputSource in = null;
   try {
     in = new InputSource(file.toURI().toString());
     return XMLUtils.getDocumentBuilder().parse(in);
   } catch (final Exception e) {
     throw new DITAOTException("Failed to parse map: " + e.getMessage(), e);
   } finally {
     try {
       close(in);
     } catch (IOException e) {
       // NOOP
     }
   }
 }
 private static Document keyDefToDoc(final String key) throws Exception {
   final InputSource inputSource = new InputSource(new StringReader(key));
   final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder();
   return documentBuilder.parse(inputSource);
 }