Package org.tei.comparator.web.client

Examples of org.tei.comparator.web.client.TableOfContentsEntry


   * @param lookUpTable
   * @param revLookUpTable
   */
  private TableOfContentsEntry generateTableOfContents(Document doc, HashMap<Node, TableOfContentsEntry> lookUpTable, HashMap<TableOfContentsEntry, Node> revLookUpTable){
    // create toc object
    TableOfContentsEntry toc = new TableOfContentsEntry("root", "root");
   
    // store root in lut
    lookUpTable.put(doc.getDocumentElement(), toc);
   
    // elements where we should use the first x words
    String[] elementsUsingFirstWords = PropertiesProvider.getInstance().getElementsForTOCUsingBeginningOfSection();
    int numberOfFirstWords = PropertiesProvider.getInstance().getNumberOfFirstWordsForTOC();
   
    // create the list of
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    xpath.setNamespaceContext(Utils.getTEINamespaceContext());
    try {
      String finalLevel = PropertiesProvider.getInstance().getFinalTOCLevel();
      XPathExpression xpexp = xpath.compile("//tei:" + finalLevel +
                          "[count(ancestor::tei:" + finalLevel + ")=0]");
      NodeList list = (NodeList) xpexp.evaluate(doc, XPathConstants.NODESET);
      for(int i = 0; i < list.getLength(); i++){
        Node parent = list.item(i);
        TableOfContentsEntry cEntry = getTocEntry((Element)parent, elementsUsingFirstWords, numberOfFirstWords);
       
        lookUpTable.put(parent, cEntry);
        revLookUpTable.put(cEntry, parent);
       
        while((parent = parent.getParentNode()) != null){
          TableOfContentsEntry pEntry;
          if(! lookUpTable.containsKey(parent)){
            pEntry = getTocEntry((Element)parent, elementsUsingFirstWords, numberOfFirstWords);
            lookUpTable.put(parent, pEntry);
            revLookUpTable.put(pEntry, parent);
          } else
            pEntry = lookUpTable.get(parent);

          // if we are not in there yet
          boolean found = false;
          for(int j = 0; j < pEntry.getChildCount(); j++ ){
            if(pEntry.getChild(j) == cEntry){
              found = true;
              break;
            }
          }
           
          if(!found)
            pEntry.add(cEntry);
          else
            break;
         
          // switch p and c
          cEntry = pEntry;
View Full Code Here


   
    return toc;
  }

  private TableOfContentsEntry getTocEntry(Element node, String[] elementsUsingFirstWords, int numberOfFirstWords) {
    TableOfContentsEntry entry;
    if(! ArrayUtils.contains(elementsUsingFirstWords, node.getNodeName()))
      entry = new TableOfContentsEntry(node.getNodeName() + (node.getAttribute("type").equals("") ? "" : " (" + node.getAttribute("type") + ")"), Utils.getUniqueXMLID());
    else {
      String textContent = node.getTextContent();
      textContent = new WhiteSpaceRemovalPreprocessing().preprocessInput(textContent);
     
      String[] words = textContent.split(" ");
      if(words.length < numberOfFirstWords){
        textContent = (textContent.equals("") ? "[Empty Section]" : textContent);
        entry = new TableOfContentsEntry(textContent, Utils.getUniqueXMLID());
      }
      else {
        String heading = words[0];
        for(int j = 1; j < numberOfFirstWords; j++)
          heading += " " + words[j];
        entry = new TableOfContentsEntry(heading, Utils.getUniqueXMLID());
      }
    }
   
    return entry;
  }
View Full Code Here

     // Tell the system that we are working
     Work.show("Load table of contents");
  }

  public void selectNextSection(final int file, final TableOfContentsEntry entry, final CommandCallback<Section> callback){
    TableOfContentsEntry next = entry.getNext();
    if(next instanceof TableOfContentsEntry)
      selectSection(file, next, callback);
    else
      Window.alert("I could not find a next section.");
    }
View Full Code Here

    else
      Window.alert("I could not find a next section.");
    }

  public void selectPreviousSection(final int file, final TableOfContentsEntry entry, final CommandCallback<Section> callback){
    TableOfContentsEntry prev = entry.getPrev();
    if(prev instanceof TableOfContentsEntry)
      selectSection(file, prev, callback);
    else
      Window.alert("I could not find a previous section.");
    }
View Full Code Here

  private void itemSelected(){
      if(tree.getSelectedItem().isLeaf()){
       hide();

       // get entry
       TableOfContentsEntry entry = (TableOfContentsEntry)tree.getSelectedItem().getModel();
      
       // call current listener
       selectionListener.tocp_itemSelected(entry);
     } else {
       com.google.gwt.user.client.Window.alert("Please select leaf.");
View Full Code Here

TOP

Related Classes of org.tei.comparator.web.client.TableOfContentsEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.