Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


        final TreeMap collections = new TreeMap();
        TreeMap documents;
        Integer hits;
        try {
      for (final SequenceIterator i = results.iterate(); i.hasNext(); ) {
          final Item item = i.nextItem();
          if(Type.subTypeOf(item.getType(), Type.NODE)) {
              final NodeValue node = (NodeValue)item;
              if(node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                  final NodeProxy p = (NodeProxy)node;
                  if ((documents = (TreeMap) collections.get(p.getDocument().getCollection().getURI())) == null) {
                      documents = new TreeMap();
View Full Code Here


            if(canCache && contextSequence.isCacheable())
        {cached = new CachedResult(contextSequence, contextItem, result);}

    // otherwise we have to walk through each item in the context
    } else {
      Item current;
      final @SuppressWarnings("unused")
      String arg;
      NodeSet nodes;
      result = new ExtArrayNodeSet();
      Sequence temp;
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext();) {
        current = i.nextItem();
        final List<String> terms = getSearchTerms(contextSequence);
        nodes =
          path == null
          ? contextSequence.toNodeSet()
              : path
              .eval(current.toSequence()).toNodeSet();
        temp = evalQuery(nodes, terms);
        result.addAll(temp);
      }
    }
        preselectResult = null;
View Full Code Here

            String name = null;
            if (qnameExpr != null) {
                Sequence nameSeq = qnameExpr.eval(contextSequence, contextItem);
                if (!nameSeq.hasOne())
                    throw new XPathException(this, "The name expression should evaluate to a single value");
                Item qnItem = nameSeq.itemAt(0);
                if (qnItem.getType() == Type.QNAME)
                    qn = ((QNameValue) qnItem).getQName();
                else
                    name = nameSeq.getStringValue();
            } else {
                name = this.name;
            }
            if (qn == null) {
                //Not in the specs but... makes sense
                if(!XMLChar.isValidName(name))
                    throw new XPathException(this, ErrorCodes.XPTY0004,
                        "'" + name + "' is not a valid attribute name");
                try {
                    qn = QName.parse(context, name, null);
                } catch (IllegalArgumentException e) {
                    throw new XPathException(this, ErrorCodes.XPTY0004,
                        "'" + name + "' is not a valid attribute name");
                }
            }
            String value = this.value;
            Sequence valueSeq = null;
            if (valueExpr != null) {
              valueSeq = valueExpr.eval(contextSequence, contextItem);
            } else {
                context.pushDocumentContext();
                valueSeq = super.eval(contextSequence, contextItem);
                context.popDocumentContext();
            }
            if (!valueSeq.isEmpty()) {
                StringBuilder buf = new StringBuilder();
                for(SequenceIterator i = valueSeq.iterate(); i.hasNext(); ) {
                    Item next = i.nextItem();
                    buf.append(next.getStringValue());
                    if(i.hasNext())
                        buf.append(' ');
                }
                value = buf.toString();
            }
View Full Code Here

   
    SortItem[] items = new SortItem[contextSequence.getItemCount()];
    int i = 0;
//    for (Item item : contextSequence) {
        for (SequenceIterator iterInner = contextSequence.iterate(); iterInner.hasNext();) {
            Item item = iterInner.nextItem();  

            items[i] = new SortItem(item, i);
      i++;
    }
   
View Full Code Here

            if(xpe.getErrorCode() == ErrorCodes.XQST0059) {
                final Sequence errorVals = xpe.getErrorVal();
               
                if(errorVals != null && errorVals.getItemCount() > 0){
                   
                    final Item errorVal1 = errorVals.itemAt(0);
                    if(errorVal1 instanceof StringValue) {
                        if(missingModuleHint == null) {
                            missingModuleHint = new MissingModuleHint();
                        }
                        missingModuleHint.moduleHint = ((StringValue)errorVal1).getStringValue();
                    }
                   
                    if(errorVals.getItemCount() == 2) {
                        final Item errorVal2 = errorVals.itemAt(1);
                        if(errorVal2 instanceof StringValue) {
                            if(missingModuleHint == null) {
                                missingModuleHint = new MissingModuleHint();
                            }
                           
View Full Code Here

        MemTreeBuilder builder = context.getDocumentBuilder();

        try {
//            for (Item item : contextSequence) {
            for (SequenceIterator iterInner = contextSequence.iterate(); iterInner.hasNext();) {
                Item i = iterInner.nextItem();
               
                org.w3c.dom.Node item;
                if (i instanceof NodeValue) {
                  item = ((NodeValue) i).getNode();
        } else
                  item = (org.w3c.dom.Node) i;

                //UNDERSTAND: strange place to workaround
              if (item instanceof org.w3c.dom.Document) {
            org.w3c.dom.Document document = (org.w3c.dom.Document) item;
            item = document.getDocumentElement();
          }
         
          if (item instanceof org.w3c.dom.Element) {
            QName qn;
                  if (item instanceof QNameValue) {
                      qn = ((QNameValue)item).getQName();
                  } else {
                      qn = ((QNameable)item).getQName();
                      if (qn.getPrefix() == null && context.getInScopeNamespace("") != null) {
                           qn.setNamespaceURI(context.getInScopeNamespace(""));
                      }
                  }
            int nodeNr = builder.startElement(qn, null);
           
            if (use_attribute_sets != null)
              getXSLContext().getXSLStylesheet().attributeSet(use_attribute_sets, contextSequence, i);

            super.eval(contextSequence, i);
           
                  builder.endElement();
                  NodeImpl node = builder.getDocument().getNode(nodeNr);
                  result.add(node);
          } else if (item instanceof org.w3c.dom.Text) {
            int nodeNr = builder.characters(i.getStringValue());
                  NodeImpl node = builder.getDocument().getNode(nodeNr);
                  result.add(node);
          } else {
            throw new XPathException("not supported node type "+i.getType());
          }
        }
        } finally {
            context.popInScopeNamespaces();
        }
View Full Code Here

        //get the url
        String     url            = args[0].itemAt( 0 ).getStringValue();

        //get the payload

        Item       payload        = args[1].itemAt( 0 );

        //get the persist state
        boolean    persistState    = args[2].effectiveBooleanValue();

        PostMethod post           = new PostMethod( url );

        if( isCalledAs( "post" ) ) {
            RequestEntity entity = null;

            if( Type.subTypeOf( payload.getType(), Type.NODE ) ) {

                //serialize the node to SAX
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                OutputStreamWriter    osw  = null;

                try {
                    osw = new OutputStreamWriter( baos, "UTF-8" );
                }
                catch( UnsupportedEncodingException e ) {
                    throw( new XPathException( this, e.getMessage() ) );
                }

                SAXSerializer sax = new SAXSerializer( osw, new Properties() );

                try {
                    payload.toSAX( context.getBroker(), sax, new Properties() );
                    osw.flush();
                    osw.close();
                }
                catch( Exception e ) {
                    throw( new XPathException( this, e.getMessage() ) );
                }

                byte[] reqPayload = baos.toByteArray();
                entity = new ByteArrayRequestEntity( reqPayload, "application/xml; charset=utf-8" );
            } else {

                try {
                    entity = new StringRequestEntity( payload.getStringValue(), "text/text; charset=utf-8", "UTF-8" );
                }
                catch( UnsupportedEncodingException uee ) {
                    uee.printStackTrace();
                }
            }
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

   
    int pos = context.getContextPosition();
   
//    for (Item item : currentSequence) {
    for (SequenceIterator iterInner = currentSequence.iterate(); iterInner.hasNext();) {
      Item item = iterInner.nextItem();
//      if (currentSequence == item)
//        item = null;

      //UNDERSTAND: work around
//      if (item instanceof org.w3c.dom.Document) {
View Full Code Here

    int pos = context.getContextPosition();

    Template template = namedTemplates.get(name);
    for (SequenceIterator iterInner = currentSequence.iterate(); iterInner.hasNext();) {
      Item item = iterInner.nextItem();  
     
      //UNDERSTAND: work around
//      if (item instanceof org.w3c.dom.Document) {
//        org.w3c.dom.Document document = (org.w3c.dom.Document) item;
//        item = (Item) document.getDocumentElement();
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.