Package org.exist.memtree

Examples of org.exist.memtree.NodeImpl$SingleNodeIterator


     *
     * @throws  IOException    
     * @throws  XPathException 
     */
    private void insertResponseBody(final XQueryContext context, final HttpMethod method, final MemTreeBuilder builder, final Map<String, Boolean>parserFeatures, final Map<String, String>parserProperties) throws IOException, XPathException {
        NodeImpl responseNode = null;
       
        final InputStream bodyAsStream = method.getResponseBodyAsStream();

        // check if there is a response body
        if(bodyAsStream != null) {

            CachingFilterInputStream cfis = null;
            FilterInputStreamCache cache = null;
            try {
                   
                //we have to cache the input stream, so we can reread it, as we may use it twice (once for xml attempt and once for string attempt)
                cache = FilterInputStreamCacheFactory.getCacheInstance(new FilterInputStreamCacheFactory.FilterInputStreamCacheConfiguration(){
                    @Override
                    public String getCacheClass() {
                        return (String) context.getBroker().getConfiguration().getProperty(Configuration.BINARY_CACHE_CLASS_PROPERTY);
                    }
                });

                cfis = new CachingFilterInputStream(cache, bodyAsStream);

                //mark the start of the stream
                cfis.mark(Integer.MAX_VALUE);


                // determine the type of the response document
                final Header responseContentType = method.getResponseHeader("Content-Type");

                final MimeType responseMimeType = getResponseMimeType(responseContentType);
                if(responseContentType != null) {
                    builder.addAttribute(new QName("mimetype", null, null), responseContentType.getValue());
                }

                //try and parse the response as XML
                try {
                    //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                    final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);
                    responseNode = (NodeImpl)ModuleUtils.streamToXML(context, shieldedInputStream);
                    builder.addAttribute(new QName("type", null, null ), "xml");
                    responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
                } catch(final SAXException se) {
                    // could not parse to xml
                    // not an error in itself, it will be treated either as HTML,
                    // text or binary here below
                    final String msg = "Request for URI '"
                        + method.getURI().toString()
                        + "' Could not parse http response content as XML (will try html, text or fallback to binary): "
                        + se.getMessage();
                    if(logger.isDebugEnabled()) {
                        logger.debug(msg, se);
                    } else {
                        logger.info(msg);
                    }
                } catch(final IOException ioe) {
                    final String msg = "Request for URI '" + method.getURI().toString() + "' Could not read http response content: " + ioe.getMessage();
                    logger.error(msg, ioe);
                    throw new XPathException(msg, ioe);
                }

                if(responseNode == null) {
                    //response is NOT parseable as XML

                    //is it a html document?
                    if(responseMimeType.getName().equals(MimeType.HTML_TYPE.getName())) {

                        //html document
                        try {

                            //reset the stream to the start, as we need to reuse since attempting to parse to XML
                            cfis.reset();

                            //parse html to xml(html)
                           
                            //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                            final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);
                           
                            responseNode = (NodeImpl)ModuleUtils.htmlToXHtml(context, method.getURI().toString(), new InputSource(shieldedInputStream), parserFeatures, parserProperties).getDocumentElement();
                            builder.addAttribute(new QName("type", null, null), "xhtml" );
                            responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
                        } catch(final URIException ue) {
                            throw new XPathException(this, ue.getMessage(), ue);
                        } catch(final SAXException se) {
                            //could not parse to xml(html)
                            logger.debug("Could not parse http response content from HTML to XML: " + se.getMessage(), se);
View Full Code Here


              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());
          }
        }
View Full Code Here

    private void sendDataToCallback() {
        // Retrieve result as document
        Document doc = docBuilderReceiver.getDocument();

        // Get the root
        NodeImpl root = (NodeImpl) doc.getDocumentElement();            

        // Construct parameters
        Sequence[] params = new Sequence[3];
        params[0] = root;
        params[1] = userData;
View Full Code Here

        context.pushDocumentContext();
        try {
            ExtendedXMLStreamReader reader;
            NodeValue nv = (NodeValue) args[0].itemAt(0);
            if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
                NodeImpl node = (NodeImpl) nv;
                reader = new InMemoryXMLStreamReader(node.getDocument(), node.getDocument());
            } else {
                NodeProxy proxy = (NodeProxy) nv;
                reader = context.getBroker().newXMLStreamReader(new NodeProxy(proxy.getDocument(), NodeId.DOCUMENT_NODE, proxy.getDocument().getFirstChildAddress()), false);
            }
View Full Code Here

     * @param queryText
     * @return search report
     */
    public NodeImpl search(final XQueryContext context, final List<String> toBeMatchedURIs, String queryText) throws XPathException {
       
        NodeImpl report = null;
       
        IndexSearcher searcher = null;
        try {
            // Get index searcher
            searcher = index.getSearcher();
View Full Code Here

       
    try {
            MemTreeBuilder builder = context.getDocumentBuilder();
            context.proceed(this, builder);
            int nodeNr = builder.characters(text);
            NodeImpl node = builder.getDocument().getNode(nodeNr);
            return node;
        } finally {
            if (newDocumentContext)
                context.popDocumentContext();
        }
View Full Code Here

//                content.eval(contextSequence, contextItem);
//            } else
              super.eval(contextSequence, contextItem);
           
            builder.endElement();
            NodeImpl node = builder.getDocument().getNode(nodeNr);
            return node;
        } finally {
            context.popInScopeNamespaces();
            if (newDocumentContext)
                context.popDocumentContext();
View Full Code Here

      TransformerHandler handler = factory.newTransformerHandler(templates);

//          TransformErrorListener errorListener = new TransformErrorListener();
//          handler.getTransformer().setErrorListener(errorListener);
     
          NodeImpl input;
      if (inputURL !=  null && inputURL != "")
            input = loadVarFromURI(context, testLocation+XSLTS_folder+"/TestInputs/"+inputURL);
          else
            input = loadVarFromString(context, "<empty/>");
View Full Code Here

    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        NodeImpl report = null;
        try {
            // Only match documents that match these URLs
            List<String> toBeMatchedURIs = new ArrayList<>();

            Sequence pathSeq = getArgumentCount() == 2 ? args[0] : contextSequence;
View Full Code Here

                final NodeList nl = (NodeList) obj;
                int last = builder.getDocument().getLastNode();
                for (int i = 0; i < nl.getLength(); i++) {
                    final Node n = nl.item(i);
                    streamer.serialize(n, false);
                    final NodeImpl created = builder.getDocument().getNode(last + 1);
                    seq.add(created);
                    last = builder.getDocument().getLastNode();
                }
                return seq;
            } catch (final SAXException e) {
View Full Code Here

TOP

Related Classes of org.exist.memtree.NodeImpl$SingleNodeIterator

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.