/**
   * Converts a xom node into something readable by Saxon
   *
   * @param node
   * @param config
   * @return
   */
  static NodeInfo wrap(Node node, Configuration config) {
    if (node == null) throw new IllegalArgumentException("node must not be null"); // $NON-NLS-1$
    if (node instanceof DocType)
      throw new IllegalArgumentException("DocType can't be queried by XQuery/XPath"); // $NON-NLS-1$

    Node root = node;
    while (root.getParent() != null) {
      root = root.getParent();
    }

    DocumentWrapper docWrapper = new DocumentWrapper(root, root.getBaseURI(), config);

    return docWrapper.wrap(node);
  }
  /**
   * Wrap or unwrap a node using this object model to return the corresponding Saxon node. If the
   * supplied source does not belong to this object model, return null
   */
  public NodeInfo unravel(Source source, Configuration config) {

    if (source instanceof DOMSource) {
      Node dsnode = ((DOMSource) source).getNode();
      if (!(dsnode instanceof NodeOverNodeInfo)) {
        // Supplied source is an ordinary DOM Node: wrap it
        Document dom;
        if (dsnode.getNodeType() == Node.DOCUMENT_NODE) {
          dom = (Document) dsnode;
        } else {
          dom = dsnode.getOwnerDocument();
        }
        DocumentWrapper docWrapper = new DocumentWrapper(dom, source.getSystemId(), config);
        return docWrapper.wrap(dsnode);
      }
    }
    return null;
  }
Beispiel #3
0
 private void insertFields(String[] fields, BibtexEntry entry, XmlDocument xmlDocument) {
   DocumentWrapper document = new DocumentWrapper(xmlDocument);
   for (String field : fields) {
     if (entry.getField(field) != null) {
       continue;
     }
     if (field.equalsIgnoreCase("author")) {
       entry.setField(field, document.getAuthors("and"));
     }
     if (field.equalsIgnoreCase("title")) {
       entry.setField(field, document.getTitle());
     }
     if (field.equalsIgnoreCase("abstract")) {
       entry.setField(field, document.getAbstract());
     }
     if (field.equalsIgnoreCase("keywords")) {
       entry.setField(field, document.getKeyWords());
     }
     if (field.equalsIgnoreCase("doi")) {
       entry.setField(field, document.getDoi());
     }
     if (field.equalsIgnoreCase("pages")) {
       entry.setField(field, document.getPages());
     }
     if (field.equalsIgnoreCase("volume")) {
       entry.setField(field, document.getVolume());
     }
     if (field.equalsIgnoreCase("number")) {
       entry.setField(field, document.getNumber());
     }
     if (field.equalsIgnoreCase("year")) {
       entry.setField(field, document.getYear());
     }
     if (field.equalsIgnoreCase("month")) {
       entry.setField(field, document.getMonth());
     }
     if (field.equalsIgnoreCase("day")) {
       entry.setField(field, document.getDay());
     }
     if (field.equalsIgnoreCase("booktitle")) {
       entry.setField(field, document.getVenue());
     }
     if (field.equalsIgnoreCase("journal")) {
       entry.setField(field, document.getVenue());
     }
   }
 }