Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


            int position = 0;

            for (final SequenceIterator i = args[0].iterate(); i.hasNext();) {

                // Get item
                final Item next = i.nextItem();

                // Only write if debug mode
                if (true) {
                   
                    String value = null;
                    position++;

                    final int type = next.getType();
                   
                    // Serialize an element type
                    if (Type.ELEMENT == type) {
                        final Writer sw = new StringWriter();
                        try {
                            serializer.serialize((NodeValue) next, sw);

                        } catch (final SAXException ex) {
                            LOG.error(ex.getMessage());
                        }
                        value = sw.toString();

                    // Get string value for other types
                    } else {
                        value = next.getStringValue();

                    }
                   
                    // Write to log
                    LOG.info(label + " [" + position + "]: " + Type.getTypeName(type) + ": " + value);
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);
            if (!Type.subTypeOf(item.getType(), Type.NODE))
              {throw new XPathException(this, ErrorCodes.XPTY0004, "item is not a node; got '" + Type.getTypeName(item.getType()) + "'");}
            //TODO : how to improve performance ?
            final Node n = ((NodeValue)item).getNode();
            //Returns an expanded-QName for node kinds that can have names.
            if (n instanceof QNameable) {
              final QName qn= ((QNameable)n).getQName();
View Full Code Here

        final Sequence seq = getArguments(contextSequence, contextItem)[0];
    if (seq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
                final Sequence tmp = new ValueSequence();
                Item item;
                for(final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                    item = i.nextItem();
                    tmp.add(item);
                }
                result = new ValueSequence();
View Full Code Here

        if (seq.isEmpty())
          //Bloody specs !
            {result = StringValue.EMPTY_STRING;}
        else {
            final Item item = seq.itemAt(0);
            if (!Type.subTypeOf(item.getType(), Type.NODE))
              {throw new XPathException(this, ErrorCodes.XPTY0004, "item is not a node; got '" + Type.getTypeName(item.getType()) + "'");}
            //TODO : how to improve performance ?
            final Node n = ((NodeValue)item).getNode()
            if (n instanceof QNameable)
              {result = new StringValue(((QNameable)n).getQName().getStringValue());}
            else
View Full Code Here

        }
       
       
        Sequence seq;
        Sequence result;
        Item item;
        if (contextItem != null)
          {contextSequence = contextItem.toSequence();}
    if (contextSequence == null || contextSequence.isEmpty())
      {result = Sequence.EMPTY_SEQUENCE;}           
       
    //If we have one argumment, we take it into account
    if (getSignature().getArgumentCount() > 0)
      {seq = getArgument(0).eval(contextSequence, contextItem);}
    //Otherwise, we take the context sequence and we iterate over it
    else
      {seq = contextSequence;}
   
    if (seq == null)
      {throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");}

        if (seq.isPersistentSet())
            {result = new ExtArrayNodeSet(seq.getItemCount());}
        else
            {result = new ValueSequence(seq.getItemCount());}

    for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
      item = i.nextItem();
            if (!Type.subTypeOf(item.getType(), Type.NODE))
                {throw new XPathException(this, ErrorCodes.XPTY0004,  "Item is not a node; got '" + item + "'", seq);}
            final Sequence s = item.toSequence();

            if (s.isPersistentSet()) {
                final NodeProxy p = s.toNodeSet().get(0);
                result.add(new NodeProxy(p.getDocument()));
            } else {
                if (seq.hasOne() && item.getType() == Type.ATTRIBUTE) {
                  result.add(item);
                } else {
                  result.add(((NodeImpl)item).getDocument());
                }
            }
View Full Code Here

            }
            if(canCache && contextSequence != null && contextSequence.isCacheable())
                {cached = new CachedResult(contextSequence, contextItem, result);}
        //Otherwise we have to walk through each item in the context
        } else {
            Item current;
            String arg;
            NodeSet nodes;
            result = new ExtArrayNodeSet();
            Sequence temp;
            for (final SequenceIterator i = contextSequence.iterate(); i.hasNext();) {
                current = i.nextItem();
                arg = searchTerm.eval(current.toSequence()).getStringValue();
                nodes = path == null ? contextSequence.toNodeSet() :
                    path.eval(current.toSequence()).toNodeSet();
                temp = evalQuery(arg, nodes);
                result.addAll(temp);
            }
            if (context.getProfiler().traceFunctions())
                {context.getProfiler().traceIndexUsage(context, FTIndex.ID, this,
View Full Code Here

           
        if (getSignature().getArgumentCount() > 1) {
          precision = (IntegerValue) getArgument(1).eval(contextSequence, contextItem).itemAt(0).convertTo(Type.INTEGER);
        }
           
          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(precision);
        }
       
View Full Code Here

        {throw new XPathException(this, ErrorCodes.FONS0005,
          "base URI of the static context has not been assigned a value.");}
      base = context.getBaseURI();
    } else {
      try {
        final Item item = getArgument(1).eval(contextSequence).itemAt(0).convertTo(Type.ANY_URI);
        base = (AnyURIValue)item;
      } catch (final XPathException e) {
            throw new XPathException(this, ErrorCodes.FORG0002, "invalid argument to fn:resolve-uri(): " + e.getMessage(), null, e);
      }
    }
   
    Sequence result;

    final Sequence seq = getArgument(0).eval(contextSequence);
    if (seq.isEmpty()) {     
      result = Sequence.EMPTY_SEQUENCE;
    } else {
      AnyURIValue relative;
      try {
        final Item item = seq.itemAt(0).convertTo(Type.ANY_URI);
        relative = (AnyURIValue)item;
      } catch (final XPathException e) {       
            throw new XPathException(this, ErrorCodes.FORG0002, "invalid argument to fn:resolve-uri(): " + e.getMessage(), seq, e);
      }     
      URI relativeURI;
View Full Code Here

                    }
                } else {
                    exString = exNode.getNodeValue();
                }

                final Item acNode = result.itemAt(ic);
                Assert.assertTrue(diffXML(exString, toString(acNode), ignorePrefixes));
            }

        } else if ("error".equals(type)) {
            Assert.assertTrue("unhandled error " + expected, false);
View Full Code Here

            sep = args[1].getStringValue();
            if(sep.length() == 0)
                {sep = null;}
        }
    final StringBuilder out = new StringBuilder();
    Item next;
    boolean gotOne = false;
    for(final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
      next = i.nextItem();
      if(gotOne && sep != null)
        {out.append(sep);}
      out.append(next.getStringValue());
      gotOne = true;
    }
    final Sequence result = new StringValue(out.toString());
       
        if (context.getProfiler().isEnabled())
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.