Search in sources :

Example 26 with DocumentType

use of org.w3c.dom.DocumentType in project robovm by robovm.

the class DocumentTypePublicId method testGetPublicId.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testGetPublicId() throws Throwable {
    Document doc;
    DocumentType docType;
    DOMImplementation domImpl;
    String publicId;
    String nullNS = null;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("l2:root", "PUB", nullNS);
    publicId = docType.getPublicId();
    assertEquals("documenttypepublicid01", "PUB", publicId);
}
Also used : DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 27 with DocumentType

use of org.w3c.dom.DocumentType in project robovm by robovm.

the class DocumentTypeSystemId method testGetSystemId.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testGetSystemId() throws Throwable {
    Document doc;
    DocumentType docType;
    DOMImplementation domImpl;
    String publicId;
    String systemId;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("l2:root", "PUB", "SYS");
    publicId = docType.getPublicId();
    systemId = docType.getSystemId();
    assertEquals("documenttypepublicid01", "PUB", publicId);
    assertEquals("documenttypesystemid01", "SYS", systemId);
}
Also used : DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 28 with DocumentType

use of org.w3c.dom.DocumentType in project gocd by gocd.

the class XmlDocument method getInternalSubset.

public IRubyObject getInternalSubset(ThreadContext context) {
    IRubyObject dtd = (IRubyObject) node.getUserData(DTD_INTERNAL_SUBSET);
    if (dtd == null) {
        Document document = getDocument();
        if (document.getUserData(XmlDocument.DTD_RAW_DOCUMENT) != null) {
            dtd = XmlDtd.newFromInternalSubset(context.getRuntime(), document);
        } else if (document.getDoctype() != null) {
            DocumentType docType = document.getDoctype();
            IRubyObject name, publicId, systemId;
            name = publicId = systemId = context.getRuntime().getNil();
            if (docType.getName() != null) {
                name = context.getRuntime().newString(docType.getName());
            }
            if (docType.getPublicId() != null) {
                publicId = context.getRuntime().newString(docType.getPublicId());
            }
            if (docType.getSystemId() != null) {
                systemId = context.getRuntime().newString(docType.getSystemId());
            }
            dtd = XmlDtd.newEmpty(context.getRuntime(), document, name, publicId, systemId);
        } else {
            dtd = context.getRuntime().getNil();
        }
        setInternalSubset(dtd);
    }
    return dtd;
}
Also used : DocumentType(org.w3c.dom.DocumentType) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document)

Example 29 with DocumentType

use of org.w3c.dom.DocumentType in project gocd by gocd.

the class XmlDtd method setNode.

public void setNode(Ruby runtime, Node dtd) {
    this.node = dtd;
    notationClass = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::Notation");
    name = pubId = sysId = runtime.getNil();
    if (dtd == null)
        return;
    // This is the dtd declaration stored in the document; it
    // contains the DTD name (root element) and public and system
    // ids. The actual declarations are in the NekoDTD 'dtd'
    // variable. I don't know of a way to consolidate the two.
    DocumentType otherDtd = dtd.getOwnerDocument().getDoctype();
    if (otherDtd != null) {
        name = stringOrNil(runtime, otherDtd.getNodeName());
        pubId = nonEmptyStringOrNil(runtime, otherDtd.getPublicId());
        sysId = nonEmptyStringOrNil(runtime, otherDtd.getSystemId());
    }
}
Also used : DocumentType(org.w3c.dom.DocumentType)

Example 30 with DocumentType

use of org.w3c.dom.DocumentType in project XobotOS by xamarin.

the class DocumentBuilderImpl method parse.

@Override
public Document parse(InputSource source) throws SAXException, IOException {
    if (source == null) {
        throw new IllegalArgumentException("source == null");
    }
    String namespaceURI = null;
    String qualifiedName = null;
    DocumentType doctype = null;
    String inputEncoding = source.getEncoding();
    String systemId = source.getSystemId();
    DocumentImpl document = new DocumentImpl(dom, namespaceURI, qualifiedName, doctype, inputEncoding);
    document.setDocumentURI(systemId);
    KXmlParser parser = new KXmlParser();
    try {
        parser.keepNamespaceAttributes();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
        if (source.getByteStream() != null) {
            parser.setInput(source.getByteStream(), inputEncoding);
        } else if (source.getCharacterStream() != null) {
            parser.setInput(source.getCharacterStream());
        } else if (systemId != null) {
            URL url = new URL(systemId);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            // TODO: if null, extract the inputEncoding from the Content-Type header?
            parser.setInput(urlConnection.getInputStream(), inputEncoding);
        } else {
            throw new SAXParseException("InputSource needs a stream, reader or URI", null);
        }
        if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
            throw new SAXParseException("Unexpected end of document", null);
        }
        parse(parser, document, document, XmlPullParser.END_DOCUMENT);
        parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException ex) {
        if (ex.getDetail() instanceof IOException) {
            throw (IOException) ex.getDetail();
        }
        if (ex.getDetail() instanceof RuntimeException) {
            throw (RuntimeException) ex.getDetail();
        }
        LocatorImpl locator = new LocatorImpl();
        locator.setPublicId(source.getPublicId());
        locator.setSystemId(systemId);
        locator.setLineNumber(ex.getLineNumber());
        locator.setColumnNumber(ex.getColumnNumber());
        SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);
        if (errorHandler != null) {
            errorHandler.error(newEx);
        }
        throw newEx;
    } finally {
        IoUtils.closeQuietly(parser);
    }
    return document;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) SAXParseException(org.xml.sax.SAXParseException) DocumentType(org.w3c.dom.DocumentType) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) IOException(java.io.IOException) DocumentImpl(org.apache.harmony.xml.dom.DocumentImpl) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

DocumentType (org.w3c.dom.DocumentType)107 Document (org.w3c.dom.Document)68 DOMImplementation (org.w3c.dom.DOMImplementation)34 Node (org.w3c.dom.Node)21 DOMException (org.w3c.dom.DOMException)19 Element (org.w3c.dom.Element)16 NamedNodeMap (org.w3c.dom.NamedNodeMap)14 NodeList (org.w3c.dom.NodeList)12 ArrayList (java.util.ArrayList)10 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)8 Entity (org.w3c.dom.Entity)8 IOException (java.io.IOException)7 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Transformer (javax.xml.transform.Transformer)4 TransformerFactory (javax.xml.transform.TransformerFactory)4 DOMSource (javax.xml.transform.dom.DOMSource)4 StreamResult (javax.xml.transform.stream.StreamResult)4 Attr (org.w3c.dom.Attr)4