Java Code Examples for org.w3c.dom.DocumentType#getSystemId()

The following examples show how to use org.w3c.dom.DocumentType#getSystemId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomWriter.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
protected void write(DocumentType node) {
    printWriter.print("<!DOCTYPE ");
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \"");
        printWriter.print(publicId);
        printWriter.print("\" \"");
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \"");
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" [");
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
Example 2
Source File: OutputFormat.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
Example 3
Source File: DomWriter.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
protected void write(DocumentType node) throws ShellException {
    printWriter.print("<!DOCTYPE "); //$NON-NLS-1$
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \""); //$NON-NLS-1$
        printWriter.print(publicId);
        printWriter.print("\" \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" ["); //$NON-NLS-1$
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
Example 4
Source File: OutputFormat.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
Example 5
Source File: OutputFormat.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
Example 6
Source File: OutputFormat.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
Example 7
Source File: OutputFormat.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
Example 8
Source File: DomParser.java    From caja with Apache License 2.0 6 votes vote down vote up
private OpenElementStack makeElementStack(Document doc, MessageQueue mq) {
  Namespaces ns = this.ns;
  DocumentType doctype = doc.getDoctype();
  if (doctype != null) {
    // If we have a DOCTYPE, use its SYSTEM ID to determine the default
    // namespace.
    String sysid = doctype.getSystemId();
    String nsUri = DoctypeMaker.systemIdToNsUri(sysid);
    if (nsUri != null) { ns = new Namespaces(ns, "", nsUri); }
  }
  return asXml
      ? OpenElementStack.Factory.createXmlElementStack(
          doc, needsDebugData, ns, mq)
      : OpenElementStack.Factory.createHtml5ElementStack(
          doc, needsDebugData, mq);
}
 
Example 9
Source File: Document.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private boolean isQuirksDocType() {
    final DocumentType docType = getPage().getDoctype();
    if (docType != null) {
        final String systemId = docType.getSystemId();
        if (systemId != null) {
            if ("http://www.w3.org/TR/html4/strict.dtd".equals(systemId)) {
                return false;
            }

            if ("http://www.w3.org/TR/html4/loose.dtd".equals(systemId)) {
                final String publicId = docType.getPublicId();
                if ("-//W3C//DTD HTML 4.01 Transitional//EN".equals(publicId)) {
                    return false;
                }
            }

            if ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".equals(systemId)
                || "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".equals(systemId)) {
                return false;
            }
        }
        else if (docType.getPublicId() == null) {
            return docType.getName() == null;
        }
    }
    return true;
}
 
Example 10
Source File: XmlUtils.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively appends a {@link Node} child to {@link DomNode} parent.
 *
 * @param page the owner page of {@link DomElement}s to be created
 * @param parent the parent DomNode
 * @param child the child Node
 * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
 *     DOM elements
 * @param attributesOrderMap (optional) the one returned by {@link #getAttributesOrderMap(Document)}
 */
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child,
    final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    final DocumentType documentType = child.getOwnerDocument().getDoctype();
    if (documentType != null && page instanceof XmlPage) {
        final DomDocumentType domDoctype = new DomDocumentType(
                page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId());
        ((XmlPage) page).setDocumentType(domDoctype);
    }
    final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
    parent.appendChild(childXml);
    copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
}
 
Example 11
Source File: XmlUtils.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML,
        final Map<Integer, List<String>> attributesOrderMap) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(),
                documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName);
        return factory.createElementNS(page, ns, localName,
                namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    }
    else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }

    final String namespaceURI = source.getNamespaceURI();
    if (Html.SVG_NAMESPACE.equals(namespaceURI)) {
        return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory()
                .createElementNS(page, namespaceURI, qualifiedName,
                        namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
    }

    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i);
        final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() != null) {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        }
        else {
            attributeQualifiedName = attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute =
                new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}
 
Example 12
Source File: DOMWriter.java    From exificient with MIT License 4 votes vote down vote up
protected void encodeChildNodes(NodeList children) throws EXIException,
		IOException {
	for (int i = 0; i < children.getLength(); i++) {
		Node n = children.item(i);
		switch (n.getNodeType()) {
		case Node.ELEMENT_NODE:
			encodeNode(n);
			break;
		case Node.ATTRIBUTE_NODE:
			break;
		case Node.TEXT_NODE:
			exiBody.encodeCharacters(new StringValue(n.getNodeValue()));
			break;
		case Node.COMMENT_NODE:
			if (preserveComments) {
				String c = n.getNodeValue();
				exiBody.encodeComment(c.toCharArray(), 0, c.length());
			}
			break;
		case Node.DOCUMENT_TYPE_NODE:
			DocumentType dt = (DocumentType) n;
			String publicID = dt.getPublicId() == null ? "" : dt
					.getPublicId();
			String systemID = dt.getSystemId() == null ? "" : dt
					.getSystemId();
			String text = dt.getInternalSubset() == null ? "" : dt
					.getInternalSubset();
			exiBody.encodeDocType(dt.getName(), publicID, systemID, text);
			break;
		case Node.ENTITY_REFERENCE_NODE:
			// checkPendingChars();
			// TODO ER
			break;
		case Node.CDATA_SECTION_NODE:
			// String cdata = n.getNodeValue();
			// exiBody.encodeCharacters(new
			// StringValue(Constants.CDATA_START
			// + cdata + Constants.CDATA_END));
			exiBody.encodeCharacters(new StringValue(n.getNodeValue()));
			break;
		case Node.PROCESSING_INSTRUCTION_NODE:
			if (preservePIs) {
				ProcessingInstruction pi = (ProcessingInstruction) n;
				exiBody.encodeProcessingInstruction(pi.getTarget(),
						pi.getData());
			}
			break;
		default:
			System.err.println("[WARNING] Unhandled DOM NodeType: "
					+ n.getNodeType());
			// throw new EXIException("Unknown NodeType? " +
			// n.getNodeType());
		}
	}
}
 
Example 13
Source File: XmlUtil.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML,
        final Map<Integer, List<String>> attributesOrderMap) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(),
                documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && HTMLParser.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = HTMLParser.getFactory(localName);
        return factory.createElementNS(page, ns, localName,
                namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    }
    else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }

    final String namespaceURI = source.getNamespaceURI();
    if (HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) {
        return HTMLParser.SVG_FACTORY.createElementNS(page, namespaceURI, qualifiedName,
                namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
    }

    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i);
        final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() != null) {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        }
        else {
            attributeQualifiedName = attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute =
                new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}
 
Example 14
Source File: AbstractXmlDocumentType.java    From JVoiceXML with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final String getSystemId() {
    final DocumentType  type = getDocumentType();
    return type.getSystemId();
}
 
Example 15
Source File: Nodes.java    From caja with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a rendering of document type.  This is handled explicitly here
 * rather than in {@link Nodes#render(Node, MarkupRenderMode)} to avoid
 * rendering a document type in the middle of a document.
 *
 * @return null if nothing to render or docType is invalid.
 */
private static @Nullable String renderDocumentType(DocumentType docType) {
  String publicId = docType.getPublicId();
  String systemId = docType.getSystemId();
  String nodeName;

  if (null != docType.getOwnerDocument() &&
      null != docType.getOwnerDocument().getDocumentElement() &&
      null != docType.getOwnerDocument().getDocumentElement().getNodeName()) {
    nodeName = docType.getOwnerDocument()
      .getDocumentElement()
      .getNodeName();
  } else {
    return null;
  }

  if (!DoctypeMaker.isHtml(nodeName, publicId, systemId)) {
    return null;
  }

  StringBuilder sb = new StringBuilder();
  sb.append("<!DOCTYPE ").append(nodeName);
  // The Name in the document type declaration must match the element type
  // of the root element.
  if (null != publicId && publicId.length() > 0) {
    sb.append(" PUBLIC ")
      .append('"')
      .append(publicId.replaceAll("\"", "%22"))
      .append('"');
  }
  if (null != systemId && systemId.length() > 0) {
    // Sanity check - system urls should parse as an absolute uris
    try {
      URI u = new URI(systemId);
      if (u.isAbsolute() &&
          ("http".equals(u.getScheme()) || "https".equals(u.getScheme()))) {
        sb.append(" ")
          .append('"')
          .append(systemId.replaceAll("\"", "%22"))
          .append('"');
      }
    } catch (URISyntaxException e) {
      return null;
    }
  }
  sb.append(">");
  return sb.toString();
}
 
Example 16
Source File: DOMNormalizer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private void processDTD(String xmlVersion, String schemaLocation) {

        String rootName = null;
        String publicId = null;
        String systemId = schemaLocation;
        String baseSystemId = fDocument.getDocumentURI();
        String internalSubset = null;

        DocumentType docType = fDocument.getDoctype();
        if (docType != null) {
            rootName = docType.getName();
            publicId = docType.getPublicId();
            if (systemId == null || systemId.length() == 0) {
                systemId = docType.getSystemId();
            }
            internalSubset = docType.getInternalSubset();
        }
        // If the DOM doesn't have a DocumentType node we may still
        // be able to fetch a DTD if the application provided a URI
        else {
            Element elem = fDocument.getDocumentElement();
            if (elem == null) return;
            rootName = elem.getNodeName();
            if (systemId == null || systemId.length() == 0) return;
        }

        XMLDTDLoader loader = null;
        try {
            fValidationHandler.doctypeDecl(rootName, publicId, systemId, null);
            loader = CoreDOMImplementationImpl.singleton.getDTDLoader(xmlVersion);
            loader.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);
            loader.setEntityResolver(fConfiguration.getEntityResolver());
            loader.setErrorHandler(fConfiguration.getErrorHandler());
            loader.loadGrammarWithContext((XMLDTDValidator) fValidationHandler, rootName,
                    publicId, systemId, baseSystemId, internalSubset);
        }
        // REVISIT: Should probably report this exception to the error handler.
        catch (IOException e) {
        }
        finally {
            if (loader != null) {
                CoreDOMImplementationImpl.singleton.releaseDTDLoader(xmlVersion, loader);
            }
        }
    }
 
Example 17
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Serializes a Document Type Node.
 *
 * @param node The Docuemnt Type Node to serialize
 * @param bStart Invoked at the start or end of node.  Default true.
 */
protected void serializeDocType(DocumentType node, boolean bStart)
    throws SAXException {
    // The DocType and internalSubset can not be modified in DOM and is
    // considered to be well-formed as the outcome of successful parsing.
    String docTypeName = node.getNodeName();
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    String internalSubset = node.getInternalSubset();

    //DocumentType nodes are never passed to the filter

    if (internalSubset != null && !"".equals(internalSubset)) {

        if (bStart) {
            try {
                // The Serializer does not provide a way to write out the
                // DOCTYPE internal subset via an event call, so we write it
                // out here.
                Writer writer = fSerializer.getWriter();
                StringBuffer dtd = new StringBuffer();

                dtd.append("<!DOCTYPE ");
                dtd.append(docTypeName);
                if (null != publicId) {
                    dtd.append(" PUBLIC \"");
                    dtd.append(publicId);
                    dtd.append('\"');
                }

                if (null != systemId) {
                    if (null == publicId) {
                        dtd.append(" SYSTEM \"");
                    } else {
                        dtd.append(" \"");
                    }
                    dtd.append(systemId);
                    dtd.append('\"');
                }

                dtd.append(" [ ");

                dtd.append(fNewLine);
                dtd.append(internalSubset);
                dtd.append("]>");
                dtd.append(fNewLine);

                writer.write(dtd.toString());
                writer.flush();

            } catch (IOException e) {
                throw new SAXException(Utils.messages.createMessage(
                        MsgKey.ER_WRITING_INTERNAL_SUBSET, null), e);
            }
        } // else if !bStart do nothing

    } else {

        if (bStart) {
            if (fLexicalHandler != null) {
                fLexicalHandler.startDTD(docTypeName, publicId, systemId);
            }
        } else {
            if (fLexicalHandler != null) {
                fLexicalHandler.endDTD();
            }
        }
    }
}
 
Example 18
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Serializes a Document Type Node.
 *
 * @param node The Docuemnt Type Node to serialize
 * @param bStart Invoked at the start or end of node.  Default true.
 */
protected void serializeDocType(DocumentType node, boolean bStart)
    throws SAXException {
    // The DocType and internalSubset can not be modified in DOM and is
    // considered to be well-formed as the outcome of successful parsing.
    String docTypeName = node.getNodeName();
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    String internalSubset = node.getInternalSubset();

    //DocumentType nodes are never passed to the filter

    if (internalSubset != null && !"".equals(internalSubset)) {

        if (bStart) {
            try {
                // The Serializer does not provide a way to write out the
                // DOCTYPE internal subset via an event call, so we write it
                // out here.
                Writer writer = fSerializer.getWriter();
                StringBuffer dtd = new StringBuffer();

                dtd.append("<!DOCTYPE ");
                dtd.append(docTypeName);
                if (null != publicId) {
                    dtd.append(" PUBLIC \"");
                    dtd.append(publicId);
                    dtd.append('\"');
                }

                if (null != systemId) {
                    if (null == publicId) {
                        dtd.append(" SYSTEM \"");
                    } else {
                        dtd.append(" \"");
                    }
                    dtd.append(systemId);
                    dtd.append('\"');
                }

                dtd.append(" [ ");

                dtd.append(fNewLine);
                dtd.append(internalSubset);
                dtd.append("]>");
                dtd.append(fNewLine);

                writer.write(dtd.toString());
                writer.flush();

            } catch (IOException e) {
                throw new SAXException(Utils.messages.createMessage(
                        MsgKey.ER_WRITING_INTERNAL_SUBSET, null), e);
            }
        } // else if !bStart do nothing

    } else {

        if (bStart) {
            if (fLexicalHandler != null) {
                fLexicalHandler.startDTD(docTypeName, publicId, systemId);
            }
        } else {
            if (fLexicalHandler != null) {
                fLexicalHandler.endDTD();
            }
        }
    }
}
 
Example 19
Source File: DOM3TreeWalker.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Serializes a Document Type Node.
 * 
 * @param node The Docuemnt Type Node to serialize
 * @param bStart Invoked at the start or end of node.  Default true. 
 */
protected void serializeDocType(DocumentType node, boolean bStart)
    throws SAXException {
    // The DocType and internalSubset can not be modified in DOM and is
    // considered to be well-formed as the outcome of successful parsing.
    String docTypeName = node.getNodeName();
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    String internalSubset = node.getInternalSubset();

    //DocumentType nodes are never passed to the filter
    
    if (internalSubset != null && !"".equals(internalSubset)) {

        if (bStart) {
            try {
                // The Serializer does not provide a way to write out the
                // DOCTYPE internal subset via an event call, so we write it
                // out here.
                Writer writer = fSerializer.getWriter();
                StringBuffer dtd = new StringBuffer();

                dtd.append("<!DOCTYPE ");
                dtd.append(docTypeName);
                if (null != publicId) {
                    dtd.append(" PUBLIC \"");
                    dtd.append(publicId);
                    dtd.append('\"');
                }

                if (null != systemId) {
                    if (null == publicId) {
                        dtd.append(" SYSTEM \"");
                    } else {
                        dtd.append(" \"");
                    }    
                    dtd.append(systemId);
                    dtd.append('\"');
                }
                
                dtd.append(" [ ");
                
                dtd.append(fNewLine);
                dtd.append(internalSubset);
                dtd.append("]>");
                dtd.append(new String(fNewLine));
                
                writer.write(dtd.toString());
                writer.flush();
                
            } catch (IOException e) {
                throw new SAXException(Utils.messages.createMessage(
                        MsgKey.ER_WRITING_INTERNAL_SUBSET, null), e);
            }
        } // else if !bStart do nothing
        
    } else {
        
        if (bStart) {
            if (fLexicalHandler != null) {
                fLexicalHandler.startDTD(docTypeName, publicId, systemId);
            }
        } else {
            if (fLexicalHandler != null) {
                fLexicalHandler.endDTD();
            }
        }
    }
}
 
Example 20
Source File: NodeDescription.java    From seleniumtestsframework with Apache License 2.0 3 votes vote down vote up
protected static void appendDocumentTypeDetail(final StringBuffer buf, final Node aNode) {

        DocumentType type = (DocumentType) aNode;

        buf.append(XMLConstants.START_DOCTYPE).append(type.getName());

        boolean hasNoPublicId = true;

        if (type.getPublicId() != null

                && type.getPublicId().length() > 0) {

            buf.append(" PUBLIC \"").append(type.getPublicId()).append('"');

            hasNoPublicId = false;

        }

        if (type.getSystemId() != null

                && type.getSystemId().length() > 0) {

            if (hasNoPublicId) {

                buf.append(" SYSTEM");

            }

            buf.append(" \"").append(type.getSystemId()).append('"');

        }

    }