Example #1
0
 public static Document getDocumentFromSource(Source source)
     throws ProcessingException, ConfigurationException {
   try {
     Transformer transformer = TransformerUtil.getTransformer();
     DOMResult result = new DOMResult();
     TransformerUtil.transform(transformer, source, result);
     return (Document) result.getNode();
   } catch (ParsingException te) {
     throw logger.processingError(te);
   }
 }
 public static Node getNodeFromSource(Source source)
     throws ProcessingException, ConfigurationException {
   try {
     Transformer transformer = TransformerUtil.getTransformer();
     DOMResult result = new DOMResult();
     transformer.transform(source, result);
     return result.getNode();
   } catch (TransformerException te) {
     throw new ProcessingException(te);
   }
 }
  /**
   * Get the {@link Source} as an {@link InputStream}
   *
   * @param source
   * @return
   * @throws ConfigurationException
   * @throws ProcessingException
   */
  public static InputStream getSourceAsStream(Source source)
      throws ConfigurationException, ProcessingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Result streamResult = new StreamResult(baos);
    // Write the DOM document to the stream
    Transformer transformer = TransformerUtil.getTransformer();
    try {
      transformer.transform(source, streamResult);
    } catch (TransformerException e) {
      throw new ProcessingException(e);
    }

    return new ByteArrayInputStream(baos.toByteArray());
  }
  /**
   * Marshall a DOM Element as string
   *
   * @param element
   * @return
   * @throws TransformerFactoryConfigurationError
   * @throws TransformerException
   */
  public static String getDOMElementAsString(Element element)
      throws ProcessingException, ConfigurationException {
    Source source = new DOMSource(element);
    StringWriter sw = new StringWriter();

    Result streamResult = new StreamResult(sw);
    // Write the DOM document to the file
    Transformer xformer = TransformerUtil.getTransformer();
    try {
      xformer.transform(source, streamResult);
    } catch (TransformerException e) {
      throw new ProcessingException(e);
    }

    return sw.toString();
  }
Example #5
0
  /**
   * Stream a DOM Node as a String
   *
   * @param node
   * @return
   * @throws ProcessingException
   * @throws TransformerFactoryConfigurationError
   * @throws TransformerException
   */
  public static String getNodeAsString(Node node)
      throws ConfigurationException, ProcessingException {
    Source source = new DOMSource(node);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Result streamResult = new StreamResult(baos);
    // Write the DOM document to the stream
    Transformer transformer = TransformerUtil.getTransformer();
    try {
      transformer.transform(source, streamResult);
    } catch (TransformerException e) {
      throw logger.processingError(e);
    }

    return new String(baos.toByteArray());
  }
Example #6
0
  /**
   * Marshall a document into a String
   *
   * @param signedDoc
   * @return
   * @throws TransformerFactoryConfigurationError
   * @throws TransformerException
   */
  public static String getDocumentAsString(Document signedDoc)
      throws ProcessingException, ConfigurationException {
    Source source = new DOMSource(signedDoc);
    StringWriter sw = new StringWriter();

    Result streamResult = new StreamResult(sw);
    // Write the DOM document to the stream
    Transformer xformer = TransformerUtil.getTransformer();
    try {
      xformer.transform(source, streamResult);
    } catch (TransformerException e) {
      throw logger.processingError(e);
    }

    return sw.toString();
  }