Package org.exist.xquery.value

Examples of org.exist.xquery.value.NodeValue


    }

    @Override
    public void add(final Source src) throws HttpClientException {
        try {
            final NodeValue nodeValue = ModuleUtils.sourceToXML(context, src);
            result.add(nodeValue);
        } catch(final SAXException saxe) {
            throw new HttpClientException("Unable to add Source to result:" + saxe.getMessage(), saxe);
        } catch(final IOException ioe) {
            throw new HttpClientException("Unable to add Source to result:" + ioe.getMessage(), ioe);
View Full Code Here


            sax.startDocument();
           
            while(siNode.hasNext())
            {
             final NodeValue next = (NodeValue)siNode.nextItem();
               serializer.toSAX(next)
            }
           
            sax.endDocument();
            writer.close();
View Full Code Here

              return new EmptySequence();
            }
            querySource = new StringSource(queryStr);
        }

        NodeValue contextInit = null;
        if(isCalledAs("eval-with-context")) {
            // set the context initialization param for later use
            contextInit = (NodeValue) args[argCount++].itemAt(0);
        }

        // should the compiled query be cached?
        boolean cache = false;
        if(argCount < getArgumentCount()) {
            cache = ((BooleanValue)args[argCount].itemAt(0)).effectiveBooleanValue();
        }

        // save some context properties
        evalContext.pushNamespaceContext();

        final LocalVariable mark = evalContext.markLocalVariables(false);

        final DocumentSet oldDocs = evalContext.getStaticallyKnownDocuments();
        if(exprContext != null) {
            evalContext.setStaticallyKnownDocuments(exprContext.getDocumentSet());
        }

        if(evalContext.isProfilingEnabled(2)) {
            evalContext.getProfiler().start(this, "eval: " + expr);
        }

        // fixme! - hook for debugger here /ljo

        final Sequence sequence = null;

        final XQuery xqueryService = evalContext.getBroker().getXQueryService();
        final XQueryContext innerContext;
        if (contextInit != null) {
            // eval-with-context: initialize a new context
            innerContext = xqueryService.newContext(evalContext.getAccessContext());
            initContextSequence = initContext(contextInit.getNode(), innerContext);
        } else {
            // use the existing outer context
            // TODO: check if copying the static context would be sufficient???
            innerContext = evalContext.copyContext();
            innerContext.setShared(true);
            //innerContext = context;
        }
       
        //set module load path
        if(Type.subTypeOf(expr.getType(), Type.ANY_URI)) {
            String uri = null;
            final Object key = querySource.getKey();
           
            if(key instanceof XmldbURI) {
                uri = XmldbURI.EMBEDDED_SERVER_URI.append(((XmldbURI)key).removeLastSegment()).toString();
//          } else if (key instanceof URL) {
//              TODO: uri = ((URL) key).getParent()
            } else if (key instanceof String && querySource instanceof FileSource) {
                uri = ((FileSource) querySource).getFile().getParent();
            }
         
            if (uri != null) {
                innerContext.setModuleLoadPath(uri);
            }
        }

        //bind external vars?
        if(isCalledAs("eval") && getArgumentCount() == 3) {
            if(!args[2].isEmpty()) {
                final Sequence externalVars = args[2];
                for(int i = 0; i < externalVars.getItemCount(); i++) {
                    final Item varName = externalVars.itemAt(i);
                    if(varName.getType() == Type.QNAME) {
                        final Item varValue = externalVars.itemAt(++i);
                        innerContext.declareVariable(((QNameValue)varName).getQName(), varValue);
                    }
                }
            }
        }


        // fixme! - hook for debugger here /ljo
        try {

            if(this.getArgumentCount() == 4) {
                final NodeValue contextItem = (NodeValue)args[3].itemAt(0);
                if (contextItem != null) {
                    //TODO : sort this out
                    if (exprContext != null) {
                        LOG.warn("exprContext and contextItem are not null");
                    }
                    exprContext = contextItem.toSequence();
                }
            }

            if(initContextSequence != null) {
                LOG.info("there now");
View Full Code Here

      //TODO : more check on attributes existence and on their values
      if (child.getNodeType() == Node.ELEMENT_NODE &&  "variable".equals(child.getLocalName())) {
        final Element elem = (Element) child;
                                final String qname = elem.getAttribute("name");
                                final String source = elem.getAttribute("source");
                                NodeValue value;
                                if (source != null && source.length() > 0) {
                                    // load variable contents from URI
                                    value = loadVarFromURI(source);
                                } else {
                                    value = (NodeValue) elem.getFirstChild();
                                    if (value instanceof ReferenceNode)
                                        {value = ((ReferenceNode) value).getReference();}
                                }
                                final String type = elem.getAttribute("type");
        if (type != null && Type.subTypeOf(Type.getType(type), Type.ATOMIC)) {
          innerContext.declareVariable(qname, value.atomize().convertTo(Type.getType(type)));
        } else {
          innerContext.declareVariable(qname, value);
        }
      } else if (child.getNodeType() == Node.ELEMENT_NODE &&  "output-size-limit".equals(child.getLocalName())) {
        final Element elem = (Element) child;
        //TODO : error check
        innerContext.getWatchDog().setMaxNodes(Integer.valueOf(elem.getAttribute("value")).intValue());
      } else if (child.getNodeType() == Node.ELEMENT_NODE &&  "current-dateTime".equals(child.getLocalName())) {
        final Element elem = (Element) child;
        //TODO : error check
        final DateTimeValue dtv = new DateTimeValue(elem.getAttribute("value"));
            innerContext.setCalendar(dtv.calendar);
      } else if (child.getNodeType() == Node.ELEMENT_NODE &&  "implicit-timezone".equals(child.getLocalName())) {
        final Element elem = (Element) child;
        //TODO : error check
        final Duration duration = TimeUtils.getInstance().newDuration(elem.getAttribute("value"));
            innerContext.setTimeZone(new SimpleTimeZone((int)duration.getTimeInMillis(new Date()), "XQuery context"));
      } else if (child.getNodeType() == Node.ELEMENT_NODE &&  "unbind-namespace".equals(child.getLocalName())) {
        final Element elem = (Element) child;
        //TODO : error check
        if (elem.getAttribute("uri") != null) {
          innerContext.removeNamespace(elem.getAttribute("uri"));
        }
      } else if (child.getNodeType() == Node.ELEMENT_NODE &&  "staticallyKnownDocuments".equals(child.getLocalName())) {
        final Element elem = (Element) child;
        //TODO : iterate over the children
        NodeValue value = (NodeValue) elem.getFirstChild();
        if (value instanceof ReferenceNode)
          {value = ((ReferenceNode) value).getReference();}
        final XmldbURI[] pathes = new XmldbURI[1];
        //TODO : aggregate !
        //TODO : cleanly seperate the statically know docollection and documents
        pathes[0] = XmldbURI.create(value.getStringValue());
        innerContext.setStaticallyKnownDocuments(pathes);
      } /*else if (child.getNodeType() == Node.ELEMENT_NODE &&  "mapModule".equals(child.getLocalName())) {
        Element elem = (Element) child;
        //TODO : error check
        if (elem.getAttribute("namespace") != null && elem.getAttribute("uri") != null) {
          innerContext.mapModule(elem.getAttribute("namespace"),
              XmldbURI.create(elem.getAttribute("uri")));
        }
      } */ else if (child.getNodeType() == Node.ELEMENT_NODE &&  "default-context".equals(child.getLocalName())) {
                          final Element elem = (Element) child;
                                final NodeValue nodevalue = (NodeValue) elem;
                                result = nodevalue.toSequence();
                        }
    }

            return result;
  }
View Full Code Here

                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
View Full Code Here

            final InMemoryNodeSet result = new InMemoryNodeSet();
            final MemTreeBuilder builder = context.getDocumentBuilder();
            final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder, true);
            for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
                final int nodeNr = builder.getDocument().getLastNode();
                final NodeValue next = (NodeValue) i.nextItem();
                next.toSAX(context.getBroker(), receiver, serializeOptions);
                result.add(builder.getDocument().getNode(nodeNr + 1));
            }
            return result;
        } catch (final SAXException e) {
            throw new XPathException(this, e);
View Full Code Here

    try
    {
      Templates templates = null;
      if(Type.subTypeOf(stylesheetItem.getType(), Type.NODE))
      {
        final NodeValue stylesheetNode = (NodeValue)stylesheetItem;
        // if the passed node is a document node or document root element,
        // we construct an XMLDB URI and use the caching implementation.
        if(stylesheetNode.getImplementationType() == NodeValue.PERSISTENT_NODE)
        {
          final NodeProxy root = (NodeProxy) stylesheetNode;
                    if (root.getNodeId() == NodeId.DOCUMENT_NODE || root.getNodeId().getTreeLevel() == 1)
                    {
            //as this is a persistent node (e.g. a stylesheet stored in the db)
View Full Code Here

       
       
        try {
       
            if(Type.subTypeOf(args[0].getItemType(), Type.NODE)) {
                final NodeValue node = (NodeValue) args[0].itemAt(0);
                if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                    final NodeProxy proxy = (NodeProxy) node;
                    doc = proxy.getDocument();
                    doc.getUpdateLock().acquire(Lock.READ_LOCK);
                }
            } else if(Type.subTypeOf(args[0].getItemType(), Type.STRING)) {
View Full Code Here

            if (contextSequence != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                    "CONTEXT SEQUENCE", contextSequence);}
        }
        Sequence result = null;
        NodeValue node = null;
        if (isCalledAs("static-base-uri")) {
            if (context.isBaseURIDeclared()) {
                result = context.getBaseURI();
                if (!((AnyURIValue) result).toURI().isAbsolute()) {
//                    throw new XPathException(this, ErrorCodes.XPST0001, "");
                    LOG.debug("URI is not absolute");
                    result = Sequence.EMPTY_SEQUENCE;
                }
            } else {
                result = Sequence.EMPTY_SEQUENCE;
            }
        } else {
            if (args.length == 0) {
                if (contextSequence == null || contextSequence.isEmpty()) {
                    throw new XPathException(this, ErrorCodes.XPDY0002,
                        "Context sequence is empty and no argument specified");
                }
                final Item item = contextSequence.itemAt(0);
                if (!Type.subTypeOf(item.getType(), Type.NODE)) {
                    throw new XPathException(this, ErrorCodes.XPTY0004,
                        "Context item is not a node");
                }
                node = (NodeValue) item;
            } else {
                if (args[0].isEmpty()) {
                    result = Sequence.EMPTY_SEQUENCE;
                } else {
                    node = (NodeValue) args[0].itemAt(0);
                }
            }
        }
        if (result == null && node != null) {
            result = Sequence.EMPTY_SEQUENCE;
            // This is implemented to be a recursive ascent according to
            // section 2.5 in www.w3.org/TR/xpath-functions
            // see memtree/ElementImpl and dom/ElementImpl. /ljo
            final Node domNode = node.getNode();
            final short type = domNode.getNodeType();
            //A direct processing instruction constructor creates a processing instruction node
            //whose target property is PITarget and whose content property is DirPIContents.
            //The base-uri property of the node is empty.
            //The parent property of the node is empty.
View Full Code Here

            if (name.startsWith(REQ_ATTRIBUTE_PREFIX) &&
                !(name.startsWith(REQ_ATTRIBUTE_OUTPUT) || REQ_ATTRIBUTE_INPUT.equals(name)
                                                            || REQ_ATTRIBUTE_STYLESHEET.equals(name))) {
                Object value = request.getAttribute(name);
                if (value instanceof NodeValue) {
                    final NodeValue nv = (NodeValue) value;
                    if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
                        value = nv.toMemNodeSet();
                    }
                }
                transformer.setParameter(name, value);
                transformer.setParameter(name.substring(REQ_ATTRIBUTE_PREFIX.length()), value);
            }
View Full Code Here

TOP

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

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.