Package org.exist.util.serializer

Examples of org.exist.util.serializer.DOMSerializer


        final VirtualTempFile vtmpfile = new VirtualTempFile();
        vtmpfile.setTempPrefix("eXistRXR");
        vtmpfile.setTempPostfix(".xml");
       
        final OutputStreamWriter osw=new OutputStreamWriter(vtmpfile,"UTF-8");
      final DOMSerializer xmlout = new DOMSerializer(osw, getProperties());
      try {
          switch (root.getNodeType()) {
            case Node.ELEMENT_NODE :
            xmlout.serialize((Element) root);
            break;
            case Node.DOCUMENT_FRAGMENT_NODE :
            xmlout.serialize((DocumentFragment) root);
            break;
            case Node.DOCUMENT_NODE :
            xmlout.serialize((Document) root);
            break;
            default :
              throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "invalid node type");
        }
      } catch (final TransformerException e) {
View Full Code Here


            DocumentBuilder builder = factory.newDocumentBuilder();
      assertNotNull(builder);
      Document doc = builder.parse(new InputSource(file));
      assertNotNull(doc);
      StringWriter writer = new StringWriter();
      DOMSerializer serializer = new DOMSerializer(writer, null);
      serializer.serialize(doc.getDocumentElement());
      System.out.println(writer.toString());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

      Document doc = receiver.getDocument();
      Node node = doc.getFirstChild();
      assertNotNull(node);
 
      StringWriter writer = new StringWriter();
      DOMSerializer serializer = new DOMSerializer(writer, null);
      serializer.serialize(node);
      System.out.println(writer.toString());
      } catch (Exception e) {
        fail(e.getMessage());
      }     
  }
View Full Code Here

        Node node = resource.getContentAsDOM();
        System.out.println("Attempting serialization using eXist's serializer");
        StringWriter writer = new StringWriter();
        Properties outputProperties = new Properties();
        outputProperties.setProperty("indent", "yes");
        DOMSerializer serializer = new DOMSerializer(writer, outputProperties);
        serializer.serialize(node);

        System.out.println("Using org.exist.util.serializer.DOMSerializer");
        System.out.println("---------------------");
        System.out.println(writer.toString());
        System.out.println("---------------------");
View Full Code Here

            }
        }
        if (root == null)
            throw new EXistException("no content element found for " + config.getNodeName());
        StringWriter writer = new StringWriter();
        DOMSerializer serializer = new DOMSerializer(writer, new Properties());
        try {
            serializer.serialize(root);
        } catch (TransformerException e) {
            throw new EXistException("exception while serializing content: " + e.getMessage(), e);
        }
        return writer.toString();
    }
View Full Code Here

            }
        }
        if (root == null)
            throw new EXistException("no content element found for generate");
        StringWriter writer = new StringWriter();
        DOMSerializer serializer = new DOMSerializer(writer, new Properties());
        try {
            serializer.serialize(root);
        } catch (TransformerException e) {
            throw new EXistException("exception while serializing generate content: " + e.getMessage(), e);
        }
        xqueryContent = writer.toString();
    }
View Full Code Here

        throws XPathException {
    final NodeValue data = (NodeValue) args[1].itemAt(0);
    final StringWriter writer = new StringWriter();
    final Properties properties = new Properties();
    properties.setProperty(OutputKeys.INDENT, "yes");
        final DOMSerializer serializer = new ExtendedDOMSerializer(context.getBroker(), writer, properties);
    try {
      serializer.serialize(data.getNode());
    } catch(final TransformerException e) {
      logger.debug("Exception while serializing XUpdate document", e);
      throw new XPathException(this, "Exception while serializing XUpdate document: " + e.getMessage(), e);
    }
    final String xupdate = writer.toString();
View Full Code Here

        if (useAttribute != null) {
            request.setAttribute(useAttribute.toString(), root);

        } else {
            final Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8");
            final DOMSerializer streamer = new DOMSerializer(writer, defaultProperties);
            try {
                streamer.serialize(root);
            } catch (final TransformerException e) {
                LOG.error(e.getMessageAndLocation());
                throw new ServletException("Error while serializing result: " + e.getMessage(), e);
            }
            writer.flush();
View Full Code Here

     * "instances", "disk", "system", "caches", "locking", "processes", "sanity", "all".
     */
    public String generateReport(String categories[]) throws TransformerException {
        final Element root = generateXMLReport(null, categories);
        final StringWriter writer = new StringWriter();
        final DOMSerializer streamer = new DOMSerializer(writer, defaultProperties);
        streamer.serialize(root);
        return writer.toString();
    }
View Full Code Here

        }

    // Case 1: content is an external DOM node
    else if (root != null && !(root instanceof NodeValue)) {
            final StringWriter writer = new StringWriter();
      final DOMSerializer serializer = new DOMSerializer(writer, getProperties());
      try {
        serializer.serialize(root);
        content = writer.toString();
      } catch (final TransformerException e) {
        throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e
            .getMessage(), e);
      }
      return content;

      // Case 2: content is an atomic value
    } else if (value != null) {
      try {
                if (Type.subTypeOf(value.getType(),Type.STRING)) {
                    return ((StringValue)value).getStringValue(true);
                }
                else {
        return value.getStringValue();
                }



      } catch (final XPathException e) {
        throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e
            .getMessage(), e);
      }

      // Case 3: content is a file
    } else if (file != null) {
      try {
        content = XMLUtil.readFile(file);
        return content;
      } catch (final IOException e) {
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
            "error while reading resource contents", e);
      }

      // Case 4: content is an input source
    } else if (inputSource != null) {
      try {
        content = XMLUtil.readFile(inputSource);
        return content;
      } catch (final IOException e) {
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
            "error while reading resource contents", e);
      }

      // Case 5: content is a document or internal node
    } else {
        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

TOP

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

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.