Package net.sf.saxon.s9api

Examples of net.sf.saxon.s9api.XdmItem


            if (runtime.getAllowGeneralExpressions()) {
                XdmValue xdmvalue = parameters.get(param).getValue();
                XdmAtomicValue atom = null;
                if (xdmvalue.size() == 1) {
                    XdmItem item = xdmvalue.itemAt(0);
                    if (item.isAtomicValue()) {
                        atom = (XdmAtomicValue) item;
                    }
                }

                if (atom != null && xdmvalue.size() == 1) {
                    treeWriter.addAttribute(_value, value);
                    treeWriter.startContent();
                } else {
                    treeWriter.startContent();
                    XdmSequenceIterator iter = xdmvalue.iterator();
                    while (iter.hasNext()) {
                        XdmItem next = iter.next();
                        QName type = next.isAtomicValue() ? ((XdmAtomicValue) next).getPrimitiveTypeName() : null;

                        treeWriter.addStartElement(cx_item);

                        if (type != null) {
                            if ("http://www.w3.org/2001/XMLSchema".equals(type.getNamespaceURI())) {
                                treeWriter.addAttribute(_type, type.getLocalName());
                            } else {
                                treeWriter.addAttribute(_type, type.getClarkName());
                            }
                        }

                        if (next.isAtomicValue()) {
                            treeWriter.addAttribute(_value, next.getStringValue());
                            treeWriter.startContent();
                        } else {
                            treeWriter.startContent();
                            treeWriter.addSubtree((XdmNode) next);
                        }
View Full Code Here


                    }

                    XdmNode element = null;
                    Iterator<XdmItem> values = selector.iterator();
                    while (values.hasNext()) {
                        XdmItem item = values.next();
                        if (element != null || item.isAtomicValue()) {
                            throw XProcException.dynamicError(9);
                        }
                        element = (XdmNode) item;
                        if (element.getNodeKind() != XdmNodeKind.ELEMENT) {
                            throw XProcException.dynamicError(9);
                        }
                    }

                    if (element == null) {
                        throw XProcException.dynamicError(9);
                    }

                    XdmSequenceIterator nsIter = element.axisIterator(Axis.NAMESPACE);
                    while (nsIter.hasNext()) {
                        XdmNode ns = (XdmNode) nsIter.next();
                        QName prefix = ns.getNodeName();
                        localBindings.put(prefix == null ? "" : prefix.getLocalName(),ns.getStringValue());
                    }
                } catch (SaxonApiException sae) {
                    throw new XProcException(sae);
                }
            } else if (nsbinding.getNamespaceBindings() != null) {
                Hashtable<String,String> bindings = nsbinding.getNamespaceBindings();
                for (String prefix : bindings.keySet()) {
                    if ("".equals(prefix) || prefix == null) {
                        // nop; the default namespace never plays a role in XPath expression evaluation
                    } else {
                        localBindings.put(prefix,bindings.get(prefix));
                    }
                }
            }

            // Remove the excluded ones
            HashSet<String> prefixes = new HashSet<String> ();
            for (String uri : nsbinding.getExcludedNamespaces()) {
                for (String prefix : localBindings.keySet()) {
                    if (uri.equals(localBindings.get(prefix))) {
                        prefixes.add(prefix);
                    }
                }
            }
            for (String prefix : prefixes) {
                localBindings.remove(prefix);
            }

            // Add them to the bindings for this value, making sure there are no errors...
            for (String pfx : localBindings.keySet()) {
                if (nsBindings.containsKey(pfx) && !nsBindings.get(pfx).equals(localBindings.get(pfx))) {
                    throw XProcException.dynamicError(13);
                }
                nsBindings.put(pfx,localBindings.get(pfx));
            }
        }

        String select = var.getSelect();
        Vector<XdmItem> results = evaluateXPath(doc, nsBindings, select, globals);
        String value = "";

        try {
            for (XdmItem item : results) {
                if (item.isAtomicValue()) {
                    value += item.getStringValue();
                } else {
                    XdmNode node = (XdmNode) item;
                    if (node.getNodeKind() == XdmNodeKind.ATTRIBUTE
                            || node.getNodeKind() == XdmNodeKind.NAMESPACE) {
                        value += node.getStringValue();
View Full Code Here

        if (c_body.equals(json.getNodeName())) {
            XdmNode jchild = null;
            XdmSequenceIterator iter = json.axisIterator(Axis.CHILD);
            while (iter.hasNext()) {
                XdmItem item = iter.next();
                if (item instanceof XdmNode) {
                    XdmNode child = (XdmNode) item;
                    if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                        if (jchild != null) {
                            throw new XProcException("Found c:body containing more than one JSON element?");
View Full Code Here

    }

    private static void processChildren(XdmNode json, JSONStringer js, int context) throws JSONException {
        XdmSequenceIterator iter = json.axisIterator(Axis.CHILD);
        while (iter.hasNext()) {
            XdmItem item = iter.next();
            if (item instanceof XdmNode) {
                XdmNode child = (XdmNode) item;
                if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                    build(child, js, context);
                }
View Full Code Here

        selector.setContextItem(node);

        Iterator<XdmItem> values = selector.iterator();

        XdmItem item = values.next();

        return item.getStringValue();
    }
View Full Code Here

            inGroup.push(false);
        }
    }

    private boolean nextMatches(XdmNode node) {
        XdmItem nodeValue = computeGroup(node);

        if (nodeValue == null) {
            return false;
        }

        XdmSequenceIterator iter = node.axisIterator(Axis.FOLLOWING_SIBLING);

        while (iter.hasNext()) {
            XdmNode chk = (XdmNode) iter.next();

            boolean skippable
                    = (chk.getNodeKind() == XdmNodeKind.COMMENT
                       || chk.getNodeKind() == XdmNodeKind.PROCESSING_INSTRUCTION);

            if (chk.getNodeKind() == XdmNodeKind.TEXT) {
                if ("".equals(chk.toString().trim())) {
                    skippable = true;
                }
            }

            if (matcher.matches(chk)) {
                XdmItem nextValue = computeGroup(chk);
                boolean same = S9apiUtils.xpathEqual(runtime.getProcessor(), nodeValue, nextValue);
                return same;
            }

            if (!skippable) {
View Full Code Here

        try {
            selector.setContextItem(doc);

            Iterator<XdmItem> iter = selector.iterator();
            while (iter.hasNext()) {
                XdmItem item = iter.next();
                XdmNode node = null;
                try {
                    node = (XdmNode) item;
                } catch (ClassCastException cce) {
                    throw new XProcException ("XPointer matched non-node item?: " + schemeName + "(" + schemeData + ")");
View Full Code Here

    this.typeFactory = typeFactory;
  }

  @Override
  public XdmValue call(XdmValue[] arguments) throws SaxonApiException {
      XdmItem item = arguments[0].itemAt(0);
      ASTNode nodeOrNull = Utils.getMappedAstNode(mapping, item);
      return (nodeOrNull == null) ? XdmEmptySequence.getInstance() : new ObjValue(nodeOrNull);
  }
View Full Code Here

    @Override
    public XdmValue call(XdmValue[] arguments) throws SaxonApiException {
      Object[] funcArguments = new Object[arguments.length];
      Class<?>[] argTypes = func.getArgumentType();
      for(int i=0; i< arguments.length; i++) {
        XdmItem item = arguments[i].itemAt(0);
        funcArguments[i] = translateValue(argTypes[i], item);
      }
        Object result = func.execute(funcArguments, analysisContext);
        if (func.getResultType() == Boolean.class)
          return new XdmAtomicValue((Boolean)result);
View Full Code Here

    this.typeFactory = typeFactory;
  }

  @Override
  public XdmValue call(XdmValue[] arguments) throws SaxonApiException {
      XdmItem item = arguments[0].itemAt(0);
      ObjectValue value = (ObjectValue) item.getUnderlyingValue();
    ASTNode node = (ASTNode) value.getObject();
    return new XdmAtomicValue(node.toString());
  }
View Full Code Here

TOP

Related Classes of net.sf.saxon.s9api.XdmItem

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.