com.ebmwebsourcing.easycommons.xml.XMLPrettyPrinter.prettify()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中com.ebmwebsourcing.easycommons.xml.XMLPrettyPrinter.prettify()方法的一些代码示例,展示了XMLPrettyPrinter.prettify()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLPrettyPrinter.prettify()方法的具体详情如下:
包路径:com.ebmwebsourcing.easycommons.xml.XMLPrettyPrinter
类名称:XMLPrettyPrinter
方法名:prettify

XMLPrettyPrinter.prettify介绍

[英]Prettify the xml input stream into the output stream.
[中]将xml输入流美化为输出流。

代码示例

代码示例来源:origin: org.ow2.easycommons/easycommons-util

/**
 * Prettify the node into the output stream.
 */
public static void prettify(final Node node, final OutputStream out) throws Exception {
  prettify(node, out, null);
}

代码示例来源:origin: org.ow2.easycommons/easycommons-util

public static void prettify(final Source source, final OutputStream out) throws TransformerException {
  prettify(source, out, null);
}

代码示例来源:origin: org.ow2.easycommons/easycommons-util

/**
 * Prettify the xml input stream into the output stream.
 */
public static void prettify(final InputStream in, final OutputStream out) throws Exception {
  prettify(new StreamSource(in), out);
}

代码示例来源:origin: org.ow2.easycommons/easycommons-util

/**
 * Prettify the node into the output stream.
 */
public static void prettify(final Node node, final OutputStream out, final String encoding) throws Exception {
  prettify(new DOMSource(node), out, encoding);
}

代码示例来源:origin: org.ow2.easycommons/easycommons-util

public static String prettyPrint(final Source source) throws TransformerException {
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  XMLPrettyPrinter.prettify(source, outStream);
  return outStream.toString();
}

代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons-util

/**
 * parse the xml String and return it pretty-printed (with correct
 * indentations, etc..)
 * 
 * @param xmlDocument
 *            the xml document to pretty print. Must be non null
 * @param encoding
 *            the encoding to use
 * 
 * @return printed string if no error occurs. If an error occurs, return an
 *         empty String
 */
public static String prettyPrint(final Node xmlDocument,String encoding) {
  String result = "";
  try {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    XMLPrettyPrinter.prettify(xmlDocument, outStream,encoding);
    result = outStream.toString(encoding);
  } catch (final Exception e) {
    System.err.println("write_dom failed:" + e);
    // if an error occurs, the result will be the original string
  }
  return result;
}

代码示例来源:origin: org.ow2.easycommons/easycommons-util

/**
 * parse the xml String and return it pretty-printed (with correct
 * indentations, etc..)
 * 
 * @param xmlDocument
 *            the xml document to pretty print. Must be non null
 * @param encoding
 *            the encoding to use
 * 
 * @return printed string if no error occurs. If an error occurs, return an
 *         empty String
 */
public static String prettyPrint(final Node xmlDocument, final String encoding) {
  String result = "";
  try {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    XMLPrettyPrinter.prettify(xmlDocument, outStream,encoding);
    result = outStream.toString(encoding);
  } catch (final Exception e) {
    System.err.println("write_dom failed:" + e);
    // if an error occurs, the result will be the original string
  }
  return result;
}

代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons.xml

/**
 * parse the xml String and return it pretty-printed (with correct
 * indentations, etc..)
 * 
 * @param xmlDocument
 *            the xml document to pretty print. Must be non null
 * @param encoding
 *            the encoding to use
 *   
 * @returnpretty printed string if no error occurs. If an error occurs,
 *               return an empty String
 */
public static String prettyPrint(final Node xmlDocument,String encoding) {
  String result = "";
  try {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    XMLPrettyPrinter.prettify(xmlDocument, outStream,encoding);
    result = outStream.toString(encoding);
  } catch (final Exception e) {
    System.err.println("write_dom failed:" + e);
    // if an error occurs, the result will be the original string
  }
  return result;
}

代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons.xml

public static String getXMLSHA1Sign(InputStream inputStream, boolean ommitComments)
    throws Exception {
  // Create a canonicalizer
  org.apache.xml.security.Init.init();
  Canonicalizer canonicalizer = null;
  if (ommitComments) {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);
  } else {
    canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS);
  }
  // Prettify the given xml input stream to remove unnecessary spaces and
  // tabs
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  XMLPrettyPrinter.prettify(inputStream, byteArrayOutputStream);
  byte[] bytes = byteArrayOutputStream.toByteArray();
  // Canonicalize the prettified xml stream
  byte[] canonBytes = canonicalizer.canonicalize(bytes);
  // Generate the SHA1 hash
  MessageDigest hash = MessageDigest.getInstance("SHA1");
  String hashString = new String(hash.digest(canonBytes));
  return hashString;
}

代码示例来源:origin: org.ow2.petals/petals-bc-soap

protected static void printWSDL(final Document wsdl, final String serviceAddress,
    final Collection<PolicyComponent> wssPolicies, final OutputStream out)
    throws Exception {
  assert wsdl != null;
  // create a easyWSDL description
  final Description desc = WSDL4ComplexWsdlFactory.newInstance().newWSDLReader().read(wsdl);
  // delete imported documents
  desc.deleteImportedDocumentsInWsdl(new URI(serviceAddress + "?wsdl="));
  // recreate a Document without imports
  final Document descWithoutImport = WSDL4ComplexWsdlFactory.newInstance().newWSDLWriter().getDocument(desc);
  // And add the WSS-Policy if exists
  for (final PolicyComponent wssPolicy : wssPolicies) {
    final OMElement policyElt = PolicyUtil.getPolicyComponentAsOMElement(wssPolicy);
    final Node policyNode = descWithoutImport.adoptNode(XMLUtils.toDOM(policyElt));
    // Remove Apache Rampart configuration from WS-Policy
    final NodeList rampartConfigElts = ((Element) policyNode)
        .getElementsByTagNameNS("http://ws.apache.org/rampart/policy", "RampartConfig");
    for (int i = 0; i < rampartConfigElts.getLength(); i++) {
      final Node rampartConfigElt = rampartConfigElts.item(i);
      rampartConfigElt.getParentNode().removeChild(rampartConfigElt);
    }
    descWithoutImport.getDocumentElement().appendChild(policyNode);
  }
  XMLPrettyPrinter.prettify(descWithoutImport, out, XMLPrettyPrinter.getEncoding(descWithoutImport));
}

代码示例来源:origin: org.ow2.petals/petals-bc-soap

final ServletOutputStream out = response.getOutputStream();
try {
  XMLPrettyPrinter.prettify(importedDoc, out, XMLPrettyPrinter.getEncoding(importedDoc));
} catch (final Exception e) {
  throw new ServletException("Error on " + queryString + " streaming serialization", e);

相关文章