java类org.w3c.dom.ls.DOMImplementationLS的实例源码

SAMLResponseCommand.java 文件源码 项目:FOXopen 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Marshall a SAML XML object into a W3C DOM and then into a String
 *
 * @param pXMLObject SAML Object to marshall
 * @return XML version of the SAML Object in string form
 */
private String marshall(XMLObject pXMLObject) {
  try {
    MarshallerFactory lMarshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
    Marshaller lMarshaller = lMarshallerFactory.getMarshaller(pXMLObject);
    Element lElement = lMarshaller.marshall(pXMLObject);

    DOMImplementationLS lDOMImplementationLS = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
    LSSerializer lSerializer = lDOMImplementationLS.createLSSerializer();
    LSOutput lOutput =  lDOMImplementationLS.createLSOutput();
    lOutput.setEncoding("UTF-8");
    Writer lStringWriter = new StringWriter();
    lOutput.setCharacterStream(lStringWriter);
    lSerializer.write(lElement, lOutput);
    return lStringWriter.toString();
  }
  catch (Exception e) {
    throw new ExInternal("Error Serializing the SAML Response", e);
  }
}
Formatter.java 文件源码 项目:simplexml 阅读 28 收藏 0 点赞 0 评论 0
private void format(Document document, Writer writer) {
   DOMImplementation implementation = document.getImplementation();

   if(implementation.hasFeature(LS_FEATURE_KEY, LS_FEATURE_VERSION) && implementation.hasFeature(CORE_FEATURE_KEY, CORE_FEATURE_VERSION)) {
      DOMImplementationLS implementationLS = (DOMImplementationLS) implementation.getFeature(LS_FEATURE_KEY, LS_FEATURE_VERSION);
      LSSerializer serializer = implementationLS.createLSSerializer();
      DOMConfiguration configuration = serializer.getDomConfig();

      configuration.setParameter("format-pretty-print", Boolean.TRUE);
      configuration.setParameter("comments", preserveComments);

      LSOutput output = implementationLS.createLSOutput();
      output.setEncoding("UTF-8");
      output.setCharacterStream(writer);
      serializer.write(document, output);
   }
}
OutputWriter.java 文件源码 项目:LaTeXEE 阅读 24 收藏 0 点赞 0 评论 0
/**
* Method to generated idented XML
* Credit: Steve McLeod and DaoWen.
* Code from http://stackoverflow.com/a/11519668
* @param xml input xml in string format
* @return indented xml in string format
*/
  public static String indentXML(String xml) {

      try {
          final InputSource src = new InputSource(new StringReader(xml));
          final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
          final Boolean keepDeclaration = xml.startsWith("<?xml");

      //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


          final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
          final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
          final LSSerializer writer = impl.createLSSerializer();

          writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
          writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

          return writer.writeToString(document);
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
  }
ConfigPersister.java 文件源码 项目:Flox 阅读 27 收藏 0 点赞 0 评论 0
public void load(File f) throws ConfigPersisterException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(f);

        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();
        String configString = lsSerializer.writeToString(doc);

        _config = (Config) _xstream.fromXML(convertToCurrent(configString));
        setConfigPath(f);
    } catch (Exception e) {
        throw new ConfigPersisterException(e);
    }
}
CodeReviewIndexMojo.java 文件源码 项目:tibco-codereview 阅读 24 收藏 0 点赞 0 评论 0
protected String formatHtml(String html) throws MojoExecutionException {
try {
    InputSource src = new InputSource(new StringReader(html));
    Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
    Boolean keepDeclaration = Boolean.valueOf(html.startsWith("<?xml"));

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();

    writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);

    return writer.writeToString(document);
} catch (Exception e) {
    throw new MojoExecutionException(e.getMessage(), e);
}
  }
ConfigPersister.java 文件源码 项目:ScreePainter 阅读 25 收藏 0 点赞 0 评论 0
public void load(File f) throws ConfigPersisterException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(f);

        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();
        String configString = lsSerializer.writeToString(doc);

        _config = (Config) _xstream.fromXML(convertToCurrent(configString));
        setConfigPath(f);
    } catch (Exception e) {
        throw new ConfigPersisterException(e);
    }
}
Utils.java 文件源码 项目:SI 阅读 17 收藏 0 点赞 0 评论 0
public static String format(String xml) {

        try {
            final InputSource src = new InputSource(new StringReader(xml));
            final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
            final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

            //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


            final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            final LSSerializer writer = impl.createLSSerializer();

            writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
            writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

            return writer.writeToString(document);
        } catch (Exception e) {
            return xml;
        }
    }
XMLUtils.java 文件源码 项目:FHIR-Server 阅读 25 收藏 0 点赞 0 评论 0
public static String serialize(Document document, boolean prettyPrint) {
    DOMImplementationLS impl = getDOMImpl();
    LSSerializer serializer = impl.createLSSerializer();
    // document.normalizeDocument();
    DOMConfiguration config = serializer.getDomConfig();
    if (prettyPrint && config.canSetParameter("format-pretty-print", Boolean.TRUE)) {
        config.setParameter("format-pretty-print", true);
    }
    config.setParameter("xml-declaration", true);        
    LSOutput output = impl.createLSOutput();
    output.setEncoding("UTF-8");
    Writer writer = new StringWriter();
    output.setCharacterStream(writer);
    serializer.write(document, output);
    return writer.toString();
}
Readability.java 文件源码 项目:openimaj 阅读 26 收藏 0 点赞 0 评论 0
protected static String nodeToString(Node n, boolean pretty) {
    try {
        final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        final LSSerializer writer = impl.createLSSerializer();

        writer.getDomConfig().setParameter("xml-declaration", false);
        if (pretty) {
            writer.getDomConfig().setParameter("format-pretty-print", true);
        }

        return writer.writeToString(n);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
ConfigFileParser.java 文件源码 项目:mondo-hawk 阅读 24 收藏 0 点赞 0 评论 0
/** Utility methods */
private void writeXmlDocumentToFile(Node node, String filename) {
    try {
        // find file or create one and save all info
        File file = new File(filename);
        if(!file.exists()) {
            file.createNewFile();
        }

        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS implementationLS =  (DOMImplementationLS)registry.getDOMImplementation("LS");

        LSOutput output = implementationLS.createLSOutput();
        output.setEncoding("UTF-8");
        output.setCharacterStream(new FileWriter(file));

        LSSerializer serializer = implementationLS.createLSSerializer();
        serializer.getDomConfig().setParameter("format-pretty-print", true);

        serializer.write(node, output);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号