Examples of Nodes


Examples of nu.xom.Nodes

   
    final ArrayList stack = new ArrayList();
    stack.add(current); // push

    while (true) {
      Nodes nodes;
      switch (reader.next()) { 
        case XMLStreamConstants.START_ELEMENT: {
          Element elem = readStartTagF(false);
          stack.add(elem); // push even if it's null
          if (elem != null) {
            current.appendChild(elem);
            addAttributesF(elem);
            addNamespaceDeclarations(elem);
            current = elem; // recurse down
          }
          continue;
        }
        case XMLStreamConstants.END_ELEMENT: {
          Element elem = (Element) stack.remove(stack.size()-1); // pop
          if (elem == null) {
            continue; // skip element
          }
          ParentNode parent = elem.getParent();
          if (parent == null) throwTamperedWithParent();
          if (parent instanceof Document) {
            return; // we're done with the root element
          }
         
          current = (Element) parent; // recurse up
          nodes = factory.finishMakingElement(elem);
                    
          if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case)
            continue; // optimization: no need to remove and then readd same element
          }
         
          if (current.getChildCount()-1 < 0) throwTamperedWithParent();       
          current.removeChild(current.getChildCount()-1);
View Full Code Here

Examples of nu.xom.Nodes

    String publicID = (String) invoke(info, "getDTDPublicId");
    if (publicID == MISSING_StAX2) return NONE;
    String systemID = (String) invoke(info, "getDTDSystemId");
    if (systemID == MISSING_StAX2) return NONE;
   
    Nodes nodes = nodeFactory.makeDocType(rootName, publicID, systemID);
    for (int k=0; k < nodes.size(); k++) {
      Node node = nodes.get(k);
      if (node instanceof DocType) {
        DocType docType = (DocType) node;
        if (docType.getInternalDTDSubset().length() == 0) {
          // xom >= 1.1 only
          String subset = (String) invoke(info, "getDTDInternalSubset");
View Full Code Here

Examples of nu.xom.Nodes

  private Nodes buildSequence() throws ParsingException {
    // approach a)
    // assert: we are currently positioned *before* the first event, with the
    // behaviour of all methods initially undefined, except for reader.hasNext()
    try {
      Nodes results = new Nodes();
      while (reader.hasNext()) {
        Node node;
        switch (reader.next()) {
          case XMLStreamConstants.START_DOCUMENT:
            node = build(); // FIXME don't auto-close reader?
            break;
          case XMLStreamConstants.START_ELEMENT:
            node = buildFragment();
            break;
          default:
            node = buildNode();
            break;
        }
        results.append(node);
      }
      return results;
    } catch (XMLStreamException e) {
      StaxUtil.wrapException(e);
      return null; // unreachable
View Full Code Here

Examples of nu.xom.Nodes

     * <code>nodes</code> does not contain duplicates wrt. node identity.
     */
    HashSet identities = null;
    for (int i=nodes.size(); --i >= 0; ) {
      Node node = nodes.get(i);
      Nodes results = EMPTY;
      if (morpher != null) {
        try {
          results = morpher.execute(node, null, variables).toNodes();
        } catch (XQueryException e) { // part of the "convenience"
          throw new RuntimeException(e);
        }
      }
     
      int size = results.size();
      if (size == 0) { // pure delete?
        node.detach();
        continue; // not really needed; just for clarity
      }
     
      if (size == 1 && node == results.get(0)) {
        continue; // nothing to do (replace X with X)
      }

      ParentNode parent = node.getParent();
      StringBuffer atomics = null;
      boolean isInitialized = false;
      int position = 0;
      if (size > 1) {
        if (identities == null) {
          identities = new HashSet();
        } else {
          identities.clear();
        }
      }
     
      for (int j=0; j < size; j++) {
        Node result = results.get(j);       
        if (DefaultResultSequence.isAtomicValue(result)) { // concat atomic values
          String value = result.getValue();
          if (atomics == null) {
            atomics = new StringBuffer(value.length());
          } else {
View Full Code Here

Examples of nu.xom.Nodes

      } catch (XQueryException e) { // part of the "convenience"
        throw new RuntimeException(e);
      }
    }
   
    Nodes nodes = xquery(contextNode, select);
    update(nodes, xmorpher, null);
  }
View Full Code Here

Examples of nu.xom.Nodes

    private Nodes transformMatch(Element elem) {
//      if (DEBUG) System.err.println("found match at level=" + level + ":"
//              + XOMUtil.toPrettyXML(elem));
      level--;
      if (transform == null) return super.finishMakingElement(elem);
      Nodes results = transform.transform(elem);

      // prevent potential nu.xom.MultipleParentException by detaching
      for (int i = results.size(); --i >= 0; ) {
        Node node = results.get(i);
        if (node != elem) node.detach();
      }
      return results;
    }
View Full Code Here

Examples of nu.xom.Nodes

    this.results = results;
    this.config = config;
  }
 
  public Nodes toNodes() throws XQueryException {
    Nodes nodes = new Nodes();
    Node next;
    while ((next = next()) != null) {
      nodes.append(next);
    }
    return nodes;
  }
View Full Code Here

Examples of nu.xom.Nodes

    File expectedDir = new File(rootDir,
      XQueryUtil.xquery(catalog, ns + "ns:test-suite/@ResultOffsetPath").get(0).getValue());
    File queryDir = new File(rootDir,
      XQueryUtil.xquery(catalog, ns + "ns:test-suite/@XQueryQueryOffsetPath").get(0).getValue());
    File testSourcesDir = new File(rootDir, "TestSources");   
    Nodes testCases = XQueryUtil.xquery(catalog, ns + "//ns:test-case");
   
    for (int i=0; i < testCases.size(); i++) {
      Node testCase = testCases.get(i);

//      String groupTitle = XQueryUtil.xquery(testCase, ns + "../ns:GroupInfo/ns:title").get(0).getValue();
      String path = XQueryUtil.xquery(testCase, "@FilePath").get(0).getValue();
      File query = new File(new File(queryDir, path),
        XQueryUtil.xquery(testCase, ns + "ns:query/@name").get(0).getValue() + ".xq");
      String squery = readQuery(query);
      System.out.println(i + ": " + query + " ...");
     
      if (XQueryUtil.xquery(testCase, ns + "ns:spec-citation[@section-pointer='id-validate']").size() > 0) {
        System.out.println("    ************* IGNORED SCHEMA AWARE FUNCTIONALITY *****");
        continue; // ignore validate() function (nux is not schema aware)
      }
         
      if (squery == null) {
        System.out.println("    ************* IGNORED *****");
        continue;
      }
           
      Nodes inputs = XQueryUtil.xquery(testCase, ns + "ns:input-file");
      Map vars = new HashMap();
      for (int j=0; j < inputs.size(); j++) {
        File input = new File(testSourcesDir, inputs.get(j).getValue() + ".xml");
        String varName = ((Element) inputs.get(j)).getAttributeValue("variable");
        Document inputDoc = buildDocument(input);
//        System.out.println(inputDoc.getBaseURI());
        if (true) XOMUtil.Normalizer.STRIP.normalize(inputDoc);
        vars.put(varName, inputDoc);
      }

      Nodes expectedErrors = XQueryUtil.xquery(testCase, ns + "ns:expected-error");         
      Nodes expectedOutputs = XQueryUtil.xquery(testCase, ns + "ns:output-file");
      boolean inspect = false;
      for (int k=0; !inspect && k < expectedOutputs.size(); k++) {
        String compare = ((Element)expectedOutputs.get(k)).getAttributeValue("compare");
        if ("Inspect".equals(compare)) inspect = true;
      }
       
      Nodes results = null;
      try { // here's where the query is actually executed
        XQuery xquery = new XQuery(squery, testSourcesDir.toURI());
//        XQuery xquery = new XQuery(squery, query.toURI());
//        XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery(squery, query.toURI());
        results = xquery.execute(null, null, vars).toNodes();
View Full Code Here

Examples of nu.xom.Nodes

              if (morpher != null && doc2 != null) {
                doc2 = new Document(doc2); // immutable for multiple iterations
              }
             
              // run the query
              Nodes results;
              if (xomXPath) {
                if (doc2 == null) throw new UsageException(
                  "A context node is required by XOM's XPath engine, but missing.");
                results = doc2.query((String)query);
              } else if (xquery != null) {
                results = xquery.execute(doc2, null, variables).toNodes();
              } else {
                results = new Nodes(); // disable XQuery for benchmarking
                results.append(doc2);
              }
             
              if (morpher != null) {
                // interpret --query as select, interpret --update as morpher
                for (int k=0; doc2 == null && k < results.size(); k++) {
                  doc2 = results.get(k).getDocument();
                }
                XQueryUtil.update(results, morpher, null);
               
                // serialize modified document if there is one
                results = new Nodes();
                if (doc2 != null) results.append(doc2);
              }
             
              // serialize results onto output, if any
              File f = (File) outputFiles.get(j);
              OutputStream out = System.out;
View Full Code Here

Examples of nu.xom.Nodes

     * nu.xom.Serializer
     */
    ResultSequenceSerializer serializer = new ResultSequenceSerializer();
    serializer.setIndent(4);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Nodes nodes = new Nodes();
    nodes.append(node);
    String xml;
    try {
      serializer.write(nodes, out);
      xml = out.toString("UTF-8"); // safe: UTF-8 support is required by JDK spec
    } catch (IOException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.