Package net.sf.saxon.sxpath

Examples of net.sf.saxon.sxpath.XPathEvaluator


    public static String xpathValue(Object doc, String xpath) throws XPathException, TeiidProcessingException {
      Source s = null;
        try {
          s = convertToSource(doc);
            XPathEvaluator eval = new XPathEvaluator();
            // Wrap the string() function to force a string return            
            XPathExpression expr = eval.createExpression(xpath);
            Object o = expr.evaluateSingle(s);
           
            if(o == null) {
                return null;
            }
View Full Code Here


    public static void validateXpath(String xpath) throws XPathException {
        if(xpath == null) {
            return;
        }
       
        XPathEvaluator eval = new XPathEvaluator();
        eval.createExpression(xpath);
    }
View Full Code Here

  private void processColumns(List<XMLTable.XMLColumn> columns, IndependentContext ic)
      throws QueryResolverException {
    if (columns == null) {
      return;
    }
        XPathEvaluator eval = new XPathEvaluator(config);
      eval.setStaticContext(ic);
    for (XMLColumn xmlColumn : columns) {
          if (xmlColumn.isOrdinal()) {
            continue;
          }
          String path = xmlColumn.getPath();
          if (path == null) {
            path = xmlColumn.getName();
          }
          path = path.trim();
          if (path.startsWith("/")) { //$NON-NLS-1$
            if (path.startsWith("//")) { //$NON-NLS-1$
              path = '.' + path;
            } else {
              path = path.substring(1);
            }
          }
        XPathExpression exp;
      try {
        exp = eval.createExpression(path);
      } catch (XPathException e) {
        throw new QueryResolverException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.invalid_path", xmlColumn.getName(), xmlColumn.getPath())); //$NON-NLS-1$
     
        xmlColumn.setPathExpression(exp);
    }
View Full Code Here

    public List selectNodes(Object node)
    {
        try
        {
            Node contextNode = (Node)node;
            XPathEvaluator xpe = new XPathEvaluator();
            Configuration config = new Configuration();
            config.setDOMLevel(2);
            config.setTreeModel(net.sf.saxon.event.Builder.STANDARD_TREE);
            IndependentContext sc = new IndependentContext(config);
            // Declare ns bindings
            if (defaultNS != null)
                sc.setDefaultElementNamespace(defaultNS);

            for (int i = 0; i < namespaceMap.length; i++)
            {
                Map.Entry entry = (Map.Entry) namespaceMap[i];
                sc.declareNamespace((String) entry.getKey(),
                        (String) entry.getValue());
            }
            xpe.setStaticContext(sc);
            XPathVariable thisVar = xpe.declareVariable("", contextVar);
            XPathExpression xpath = xpe.createExpression(path);
            NodeInfo contextItem =
                //config.buildDocument(new DOMSource(contextNode));
                config.unravel(new DOMSource(contextNode));
            XPathDynamicContext dc = xpath.createDynamicContext(null);
            dc.setContextItem(contextItem);
View Full Code Here

                                builder.setPipelineConfiguration(saConfig.makePipelineConfiguration());
                                ExpressionPresenter presenter = new ExpressionPresenter(saConfig, builder);
                                xqe.explain(presenter);
                                presenter.close();
                                NodeInfo expressionTree = builder.getCurrentRoot();
                                XPathEvaluator xpe = new XPathEvaluator(saConfig);
                                XPathExpression exp = xpe.createExpression(assertion);
                                try {
                                    Boolean bv = (Boolean)exp.evaluateSingle(expressionTree);
                                    if (bv == null || !bv.booleanValue()) {
                                        log.println("** Optimization assertion failed");
                                        optimizationOK = false;
View Full Code Here

        config.setOptimizerTracing(false);
        if (xml != null) {
            source = buildSource(xml, validationMode);
            if (initialContextPath != null) {
                DocumentInfo doc = config.buildDocument(source);
                XPathEvaluator xpe = new XPathEvaluator(config);
                XPathExpression expr = xpe.createExpression(initialContextPath);
                source = (NodeInfo)expr.evaluateSingle(doc);
            }
        }
        Templates sheet;
        try {
            Source styleSource;
            if (useAssociated) {
                styleSource = f.getAssociatedStylesheet(source, null, null, null);
            } else {
                styleSource = new StreamSource(new File(xsl));
            }
            sheet = f.newTemplates(styleSource);
        } catch (TransformerConfigurationException e) {
            XPathException e2 = XPathException.makeXPathException(e);
            e2.setIsStaticError(true);
            throw e2;
        }

        if (assertion != null) {
            TinyBuilder builder = new TinyBuilder();
            builder.setPipelineConfiguration(config.makePipelineConfiguration());
            ExpressionPresenter presenter = new ExpressionPresenter(config, builder);
            ((PreparedStylesheet)sheet).explain(presenter);
            presenter.close();
            NodeInfo expressionTree = builder.getCurrentRoot();
            XPathEvaluator xpe = new XPathEvaluator(config);
            XPathExpression exp = xpe.createExpression(assertion);
            Boolean bv = (Boolean)exp.evaluateSingle(expressionTree);
            if (!bv.booleanValue()) {
                System.err.println("** Optimization assertion failed");
                presenter = new ExpressionPresenter(config);
                ((PreparedStylesheet)sheet).explain(presenter);
View Full Code Here

    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        Expression exp;
        if (args[0].equals("xpath")) {
            XPathEvaluator xpath = new XPathEvaluator(config);
            XPathExpression xpexp = xpath.createExpression(args[1]);
            exp = xpexp.getInternalExpression();
        } else if (args[0].equals("xquery")) {
            StaticQueryContext sqc = config.newStaticQueryContext();
            sqc.setBaseURI(new File(args[1]).toURI().toString());
            XQueryExpression xqe = sqc.compileQuery(new FileReader(args[1]));
View Full Code Here

        if (argument.length > 2) {
            Value errorObject = ((Value)SequenceExtent.makeSequenceExtent(argument[2].iterate(context))).reduce();
            if (errorObject instanceof SingletonItem) {
                Item root = ((SingletonItem)errorObject).getItem();
                if ((root instanceof NodeInfo) && ((NodeInfo)root).getNodeKind() == Type.DOCUMENT) {
                    XPathEvaluator xpath = new XPathEvaluator();
                    XPathExpression exp = xpath.createExpression("/error/@module");
                    NodeInfo moduleAtt = (NodeInfo)exp.evaluateSingle((NodeInfo)root);
                    String module = (moduleAtt == null ? null : moduleAtt.getStringValue());
                    exp = xpath.createExpression("/error/@line");
                    NodeInfo lineAtt = (NodeInfo)exp.evaluateSingle((NodeInfo)root);
                    int line = (lineAtt == null ? -1 : Integer.parseInt(lineAtt.getStringValue()));
                    exp = xpath.createExpression("/error/@column");
                    NodeInfo columnAtt = (NodeInfo)exp.evaluateSingle((NodeInfo)root);
                    int column = (columnAtt == null ? -1 : Integer.parseInt(columnAtt.getStringValue()));
                    ExpressionLocation locator = new ExpressionLocation();
                    locator.setSystemId(module);
                    locator.setLineNumber(line);
View Full Code Here

                // parameters starting with "+" are taken as input documents
                Object sources = Transform.loadDocuments(argvalue, useURLs, config, true);
                dynamicEnv.setParameter(argname.substring(1), sources);
            } else if (argname.startsWith("?")) {
                // parameters starting with "?" are taken as XPath expressions
                XPathEvaluator xpe = new XPathEvaluator(getConfiguration());
                XPathExpression expr = xpe.createExpression(argvalue);
                XPathDynamicContext context = expr.createDynamicContext(null);
                ValueRepresentation val = SequenceExtent.makeSequenceExtent(expr.iterate(context));
                dynamicEnv.setParameter(argname.substring(1), val);               
            } else {
                dynamicEnv.setParameter(argname, new UntypedAtomicValue(argvalue));
View Full Code Here

                // parameters starting with "+" are taken as input documents
                Object sources = loadDocuments(argvalue, useURLs, config, true);
                controller.setParameter(argname.substring(1), sources);
            } else if (argname.startsWith("?")) {
                // parameters starting with "?" are taken as XPath expressions
                XPathEvaluator xpe = new XPathEvaluator(controller.getConfiguration());
                XPathExpression expr = xpe.createExpression(argvalue);
                XPathDynamicContext context = expr.createDynamicContext(null);
                ValueRepresentation val = SequenceExtent.makeSequenceExtent(expr.iterate(context));
                controller.setParameter(argname.substring(1), val);
            } else {
                controller.setParameter(argname, new UntypedAtomicValue(argvalue));
View Full Code Here

TOP

Related Classes of net.sf.saxon.sxpath.XPathEvaluator

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.