Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


        XQuery xquery = broker.getXQueryService();
        Sequence seq = xquery.execute(query, null, AccessContext.TEST);
        assertEquals(expected, seq.getItemCount());
       
        if (expectedResult != null) {
            Item item = seq.itemAt(0);
            String value = serialize(broker, item);
            assertEquals(expectedResult, value);
        }
        return seq;
    }
View Full Code Here


    // create the output
    MemTreeBuilder builder = context.getDocumentBuilder();
    DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);   
    try {
      SequenceIterator i = result.iterate();
      Item next = i.nextItem();   
      StringBuilder buf = null;
            boolean allowAttribs = true;
            while (next != null) {
          context.proceed(this, builder);
        // if item is an atomic value, collect the string values of all
        // following atomic values and seperate them by a space.
        if (Type.subTypeOf(next.getType(), Type.ATOMIC)) {
            if(buf == null)
                buf = new StringBuilder();
          else if (buf.length() > 0)
            buf.append(' ');
          buf.append(next.getStringValue());
                    allowAttribs = false;
                    next = i.nextItem();            // if item is a node, flush any collected character data and
        //  copy the node to the target doc.
        } else if (Type.subTypeOf(next.getType(), Type.NODE)) {
                    if (buf != null && buf.length() > 0) {
            receiver.characters(buf);
            buf.setLength(0);
          }
                    if (next.getType() == Type.ATTRIBUTE && !allowAttribs)
                        throw new XPathException(this, "XQTY0024: An attribute may not appear after " +
                            "another child node.");
                    next.copyTo(context.getBroker(), receiver);
                    allowAttribs = next.getType() == Type.ATTRIBUTE;
                    next = i.nextItem();
        }
            }
      // flush remaining character data
      if (buf != null && buf.length() > 0)
View Full Code Here

        XSLStylesheet xslt = getXSLContext().getXSLStylesheet();
 
      int pos = 0;
  //      for (Item item : selected) {
          for (SequenceIterator iterInner = selected.iterate(); iterInner.hasNext();) {
              Item item = iterInner.nextItem();  
         
            context.setContextSequencePosition(pos, selected);
          Sequence res = xslt.templates(selected, item);
          if (res == null) {
                if (item instanceof Text) {
                      MemTreeBuilder builder = context.getDocumentBuilder();
                  builder.characters(item.getStringValue());
                  result.add(item);
                } else if (item instanceof Node || item instanceof NodeValue) {
                  res = eval(selected, item); //item.toSequence();//
                } else
                  throw new XPathException("not supported item type");
View Full Code Here

        try {
            if(!contentSeq.isEmpty()) {
                StringBuilder buf = null;
                final SequenceIterator i = contentSeq.iterate();
                Item next = i.nextItem();
                while(next != null) {
                    context.proceed(this, builder);
                    if (next.getType() == Type.ATTRIBUTE || next.getType() == Type.NAMESPACE)
                        {throw new XPathException(this, "Found a node of type " +
                            Type.getTypeName(next.getType()) + " inside a document constructor");}
                    // if item is an atomic value, collect the string values of all
                    // following atomic values and seperate them by a space.
                    if (Type.subTypeOf(next.getType(), Type.ATOMIC)) {
                        if(buf == null)
                            {buf = new StringBuilder();}
                        else if (buf.length() > 0)
                            {buf.append(' ');}
                        buf.append(next.getStringValue());
                        next = i.nextItem();
                    // if item is a node, flush any collected character data and
                    // copy the node to the target doc.
                    } else if (next.getType() == Type.DOCUMENT) {
                        if (buf != null && buf.length() > 0) {
                            receiver.characters(buf);
                            buf.setLength(0);
                        }
                        next.copyTo(context.getBroker(), receiver);
                        next = i.nextItem();
                    } else if (Type.subTypeOf(next.getType(), Type.NODE)) {
                        if (buf != null && buf.length() > 0) {
                            receiver.characters(buf);
                            buf.setLength(0);
                        }
                        next.copyTo(context.getBroker(), receiver);
                        next = i.nextItem();
                    }
                }
                // flush remaining character data
                if (buf != null && buf.length() > 0) {
View Full Code Here

            this.proxy = proxy;
            try {
                final Sequence seq = expr.eval(proxy);
                final StringBuilder buf = new StringBuilder();
                final OrderedLinkedList strings = new OrderedLinkedList();
                Item item;
                for(final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                    item = i.nextItem();
                    strings.add(new OrderedLinkedList.SimpleNode(item.getStringValue().toUpperCase()));
                }
                for (final Iterator<OrderedLinkedList.SimpleNode> j = strings.iterator(); j.hasNext();)
                    buf.append((j.next()).getData());
                value = buf.toString();
            } catch (final XPathException e) {
View Full Code Here

        final MemTreeBuilder builder = context.getDocumentBuilder();
        final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
        receiver.checkNS = true;
        try {
            final SequenceIterator i = result.iterate();
            Item next = i.nextItem();
            StringBuilder buf = null;
            boolean allowAttribs = true;
            while (next != null) {
                context.proceed(this, builder);
                // if item is an atomic value, collect the string values of all
                // following atomic values and separate them by a space.
                if (Type.subTypeOf(next.getType(), Type.ATOMIC)) {
                    if (buf == null)
                        {buf = new StringBuilder();}
                    else if (buf.length() > 0)
                        {buf.append(' ');}
                    buf.append(next.getStringValue());
                    allowAttribs = false;
                    next = i.nextItem();
                //If the item is a node, flush any collected character data and
                //copy the node to the target doc.
                } else if (Type.subTypeOf(next.getType(), Type.NODE)) {
                 
                    //It is possible for a text node constructor to construct a text node containing a zero-length string.
                    //However, if used in the content of a constructed element or document node,
                    //such a text node will be deleted or merged with another text node.
                  if (next instanceof TextImpl && ((TextImpl)next).getStringValue().isEmpty()) {
                        next = i.nextItem();
            continue;
          }
                    if (buf != null && buf.length() > 0) {
                        receiver.characters(buf);
                        buf.setLength(0);
                    }
                    if (next.getType() == Type.ATTRIBUTE && !allowAttribs)
                        {throw new XPathException(this, ErrorCodes.XQTY0024,
                            "An attribute may not appear after another child node.");}
                    next.copyTo(context.getBroker(), receiver);
                    allowAttribs = next.getType() == Type.ATTRIBUTE || next.getType() == Type.NAMESPACE;
                    next = i.nextItem();
                }
            }
            // flush remaining character data
            if (buf != null && buf.length() > 0)
View Full Code Here

        final Sequence inner = getArgument(0).eval(contextSequence, contextItem);
        if (inner.isEmpty()) {
            result = Sequence.EMPTY_SEQUENCE;
        } else {
            final SequenceIterator iter = inner.iterate();
            Item item = iter.nextItem();
            AtomicValue value = item.atomize();
            //Any values of type xdt:untypedAtomic are cast to xs:double
            if (value.getType() == Type.UNTYPED_ATOMIC)
                {value = value.convertTo(Type.DOUBLE);}
            if (!(value instanceof ComputableValue)) {
                throw new XPathException(this, ErrorCodes.FORG0006,
                    Type.getTypeName(value.getType()) + "(" + value + ") " +
                    "can not be an operand in a sum", value);
            }
            //Set the first value
            ComputableValue sum = (ComputableValue) value;
            while (iter.hasNext()) {
                item = iter.nextItem();
                value = item.atomize();
                //Any value of type xdt:untypedAtomic are cast to xs:double
                if (value.getType() == Type.UNTYPED_ATOMIC)
                    {value = value.convertTo(Type.DOUBLE);}
                if (!(value instanceof ComputableValue)) {
                    throw new XPathException(this, ErrorCodes.FORG0006, "" +
View Full Code Here

          //TODO : test if a range index is defined *iff* it is compatible with the collator
        final Collator collator = getCollator(contextSequence, contextItem, 2);
        final SequenceIterator iter = arg.unorderedIterator();
        AtomicValue min = null;
        while (iter.hasNext()) {
                final Item item = iter.nextItem();
                if (item instanceof QNameValue)
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(item.getType()), arg);}
                AtomicValue value = item.atomize();

                //Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.
            if (Type.subTypeOf(value.getType(), Type.DURATION)) {
              value = ((DurationValue)value).wrap();
              if (value.getType() == Type.YEAR_MONTH_DURATION) {
View Full Code Here

          //TODO : test if a range index is defined *iff* it is compatible with the collator
        final Collator collator = getCollator(contextSequence, contextItem, 2);
        final SequenceIterator iter = arg.unorderedIterator();
        AtomicValue max = null;
        while (iter.hasNext()) {
                final Item item = iter.nextItem();

                if (item instanceof QNameValue)
                {throw new XPathException(this, ErrorCodes.FORG0006, "Cannot compare " + Type.getTypeName(item.getType()), arg);}
               
                AtomicValue value = item.atomize();                

                //Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values.
            if (Type.subTypeOf(value.getType(), Type.DURATION)) {
              value = ((DurationValue)value).wrap();
              if (value.getType() == Type.YEAR_MONTH_DURATION) {
View Full Code Here

        }
        final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
        final Collator collator = getCollator(contextSequence, contextItem, 2);   
        final TreeSet<AtomicValue> set = new TreeSet<AtomicValue>(new ValueComparator(collator));
        final ValueSequence result = new ValueSequence();
        Item item;
        AtomicValue value;
        boolean hasAlreadyNaN = false;
        for (final SequenceIterator i = seq.iterate(); i.hasNext();) {
            item = i.nextItem();
            value = item.atomize();
            if (!set.contains(value)) {
                if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
                    if (((NumericValue)value).isNaN()) {
                        //although NaN does not equal itself, if $arg
                        //contains multiple NaN values a single NaN is returned.
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.