/**
  * Get n'th attribute (DOM NamedNodeMap method). In this implementation we number the attributes
  * as follows: 0 - the xmlns:xml namespace declaration 1-n further namespace declarations n+1...
  * "real" attribute declarations
  */
 public Node item(int index) {
   if (index < 0) {
     return null;
   }
   if (index == 0) {
     NamespaceIterator.NamespaceNodeImpl nn =
         new NamespaceIterator.NamespaceNodeImpl(parent, NamespaceConstant.XML_NAMESPACE_CODE, 0);
     return NodeOverNodeInfo.wrap(nn);
   }
   int nscount = getNumberOfNamespaces();
   if (index < nscount) {
     int[] buffer = new int[8];
     int[] nsList = parent.getDeclaredNamespaces(buffer);
     int nscode = nsList[index - 1];
     NamespaceIterator.NamespaceNodeImpl nn =
         new NamespaceIterator.NamespaceNodeImpl(parent, nscode, index);
     return NodeOverNodeInfo.wrap(nn);
   }
   int pos = 0;
   int attNr = (index - nscount);
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (true) {
     NodeInfo att = (NodeInfo) atts.next();
     if (att == null) {
       return null;
     }
     if (pos == attNr) {
       return NodeOverNodeInfo.wrap(att);
     }
     pos++;
   }
 }
 /** Get number of attributes and namespaces (DOM NamedNodeMap method). */
 public int getLength() {
   int length = 0;
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (atts.next() != null) {
     length++;
   }
   return getNumberOfNamespaces() + length;
 }
Exemplo n.º 3
0
 /**
  * Set all the declared namespaces to be the namespaces that are in-scope for a given node. In
  * addition, the standard namespaces (xml, xslt, saxon) are declared.
  *
  * @param node The node whose in-scope namespaces are to be used as the context namespaces. Note
  *     that this will have no effect unless this node is an element.
  */
 public void setNamespaces(NodeInfo node) {
   namespaces.clear();
   AxisIterator iter = node.iterateAxis(Axis.NAMESPACE);
   while (true) {
     NodeInfo ns = (NodeInfo) iter.next();
     if (ns == null) {
       return;
     }
     declareNamespace(ns.getLocalPart(), ns.getStringValue());
   }
 }
 /** Get named attribute (DOM NamedNodeMap method) */
 public Node getNamedItem(String name) {
   if (name.equals("xmlns")) {
     int[] nsarray = parent.getDeclaredNamespaces(null);
     for (int i = 0; i < nsarray.length; i++) {
       if (nsarray[i] == -1) {
         return null;
       } else if (((nsarray[i] >> 16) & 0xffff) == 0) {
         NamespaceIterator.NamespaceNodeImpl nn =
             new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
         return NodeOverNodeInfo.wrap(nn);
       }
     }
     return null;
   } else if (name.startsWith("xmlns:")) {
     String prefix = name.substring(6);
     if (prefix.equals("xml")) {
       NamespaceIterator.NamespaceNodeImpl nn =
           new NamespaceIterator.NamespaceNodeImpl(parent, NamespaceConstant.XML_CODE, 0);
       return NodeOverNodeInfo.wrap(nn);
     }
     int[] buffer = new int[8];
     int[] nsarray = parent.getDeclaredNamespaces(buffer);
     for (int i = 0; i < nsarray.length; i++) {
       if (nsarray[i] == -1) {
         return null;
       } else if (prefix.equals(parent.getNamePool().getPrefixFromNamespaceCode(nsarray[i]))) {
         NamespaceIterator.NamespaceNodeImpl nn =
             new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
         return NodeOverNodeInfo.wrap(nn);
       }
     }
     return null;
   } else {
     AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
     while (true) {
       NodeInfo att = (NodeInfo) atts.next();
       if (att == null) {
         return null;
       }
       if (name.equals(att.getDisplayName())) {
         return NodeOverNodeInfo.wrap(att);
       }
     }
   }
 }
 /** Get named attribute (DOM NamedNodeMap method) */
 public Node getNamedItemNS(String uri, String localName) {
   if (uri == null) {
     uri = "";
   }
   if (NamespaceConstant.XMLNS.equals(uri)) {
     return getNamedItem("xmlns:" + localName);
   }
   if (uri.equals("") && localName.equals("xmlns")) {
     return getNamedItem("xmlns");
   }
   AxisIterator atts = parent.iterateAxis(Axis.ATTRIBUTE);
   while (true) {
     NodeInfo att = (NodeInfo) atts.next();
     if (att == null) {
       return null;
     }
     if (uri.equals(att.getURI()) && localName.equals(att.getLocalPart())) {
       return NodeOverNodeInfo.wrap(att);
     }
   }
 }
Exemplo n.º 6
0
 NodeInfoSequence(NodeInfo nodeInfo, byte axis) {
   this.nodeInfo = nodeInfo;
   this.axis = axis;
   iterator = nodeInfo.iterateAxis(axis);
 }
Exemplo n.º 7
0
  public SequenceIterator iterate(XPathContext context) throws XPathException {
    Controller controller = context.getController();
    ObjectValue ov = (ObjectValue) controller.getParameter("{" + Test.TE_NS + "}core");
    TECore core = (TECore) ov.getObject();

    Expression[] argExpressions = getArguments();
    String xml = "<params>\n";
    List<QName> params = fe.getParams();
    for (int i = 0; i < params.size(); i++) {
      QName param = params.get(i);
      xml += "<param";
      xml += " local-name=\"" + param.getLocalPart() + "\"";
      xml += " namespace-uri=\"" + param.getNamespaceURI() + "\"";
      xml += " prefix=\"" + param.getPrefix() + "\"";
      ValueRepresentation vr = ExpressionTool.eagerEvaluate(argExpressions[i], context);
      // ValueRepresentation vr =
      // ExpressionTool.lazyEvaluate(argExpressions[i], context, 1);
      Value v = Value.asValue(vr);
      try {
        Node n = (Node) v.convertToJava(Node.class, context);
        int type = n.getNodeType();
        if (type == Node.ATTRIBUTE_NODE) {
          xml += ">\n";
          Attr attr = (Attr) n;
          xml +=
              "<value " + attr.getNodeName() + "=\"" + attr.getValue().replace("&", "&amp;") + "\"";
          if (attr.getPrefix() != null) {
            xml += " xmlns:" + attr.getPrefix() + "=\"" + attr.getNamespaceURI() + "\"";
          }
          xml += "/>\n";
          // } else if (type == Node.ELEMENT_NODE || type ==
          // Node.DOCUMENT_NODE) {
          // xml += ">\n";
          // xml += "<value>";
          // xml += DomUtils.serializeNode(n);
          // xml += "</value>\n";
        } else if (type == Node.ELEMENT_NODE) {
          xml += " type=\"node()\">\n";
          xml += "<value>";
          xml += DomUtils.serializeNode(n);
          xml += "</value>\n";
        } else if (type == Node.DOCUMENT_NODE) {
          xml += " type=\"document-node()\">\n";
          xml += "<value>";
          xml += DomUtils.serializeNode(n);
          xml += "</value>\n";
        } else {
          ItemType it = v.getItemType(context.getConfiguration().getTypeHierarchy());
          xml += " type=\"" + getTypeName(it) + "\">\n";
          xml += "<value>" + n.getNodeValue() + "</value>\n";
        }
      } catch (Exception e) {
        ItemType it = v.getItemType(context.getConfiguration().getTypeHierarchy());
        xml += " type=\"" + getTypeName(it) + "\">\n";
        xml += "<value>" + v.getStringValue() + "</value>\n";
      }
      xml += "</param>\n";
    }
    xml += "</params>";
    // System.out.println(xml);
    Source src = new StreamSource(new CharArrayReader(xml.toCharArray()));
    // XdmValue result = null;
    NodeInfo result = null;
    try {
      // result = core.executeTemplate(fe, Globals.builder.build(src),
      // context);
      NodeInfo paramsNode = core.getEngine().getBuilder().build(src).getUnderlyingNode();
      result = core.executeXSLFunction(context, fe, paramsNode);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    if (result == null) {
      return EmptyIterator.getInstance();
    } else {
      // Value v = Value.asValue(result);
      // return v.iterate();
      return result.iterateAxis(Axis.CHILD);
    }
  }