Package org.exist.xquery.value

Examples of org.exist.xquery.value.Sequence


                "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                "CONTEXT ITEM", contextItem.toSequence());}
        }
        Sequence result;
        final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
        if (seq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
          final Item item = seq.itemAt(0);
          NumericValue value;
          if (item instanceof NumericValue) {
        value = (NumericValue) item;
      } else {
        value = (NumericValue) item.convertTo(Type.NUMBER);
View Full Code Here


            return Sequence.EMPTY_SEQUENCE;
        }

        if (isCalledAs("available-environment-variables")) {

            final Sequence result = new ValueSequence();

            final Map<String, String> env = context.getEnvironmentVariables();
            for (final String key : env.keySet()) {
                result.add(new StringValue(key));
            }

            return result;

        } else {
View Full Code Here

    Expression argLength = null;
   
    //get the context sequence
    if(contextItem != null)
      {contextSequence = contextItem.toSequence();}
        Sequence result;
    final Sequence seqSourceString = argSourceString.eval(contextSequence);
   
    //If the value of $sourceString is the empty sequence return EMPTY_STRING, there must be a string to operate on!
    if(seqSourceString.isEmpty()) {
      result = StringValue.EMPTY_STRING;
    } else {
      //get the string to substring
          final String sourceString = seqSourceString.getStringValue();
       
          //check for a valid start position for the substring
          final NumericValue startingLoc = ((NumericValue)(argStartingLoc.eval(contextSequence).itemAt(0).convertTo(Type.NUMBER))).round();
          if(!validStartPosition(startingLoc, sourceString.length())) {
            //invalid start position
View Full Code Here

            String query = "declare namespace catalog=\"http://www.w3.org/2005/02/query-test-XQTSCatalog\";"+
            "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml') "+
            "return $XQTSCatalog//catalog:sources//catalog:source";

            Sequence results = xquery.execute(query, null, AccessContext.TEST);

            for (NodeProxy node : results.toNodeSet()) {
                ElementImpl source = (ElementImpl) node.getNode();
                sources.put(source.getAttribute("ID"), XQTS_folder + source.getAttribute("FileName"));
            }
        }
        if (moduleSources == null) {
            moduleSources = new HashMap<String, String>();

            String query = "declare namespace catalog=\"http://www.w3.org/2005/02/query-test-XQTSCatalog\";"+
                "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml') "+
                "return $XQTSCatalog//catalog:sources//catalog:module";

            Sequence results = xquery.execute(query, null, AccessContext.TEST);

            for (NodeProxy node : results.toNodeSet()) {
                ElementImpl source = (ElementImpl) node.getNode();
                moduleSources.put(source.getAttribute("ID"), "test/external/XQTS_1_0_3/"+source.getAttribute("FileName")+".xq");
            }
        }
    }
View Full Code Here

            String query = "declare namespace catalog=\"http://www.w3.org/2005/02/query-test-XQTSCatalog\";\n"+
            "let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml')\n"+
            "let $tc := $XQTSCatalog/catalog:test-suite//catalog:test-group[@name eq \""+testGroup+"\"]/catalog:test-case[@name eq \""+testCase+"\"]\n"+
            "return $tc";

            Sequence results = xquery.execute(query, null, AccessContext.TEST);
           
            Assert.assertFalse("", !results.hasOne());

            ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode();

            //collect test case information
            String folder = "";
            String scenario = "";
            String script = "";
            //DateTimeValue scriptDateTime = null;
            NodeListImpl inputFiles = new NodeListImpl();
            NodeListImpl outputFiles = new NodeListImpl();
            ElementImpl contextItem = null;
            NodeListImpl modules = new NodeListImpl();
            String expectedError = "";

            String name = null;

            NodeList childNodes = TC.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node child = childNodes.item(i);
                switch (child.getNodeType()) {
                    case Node.ATTRIBUTE_NODE:
                        name = ((Attr)child).getName();
                        if (name.equals("FilePath"))
                            folder = ((Attr)child).getValue();
                        else if (name.equals("scenario"))
                            scenario = ((Attr)child).getValue();
                        break;
                    case Node.ELEMENT_NODE:
                        name = ((ElementImpl) child).getLocalName();
                        if (name.equals("query")) {
                            ElementImpl el = ((ElementImpl) child);
                            script = el.getAttribute("name");
                            //scriptDateTime = new DateTimeValue(el.getAttribute("date"));
                        }
                        else if (name.equals("input-file"))
                            inputFiles.add(child);
                        else if (name.equals("output-file"))
                            outputFiles.add(child);
                        else if (name.equals("contextItem"))
                            contextItem = (ElementImpl)child;
                        else if (name.equals("module"))
                            modules.add(child);
                        else if (name.equals("expected-error"))
                            expectedError = ((ElementImpl) child).getNodeValue();
                        break;
                    default :
                        ;
                }
            }

            Sequence result = null;

            //compile & evaluate
            File caseScript = new File(XQTS_folder+"Queries/XQuery/"+folder, script+".xq");
            try {
                XQueryContext context;

                context = xquery.newContext(AccessContext.TEST);

                //map modules' namespaces to location
                Map<String, String> moduleMap = (Map<String, String>)broker.getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
                for (int i = 0; i < modules.getLength(); i++) {
                    ElementImpl module = (ElementImpl)modules.item(i);
                    String id = module.getNodeValue();
                    moduleMap.put(module.getAttribute("namespace"), moduleSources.get(id));
                }
                broker.getConfiguration().setProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP, moduleMap);

                //declare variable
                for (int i = 0; i < inputFiles.getLength(); i++) {
                    ElementImpl inputFile = (ElementImpl)inputFiles.item(i);
                    String id = inputFile.getNodeValue();

                    //use DocUtils
                    //context.declareVariable(
                        //inputFile.getAttribute("variable"),
                        //DocUtils.getDocument(context, sources.get(id))
                    //);

                    //in-memory nodes
                    context.declareVariable(inputFile.getAttribute("variable"), loadVarFromURI(context, sources.get(id)));
                }

                Sequence contextSequence = null;
                //set context item
                if (contextItem != null) {
                    String id = contextItem.getNodeValue();
                    contextSequence = loadVarFromURI(context, sources.get(id));
                }
View Full Code Here

                    "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                    "CONTEXT ITEM", contextItem.toSequence());}
        }
        final Sequence arg = getArgument(0).eval(contextSequence, contextItem);
        Sequence result;
        if (arg.isEmpty()) {
            result = Sequence.EMPTY_SEQUENCE;
        } else {
            result = new ValueSequence();
            Item item;
            for (final SequenceIterator i = arg.iterate(); i.hasNext(); ) {
                item = i.nextItem();
                result.add(item.atomize());
            }
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
View Full Code Here

            context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
            if (contextSequence != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);}
        }
       
        Sequence result;
        if (args[0].isEmpty())
          {result = Sequence.EMPTY_SEQUENCE;}
        else {
          final Item arg = args[0].itemAt(0);
          if (!Type.subTypeOf(arg.getType(), Type.ELEMENT))
View Full Code Here

  }
 
  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence)
      throws XPathException {
    final Sequence seq = args[0];
    Sequence tmp;
    if (seq.isEmpty()) {
      tmp = Sequence.EMPTY_SEQUENCE;
    } else if (isCalledAs("head")) {
      tmp = seq.itemAt(0).toSequence();
    } else {
View Full Code Here

                    "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                    "CONTEXT ITEM", contextItem.toSequence());}
        }
        Sequence result;
        final String s1 = getArgument(0).eval(contextSequence, contextItem).getStringValue();
        final String s2 = getArgument(1).eval(contextSequence, contextItem).getStringValue();
        if (s1.length() == 0 || s2.length() == 0 ) {
            if (s1.length() == 0 && s2.length() == 0 ) {
                result = BooleanValue.TRUE;
View Full Code Here

     */
    private List<String> getParameterValues(Sequence contextSequence,
            Item contextItem) throws XPathException {
        final List<String> args = new ArrayList<String>(getArgumentCount() + 10);
        for (int i = 0; i < getArgumentCount(); i++) {
            final Sequence seq = getArgument(i).eval(contextSequence, contextItem);
            for (final SequenceIterator j = seq.iterate(); j.hasNext();) {
                final Item next = j.nextItem();
                args.add(next.getStringValue());
            }
        }
        return args;
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.Sequence

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.