Code example for DOMConfiguration

Methods: canSetParameter, getParameter, setParameter

0
        assertSupported("validate-if-schema", false); 
        assertUnsupported("validate-if-schema", true); 
    } 
 
    public void testWellFormed() { 
        assertEquals(true, domConfiguration.getParameter("well-formed"));
        assertSupported("well-formed", false); 
        assertSupported("well-formed", true); 
    } 
 
    public void testMissingParameter() { 
        assertFalse(domConfiguration.canSetParameter("foo", true));
        try { 
            domConfiguration.getParameter("foo");
            fail();
        } catch (DOMException e) {
        } 
        try { 
            domConfiguration.setParameter("foo", true);
            fail();
        } catch (DOMException e) {
        } 
    } 
 
    public void testNullKey() { 
        try { 
            domConfiguration.canSetParameter(null, true);
            fail();
        } catch (NullPointerException e) {
        } 
        try { 
            domConfiguration.getParameter(null);
            fail();
        } catch (NullPointerException e) {
        } 
        try { 
            domConfiguration.setParameter(null, true);
            fail();
        } catch (NullPointerException e) {
        } 
    } 
 
    public void testNullValue() { 
        String message = "This implementation's canSetParameter() disagrees"
                + " with its setParameter()"; 
        try { 
            domConfiguration.setParameter("well-formed", null);
            fail(message);
        } catch (DOMException e) {
        } 
        assertEquals(message, false, domConfiguration.canSetParameter("well-formed", null));
    } 
 
    public void testTypeMismatch() { 
        assertEquals(false, domConfiguration.canSetParameter("well-formed", "true"));
        try { 
            domConfiguration.setParameter("well-formed", "true");
            fail();
        } catch (DOMException e) {
        } 
 
        assertEquals(false, domConfiguration.canSetParameter("well-formed", new Object()));
        try { 
            domConfiguration.setParameter("well-formed", new Object());
            fail();
        } catch (DOMException e) {
        } 
    } 
 
    private void assertUnsupported(String name, Object value) {
        String message = "This implementation's setParameter() supports an unexpected value: "
                + name + "=" + value;
        assertFalse(message, domConfiguration.canSetParameter(name, value));
        try { 
            domConfiguration.setParameter(name, value);
            fail(message);
        } catch (DOMException e) {
            assertEquals(DOMException.NOT_SUPPORTED_ERR, e.code);
        } 
        try { 
            domConfiguration.setParameter(name.toUpperCase(), value);
            fail(message);
        } catch (DOMException e) {
            assertEquals(DOMException.NOT_SUPPORTED_ERR, e.code);
        } 
        assertFalse(value.equals(domConfiguration.getParameter(name)));
    } 
 
    private void assertSupported(String name, Object value) {
        String message = "This implementation's canSetParameter() disagrees"
                + " with its setParameter() for " + name + "=" + value;
        try { 
            domConfiguration.setParameter(name, value);
        } catch (DOMException e) {
            if (domConfiguration.canSetParameter(name, value)) {
                fail(message);
            } else { 
                fail("This implementation's setParameter() doesn't support: "
                        + name + "=" + value);
            } 
        } 
        assertTrue(message, domConfiguration.canSetParameter(name.toUpperCase(), value));
        assertTrue(message, domConfiguration.canSetParameter(name, value));
        assertEquals(value, domConfiguration.getParameter(name));
        domConfiguration.setParameter(name.toUpperCase(), value);
        assertEquals(value, domConfiguration.getParameter(name.toUpperCase()));
    } 
 
    public void testCdataSectionsNotHonoredByNodeNormalize() throws Exception { 
        String xml = "<foo>ABC<![CDATA[DEF]]>GHI</foo>";
        parse(xml);