예제 #1
0
  public void createAndAddIndexGroups(
      final IndexEntry[] theIndexEntries,
      final IndexConfiguration theConfiguration,
      final Document theDocument,
      final Locale theLocale) {
    final IndexComparator indexEntryComparator = new IndexComparator(theLocale);

    final IndexGroup[] indexGroups =
        indexGroupProcessor.process(theIndexEntries, theConfiguration, theLocale);

    final Element rootElement = theDocument.getDocumentElement();

    final Element indexGroupsElement = theDocument.createElementNS(namespace_url, "index.groups");
    indexGroupsElement.setPrefix(prefix);

    for (final IndexGroup group : indexGroups) {
      // Create group element
      final Node groupElement = theDocument.createElementNS(namespace_url, "index.group");
      groupElement.setPrefix(prefix);
      // Create group label element and index entry childs
      final Element groupLabelElement = theDocument.createElementNS(namespace_url, "label");
      groupLabelElement.setPrefix(prefix);
      groupLabelElement.appendChild(theDocument.createTextNode(group.getLabel()));
      groupElement.appendChild(groupLabelElement);

      final Node[] entryNodes =
          transformToNodes(group.getEntries(), theDocument, indexEntryComparator);
      for (final Node entryNode : entryNodes) {
        groupElement.appendChild(entryNode);
      }

      indexGroupsElement.appendChild(groupElement);
    }

    rootElement.appendChild(indexGroupsElement);
  }
  // DOM output
  public void setupNamespace(Element element) {
    String uri = element.getNamespaceURI();
    String myPrefix = getPrefixByUri(uri);
    element.setPrefix(myPrefix);

    if (myPrefix != null) {
      IRNSContainer parent = (IRNSContainer) rnode_.getParentRNode();

      if (parent == null) {
        addPrefixDecl(element, myPrefix, uri);

        return;
      }

      RNSContext parentContext = parent.getRNSContext();
      String parentPrefix = parentContext.getPrefixByUri(uri);

      if (!myPrefix.equals(parentPrefix)) {
        addPrefixDecl(element, myPrefix, uri);
      }
    }
  }
예제 #3
0
 /**
  * Creates element with "prefix" in "namespace_url" with given name for the target document
  *
  * @param theTargetDocument target document
  * @param theName name
  * @return new element
  */
 private Element createElement(final Document theTargetDocument, final String theName) {
   final Element indexEntryNode = theTargetDocument.createElementNS(this.namespace_url, theName);
   indexEntryNode.setPrefix(this.prefix);
   return indexEntryNode;
 }