Package org.exist.xquery.value

Examples of org.exist.xquery.value.ValueSequence


            final boolean reverseAxis = Type.subTypeOf(contextSequence.getItemType(),
                    Type.NODE) && (mode == Constants.ANCESTOR_AXIS ||
                    mode == Constants.ANCESTOR_SELF_AXIS || mode == Constants.PARENT_AXIS ||
                    mode == Constants.PRECEDING_AXIS || mode == Constants.PRECEDING_SIBLING_AXIS);
            final Set<NumericValue> set = new TreeSet<NumericValue>();
            final ValueSequence result = new ValueSequence();
            for (final SequenceIterator i = innerSeq.iterate(); i.hasNext();) {
                final NumericValue v = (NumericValue) i.nextItem();
                // Non integers return... nothing, not even an error !
                if (!v.hasFractionalPart() && !v.isZero()) {
                    final int pos = (reverseAxis ? contextSequence.getItemCount()
                        - v.getInt() : v.getInt() - 1);
                    // Other positions are ignored
                    if (pos >= 0 && pos < contextSequence.getItemCount() && !set.contains(v)) {
                        result.add(contextSequence.itemAt(pos));
                        set.add(v);
                    }
                }
            }
            return result;
View Full Code Here


    else
      {docs = context.getStaticallyKnownDocuments();}
    final String term = args[0].getStringValue();
    final String[] matches =
      context.getBroker().getTextEngine().getIndexTerms(docs, new FuzzyMatcher(term, 0.65));
    final ValueSequence result = new ValueSequence();
    for(int i = 0; i < matches.length; i++)
      result.add(new StringValue(matches[i]));
    return result;
  }
View Full Code Here

  public Sequence eval(Sequence[] args, Sequence contextSequence)
    throws XPathException {
    if(args[0].isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
   
    final ValueSequence result = new ValueSequence();
    final SimpleTokenizer tokenizer = new SimpleTokenizer();
    tokenizer.setText(args[0].getStringValue());
    TextToken token = tokenizer.nextToken(false);
    while(token != null && token.getType() != TextToken.EOF) {
      result.add(new StringValue(token.getText()));
      token = tokenizer.nextToken(false);
    }
    return result;
  }
View Full Code Here

            }
        }

        // Create response
        if (isCalledAs("validate") || isCalledAs("jing")) {
            final Sequence result = new ValueSequence();
            result.add(new BooleanValue(report.isValid()));
            return result;

        } else  /* isCalledAs("validate-report") || isCalledAs("jing-report") */{
            final MemTreeBuilder builder = context.getDocumentBuilder();
            final NodeImpl result = Shared.writeReport(report, builder);
View Full Code Here

        final FunctionReference func = (FunctionReference) args[1].itemAt(0);
       
        context.pushDocumentContext();
       
        final MemTreeBuilder builder = context.getDocumentBuilder();
        final ValueSequence result = new ValueSequence();
        for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
            final NodeValue v = (NodeValue) i.nextItem();
            if (v.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
                result.add(v);
            } else {
                final NodeProxy p = (NodeProxy) v;
                processText(builder, p, result, func, args[2]);
            }
        }
View Full Code Here

            Shared.closeStreamSources(grammars);
        }

        // Create response
        if (isCalledAs("jaxv")) {
            final Sequence result = new ValueSequence();
            result.add(new BooleanValue(report.isValid()));
            return result;

        } else /* isCalledAs("jaxv-report") */ {
            final MemTreeBuilder builder = context.getDocumentBuilder();
            final NodeImpl result = Shared.writeReport(report, builder);
View Full Code Here

        // Match pattern on string
        final Matcher matcher = pattern.matcher( args[0].getStringValue() );
       
        // Create response
        final Sequence result = new ValueSequence();
       
        // Add each match to response sequence
        while( matcher.find() ){
            result.add( new StringValue(matcher.group()) );
        }
       
        return result;
    }
View Full Code Here

           
      if(!matcher.find()) {
        return Sequence.EMPTY_SEQUENCE;
      } else {
        final int items = matcher.groupCount() + 1;
        final Sequence seq = new ValueSequence();
        seq.add(new StringValue(string));
        for(int i=1;i<items;i++) {
          String val = matcher.group(i);
          if(val==null) {
            val="";
          }
          seq.add(new StringValue(val));
        }
        return seq;
      }
    } catch (final PatternSyntaxException e) {
      throw new XPathException(this, "err:FORX0001: Invalid regular expression: " + e.getMessage(), e);
View Full Code Here

        final GrammarPool grammarpool
            = (GrammarPool) config.getProperty(XMLReaderObjectFactory.GRAMMER_POOL);
       
        if (isCalledAs("clear-grammar-cache")){
           
            final Sequence result = new ValueSequence();
           
            final int before = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Clearing "+before+" grammars");
           
            clearGrammarPool(grammarpool);
           
            final int after = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Remained "+after+" grammars");
           
            final int delta=before-after;
           
            result.add(new IntegerValue(delta));
           
            return result;
           
           
        } else if (isCalledAs("show-grammar-cache")){
            final MemTreeBuilder builder = context.getDocumentBuilder();
            final NodeImpl result = writeReport(grammarpool, builder);
            return result;
           
        } else if (isCalledAs("pre-parse-grammar")){
           
            if (args[0].isEmpty())
                {return Sequence.EMPTY_SEQUENCE;}
           
            // Setup for XML schema support only
            final XMLGrammarPreparser parser = new XMLGrammarPreparser();
            parser.registerPreparser(TYPE_XSD , null);
           
          
            final List<Grammar> allGrammars = new ArrayList<Grammar>();
           
             // iterate through the argument sequence and parse url
            for (final SequenceIterator i = args[0].iterate(); i.hasNext();) {
                String url = i.nextItem().getStringValue();
               
                // Fix database urls
                if(url.startsWith("/")){
                    url="xmldb:exist://"+url;
                }
              
                LOG.debug("Parsing "+url);
               
                // parse XSD grammar
                try {
                    if(url.endsWith(".xsd")){
                       
                        final InputStream is = new URL(url).openStream();
                        final XMLInputSource xis = new XMLInputSource(null, url, url, is, null);
                        final Grammar schema = parser.preparseGrammar(TYPE_XSD, xis);
                        is.close();

                        allGrammars.add(schema);

                    } else {
                        throw new XPathException(this, "Only XMLSchemas can be preparsed.");
                    }

                } catch(final IOException ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                   
                } catch(final Exception ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                }
               
               
            }

            LOG.debug("Successfully parsed "+allGrammars.size()+" grammars.");
           
            // Send all XSD grammars to grammarpool
            Grammar grammars[] = new Grammar[allGrammars.size()];
            grammars = allGrammars.toArray(grammars);
            grammarpool.cacheGrammars(TYPE_XSD, grammars);
            // Construct result to end user
            final ValueSequence result = new ValueSequence();
            for(final Grammar one : grammars){
                result.add( new StringValue(one.getGrammarDescription().getNamespace()) );
            }
           

            return result;
           
View Full Code Here

         * TODO: Maybe we could provide more detailed messages in the trap, e.g. couldnt replace node `xyz` into `abc` becuase... this would be nicer for the end user of the xquery application
         */
        if (!Type.subTypeOf(inSeq.getItemType(), Type.NODE))
        {
          //Indicate the failure to perform this update by adding it to the sequence in the context variable XQueryContext.XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR
          ValueSequence prevUpdateErrors = null;
         
          final XPathException xpe = new XPathException(this, Messages.getMessage(Error.UPDATE_SELECT_TYPE));
          final Object ctxVarObj = context.getXQueryContextVar(XQueryContext.XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR);
          if(ctxVarObj == null)
          {
            prevUpdateErrors = new ValueSequence();
          }
          else
          {
            prevUpdateErrors = (ValueSequence)XPathUtil.javaObjectToXPath(ctxVarObj, context);
          }
          prevUpdateErrors.add(new StringValue(xpe.getMessage()));
      context.setXQueryContextVar(XQueryContext.XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR, prevUpdateErrors);
     
          if(!inSeq.isEmpty())
            {throw xpe;//TODO: should we trap this instead of throwing an exception - deliriumsky?
        }
View Full Code Here

TOP

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

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.