/**
   * generateDoctype method
   *
   * @return java.lang.String
   * @param docType org.w3c.dom.DocumentType
   */
  public String generateDoctype(DocumentType docType) {
    if (docType == null) return null;

    String name = docType.getName();
    int length = (name != null ? name.length() : 0);
    StringBuffer buffer = new StringBuffer(length + 16);
    buffer.append(DOCTYPE_OPEN);
    buffer.append(' ');
    if (name != null) buffer.append(name);
    DocumentTypeImpl dt = (DocumentTypeImpl) docType;
    String publicID = dt.getPublicId();
    String systemID = dt.getSystemId();
    if (publicID != null) {
      buffer.append(' ');
      buffer.append(PUBLIC_ID);
      buffer.append(' ');
      buffer.append('"');
      buffer.append(publicID);
      buffer.append('"');
      if (systemID != null) {
        buffer.append(' ');
        buffer.append('"');
        buffer.append(systemID);
        buffer.append('"');
      }
    } else {
      if (systemID != null) {
        buffer.append(' ');
        buffer.append(SYSTEM_ID);
        buffer.append(' ');
        buffer.append('"');
        buffer.append(systemID);
        buffer.append('"');
      }
    }
    buffer.append('>');
    return buffer.toString();
  }
Example #2
0
 protected void registerDocumentType(DocumentTypeImpl docType) {
   String name = docType.getName();
   documentTypes.put(name, docType);
   documentTypesExtending.put(name, new HashSet<>(Collections.singleton(name)));
 }