Package org.tei.comparator.web.client

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


 
  public Section getSection(int file, TableOfContentsEntry entry) {
    DocumentContainer docContainer = DocumentContainer.getInstance();

    Section sec = new Section();
   
    Node section = docContainer.lookUpTocEntryIn(entry, file);
   
    DocumentBuilderFactory documentBuilderFactory =  DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    Document doc = null;
    DOMResult xmlResult = null;
    try {
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      doc = documentBuilder.newDocument();
      Node importedNode = doc.importNode(section, true);
      doc.appendChild(importedNode);
     
      // search for all matchable nodes
      XPathFactory xpf = XPathFactory.newInstance();
      XPath xpath = xpf.newXPath();
      xpath.setNamespaceContext(Utils.getTEINamespaceContext());
      XPathExpression xpexp = xpath.compile("//attribute::tc:cid/..");
      NodeList list = (NodeList) xpexp.evaluate(doc, XPathConstants.NODESET);
      // loop over matchable elements and add tc:match attribute if matched
      for(int i = 0; i < list.getLength(); i++){
        Node node = list.item(i);
        if (node instanceof Element) {
          Element el = (Element) node;
          if(DBManager.getInstance().isConfirmed(el.getAttributeNS(Utils.TEI_COMPARATOR_NAMESPACE, "cid"))){
            el.setAttributeNS(Utils.TEI_COMPARATOR_NAMESPACE, "confirmedMatch", "true");
          } else if(DBManager.getInstance().isMatched(el.getAttributeNS(Utils.TEI_COMPARATOR_NAMESPACE, "cid"))){
              el.setAttributeNS(Utils.TEI_COMPARATOR_NAMESPACE, "matched", "true")
          }
         
          // get notes for section
          List<TCNote> notes = DBManager.getInstance().getNotesFor(TCNote.TYPE_PARAGRAPH, el.getAttributeNS(Utils.TEI_COMPARATOR_NAMESPACE, "cid"));
          sec.addNotes(notes);
        }
      }
     
      // get transformer and transform
      Transformer tf = docContainer.getTEIToHTMLTransformer(file);
      xmlResult = new DOMResult();
      DOMSource source = new DOMSource(doc);
      tf.transform(source, xmlResult);
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    } catch (XPathExpressionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
   
    sec.setText(Utils.getXMLNodeAsString(xmlResult.getNode()));
   
    return sec;
  }
View Full Code Here

TOP

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

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.