コード例 #1
0
ファイル: NodeConvertorImpl.java プロジェクト: adsefr/rmscode
  @Override
  public DocumentTypeNode convert(DocumentType documentType) {

    DocumentTypeBuilder documentTypeBuilder = NodeBuilderFactory.newdoDocumentTypeBuilder();
    DocumentTypeNode documentTypeNode = null;

    documentTypeNode =
        documentTypeBuilder //
            .nodeName(documentType.getNodeName()) //
            .name(documentType.getName()) //
            .publicId(documentType.getPublicId()) //
            .systemId(documentType.getSystemId()) //
            .internalSubSet(documentType.getInternalSubset()) //
            .build();

    return documentTypeNode;
  }
コード例 #2
0
 public boolean enter(DocumentType docType) {
   String name = docType.getName();
   String pubId = docType.getPublicId();
   String sysId = docType.getSystemId();
   String internalSubset = docType.getInternalSubset();
   if (docType.getPreviousSibling() != null) {
     buffer.append("\n");
   }
   buffer.append("<!DOCTYPE " + name + " ");
   if (pubId != null) {
     buffer.append("PUBLIC \"" + pubId + "\"");
     if (sysId != null) buffer.append(" \"" + sysId + "\"");
   } else if (sysId != null) {
     buffer.append("SYSTEM \"" + sysId + "\"");
   }
   if (internalSubset != null) {
     buffer.append(" [");
     buffer.append(internalSubset);
     buffer.append("]");
   }
   buffer.append(">\n");
   return true;
 }
コード例 #3
0
ファイル: DOMWriter.java プロジェクト: kamalhg/biodiv
  /** Writes the specified node, recursively. */
  public void write(Node node) {

    // is there anything to do?
    if (node == null) {
      return;
    }

    short type = node.getNodeType();
    switch (type) {
      case Node.DOCUMENT_NODE:
        {
          Document document = (Document) node;
          if (!fCanonical) {
            fOut.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            fOut.flush();
            write(document.getDoctype());
          }
          write(document.getDocumentElement());
          break;
        }

      case Node.DOCUMENT_TYPE_NODE:
        {
          DocumentType doctype = (DocumentType) node;
          fOut.print("<!DOCTYPE ");
          fOut.print(doctype.getName());
          String publicId = doctype.getPublicId();
          String systemId = doctype.getSystemId();
          if (publicId != null) {
            fOut.print(" PUBLIC '");
            fOut.print(publicId);
            fOut.print("' '");
            fOut.print(systemId);
            fOut.print('\'');
          } else {
            fOut.print(" SYSTEM '");
            fOut.print(systemId);
            fOut.print('\'');
          }
          String internalSubset = doctype.getInternalSubset();
          if (internalSubset != null) {
            fOut.println(" [");
            fOut.print(internalSubset);
            fOut.print(']');
          }
          fOut.println('>');
          break;
        }

      case Node.ELEMENT_NODE:
        {
          fOut.print('<');
          fOut.print(node.getNodeName());
          Attr attrs[] = sortAttributes(node.getAttributes());
          for (int i = 0; i < attrs.length; i++) {
            Attr attr = attrs[i];
            fOut.print(' ');
            fOut.print(attr.getNodeName());
            fOut.print("=\"");
            normalizeAndPrint(attr.getNodeValue());
            fOut.print('"');
          }
          fOut.print('>');
          fOut.flush();

          Node child = node.getFirstChild();
          while (child != null) {
            write(child);
            child = child.getNextSibling();
          }
          break;
        }

      case Node.ATTRIBUTE_NODE:
        {
          Attr attr = (Attr) node;
          fOut.print(attr.getValue());
          fOut.flush();
          break;
        }

      case Node.ENTITY_REFERENCE_NODE:
        {
          if (fCanonical) {
            Node child = node.getFirstChild();
            while (child != null) {
              write(child);
              child = child.getNextSibling();
            }
          } else {
            fOut.print('&');
            fOut.print(node.getNodeName());
            fOut.print(';');
            fOut.flush();
          }
          break;
        }

      case Node.CDATA_SECTION_NODE:
        {
          if (fCanonical) {
            normalizeAndPrint(node.getNodeValue());
          } else {
            fOut.print("<![CDATA[");
            fOut.print(node.getNodeValue());
            fOut.print("]]>");
          }
          fOut.flush();
          break;
        }

      case Node.TEXT_NODE:
        {
          normalizeAndPrint(node.getNodeValue());
          fOut.flush();
          break;
        }

      case Node.PROCESSING_INSTRUCTION_NODE:
        {
          fOut.print("<?");
          fOut.print(node.getNodeName());
          String data = node.getNodeValue();
          if (data != null && data.length() > 0) {
            fOut.print(' ');
            fOut.print(data);
          }
          fOut.println("?>");
          fOut.flush();
          break;
        }
    }

    if (type == Node.ELEMENT_NODE) {
      fOut.print("</");
      fOut.print(node.getNodeName());
      fOut.print('>');
      fOut.flush();
    }
  } // write(Node)