Package org.exist.xquery.value

Examples of org.exist.xquery.value.SequenceIterator


      Sequence zero = IntegerValue.ZERO;
      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)) {
View Full Code Here


  /* (non-Javadoc)
   * @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
  {
    SequenceIterator i;
   
    if( isCalledAs( "log" ) ) {
      i = args[1].unorderedIterator();
      if( args[1].isEmpty() ) {
        return( Sequence.EMPTY_SEQUENCE );
      }
    } else if( isCalledAs( "log-app" ) ) {
      i = args[2].unorderedIterator();
      if( args[2].isEmpty() ) {
        return( Sequence.EMPTY_SEQUENCE );
      }
    } else {
      i = args[0].unorderedIterator();
      if( args[0].isEmpty() ) {
        return( Sequence.EMPTY_SEQUENCE );
      }
    }
   
    // add line of the log statement
    final StringBuilder buf = new StringBuilder();
                buf.append("(");
               
    buf.append("Line: ");
    buf.append(this.getLine());
               
                //add the source to the log statement
                if(getSource() != null && getSource().getKey() != null) {
                    buf.append(" ");
                    buf.append(getSource().getKey());
                }
               
    buf.append(") ");
   
    while(i.hasNext()) {
      final Item next = i.nextItem();
      if( Type.subTypeOf( next.getType(), Type.NODE ) ) {
        final Serializer serializer = context.getBroker().getSerializer();
        serializer.reset();
        try {
          buf.append( serializer.serialize( (NodeValue)next ) );
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)
        receiver.characters(buf);
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)
        receiver.characters(buf);
View Full Code Here

    }

  public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathException
  {
    List <InetSocketAddress> ialist = new ArrayList <InetSocketAddress>();
    SequenceIterator i = args[0].iterate();
    do {
      Properties props = ModuleUtils.parseProperties( ((NodeValue) i.nextItem()).getNode() );
      String host = props.getProperty("host");
      String tmp  = props.getProperty("port");
      int    port  = tmp == null ? 11211 : new Integer(tmp).intValue();  
      InetSocketAddress ia = new InetSocketAddress(host, port);
      ialist.add(ia);
    } while (i.hasNext());
   
    boolean isbinary = args[1].isEmpty() ? false : new Boolean(args[1].itemAt(0).getStringValue());
   
    MemcachedClient client;
    try {
View Full Code Here

        outputProperties.setProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );

        if (sSerializeParams.hasOne() && Type.subTypeOf(sSerializeParams.getItemType(), Type.NODE)) {
            SerializerUtils.getSerializationOptions(this, (NodeValue) sSerializeParams.itemAt(0), outputProperties);
        } else {
            SequenceIterator siSerializeParams = sSerializeParams.iterate();
            while(siSerializeParams.hasNext()) {
                final String serializeParam = siSerializeParams.nextItem().getStringValue();
                final String opt[] = Option.parseKeyValuePair(serializeParam);
                if(opt != null && opt.length == 2) {
                    outputProperties.setProperty( opt[0], opt[1] );
                }
            }
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)
        receiver.characters(buf);
View Full Code Here

        final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);

        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) {
                    receiver.characters(buf);
View Full Code Here

        // create the output
        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)
                {receiver.characters(buf);}
View Full Code Here

        Sequence result;
        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)) {
View Full Code Here

TOP

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

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.