* @return XmlDoctype
   */
  public static XmlDoctype processDoctype(Cons doctypeDeclaration) {
    if ((doctypeDeclaration != null) &&
        ((!(doctypeDeclaration == Stella.NIL)) &&
         (Stella_Object.isaP(doctypeDeclaration.value, Stella.SGT_STELLA_XML_DECLARATION) &&
          Stella.stringEqlP("DOCTYPE", ((XmlDeclaration)(doctypeDeclaration.value)).name)))) {
      { XmlDoctype doctype = XmlDoctype.newXmlDoctype();
        InputStream definitionStream = null;
        XmlExpressionIterator iterator = null;

        try {
          doctype.name = ((StringWrapper)(((Cons)(doctypeDeclaration.rest.value)).value)).wrapperValue;
          definitionStream = Cons.getDoctypeDefinition(doctypeDeclaration);
          if (definitionStream != null) {
            { XmlExpressionIterator self001 = XmlExpressionIterator.newXmlExpressionIterator();

              self001.theStream = definitionStream;
              self001.doctypeIteratorP = true;
              self001.doctype = doctype;
              iterator = self001;
            }
            { Stella_Object declaration = null;
              XmlExpressionIterator iter000 = iterator;

              while (iter000.nextP()) {
                declaration = iter000.value;
                if (Stella_Object.isaP(((Cons)(declaration)).value, Stella.SGT_STELLA_XML_DECLARATION) &&
                    Stella.stringEqlP("ENTITY", ((XmlDeclaration)(((Cons)(declaration)).value)).name)) {
                  { Cons attributes = ((Cons)(((Cons)(declaration)).rest.value));

                    if (Stella.stringEqlP("%", ((StringWrapper)(attributes.value)).wrapperValue)) {
                      if ((attributes.length() > 3) &&
                          Stella_Object.externalIdHeadP(attributes.rest.rest.value)) {
                        { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

                          stream000.nativeStream.print("Can't handle external entity definitions: `" + declaration + "'");
                          throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
                        }
                      }
                      else {
                        Stella.addXmlReference(((StringWrapper)(attributes.rest.value)).wrapperValue, ((StringWrapper)(attributes.rest.rest.value)).wrapperValue, doctype.parameterEntityTable);
                      }
                    }
                    else {
                      if ((attributes.length() > 2) &&
                          Stella_Object.externalIdHeadP(attributes.rest.value)) {
                        { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

                          stream001.nativeStream.print("Can't handle external entity definitions: `" + declaration + "'");
                          throw ((StellaException)(StellaException.newStellaException(stream001.theStringReader()).fillInStackTrace()));
                        }
                      }
                      else {
                        Stella.addXmlReference(((StringWrapper)(attributes.value)).wrapperValue, ((StringWrapper)(attributes.rest.value)).wrapperValue, doctype.entityTable);
                      }
                    }
                  }
                }
              }
            }
          }
          if (definitionStream != null) {
            definitionStream.free();
          }

        } finally {
        }
        return (doctype);
      }
    }
    else {
      return (null);
    }
  }