Package org.exist.util.serializer

Examples of org.exist.util.serializer.ReceiverToSAX


        final MemTreeBuilder builder = context.getDocumentBuilder();
        final DocumentBuilderReceiver builderReceiver = new DocumentBuilderReceiver(builder, true);
        final SAXResult result = new SAXResult(builderReceiver);
        result.setLexicalHandler(builderReceiver);    //preserve comments etc... from xslt output
        handler.setResult(result);
            final Receiver receiver = new ReceiverToSAX(handler);
            final Serializer serializer = context.getBroker().getSerializer();
            serializer.reset();
            try {
                serializer.setProperties(serializationProps);
                serializer.setReceiver(receiver, true);
                if (expandXIncludes) {
                    String xipath = serializationProps.getProperty(EXistOutputKeys.XINCLUDE_PATH);
                    if (xipath != null) {
                        final File f = new File(xipath);
                        if (!f.isAbsolute())
                            {xipath = new File(context.getModuleLoadPath(), xipath).getAbsolutePath();}
                    } else
                        {xipath = context.getModuleLoadPath();}
                    serializer.getXIncludeFilter().setModuleLoadPath(xipath);
                }
          serializer.toSAX(inputNode, 1, inputNode.getItemCount(), false, false);
        } catch (final Exception e) {
          throw new XPathException(this, "Exception while transforming node: " + e.getMessage(), e);
        }
            errorListener.checkForErrors();
        Node next = builder.getDocument().getFirstChild();
            while (next != null) {
                seq.add((NodeValue) next);
                next = next.getNextSibling();
            }
        context.popDocumentContext();
        return seq;
          }
        }
        else
        {
          //transform:stream-transform()
         
            final ResponseModule myModule = (ResponseModule)context.getModule(ResponseModule.NAMESPACE_URI);
            // response object is read from global variable $response
            final Variable respVar = myModule.resolveVariable(ResponseModule.RESPONSE_VAR);
            if(respVar == null)
                {throw new XPathException(this, "No response object found in the current XQuery context.");}
            if(respVar.getValue().getItemType() != Type.JAVA_OBJECT)
                {throw new XPathException(this, "Variable $response is not bound to an Java object.");}
            final JavaObjectValue respValue = (JavaObjectValue)
                respVar.getValue().itemAt(0);
            if (!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName()))
                {throw new XPathException(this, signatures[1].toString() +
                        " can only be used within the EXistServlet or XQueryServlet");}
            final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
           
            //setup the response correctly
            final String mediaType = handler.getTransformer().getOutputProperty("media-type");
            final String encoding = handler.getTransformer().getOutputProperty("encoding");
            if(mediaType != null)
            {
              if(encoding == null)
              {
                response.setContentType(mediaType);
              }
              else
              {
                response.setContentType(mediaType + "; charset=" + encoding);
              }
            }
           
            //do the transformation
            try {
                final OutputStream os = new BufferedOutputStream(response.getOutputStream());
                final StreamResult result = new StreamResult(os);
                handler.setResult(result);
                final Serializer serializer = context.getBroker().getSerializer();
                serializer.reset();
                Receiver receiver = new ReceiverToSAX(handler);
                try {
                    serializer.setProperties(serializationProps);
                    if (expandXIncludes) {
                        XIncludeFilter xinclude = new XIncludeFilter(serializer, receiver);
                        String xipath = serializationProps.getProperty(EXistOutputKeys.XINCLUDE_PATH);
View Full Code Here


            handler.setResult(result);
           
            final Serializer serializer = broker.getSerializer();
            serializer.reset();
           
            Receiver receiver = new ReceiverToSAX(handler);
            try {
                XIncludeFilter xinclude = new XIncludeFilter(serializer, receiver);
                receiver = xinclude;
                String moduleLoadPath;
View Full Code Here

   */
  protected void applyXSLHandler(Writer writer) {
    final StreamResult result = new StreamResult(writer);
    xslHandler.setResult(result);
    if ("yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"))) {
      xinclude.setReceiver(new ReceiverToSAX(xslHandler));
      receiver = xinclude;
    } else
      {receiver = new ReceiverToSAX(xslHandler);}
  }
View Full Code Here

   *  Set the ContentHandler to be used during serialization.
   *
   *@param  contentHandler  The new contentHandler value
   */
  public void setSAXHandlers(ContentHandler contentHandler, LexicalHandler lexicalHandler) {
    ReceiverToSAX toSAX = new ReceiverToSAX(contentHandler);
    toSAX.setLexicalHandler(lexicalHandler);
    if ("yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"))) {
      xinclude.setReceiver(toSAX);
      receiver = xinclude;
    } else
      {receiver = toSAX;}
View Full Code Here

            Receiver oldReceiver = receiver;

            // compile stylesheet
            factory.setErrorListener(new ErrorListener());
            final TemplatesHandler handler = factory.newTemplatesHandler();
            receiver = new ReceiverToSAX(handler);
            try {
                this.serializeToReceiver(xsl, true);
                templates = handler.getTemplates();
            } catch (final SAXException e) {
                throw new TransformerConfigurationException(e.getMessage(), e);
View Full Code Here

  protected void setXSLHandler(NodeProxy root, boolean applyFilters) {
    if (templates != null && xslHandler != null) {
      final SAXResult result = new SAXResult();
      boolean processXInclude =
        "yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"));
      ReceiverToSAX filter;
      if (processXInclude) {
        filter = (ReceiverToSAX)xinclude.getReceiver();
      } else {
        filter = (ReceiverToSAX) receiver;
      }
      result.setHandler(filter.getContentHandler());
      result.setLexicalHandler(filter.getLexicalHandler());
      filter.setLexicalHandler(xslHandler);
      filter.setContentHandler(xslHandler);
      xslHandler.setResult(result);
      if (processXInclude) {
        xinclude.setReceiver(new ReceiverToSAX(xslHandler));
        receiver = xinclude;
      } else
        {receiver = new ReceiverToSAX(xslHandler);}
    }
        if (root != null && getHighlightingMode() != TAG_NONE) {
            final IndexController controller = broker.getIndexController();
            MatchListener listener = controller.getMatchListener(root);
            if (listener != null) {
View Full Code Here

TOP

Related Classes of org.exist.util.serializer.ReceiverToSAX

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.