Package org.exist.storage.serializers

Examples of org.exist.storage.serializers.Serializer


                LOG.debug("Document detected, adding URL " + url);
                streamSource.setSystemId(url);
            }

            // Node provided
            final Serializer serializer = context.getBroker().newSerializer();

            final NodeValue node = (NodeValue) item;
            final InputStream is = new NodeInputStream(serializer, node);
            streamSource.setInputStream(is);
View Full Code Here


            os.flush();
        } else {
            // xml resource

            SAXSerializer sax = null;
            final Serializer serializer = broker.getSerializer();
            serializer.reset();

            //setup the http context
            final HttpContext httpContext = serializer.new HttpContext();
            final HttpRequestWrapper reqw = new HttpRequestWrapper(request, formEncoding, containerEncoding);
            httpContext.setRequest(reqw);
            httpContext.setSession(reqw.getSession(false));
            serializer.setHttpContext(httpContext);


            // Serialize the document
            try {
                sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);

                // use a stylesheet if specified in query parameters
                if (stylesheet != null) {
                    serializer.setStylesheet(resource, stylesheet);
                }
                serializer.setProperties(outputProperties);
                serializer.prepareStylesheets(resource);

                if (asMimeType != null) { // was a mime-type specified?
                    response.setContentType(asMimeType + "; charset=" + encoding);
                } else {
                    if (serializer.isStylesheetApplied()
                            || serializer.hasXSLPi(resource) != null) {

                        asMimeType = serializer.getStylesheetProperty(OutputKeys.MEDIA_TYPE);
                        if (!useDynamicContentType || asMimeType == null) {
                            asMimeType = MimeType.HTML_TYPE.getName();
                        }

                        if (LOG.isDebugEnabled()) {
                            LOG.debug("media-type: " + asMimeType);
                        }

                        response.setContentType(asMimeType + "; charset=" + encoding);
                    } else {
                        asMimeType = resource.getMetadata().getMimeType();
                        response.setContentType(asMimeType + "; charset=" + encoding);
                    }
                }
                if (asMimeType.equals(MimeType.HTML_TYPE.getName())) {
                    outputProperties.setProperty("method", "xhtml");
                    outputProperties.setProperty("media-type", "text/html; charset=" + encoding);
                    outputProperties.setProperty("indent", "yes");
                    outputProperties.setProperty("omit-xml-declaration", "no");
                }

                final OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), encoding);
                sax.setOutput(writer, outputProperties);
                serializer.setSAXHandlers(sax, sax);

                serializer.toSAX(resource);

                writer.flush();
                writer.close();
            } catch (final SAXException saxe) {
                LOG.warn(saxe);
View Full Code Here

        final DBBroker broker, final Sequence results, final int howmany,
        final int start, final boolean typed, final Properties outputProperties,
        final boolean wrap) throws BadRequestException {
       
        // 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());
            serializer.toSAX(results, start, howmany, wrap, typed);

            writer.flush();
            writer.close();

        } catch (final SAXException e) {
View Full Code Here

            }
        } else {
            howmany = 0;
        }

        final Serializer serializer = broker.getSerializer();
        serializer.reset();
        outputProperties.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
        try {
            serializer.setProperties(outputProperties);
            final Writer writer = new OutputStreamWriter(response.getOutputStream(), outputProperties.getProperty(OutputKeys.ENCODING));
            final JSONObject root = new JSONObject();
            root.addObject(new JSONSimpleProperty("start", Integer.toString(start), true));
            root.addObject(new JSONSimpleProperty("count", Integer.toString(howmany), true));
            root.addObject(new JSONSimpleProperty("hits", Integer.toString(results.getItemCount()), true));
            if (outputProperties.getProperty(Serializer.PROPERTY_SESSION_ID) != null) {
                root.addObject(new JSONSimpleProperty("session",
                        outputProperties.getProperty(Serializer.PROPERTY_SESSION_ID)));
            }

            final JSONObject data = new JSONObject("data");
            root.addObject(data);

            Item item;
            for (int i = --start; i < start + howmany; i++) {
                item = results.itemAt(i);
                if (Type.subTypeOf(item.getType(), Type.NODE)) {
                    final NodeValue value = (NodeValue) item;
                    JSONValue json;
                    if ("json".equals(outputProperties.getProperty("method", "xml"))) {
                        json = new JSONValue(serializer.serialize(value), false);
                        json.setSerializationType(JSONNode.SerializationType.AS_LITERAL);
                    } else {
                        json = new JSONValue(serializer.serialize(value));
                        json.setSerializationType(JSONNode.SerializationType.AS_ARRAY);
                    }
                    data.addObject(json);
                } else {
                    final JSONValue json = new JSONValue(item.getStringValue());
View Full Code Here

        DocumentImpl document = null;
      final Subject preserveSubject = pool.getSubject();
      DBBroker broker = null;
      try {
        broker = pool.get(user);
        final Serializer serializer = broker.getSerializer();
        serializer.setUser(user);
        serializer.setProperties(getProperties());
        if (root != null) {
          content = serializer.serialize((NodeValue) root);
                   
                } else if (proxy != null) {
                    content = serializer.serialize(proxy);
                   
                } else {
            document = openDocument(broker, Lock.READ_LOCK);
          if (!document.getPermissions().validate(user,
              Permission.READ))
            {throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,
                "permission denied to read resource");}
          content = serializer.serialize(document);
                }
        return content;
      } catch (final SAXException saxe) {
        saxe.printStackTrace();
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR, saxe
View Full Code Here

     
    // case 3: content is an internal node or a document
    } else {
      try {
        broker = pool.get(user);
        final Serializer serializer = broker.getSerializer();
        serializer.setUser(user);
        serializer.setProperties(getProperties());
        serializer.setSAXHandlers(handler, lexicalHandler);
        if (root != null) {
          serializer.toSAX((NodeValue) root);
                   
                } else if (proxy != null) {
                    serializer.toSAX(proxy);
                   
                } else {
          DocumentImpl document = null;
          try {
            document = openDocument(broker, Lock.READ_LOCK);
            if (!document.getPermissions().validate(user,
                Permission.READ))
              {throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,
              "permission denied to read resource");}
            serializer.toSAX(document);
          } finally {
              closeDocument(document, Lock.READ_LOCK);
          }
        }
      } catch (final EXistException e) {
View Full Code Here

        final String encoding = serializeOptions.getProperty("encoding", "UTF-8");
        if(mediaType != null) {
            response.setContentType(mediaType + "; charset=" + encoding);
        }
       
        Serializer serializer = null;
       
        BrokerPool db = null;
        DBBroker broker = null;
        try {
          db = BrokerPool.getInstance();
          broker = db.get(null);
         
            serializer = broker.getSerializer();
            serializer.reset();
           
            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);
             
          } catch (final SAXException e) {
            e.printStackTrace();
            throw new IOException(e);
          } finally {
View Full Code Here

                  "I/O error on read of resource "
                      + request.getPath(), ex);
            }
          } else {
            // xml resource
            final Serializer serializer = broker.getSerializer();
            serializer.reset();

            final String charset = getContext().getDefaultCharset();
            // Serialize the document
            try {
              response.setContentType(resource.getMetadata()
                  .getMimeType() + "; charset=" + charset);
              final Writer w = new OutputStreamWriter(
                  response.getOutputStream(), charset);
              serializer.serialize(resource, w);
              w.flush();
              w.close();
            } catch (final IOException ex) {
              LOG.fatal(
                  "Cannot read resource " + request.getPath(),
View Full Code Here

        throw new BadRequestException("No topic was found.");
      }

      final String charset = getContext().getDefaultCharset();
      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);

        SerializerPool.getInstance().returnObject(sax);
        w.flush();
        w.close();
      } catch (final IOException ex) {
View Full Code Here

        throw new BadRequestException("No feed was found.");
      }

      final String charset = getContext().getDefaultCharset();
      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);

        SerializerPool.getInstance().returnObject(sax);
        w.flush();
        w.close();
View Full Code Here

TOP

Related Classes of org.exist.storage.serializers.Serializer

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.