Package org.exist.xquery.value

Examples of org.exist.xquery.value.Item


        return result;
    }

    protected Item getKey(Sequence contextSequence, Item contextItem) throws XPathException {
        Sequence keySeq = getArgument(1).eval(contextSequence, contextItem);
        Item key = keySeq.itemAt(0);
        if (!(Type.subTypeOf(key.getType(), Type.STRING) || Type.subTypeOf(key.getType(), Type.NODE)))
            throw new XPathException(this, "Second argument to ft:query should either be a query string or " +
                    "an XML element describing the query. Found: " + Type.getTypeName(key.getType()));
        return key;
    }
View Full Code Here


                    Sequence.EMPTY_SEQUENCE
            };
            context.pushDocumentContext();
            Sequence seq = callback.evalFunction(null, null, params);
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                next.copyTo(context.getBroker(), docBuilder);
            }
            context.popDocumentContext();
        }
View Full Code Here

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      EXISerializer exiSerializer = null;
      if(args.length > 1) {
        if(!args[1].isEmpty()) {
          Item xsdItem = args[1].itemAt(0);
          InputStream xsdInputStream = EXIUtils.getInputStream(xsdItem, context);
          exiSerializer = new EXISerializer(baos, xsdInputStream);
        }
        else {
          exiSerializer = new EXISerializer(baos);
        }
      }
      else {
        exiSerializer = new EXISerializer(baos);
      }
      Item inputNode = args[0].itemAt(0);
      exiSerializer.startDocument();
          inputNode.toSAX(context.getBroker(), exiSerializer, new Properties());
          exiSerializer.endDocument();
          return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new ByteArrayInputStream(baos.toByteArray()));
    }
    catch(IOException ioex) {
      // TODO - test!
View Full Code Here

     
      // create default factory and EXI grammar for schema
      EXIFactory exiFactory = DefaultEXIFactory.newInstance();
      if(args.length > 1) {
        if(!args[1].isEmpty()) {
          Item xsdItem = args[1].itemAt(0);
          InputStream xsdInputStream = EXIUtils.getInputStream(xsdItem, context);
          GrammarFactory grammarFactory = GrammarFactory.newInstance();
          Grammar grammar = grammarFactory.createGrammar(xsdInputStream);
          exiFactory.setGrammar(grammar);
        }
View Full Code Here

    private <X> TypedValue<X> convertToType(final XQueryContext xqueryContext, final String argumentName, final TypedValue typedValue, final org.exquery.xquery.Type destinationType, final Class<X> underlyingDestinationClass) throws RestXqServiceException {
       
        //TODO consider changing Types that can be used as <T> to TypedValue to a set of interfaces for XDM types that
        //require absolute minimal implementation, and we provide some default or abstract implementations if possible
       
        final Item convertedValue;
        try {
            final int existDestinationType = TypeAdapter.toExistType(destinationType);
           
            final Item value;
           
            //TODO This type system is a complete mess:
            //EXQuery XDM should not have any concrete types, just interfaces
            //some of the abstract code in EXQuery needs to be able to instantiate types.
            //Consider a factory or java.util.ServiceLoader pattern
            if(typedValue instanceof org.exquery.xdm.type.StringTypedValue) {
                value = new StringValue(((org.exquery.xdm.type.StringTypedValue)typedValue).getValue());
            } else if(typedValue instanceof org.exquery.xdm.type.Base64BinaryTypedValue) {
                value = BinaryValueFromInputStream.getInstance(xqueryContext, new Base64BinaryValueType(), ((org.exquery.xdm.type.Base64BinaryTypedValue)typedValue).getValue());
            } else {
                value = (Item)typedValue.getValue();
            }

            if(existDestinationType == value.getType()) {
                convertedValue = value;
            } else if(value instanceof AtomicValue) {
                convertedValue = value.convertTo(existDestinationType);
            } else {
                LOG.warn("Could not convert parameter '" + argumentName + "' from '" + typedValue.getType().name() + "' to '" + destinationType.name() + "'.");
                convertedValue = value;
            }
           
View Full Code Here

//              qnameSeq = super.eval(contextSequence, contextItem);
           
            if (qnameSeq != null) {
              if(!qnameSeq.hasOne())
                throw new XPathException(this, "Type error: the node name should evaluate to a single item");
              Item qnitem = qnameSeq.itemAt(0);
              if (qnitem instanceof QNameValue) {
                qn = ((QNameValue)qnitem).getQName();
              } else {
                tagName = qnitem.getStringValue();
              }
            }
            if (qn == null) {
              if (tagName == null)
                  throw new XPathException(this, ErrorCodes.XPTY0004, "element name wasn't provided");
View Full Code Here

            Properties props = new Properties();
            props.setProperty(OutputKeys.INDENT, "yes");
            SAXSerializer serializer = new SAXSerializer(out, props);
            serializer.startDocument();
            for(SequenceIterator i = result.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                next.toSAX(broker, serializer, props);
            }
            serializer.endDocument();
            System.out.println(out.toString());
        } finally {
            pool.release(broker);
View Full Code Here

            assertNotNull(xquery);
            Sequence seq = xquery.execute("//SPEECH[ft:query(LINE, 'king')]", null, AccessContext.TEST);
            assertNotNull(seq);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                String value = serializer.serialize((NodeValue) next);
                //System.out.println(value);
            }
           
            BinaryDocument binDoc = (BinaryDocument) broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_BINARY_URI), Lock.READ_LOCK);
View Full Code Here

        if (select == null)
          {throw new SAXException("value-of requires a select attribute");}
        final Sequence seq = processQuery(select);
        if (LOG.isDebugEnabled())
          {LOG.debug("Found " + seq.getItemCount() + " items for value-of");}
        Item item;
        try {
          for (final SequenceIterator i = seq.iterate(); i.hasNext();) {
            item = i.nextItem();
            if(Type.subTypeOf(item.getType(), Type.NODE)) {
              final Node node = NodeSetHelper.copyNode(doc, ((NodeValue)item).getNode());
              if (stack.isEmpty())
                {contents.add(node);}
              else {
                final Element last = (Element) stack.peek();
                last.appendChild(node);
              }
            } else {
              final String value = item.getStringValue();
              characters(value.toCharArray(), 0, value.length());
            }
          }
        } catch (final XPathException e) {
          throw new SAXException(e.getMessage(), e);
View Full Code Here

           
            XQuery xquery = broker.getXQueryService();
            Sequence seq = xquery.execute("/products/product[last()]", null, AccessContext.TEST);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                System.out.println(serializer.serialize((NodeValue) next));
            }
        } catch (Exception e) {           
            fail(e.getMessage());
        } finally {
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.