Exemple #1
0
  /**
   * Handle the declaration of a Notation in a DTD
   *
   * @param name name of the notation
   * @param publicID the public ID of the notation
   * @param systemID the system ID of the notation
   */
  public void notationDecl(String name, String publicID, String systemID) throws SAXException {

    if (!inInternalSubset) return;

    internalSubset.append("  <!NOTATION ").append(name);
    appendExternalId(publicID, systemID);
    internalSubset.append(">\n");
  }
Exemple #2
0
  /**
   * Handler for unparsed entity declarations in the DTD
   *
   * @param name <code>String</code> of the unparsed entity decl
   * @param publicID <code>String</code> of the unparsed entity decl
   * @param systemID <code>String</code> of the unparsed entity decl
   * @param notationName <code>String</code> of the unparsed entity decl
   */
  public void unparsedEntityDecl(String name, String publicID, String systemID, String notationName)
      throws SAXException {

    if (!inInternalSubset) return;

    internalSubset.append("  <!ENTITY ").append(name);
    appendExternalId(publicID, systemID);
    internalSubset.append(" NDATA ").append(notationName);
    internalSubset.append(">\n");
  }
Exemple #3
0
  /**
   * This is called when the parser encounters an external entity declaration.
   *
   * @param name entity name
   * @param publicID public id
   * @param systemID system id
   * @throws SAXException when things go wrong
   */
  public void externalEntityDecl(String name, String publicID, String systemID)
      throws SAXException {
    // Store the public and system ids for the name
    externalEntities.put(name, new String[] {publicID, systemID});

    if (!inInternalSubset) return;

    internalSubset.append("  <!ENTITY ").append(name);
    appendExternalId(publicID, systemID);
    internalSubset.append(">\n");
  }
Exemple #4
0
 /**
  * Appends an external ID to the internal subset buffer. Either publicID or systemID may be null,
  * but not both.
  *
  * @param publicID the public ID
  * @param systemID the system ID
  */
 private void appendExternalId(String publicID, String systemID) {
   if (publicID != null) {
     internalSubset.append(" PUBLIC \"").append(publicID).append('\"');
   }
   if (systemID != null) {
     if (publicID == null) {
       internalSubset.append(" SYSTEM ");
     } else {
       internalSubset.append(' ');
     }
     internalSubset.append('\"').append(systemID).append('\"');
   }
 }
Exemple #5
0
  /**
   * Handle an internal entity declaration in a DTD.
   *
   * @param name <code>String</code> name of entity
   * @param value <code>String</code> value of the entity
   * @throws SAXException
   */
  public void internalEntityDecl(String name, String value) throws SAXException {

    // Skip entities that come from the external subset
    if (!inInternalSubset) return;

    internalSubset.append("  <!ENTITY ");
    if (name.startsWith("%")) {
      internalSubset.append("% ").append(name.substring(1));
    } else {
      internalSubset.append(name);
    }
    internalSubset.append(" \"").append(value).append("\">\n");
  }
Exemple #6
0
  /**
   * This handles an attribute declaration in the internal subset.
   *
   * @param eName <code>String</code> element name of attribute
   * @param aName <code>String</code> attribute name
   * @param type <code>String</code> attribute type
   * @param valueDefault <code>String</code> default value of attribute
   * @param value <code>String</code> value of attribute
   * @throws SAXException
   */
  public void attributeDecl(
      String eName, String aName, String type, String valueDefault, String value)
      throws SAXException {

    if (!inInternalSubset) return;

    internalSubset
        .append("  <!ATTLIST ")
        .append(eName)
        .append(' ')
        .append(aName)
        .append(' ')
        .append(type)
        .append(' ');
    if (valueDefault != null) {
      internalSubset.append(valueDefault);
    } else {
      internalSubset.append('\"').append(value).append('\"');
    }
    if ((valueDefault != null) && (valueDefault.equals("#FIXED"))) {
      internalSubset.append(" \"").append(value).append('\"');
    }
    internalSubset.append(">\n");
  }
Exemple #7
0
  /**
   * This reports that a comments is parsed. If not in the DTD, this comment is added to the current
   * JDOM <code>Element</code>, or the <code>Document</code> itself if at that level.
   *
   * @param ch <code>ch[]</code> array of comment characters.
   * @param start <code>int</code> index to start reading from.
   * @param length <code>int</code> length of data.
   * @throws SAXException
   */
  public void comment(char[] ch, int start, int length) throws SAXException {

    if (suppress) return;

    flushCharacters();

    String commentText = new String(ch, start, length);
    if (inDTD && inInternalSubset && (expand == false)) {
      internalSubset.append("  <!--").append(commentText).append("-->\n");
      return;
    }
    if ((!inDTD) && (!commentText.equals(""))) {
      if (atRoot) {
        factory.addContent(document, factory.comment(commentText));
      } else {
        factory.addContent(getCurrentElement(), factory.comment(commentText));
      }
    }
  }
Exemple #8
0
  /**
   * This signifies that the reading of the DTD is complete.
   *
   * @throws SAXException
   */
  public void endDTD() throws SAXException {

    document.getDocType().setInternalSubset(internalSubset.toString());
    inDTD = false;
    inInternalSubset = false;
  }
Exemple #9
0
  /**
   * Handle an element declaration in a DTD.
   *
   * @param name <code>String</code> name of element
   * @param model <code>String</code> model of the element in DTD syntax
   * @throws SAXException
   */
  public void elementDecl(String name, String model) throws SAXException {
    // Skip elements that come from the external subset
    if (!inInternalSubset) return;

    internalSubset.append("  <!ELEMENT ").append(name).append(' ').append(model).append(">\n");
  }