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


Java DOMConfiguration.getParameter方法代码示例

本文整理汇总了Java中org.w3c.dom.DOMConfiguration.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java DOMConfiguration.getParameter方法的具体用法?Java DOMConfiguration.getParameter怎么用?Java DOMConfiguration.getParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.DOMConfiguration的用法示例。


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

示例1: testDOMConfiguration

import org.w3c.dom.DOMConfiguration; //导入方法依赖的package包/类
@Test
public void testDOMConfiguration() {

    final DOMErrorHandler handler = new DOMErrorHandler() {
        public boolean handleError(final DOMError error) {
            return false;
        }
    };

    final LSResourceResolver resolver = new LSResourceResolver() {
        public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
            return null;
        }
    };

    final Object[][] values = {
            // parameter, value
            { "canonical-form", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, { "cdata-sections", Boolean.TRUE },
            { "check-character-normalization", Boolean.FALSE }, { "comments", Boolean.FALSE }, { "comments", Boolean.TRUE },
            { "datatype-normalization", Boolean.FALSE }, { "entities", Boolean.FALSE }, { "entities", Boolean.TRUE }, { "error-handler", handler },
            { "infoset", Boolean.TRUE }, { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE },
            { "namespace-declarations", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "split-cdata-sections", Boolean.TRUE },
            { "split-cdata-sections", Boolean.FALSE }, { "validate", Boolean.FALSE }, { "validate-if-schema", Boolean.FALSE },
            { "well-formed", Boolean.TRUE }, { "element-content-whitespace", Boolean.TRUE },

            { "charset-overrides-xml-encoding", Boolean.TRUE }, { "charset-overrides-xml-encoding", Boolean.FALSE }, { "disallow-doctype", Boolean.FALSE },
            { "ignore-unknown-character-denormalizations", Boolean.TRUE }, { "resource-resolver", resolver }, { "resource-resolver", null },
            { "supported-media-types-only", Boolean.FALSE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    }

    DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");

    LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    DOMConfiguration config = lsParser.getDomConfig();

    for (int i = values.length; --i >= 0;) {
        Object val = values[i][1];
        String param = (String) values[i][0];
        try {
            config.setParameter(param, val);
            Object returned = config.getParameter(param);
            Assert.assertEquals(val, returned, "'" + param + "' is set to " + returned + ", but expected " + val);
            System.out.println("set '" + param + "'" + " to '" + val + "'" + " and returned '" + returned + "'");
        } catch (DOMException e) {
            String settings = "setting '" + param + "' to " + val;
            System.err.println(settings);
            e.printStackTrace();
            Assert.fail(settings + ", " + e.toString());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:LSParserTest.java

示例2: testCanonicalForm002

import org.w3c.dom.DOMConfiguration; //导入方法依赖的package包/类
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the parameters "namespaces",
 * "namespace-declarations", "well-formed", "element-content-whitespace" are
 * set to false if possible; the parameters "entities",
 * "normalize-characters", "cdata-sections" are set to true if possible, <br>
 * <b>name</b>: canonical-form <br>
 * <b>value</b>: true. <br>
 * <b>Expected results</b>: the parameters "namespaces",
 * "namespace-declarations", "well-formed", "element-content-whitespace" are
 * set to true; the parameters "entities", "normalize-characters",
 * "cdata-sections" are set to false
 */
@Test
public void testCanonicalForm002() {
    Object[][] params = { { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE }, { "well-formed", Boolean.TRUE },
            { "element-content-whitespace", Boolean.TRUE },

            { "entities", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);

    DOMConfiguration config = doc.getDomConfig();

    if (!config.canSetParameter("canonical-form", Boolean.TRUE)) {
        System.out.println("OK, setting 'canonical-form' to true is not supported");
        return;
    }

    for (int i = params.length; --i >= 0;) {
        Boolean reset = params[i][1].equals(Boolean.TRUE) ? Boolean.FALSE : Boolean.TRUE;
        if (config.canSetParameter(params[i][0].toString(), reset)) {
            config.setParameter(params[i][0].toString(), reset);
        }
    }

    config.setParameter("canonical-form", Boolean.TRUE);

    StringBuffer result = new StringBuffer();

    for (int i = params.length; --i >= 0;) {
        Object param = config.getParameter(params[i][0].toString());
        if (!params[i][1].equals(param)) {
            result.append("; the parameter \'" + params[i][0] + "\' is set to " + param + ", expected: " + params[i][1]);
        }
    }

    if (result.length() > 0) {
        Assert.fail(result.toString().substring(2));
    }

    return; // Status.passed("OK");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:65,代码来源:DOMConfigurationTest.java

示例3: testCanonicalForm004

import org.w3c.dom.DOMConfiguration; //导入方法依赖的package包/类
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: setting the "canonical-form" to true is supported, <br>
 * <b>name</b>: canonical-form <br>
 * <b>value</b>: true. <br>
 * <b>Expected results</b>: one of the following parameters is changed:
 * "namespaces", "namespace-declarations", "well-formed",
 * "element-content-whitespace", "entities", "normalize-characters",
 * "cdata-sections" then "canonical-form" becomes false
 */
@Test
public void testCanonicalForm004() {
    Object[][] params = { { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE }, { "well-formed", Boolean.TRUE },
            { "element-content-whitespace", Boolean.TRUE },

            { "entities", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);

    DOMConfiguration config = doc.getDomConfig();

    if (!config.canSetParameter("canonical-form", Boolean.TRUE)) {
        System.out.println("OK, setting 'canonical-form' to true is not supported");
        return;
    }

    StringBuffer result = new StringBuffer();

    for (int i = params.length; --i >= 0;) {
        config.setParameter("canonical-form", Boolean.TRUE);
        Boolean changedValue = (params[i][1].equals(Boolean.TRUE)) ? Boolean.FALSE : Boolean.TRUE;
        if (config.canSetParameter(params[i][0].toString(), changedValue)) {
            config.setParameter(params[i][0].toString(), changedValue);
            Object param = config.getParameter("canonical-form");
            if (!Boolean.FALSE.equals(param)) {
                result.append("; setting the parameter '" + params[i][0] + "' to " + changedValue + " does not change 'canonical-form' to false");
            }
        }
    }

    if (result.length() > 0) {
        Assert.fail(result.toString().substring(2));
    }

    return; // Status.passed("OK");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:DOMConfigurationTest.java

示例4: testInfoset001

import org.w3c.dom.DOMConfiguration; //导入方法依赖的package包/类
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the 'infoset' parameter is set to true, <br>
 * <b>name</b>: infoset <br>
 * <b>value</b>: false. <br>
 * <b>Expected results</b>: the parameters "validate-if-schema", "entities",
 * "datatype-normalization", "cdata-sections", "namespace-declarations",
 * "well-formed", "element-content-whitespace", "comments", "namespaces" are
 * left unchanged
 */
@Test
public void testInfoset001() {
    Object[][] params = { { "validate-if-schema", Boolean.FALSE }, { "entities", Boolean.FALSE }, { "datatype-normalization", Boolean.FALSE },
            { "cdata-sections", Boolean.FALSE },

            { "namespace-declarations", Boolean.TRUE }, { "well-formed", Boolean.TRUE }, { "element-content-whitespace", Boolean.TRUE },
            { "comments", Boolean.TRUE }, { "namespaces", Boolean.TRUE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);

    DOMConfiguration config = doc.getDomConfig();

    if (!config.canSetParameter("infoset", Boolean.TRUE)) {
        Assert.fail("setting 'infoset' to true is not supported");
    }

    for (int i = params.length; --i >= 0;) {
        Boolean reset = params[i][1].equals(Boolean.TRUE) ? Boolean.FALSE : Boolean.TRUE;
        if (config.canSetParameter(params[i][0].toString(), reset)) {
            config.setParameter(params[i][0].toString(), reset);
        }
    }

    config.setParameter("infoset", Boolean.TRUE);
    config.setParameter("infoset", Boolean.FALSE); // has no effect

    StringBuffer result = new StringBuffer();

    for (int i = params.length; --i >= 0;) {
        Object param = config.getParameter(params[i][0].toString());
        if (!params[i][1].equals(param)) {
            result.append("; the parameter \'" + params[i][0] + "\' is set to " + param + ", expected: " + params[i][1]);
        }
    }

    if (result.length() > 0) {
        Assert.fail(result.toString().substring(2));
    }

    return; // Status.passed("OK");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:63,代码来源:DOMConfigurationTest.java


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