Package org.exist.util.serializer

Examples of org.exist.util.serializer.SAXSerializer


       
        // serialize the results to the response output stream
        final Serializer serializer = broker.getSerializer();
        serializer.reset();
        outputProperties.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
        SAXSerializer sax = null;
        try {
            sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(
                    SAXSerializer.class);

            // set output headers
            final String encoding = outputProperties.getProperty(OutputKeys.ENCODING);
            if (!response.containsHeader("Content-Type")) {
                String mimeType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE);
                if (mimeType != null) {
                    final int semicolon = mimeType.indexOf(';');
                    if (semicolon != Constants.STRING_NOT_FOUND) {
                        mimeType = mimeType.substring(0, semicolon);
                    }
                    if (wrap) {
                        mimeType = "application/xml";
                    }
                    response.setContentType(mimeType + "; charset=" + encoding);
                }
            }
            if (wrap) {
                outputProperties.setProperty("method", "xml");
            }
            final Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);
            sax.setOutput(writer, outputProperties);

            serializer.setProperties(outputProperties);
            serializer.setSAXHandlers(sax, sax);

            //Marshaller.marshall(broker, results, start, howmany, serializer.getContentHandler());
View Full Code Here


            final OutputStream sout = response.getOutputStream();
            final PrintWriter output = new PrintWriter(new OutputStreamWriter(sout, encoding));

          final SerializerPool serializerPool = SerializerPool.getInstance();

          final SAXSerializer sax = (SAXSerializer) serializerPool.borrowObject(SAXSerializer.class);
          try {
            sax.setOutput(output, serializeOptions);

            serializer.setProperties(serializeOptions);
            serializer.setSAXHandlers(sax, sax);
              serializer.toSAX(inputNode, 1, inputNode.getItemCount(), false, false);
             
View Full Code Here

      response.setContentType("application/atom+xml; charset=" + charset);
      final Serializer serializer = broker.getSerializer();
      serializer.reset();
      try {
        final Writer w = new OutputStreamWriter(response.getOutputStream(), charset);
        final SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        final Properties outputProperties = new Properties();
        sax.setOutput(w, outputProperties);
        serializer.setProperties(outputProperties);
        serializer.setSAXHandlers(sax, sax);

        serializer.toSAX(resultSequence, 1, 1, false, false);
View Full Code Here

      final Serializer serializer = broker.getSerializer();
      serializer.reset();

      try {
        final Writer w = new OutputStreamWriter(response.getOutputStream(), charset);
        final SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        final Properties outputProperties = new Properties();
        sax.setOutput(w, outputProperties);
        serializer.setProperties(outputProperties);
        serializer.setSAXHandlers(sax, sax);

        serializer.toSAX(resultSequence, 1, 1, false, false);
View Full Code Here

     
    public static void serialize(Serializer serializer, NodeValue node,
        Properties outputProperties, OutputStream os) throws IOException {
       
        LOG.debug("Serializing started.");
        final SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        try {
            final String encoding = outputProperties.getProperty(OutputKeys.ENCODING, "UTF-8");
            final Writer writer = new OutputStreamWriter(os, encoding);
            sax.setOutput(writer, outputProperties);

            serializer.reset();
            serializer.setProperties(outputProperties);
            serializer.setSAXHandlers(sax, sax);

           
            sax.startDocument();
            serializer.toSAX(node);
           
//            while(node.hasNext()) {
//                NodeValue next = (NodeValue)node.nextItem();
//                serializer.toSAX(next);
//            }
           
            sax.endDocument();
            writer.close();
           
        } catch(final Exception e) {
            final String txt = "A problem occurred while serializing the node set";
            LOG.debug(txt+".", e);
View Full Code Here

      XQuery service = broker.getXQueryService();
      CompiledXQuery compiled = service.compile(context, script);
     
      Sequence resultSequence = service.execute(compiled, null);
 
          SAXSerializer sax = null;
          Serializer serializer = broker.getSerializer();
      serializer.reset();
          try {
              sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
              Properties outputProps = new Properties();
              StringWriter writer = new StringWriter();
              sax.setOutput(writer, outputProps);
              serializer.setSAXHandlers(sax, sax);
              for (SequenceIterator i = resultSequence.iterate(); i.hasNext();) {
                  Item next = i.nextItem();
                  if (Type.subTypeOf(next.getType(), Type.NODE))
                      serializer.toSAX((NodeValue) next);
View Full Code Here

        final Serializer serializer = broker.getSerializer();
        serializer.reset();
        try {
          final Writer w = new OutputStreamWriter(
              response.getOutputStream(), charset);
          final SAXSerializer sax = (SAXSerializer) SerializerPool
              .getInstance().borrowObject(SAXSerializer.class);
          final Properties outputProperties = new Properties();
          sax.setOutput(w, outputProperties);
          serializer.setProperties(outputProperties);
          serializer.setSAXHandlers(sax, sax);

          serializer.toSAX(resultSequence, 1, 1, false, false);
View Full Code Here

      response.setContentType(config.contentType + "; charset=" + charset);
      final Serializer serializer = broker.getSerializer();
      serializer.reset();
      try {
        final Writer w = new OutputStreamWriter(response.getOutputStream(), charset);
        final SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
       
        final Properties outputProperties = new Properties();
        sax.setOutput(w, outputProperties);
        serializer.setProperties(outputProperties);
        serializer.setSAXHandlers(sax, sax);

        serializer.toSAX(resultSequence, 1, 1, false, false);
View Full Code Here

  public ResourceIterator getIterator(long start) throws XMLDBException {
    return new NewResourceIterator(start);
  }

  public Resource getMembersAsResource() throws XMLDBException {
        final SAXSerializer handler = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
    final StringWriter writer = new StringWriter();
    handler.setOutput(writer, outputProperties);
   
    DBBroker broker = null;
    try {
      broker = brokerPool.get(user);
      // configure the serializer
      final Serializer serializer = broker.getSerializer();
      serializer.reset();
      collection.properties.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
      serializer.setProperties(outputProperties);
      serializer.setUser(user);
      serializer.setSAXHandlers(handler, handler);

      //  serialize results
      handler.startDocument();
      handler.startPrefixMapping("exist", Namespaces.EXIST_NS);
      final AttributesImpl attribs = new AttributesImpl();
      attribs.addAttribute(
        "",
        "hitCount",
        "hitCount",
        "CDATA",
        Integer.toString(resources.size()));
      handler.startElement(
          Namespaces.EXIST_NS,
            "result",
            "exist:result",
            attribs);
      Item current;
      char[] value;
      for(final Iterator<Object> i = resources.iterator(); i.hasNext(); ) {
        current = (Item)i.next();
        if(Type.subTypeOf(current.getType(), Type.NODE)) {
          ((NodeValue)current).toSAX(broker, handler, outputProperties);
        } else {
          value = current.toString().toCharArray();
          handler.characters(value, 0, value.length);
        }
      }
      handler.endElement(Namespaces.EXIST_NS, "result", "exist:result");
      handler.endPrefixMapping("exist");
      handler.endDocument();
    } catch (final EXistException e) {
      throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, "serialization error", e);
    } catch (final SAXException e) {
      throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, "serialization error", e);
    } finally {
View Full Code Here

        //get the test document
        DocumentImpl doc = root.getDocumentWithLock(broker, XmldbURI.create(documentName), Lock.READ_LOCK);
       
        Serializer serializer = broker.getSerializer();
        serializer.reset();
        SAXSerializer sax = null;
        StringWriter writer = new StringWriter();
        sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
        Properties outputProperties = new Properties();
        outputProperties.setProperty(OutputKeys.INDENT, "no");
        outputProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
        sax.setOutput(writer, outputProperties);
        serializer.setProperties(outputProperties);
        serializer.setSAXHandlers(sax, sax);
        serializer.toSAX(doc);
        SerializerPool.getInstance().returnObject(sax);
       
View Full Code Here

TOP

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

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.