当前位置: 首页>>代码示例>>Java>>正文


Java LSSerializer类代码示例

本文整理汇总了Java中org.w3c.dom.ls.LSSerializer的典型用法代码示例。如果您正苦于以下问题:Java LSSerializer类的具体用法?Java LSSerializer怎么用?Java LSSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LSSerializer类属于org.w3c.dom.ls包,在下文中一共展示了LSSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateXmlResult

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
private void validateXmlResult(Element resultXml) throws KalturaApiException {

        Element resultElement = null;
        try {
            resultElement = XmlUtils.getElementByXPath(resultXml, "/xml/result");
        } catch (XPathExpressionException xee) {
            // AZ (unicon) - necessary in order to debug 
            String resultXmlStr;
            try {
                Document document = resultXml.getOwnerDocument();
                DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
                LSSerializer serializer = domImplLS.createLSSerializer();
                resultXmlStr = serializer.writeToString(resultXml);
            } catch (Exception e) {
                resultXmlStr = "Unable to get XML result: "+e;
            }
            throw new KalturaApiException("XPath expression exception ("+xee+") evaluating result:"+resultXmlStr);
        }

        if (resultElement != null) {
            return;            
        } else {
        	throw new KalturaApiException("Invalid result");
        }
    }
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:26,代码来源:KalturaClientBase.java

示例2: getLSSerializer

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Obtain a the DOM, level 3, Load/Save serializer {@link LSSerializer} instance from the
 * given {@link DOMImplementationLS} instance.
 * 
 * <p>
 * The serializer instance will be configured with the parameters passed as the <code>serializerParams</code>
 * argument. It will also be configured with an {@link LSSerializerFilter} that shows all nodes to the filter, 
 * and accepts all nodes shown.
 * </p>
 * 
 * @param domImplLS the DOM Level 3 Load/Save implementation to use
 * @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
 *         instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
 *         
 * @return a new LSSerializer instance
 */
public static LSSerializer getLSSerializer(DOMImplementationLS domImplLS, Map<String, Object> serializerParams) {
    LSSerializer serializer = domImplLS.createLSSerializer();
    
    serializer.setFilter(new LSSerializerFilter() {

        public short acceptNode(Node arg0) {
            return FILTER_ACCEPT;
        }

        public int getWhatToShow() {
            return SHOW_ALL;
        }
    });
    
    
    if (serializerParams != null) {
        DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
        for (String key : serializerParams.keySet()) {
            serializerDOMConfig.setParameter(key, serializerParams.get(key));
        }
    }
    
    return serializer;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:XMLHelper.java

示例3: main

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();

    DOMImplementation impl = document.getImplementation();
    DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSSerializer dsi = implLS.createLSSerializer();

    /* We should have here incorrect document without getXmlVersion() method:
     * Such Document is generated by replacing the JDK bootclasses with it's
     * own Node,Document and DocumentImpl classes (see run.sh). According to
     * XERCESJ-1007 the AbstractMethodError should be thrown in such case.
     */
    String result = dsi.writeToString(document);
    System.out.println("Result:" + result);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:AbstractMethodErrorTest.java

示例4: testCreateNewItem2Sell

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
 * DOMConfiguration.setParameter("well-formed",true) throws an exception.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testCreateNewItem2Sell() throws Exception {
    String xmlFile = XML_DIR + "novelsInvalid.xml";

    Document document = DocumentBuilderFactory.newInstance()
            .newDocumentBuilder().parse(xmlFile);

    document.getDomConfig().setParameter("well-formed", true);

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    MyDOMOutput domOutput = new MyDOMOutput();
    domOutput.setByteStream(System.out);
    LSSerializer writer = impl.createLSSerializer();
    writer.write(document, domOutput);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:AuctionController.java

示例5: testCreateNewItem2SellRetry

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132
 * test throws DOM Level 1 node error.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testCreateNewItem2SellRetry() throws Exception  {
    String xmlFile = XML_DIR + "accountInfo.xml";

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document document = dbf.newDocumentBuilder().parse(xmlFile);

    DOMConfiguration domConfig = document.getDomConfig();
    MyDOMErrorHandler errHandler = new MyDOMErrorHandler();
    domConfig.setParameter("error-handler", errHandler);

    DOMImplementationLS impl =
         (DOMImplementationLS) DOMImplementationRegistry.newInstance()
                 .getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();
    MyDOMOutput domoutput = new MyDOMOutput();

    domoutput.setByteStream(System.out);
    writer.write(document, domoutput);

    document.normalizeDocument();
    writer.write(document, domoutput);
    assertFalse(errHandler.isError());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:AuctionController.java

示例6: testLSInputParsingString

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
@Test
public void testLSInputParsingString() throws Exception {
    DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
    String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";

    LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    LSSerializer domSerializer = impl.createLSSerializer();
    // turn off xml decl in serialized string for comparison
    domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
    LSInput src = impl.createLSInput();
    src.setStringData(xml);
    assertEquals(src.getStringData(), xml);

    Document doc = domParser.parse(src);
    String result = domSerializer.writeToString(doc);

    assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DocumentLSTest.java

示例7: testCreateNewItem2Sell

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
 * DOMConfiguration.setParameter("well-formed",true) throws an exception.
 *
 * @throws Exception If any errors occur.
 */
@Test(groups = {"readLocalFiles"})
public void testCreateNewItem2Sell() throws Exception {
    String xmlFile = XML_DIR + "novelsInvalid.xml";

    Document document = DocumentBuilderFactory.newInstance()
            .newDocumentBuilder().parse(xmlFile);

    document.getDomConfig().setParameter("well-formed", true);

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    MyDOMOutput domOutput = new MyDOMOutput();
    domOutput.setByteStream(System.out);
    LSSerializer writer = impl.createLSSerializer();
    writer.write(document, domOutput);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:23,代码来源:AuctionController.java

示例8: testCreateNewItem2SellRetry

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132
 * test throws DOM Level 1 node error.
 *
 * @throws Exception If any errors occur.
 */
@Test(groups = {"readLocalFiles"})
public void testCreateNewItem2SellRetry() throws Exception  {
    String xmlFile = XML_DIR + "accountInfo.xml";

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document document = dbf.newDocumentBuilder().parse(xmlFile);

    DOMConfiguration domConfig = document.getDomConfig();
    MyDOMErrorHandler errHandler = new MyDOMErrorHandler();
    domConfig.setParameter("error-handler", errHandler);

    DOMImplementationLS impl =
         (DOMImplementationLS) DOMImplementationRegistry.newInstance()
                 .getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();
    MyDOMOutput domoutput = new MyDOMOutput();

    domoutput.setByteStream(System.out);
    writer.write(document, domoutput);

    document.normalizeDocument();
    writer.write(document, domoutput);
    assertFalse(errHandler.isError());
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:32,代码来源:AuctionController.java

示例9: marshall

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * `
 * Serialize XML objects
 *
 * @param xmlObject : XACML or SAML objects to be serialized
 * @return serialized XACML or SAML objects
 * @throws EntitlementException
 */
private String marshall(XMLObject xmlObject) throws EntitlementException {

    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl =
                (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new EntitlementException("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:34,代码来源:WSXACMLMessageReceiver.java

示例10: saveConfiguration

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Saves the process configuration.
 */
private void saveConfiguration(Document docXMLConfig) {
  String fileToSaveConf = properties.getSaveRemoteConfig();
  if (fileToSaveConf.length() > 0 && docXMLConfig != null) {
    log.info("saveConfiguration - saving the process configuration XML in a file " + fileToSaveConf + " due to user request");

    File file = new File(fileToSaveConf);
    if (file.isDirectory() || !fileToSaveConf.endsWith(".xml")) {
      throw new RuntimeException("Path to which to save remote config must end with '.xml'");
    }

    try {
      DOMImplementationLS domImplementation = (DOMImplementationLS) docXMLConfig.getImplementation();
      LSSerializer lsSerializer = domImplementation.createLSSerializer();
      lsSerializer.writeToURI(docXMLConfig, file.toURI().toURL().toString());
    } catch (java.io.IOException ex) {
      log.error("saveConfiguration - Could not save the configuration to the file " + fileToSaveConf, ex);
    }
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:23,代码来源:ConfigurationController.java

示例11: marshall

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax
 * representation.
 *
 * @param xmlObject the SAML 2.0 based XML content object
 * @return a {@link String} representation of the actual XML representation of the SAML 2.0 based XML content
 * representation
 * @throws SSOException if an error occurs during the marshalling process
 */
public static String marshall(XMLObject xmlObject) throws SSOException {
    try {
        Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(xmlObject);
        Element element = null;
        if (marshaller != null) {
            element = marshaller.marshall(xmlObject);
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS implementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = implementation.createLSSerializer();
        LSOutput output = implementation.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
    } catch (ClassNotFoundException | InstantiationException | MarshallingException | IllegalAccessException e) {
        throw new SSOException("Error in marshalling SAML 2.0 Assertion", e);
    }
}
 
开发者ID:wso2-extensions,项目名称:tomcat-extension-samlsso,代码行数:29,代码来源:SSOUtils.java

示例12: toXml

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
public static String toXml(Document domDoc) throws TransformerException {
    DOMImplementation domImplementation = domDoc.getImplementation();
    if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
        DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
        LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
        DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
        if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE))
            lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
        if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
            lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
            LSOutput lsOutput = domImplementationLS.createLSOutput();
            lsOutput.setEncoding("UTF-8");
            StringWriter stringWriter = new StringWriter();
            lsOutput.setCharacterStream(stringWriter);
            lsSerializer.write(domDoc, lsOutput);
            return stringWriter.toString();
        }
    }
    return toXml((Node)domDoc);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:21,代码来源:DomHelper.java

示例13: createMetadataFile

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
/**
 * Creates the metadata file for the file that was created by the wizard.
 *
 * @param targetFolder The folder on which the metadata file will be created.
 */
private void createMetadataFile(FileObject targetFolder) {
    try {
        Document newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element rootElement = newXmlDocument.createElementNS(SALESFORCE_METADATA_NAMESPACE, getMetadataName());
        Element childElement;
        for (Map.Entry<String, String> node : getMetadataParameters().entrySet()) {
            childElement = newXmlDocument.createElement(node.getKey());
            childElement.setTextContent(node.getValue());
            rootElement.appendChild(childElement);
        }
        FileObject createdData = targetFolder.createData(getMetadataFileName());
        DOMImplementationLS domImplementation = (DOMImplementationLS) newXmlDocument.getImplementation();
        LSSerializer serializer = domImplementation.createLSSerializer();
        serializer.writeToURI(rootElement, createdData.toURI().toString());
    } catch (ParserConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:24,代码来源:AbstractFileTypeWizardIterator.java

示例14: format

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
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;
        }
    }
 
开发者ID:iotoasis,项目名称:SI,代码行数:23,代码来源:Utils.java

示例15: main

import org.w3c.dom.ls.LSSerializer; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
   ArrayList<LineItem> items = new ArrayList<>();
   items.add(new LineItem(new Product("Toaster", 29.95), 3));
   items.add(new LineItem(new Product("Hair dryer", 24.95), 1));

   ItemListBuilder builder = new ItemListBuilder();
   Document doc = builder.build(items);         
   DOMImplementation impl = doc.getImplementation();
   DOMImplementationLS implLS 
         = (DOMImplementationLS) impl.getFeature("LS", "3.0");
   LSSerializer ser = implLS.createLSSerializer();
   String out = ser.writeToString(doc);      
   
   System.out.println(out);
}
 
开发者ID:shashanksingh28,项目名称:code-similarity,代码行数:17,代码来源:ItemListBuilderDemo.java


注:本文中的org.w3c.dom.ls.LSSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。