FileDocCategorySizeDatePackage
CreateDocumentType.javaAPI DocAndroid 1.5 API8175Wed May 06 22:41:06 BST 2009tests.org.w3c.dom

CreateDocumentType

public final class CreateDocumentType extends DOMTestCase
The "createDocumentType(qualifiedName,publicId,systemId)" method for a DOMImplementation should raise NAMESPACE_ERR DOMException if qualifiedName is malformed. Retrieve the DOMImplementation on the XMLNS Document. Invoke method createDocumentType(qualifiedName,publicId,systemId) on the retrieved DOMImplementation with qualifiedName being the literal string "prefix::local", publicId as "STAFF", and systemId as "staff". Method should raise NAMESPACE_ERR DOMException.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
see
http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration1());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    
protected voidtearDown()

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestCreateDocumentType1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

        String publicId = "STAFF";
        String systemId = "staff.xml";
        String malformedName = "prefix::local";
        Document doc;
        DOMImplementation domImpl;

        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();

        {
            boolean success = false;
            try {
                domImpl.createDocumentType(malformedName, publicId, systemId);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }
    
public voidtestCreateDocumentType2()

        String publicId = "http://www.localhost.com/";
        String systemId = "myDoc.dtd";
        String qualifiedName;
        Document doc;

        DOMImplementation domImpl;
        List<String> illegalQNames = new ArrayList<String>();
        illegalQNames.add("edi:{");
        illegalQNames.add("edi:}");
        illegalQNames.add("edi:~");
        illegalQNames.add("edi:'");
        illegalQNames.add("edi:!");
        illegalQNames.add("edi:@");
        illegalQNames.add("edi:#");
        illegalQNames.add("edi:$");
        illegalQNames.add("edi:%");
        illegalQNames.add("edi:^");
        illegalQNames.add("edi:&");
        illegalQNames.add("edi:*");
        illegalQNames.add("edi:(");
        illegalQNames.add("edi:)");
        illegalQNames.add("edi:+");
        illegalQNames.add("edi:=");
        illegalQNames.add("edi:[");
        illegalQNames.add("edi:]");
        illegalQNames.add("edi:\\");
        illegalQNames.add("edi:/");
        illegalQNames.add("edi:;");
        illegalQNames.add("edi:`");
        illegalQNames.add("edi:<");
        illegalQNames.add("edi:>");
        illegalQNames.add("edi:,");
        illegalQNames.add("edi:a ");
        illegalQNames.add("edi:\"");

        doc = (Document) load("staffNS", builder);
        for (int indexN1009A = 0; indexN1009A < illegalQNames.size(); indexN1009A++) {
            qualifiedName = (String) illegalQNames.get(indexN1009A);
            domImpl = doc.getImplementation();

            {
                boolean success = false;
                try {
                    domImpl.createDocumentType(qualifiedName, publicId,
                            systemId);
                } catch (DOMException ex) {
                    success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
                }
                assertTrue("throw_INVALID_CHARACTER_ERR", success);
            }
        }
    
public voidtestCreateDocumentType3()

        
        String qualifiedName = "prefix:myDoc";
        String publicId = "http://www.localhost.com";
        String systemId = "myDoc.dtd";
        Document doc;
        DOMImplementation domImpl;
        DocumentType newType = null;

        String nodeName;
        String nodeValue;
        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();
        newType = domImpl.createDocumentType(qualifiedName, publicId, systemId);
        nodeName = newType.getNodeName();
        assertEquals("nodeName", "prefix:myDoc", nodeName);
        nodeValue = newType.getNodeValue();
        assertNull("nodeValue", nodeValue);
    
public voidtestCreateDocumentType4()

        String publicId = "http://www.example.com/";
        String systemId = "myDoc.dtd";

        DOMImplementation domImpl;
        domImpl = builder.getDOMImplementation();

        {
            boolean success = false;
            try {
                domImpl.createDocumentType("", publicId, systemId);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            }
            assertTrue("throw_NAMESPACE_ERR", success);
        }