Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


                // the current expression context
                exprContext = args[argCount++];
        }

        // get the query expression
        final Item expr = args[argCount++].itemAt(0);
        Source querySource;
        if (Type.subTypeOf(expr.getType(), Type.ANY_URI)) {
            querySource = loadQueryFromURI(expr);
        } else {
            final String queryStr = expr.getStringValue();
            if("".equals(queryStr.trim())) {
              return new EmptySequence();
            }
            querySource = new StringSource(queryStr);
        }

        NodeValue contextInit = null;
        if(isCalledAs("eval-with-context")) {
            // set the context initialization param for later use
            contextInit = (NodeValue) args[argCount++].itemAt(0);
        }

        // should the compiled query be cached?
        boolean cache = false;
        if(argCount < getArgumentCount()) {
            cache = ((BooleanValue)args[argCount].itemAt(0)).effectiveBooleanValue();
        }

        // save some context properties
        evalContext.pushNamespaceContext();

        final LocalVariable mark = evalContext.markLocalVariables(false);

        final DocumentSet oldDocs = evalContext.getStaticallyKnownDocuments();
        if(exprContext != null) {
            evalContext.setStaticallyKnownDocuments(exprContext.getDocumentSet());
        }

        if(evalContext.isProfilingEnabled(2)) {
            evalContext.getProfiler().start(this, "eval: " + expr);
        }

        // fixme! - hook for debugger here /ljo

        final Sequence sequence = null;

        final XQuery xqueryService = evalContext.getBroker().getXQueryService();
        final XQueryContext innerContext;
        if (contextInit != null) {
            // eval-with-context: initialize a new context
            innerContext = xqueryService.newContext(evalContext.getAccessContext());
            initContextSequence = initContext(contextInit.getNode(), innerContext);
        } else {
            // use the existing outer context
            // TODO: check if copying the static context would be sufficient???
            innerContext = evalContext.copyContext();
            innerContext.setShared(true);
            //innerContext = context;
        }
       
        //set module load path
        if(Type.subTypeOf(expr.getType(), Type.ANY_URI)) {
            String uri = null;
            final Object key = querySource.getKey();
           
            if(key instanceof XmldbURI) {
                uri = XmldbURI.EMBEDDED_SERVER_URI.append(((XmldbURI)key).removeLastSegment()).toString();
//          } else if (key instanceof URL) {
//              TODO: uri = ((URL) key).getParent()
            } else if (key instanceof String && querySource instanceof FileSource) {
                uri = ((FileSource) querySource).getFile().getParent();
            }
         
            if (uri != null) {
                innerContext.setModuleLoadPath(uri);
            }
        }

        //bind external vars?
        if(isCalledAs("eval") && getArgumentCount() == 3) {
            if(!args[2].isEmpty()) {
                final Sequence externalVars = args[2];
                for(int i = 0; i < externalVars.getItemCount(); i++) {
                    final Item varName = externalVars.itemAt(i);
                    if(varName.getType() == Type.QNAME) {
                        final Item varValue = externalVars.itemAt(++i);
                        innerContext.declareVariable(((QNameValue)varName).getQName(), varValue);
                    }
                }
            }
        }
View Full Code Here


//            context.popDocumentContext();
            context.getWatchDog().reset();

            // Iterate over all exception parameters
            for (final SequenceIterator i = exceptionClasses.iterate(); i.hasNext();) {
                final Item currentItem = i.nextItem();
                try {
                    // Get value of execption argument
                    final String exClassName = currentItem.getStringValue();
                    Class<?> exClass = null;

                    // Get exception class, if available
                    if (!"*".equals(exClassName)) {
                        exClass = Class.forName(currentItem.getStringValue());
                    }

                    // If value is '*' or if class actually matches
                    if ("*".equals(exClassName)
                            || exClass.getName().equals(expException.getClass().getName())
View Full Code Here

   * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
   */
  public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    final Sequence inputNode = args[0];
    final Item stylesheetItem = args[1].itemAt(0);
   
    Node options = null;
    if(!args[2].isEmpty())
      {options = ((NodeValue)args[2].itemAt(0)).getNode();}

View Full Code Here

        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);
      }
            result = value.round();
        }

        if (context.getProfiler().isEnabled())
View Full Code Here

            if (args.length == 0) {
                if (contextSequence == null || contextSequence.isEmpty()) {
                    throw new XPathException(this, ErrorCodes.XPDY0002,
                        "Context sequence is empty and no argument specified");
                }
                final Item item = contextSequence.itemAt(0);
                if (!Type.subTypeOf(item.getType(), Type.NODE)) {
                    throw new XPathException(this, ErrorCodes.XPTY0004,
                        "Context item is not a node");
                }
                node = (NodeValue) item;
            } else {
View Full Code Here

        final String stylesheet = (String) request.getAttribute(REQ_ATTRIBUTE_STYLESHEET);
        if (stylesheet == null){
            throw new ServletException("No stylesheet source specified!");
        }

        Item inputNode = null;
       
        final String sourceAttrib = (String) request.getAttribute(REQ_ATTRIBUTE_INPUT);
        if (sourceAttrib != null) {

            Object sourceObj = request.getAttribute(sourceAttrib);
            if (sourceObj != null) {
              if (sourceObj instanceof ValueSequence) {
          final ValueSequence seq = (ValueSequence) sourceObj;
         
          if (seq.size() == 1) {
            sourceObj = seq.itemAt(0);
                    }
        }
             
                if (sourceObj instanceof Item) {
                    inputNode = (Item) sourceObj;
                    if (!Type.subTypeOf(inputNode.getType(), Type.NODE)) {
                        throw new ServletException("Input for XSLT servlet is not a node. Read from attribute " +
                                sourceAttrib);
                    }

                    LOG.debug("Taking XSLT input from request attribute " + sourceAttrib);
View Full Code Here

      if(getSignature().getArgumentCount() == 2)
        {zero = getArgument(1).eval(contextSequence, contextItem);}
      result = zero;
    } else {
        final SequenceIterator iter = inner.iterate();
        Item item = iter.nextItem();
        AtomicValue value = item.atomize();

          value = check(value, null);
       
        //Set the first value
        ComputableValue sum = (ComputableValue) value;
        while (iter.hasNext()) {
          item = iter.nextItem();
          value = item.atomize();

              value = check(value, sum);
         
            if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
            if (((NumericValue)value).isInfinite())
View Full Code Here

                }
                // now execute the callback func.
                final Sequence callbackResult = callback.evalFunction(null, null, params);
                // iterate through the result of the callback
                for (final SequenceIterator iter = callbackResult.iterate(); iter.hasNext(); ) {
                  final Item next = iter.nextItem();
                  if (Type.subTypeOf(next.getType(), Type.NODE)) {
                    nodeNr = builder.getDocument().getLastNode();
                    try {
              next.copyTo(context.getBroker(), receiver);
              result.add(builder.getDocument().getNode(++nodeNr));
              lastNodeNr = nodeNr;
            } catch (final SAXException e) {
              throw new XPathException(this, "Internal error while copying nodes: " + e.getMessage(), e);
            }
                  }
                }
                currentWidth += firstMatch.getLength();
                pos += firstMatch.getLength();
            } else
                {width = str.length();}
           
            // output the rest of the text and matches
            Match.Offset offset;
            for (int i = nextOffset; i < offsets.size() && currentWidth < width; i++) {
                offset = offsets.get(i);
                if (offset.getOffset() > pos) {
                    int len = offset.getOffset() - pos;
                    if (currentWidth + len > width)
                        {len = width - currentWidth;}
                    nodeNr = builder.characters(str.substring(pos, pos + len));
                    if (lastNodeNr != nodeNr)
                      {result.add(builder.getDocument().getNode(nodeNr));}
                    currentWidth += len;
                    pos += len;
                }
               
                if (currentWidth + offset.getLength() < width) {
                  // put the matching term into argument 0 of the callback function
                    params[0] = new StringValue(str.substring(offset.getOffset(), offset.getOffset() + offset.getLength()));
                    // if the callback function accepts 4 arguments, the last argument should contain additional
                    // information on the match:
                    if (callback.getSignature().getArgumentCount() == 4) {
                      params[3] = new ValueSequence();
                      params[3].add(new IntegerValue(i));
                      params[3].add(new IntegerValue(offset.getOffset()));
                      params[3].add(new IntegerValue(offset.getLength()));
                    }
                    // execute the callback function
                    final Sequence callbackResult = callback.evalFunction(null, null, params);
                    for (final SequenceIterator iter = callbackResult.iterate(); iter.hasNext(); ) {
                      final Item next = iter.nextItem();
                      if (Type.subTypeOf(next.getType(), Type.NODE)) {
                        nodeNr = builder.getDocument().getLastNode();
                        try {
                  next.copyTo(context.getBroker(), receiver);
                  result.add(builder.getDocument().getNode(++nodeNr));
                  lastNodeNr = nodeNr;
                } catch (final SAXException e) {
                  throw new XPathException(this, "Internal error while copying nodes: " + e.getMessage(), e);
                }
View Full Code Here

        //END trap Rename failure
       
        if (!inSeq.isEmpty()) {
               
            QName newQName;
            final Item item = contentSeq.itemAt(0);
            if (item.getType() == Type.QNAME) {
                newQName = ((QNameValue) item).getQName();
            } else {
                newQName = QName.parse(context, item.getStringValue());
            }

            //start a transaction
            final Txn transaction = getTransaction();
        try {
View Full Code Here

        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.Item

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.