Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


        Sequence result = new ValueSequence();
        if (isCalledAs("map")) {
            final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
            ref.analyze(cachedContextInfo);
            for (final SequenceIterator i = args[1].iterate(); i.hasNext(); ) {
                final Item item = i.nextItem();
                final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[]{item.toSequence()});
                result.addAll(r);
            }
        } else if (isCalledAs("for-each")) {
            final FunctionReference ref = (FunctionReference) args[1].itemAt(0);
            ref.analyze(cachedContextInfo);
            for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
                final Item item = i.nextItem();
                final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[]{item.toSequence()});
                result.addAll(r);
            }
        } else if (isCalledAs("filter")) {
            FunctionReference ref;
            Sequence seq;
            // Hack: switch parameters for backwards compatibility
            if (Type.subTypeOf(args[1].getItemType(), Type.FUNCTION_REFERENCE)) {
                ref = (FunctionReference) args[1].itemAt(0);
                seq = args[0];
            } else {
                ref = (FunctionReference) args[0].itemAt(0);
                seq = args[1];
            }

            ref.analyze(cachedContextInfo);
          for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            final Item item = i.nextItem();
            final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[] { item.toSequence() });
            if (r.effectiveBooleanValue())
              {result.add(item);}
          }
        } else if (isCalledAs("fold-left")) {
            final FunctionReference ref = (FunctionReference) args[2].itemAt(0);
View Full Code Here


        final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
        Sequence result;
        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.ceiling();
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
View Full Code Here

            } else {
                tmp = new ValueSequence();
                ((ValueSequence)tmp).keepUnOrdered(unordered);
            }
           
            Item item;
            final SequenceIterator iterator = seq.iterate();
            for(int i = 0; i < start; i++) {
                item = iterator.nextItem();
            }
            int i=0;
View Full Code Here

            {throw new XPathException(this, "Expected a collection as the argument " + (paramNumber + 1) + ".");}
       
        final boolean collectionNeedsClose = false;
       
        Collection collection = null;
        final Item item = args[paramNumber].itemAt(0);
        if(Type.subTypeOf(item.getType(), Type.NODE))
        {
          final NodeValue node = (NodeValue)item;
          logger.debug("Found node");
          if(node.getImplementationType() == NodeValue.PERSISTENT_NODE)
          {
View Full Code Here

                    switch (node.getNodeType())
                    {
                        case Node.ELEMENT_NODE:
                final NodeListImpl content = new NodeListImpl();
                for (final SequenceIterator j = contentSeq.iterate(); j.hasNext(); ) {
                  final Item next = j.nextItem();
                  if (Type.subTypeOf(next.getType(), Type.NODE))
                    {content.add(((NodeValue)next).getNode());}
                  else {
                    text = new TextImpl(next.getStringValue());
                    content.add(text);
                  }
                }
                            ((ElementImpl) node).update(transaction, content);
                            break;
View Full Code Here

    }

    @Override
    public Sequence next() throws HttpClientException {
        try {
            Item item = sequenceIterator.nextItem();
            org.exist.xquery.value.Sequence singleton = (org.exist.xquery.value.Sequence) item;
            return new EXistSequence(singleton, context);
        } catch (XPathException xpe) {
            throw new HttpClientException(xpe.getMessage(), xpe);
        }
View Full Code Here

        else {actualCardinality = Cardinality.ONE;}
       
        if (!Cardinality.checkCardinality(requiredCardinality, actualCardinality))
            {return false;}
        for(final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            final Item next = i.nextItem();
            if(!type.checkType(next)) {
                return false;
            }
        }
        return true;
View Full Code Here

    if(docName != null && docName.length() == 0)
      {docName = null;}
    else if(docName != null)
      {docName = new AnyURIValue(docName).toXmldbURI().toString();}
   
    final Item item = args[2].itemAt(0);
        String mimeType = MimeType.XML_TYPE.getName();
    boolean binary = !Type.subTypeOf(item.getType(), Type.NODE);
   
    if(getSignature().getArgumentCount() == 4) {
        mimeType = args[3].getStringValue();
        final MimeType mime = MimeTable.getInstance().getContentType(mimeType);
        if (mime != null)
      {binary = !mime.isXMLType();}
           
    } else if (docName != null){
        final MimeType mime = MimeTable.getInstance().getContentTypeFor(docName);
            if (mime != null) {
                mimeType = mime.getName();
                binary = !mime.isXMLType();
            }
        }
   
    Resource resource;
    try {
      if(Type.subTypeOf(item.getType(), Type.JAVA_OBJECT)) {
        final Object obj = ((JavaObjectValue)item).getObject();
        if(!(obj instanceof File)) {
                    logger.error("Passed java object should be a File");
          throw new XPathException(this, "Passed java object should be a File");
                }
        resource = loadFromFile(collection, (File)obj, docName, binary, mimeType);

      } else if(Type.subTypeOf(item.getType(), Type.ANY_URI)) {
        try {
          final URI uri = new URI(item.getStringValue());
          resource = loadFromURI(collection, uri, docName, binary, mimeType);

        } catch (final URISyntaxException e) {
                    logger.error("Invalid URI: " + item.getStringValue());
          throw new XPathException(this, "Invalid URI: " + item.getStringValue(), e);
        }

      } else {
        if(binary) {
          resource = collection.createResource(docName, "BinaryResource");
                } else {
          resource = collection.createResource(docName, "XMLResource");
                }

        if(Type.subTypeOf(item.getType(), Type.STRING)) {
          resource.setContent(item.getStringValue());

        } else if(item.getType() == Type.BASE64_BINARY) {
          resource.setContent(((BinaryValue)item).toJavaObject());

        } else if(Type.subTypeOf(item.getType(), Type.NODE)) {
          if(binary) {
            final StringWriter writer = new StringWriter();
            final SAXSerializer serializer = new SAXSerializer();
            serializer.setOutput(writer, null);
            item.toSAX(context.getBroker(), serializer, SERIALIZATION_PROPERTIES);
            resource.setContent(writer.toString());
          } else {
            final ContentHandler handler = ((XMLResource)resource).setContentAsSAX();
            handler.startDocument();

            item.toSAX(context.getBroker(), handler, SERIALIZATION_PROPERTIES);
            handler.endDocument();
          }
        } else {
                    logger.error("Data should be either a node or a string");
          throw new XPathException(this, "Data should be either a node or a string");
View Full Code Here

            final RootNode rootNode = new RootNode(context);
            contextSequence = rootNode.eval(null, null);
        }
        final Sequence[] args = getArguments(null, null);
       
        final Item item = args[0].itemAt(0);
        QNameValue qval;
        try {
            // attempt to convert the first argument to a QName
            qval = (QNameValue) item.convertTo(Type.QNAME);
        } catch (final XPathException e) {
            // wrong type: generate a diagnostic error
            throw new XPathException(this,
                    Messages.formatMessage(Error.FUNC_PARAM_TYPE,
                            new Object[] { "1", mySignature.toString(), null,
                            Type.getTypeName(Type.QNAME), Type.getTypeName(item.getType()) }
                    ));
        }
        final QName qname = qval.getQName();
       
        final AtomicValue comparisonCriterium = args[1].itemAt(0).atomize();
View Full Code Here

    throws XPathException {
   
      if(args[0].isEmpty()) {
          return Sequence.EMPTY_SEQUENCE;
      }
    final Item item = args[0].itemAt(0);
    if(item.getType() == Type.JAVA_OBJECT) {
      final Object o = ((JavaObjectValue) item).getObject();
            if (!(o instanceof Collection))
                {throw new XPathException(this, "Passed Java object should be of type org.xmldb.api.base.Collection");}
            final Collection collection = (Collection)o;
            try {
        return new StringValue(collection.getName());
      } catch (final XMLDBException e) {
        throw new XPathException(this, "Failed to retrieve collection name", e);
      }
        } else if (Type.subTypeOf(item.getType(), Type.STRING)) {
            final String path = item.getStringValue();
            try {
                final XmldbURI uri = XmldbURI.xmldbUriFor(path).removeLastSegment();
                return new StringValue(uri.toString());
            } catch (final URISyntaxException e) {
                throw new XPathException(this, "Illegal URI for resource path: " + path);
            }
        } else if(Type.subTypeOf(item.getType(), Type.NODE)) {
      final NodeValue node = (NodeValue) item;
      if(node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
        final NodeProxy p = (NodeProxy) node;
        //TODO: use xmldbUri
        return new StringValue(p.getDocument().getCollection().getURI().toString())
      }
    } else
      {throw new XPathException(this, "First argument to util:collection-name should be either " +
        "a Java object of type org.xmldb.api.base.Collection or a node; got: " +
        Type.getTypeName(item.getType()));}
    return Sequence.EMPTY_SEQUENCE;
  }
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.