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

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