home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / JAVA / MSJAVX86.EXE / xmldso.cab / com / ms / xml / parser / DTD.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  5.3 KB  |  262 lines

  1. package com.ms.xml.parser;
  2.  
  3. import com.ms.xml.om.Element;
  4. import com.ms.xml.om.ElementImpl;
  5. import com.ms.xml.util.Atom;
  6. import com.ms.xml.util.EnumWrapper;
  7. import com.ms.xml.util.Name;
  8. import com.ms.xml.util.XMLOutputStream;
  9. import java.io.IOException;
  10. import java.util.Enumeration;
  11. import java.util.Hashtable;
  12.  
  13. public class DTD {
  14.    static Hashtable builtin = new Hashtable();
  15.    Hashtable entities;
  16.    Hashtable elementdecls;
  17.    Hashtable notations;
  18.    Hashtable shortNameSpaces;
  19.    Hashtable longNameSpaces;
  20.    Hashtable loadedNameSpaces;
  21.    transient Hashtable ids;
  22.    transient IDCheck idCheck;
  23.    Name docType;
  24.    Element schema = null;
  25.    static Atom nameXML = Atom.create("XML");
  26.  
  27.    public final void addLoadedNameSpace(Atom var1) {
  28.       if (this.loadedNameSpaces == null) {
  29.          this.loadedNameSpaces = new Hashtable();
  30.       }
  31.  
  32.       this.loadedNameSpaces.put(var1, var1);
  33.    }
  34.  
  35.    public final Atom findShortNameSpace(Atom var1) {
  36.       return this.shortNameSpaces == null ? null : (Atom)this.shortNameSpaces.get(var1);
  37.    }
  38.  
  39.    public static boolean isReservedNameSpace(Atom var0) {
  40.       return var0 == nameXML;
  41.    }
  42.  
  43.    final Element findID(Name var1) {
  44.       return this.ids == null ? null : (Element)this.ids.get(var1);
  45.    }
  46.  
  47.    final void addIDCheck(Name var1, int var2, int var3, Object var4) {
  48.       this.idCheck = new IDCheck(this.idCheck, var1, var2, var3, var4);
  49.    }
  50.  
  51.    public final Name getDocType() {
  52.       return this.docType;
  53.    }
  54.  
  55.    public final Enumeration entityDeclarations() {
  56.       return (Enumeration)(this.entities == null ? EnumWrapper.emptyEnumeration : this.entities.elements());
  57.    }
  58.  
  59.    public final Enumeration notationDeclarations() {
  60.       return (Enumeration)(this.notations == null ? EnumWrapper.emptyEnumeration : this.notations.elements());
  61.    }
  62.  
  63.    final void addEntity(Entity var1) {
  64.       if (this.entities == null) {
  65.          this.entities = new Hashtable();
  66.       }
  67.  
  68.       this.entities.put(var1.name, var1);
  69.    }
  70.  
  71.    final void addElementDecl(ElementDecl var1) {
  72.       if (this.elementdecls == null) {
  73.          this.elementdecls = new Hashtable();
  74.       }
  75.  
  76.       this.elementdecls.put(var1.name, var1);
  77.    }
  78.  
  79.    final void addNotation(Notation var1) {
  80.       if (this.notations == null) {
  81.          this.notations = new Hashtable();
  82.       }
  83.  
  84.       this.notations.put(var1.name, var1);
  85.    }
  86.  
  87.    public final void addNameSpace(Atom var1, Atom var2) {
  88.       if (this.shortNameSpaces == null) {
  89.          this.shortNameSpaces = new Hashtable();
  90.          this.longNameSpaces = new Hashtable();
  91.       }
  92.  
  93.       this.shortNameSpaces.put(var2, var1);
  94.       this.longNameSpaces.put(var1, var2);
  95.    }
  96.  
  97.    public final Atom findLongNameSpace(Atom var1) {
  98.       return this.longNameSpaces == null ? null : (Atom)this.longNameSpaces.get(var1);
  99.    }
  100.  
  101.    public final Atom findLoadedNameSpace(Atom var1) {
  102.       if (var1 == null) {
  103.          return null;
  104.       } else {
  105.          return this.loadedNameSpaces == null ? null : (Atom)this.loadedNameSpaces.get(var1);
  106.       }
  107.    }
  108.  
  109.    static {
  110.       String var0 = "apos";
  111.       builtin.put("apos", new Entity(Name.create(var0), false, 39));
  112.       var0 = "quot";
  113.       builtin.put(var0, new Entity(Name.create(var0), false, 34));
  114.       var0 = "amp";
  115.       builtin.put(var0, new Entity(Name.create(var0), false, 38));
  116.       var0 = "lt";
  117.       builtin.put(var0, new Entity(Name.create(var0), false, 60));
  118.       var0 = "gt";
  119.       builtin.put(var0, new Entity(Name.create(var0), false, 62));
  120.       var0 = "nbsp";
  121.       builtin.put(var0, new Entity(Name.create(var0), false, 160));
  122.    }
  123.  
  124.    public final void save(XMLOutputStream var1) throws IOException {
  125.       if (this.notations != null) {
  126.          Enumeration var2 = this.notations.elements();
  127.  
  128.          while(var2.hasMoreElements()) {
  129.             Notation var3 = (Notation)var2.nextElement();
  130.             var1.writeIndent();
  131.             var3.save(var1);
  132.          }
  133.       }
  134.  
  135.       if (this.entities != null) {
  136.          Enumeration var4 = this.entities.elements();
  137.  
  138.          while(var4.hasMoreElements()) {
  139.             Entity var6 = (Entity)var4.nextElement();
  140.             var1.writeIndent();
  141.             var6.save(var1);
  142.          }
  143.       }
  144.  
  145.       if (this.elementdecls != null) {
  146.          Enumeration var5 = this.elementdecls.elements();
  147.  
  148.          while(var5.hasMoreElements()) {
  149.             ElementDecl var7 = (ElementDecl)var5.nextElement();
  150.             var1.writeIndent();
  151.             var7.save(var1);
  152.          }
  153.       }
  154.  
  155.    }
  156.  
  157.    public final Enumeration elementDeclarations() {
  158.       return (Enumeration)(this.elementdecls == null ? EnumWrapper.emptyEnumeration : this.elementdecls.elements());
  159.    }
  160.  
  161.    final void addID(Name var1, Element var2) {
  162.       if (this.ids == null) {
  163.          this.ids = new Hashtable();
  164.       }
  165.  
  166.       this.ids.put(var1, var2);
  167.    }
  168.  
  169.    final void checkIDs() throws ParseException {
  170.       while(this.idCheck != null) {
  171.          if (this.findID(this.idCheck.name) == null) {
  172.             throw new ParseException("Couldn't find element with ID '" + this.idCheck.name.toString() + "'", this.idCheck.line, this.idCheck.col, this.idCheck.owner);
  173.          }
  174.  
  175.          this.idCheck = this.idCheck.next;
  176.       }
  177.  
  178.    }
  179.  
  180.    public final void clear() {
  181.       if (this.ids != null) {
  182.          this.ids.clear();
  183.       }
  184.  
  185.       this.idCheck = null;
  186.    }
  187.  
  188.    public final ElementDecl findElementDecl(Name var1) {
  189.       return this.elementdecls == null ? null : (ElementDecl)this.elementdecls.get(var1);
  190.    }
  191.  
  192.    public final Entity findEntity(Name var1) {
  193.       Object var2 = null;
  194.       if (this.entities != null) {
  195.          var2 = (Entity)this.entities.get(var1);
  196.       }
  197.  
  198.       if (var2 == null) {
  199.          var2 = builtin.get(var1.getName());
  200.       }
  201.  
  202.       return var2 != null ? (Entity)var2 : null;
  203.    }
  204.  
  205.    public final Element getSchema() {
  206.       if (this.schema == null) {
  207.          this.schema = new ElementImpl(Name.create("SCHEMA", "XML"), 0);
  208.          if (this.docType != null) {
  209.             this.schema.setAttribute(Name.create("ID", "XML"), this.docType);
  210.          }
  211.  
  212.          if (this.longNameSpaces != null) {
  213.             Enumeration var1 = this.longNameSpaces.keys();
  214.  
  215.             while(var1.hasMoreElements()) {
  216.                Atom var2 = (Atom)var1.nextElement();
  217.                ElementImpl var3 = new ElementImpl(Name.create("NAMESPACE", "XML"), 5);
  218.                var3.setAttribute(Name.create("HREF", "XML"), this.longNameSpaces.get(var2));
  219.                var3.setAttribute(Name.create("AS", "XML"), var2);
  220.                this.schema.addChild(var3, (Element)null);
  221.             }
  222.          }
  223.  
  224.          Enumeration var4 = this.notationDeclarations();
  225.  
  226.          while(var4.hasMoreElements()) {
  227.             Element var7 = (Element)var4.nextElement();
  228.             Element var10 = var7.toSchema();
  229.             if (var10 != null) {
  230.                this.schema.addChild(var10, (Element)null);
  231.             }
  232.          }
  233.  
  234.          var4 = this.entityDeclarations();
  235.  
  236.          while(var4.hasMoreElements()) {
  237.             Element var8 = (Element)var4.nextElement();
  238.             Element var11 = var8.toSchema();
  239.             if (var11 != null) {
  240.                this.schema.addChild(var11, (Element)null);
  241.             }
  242.          }
  243.  
  244.          var4 = this.elementDeclarations();
  245.  
  246.          while(var4.hasMoreElements()) {
  247.             Element var9 = (Element)var4.nextElement();
  248.             Element var12 = var9.toSchema();
  249.             if (var12 != null) {
  250.                this.schema.addChild(var12, (Element)null);
  251.             }
  252.          }
  253.       }
  254.  
  255.       return this.schema;
  256.    }
  257.  
  258.    public final Notation findNotation(Name var1) {
  259.       return this.notations == null ? null : (Notation)this.notations.get(var1);
  260.    }
  261. }
  262.