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

  1. package com.ms.xml.parser;
  2.  
  3. import com.ms.xml.om.ElementImpl;
  4. import com.ms.xml.util.Atom;
  5. import com.ms.xml.util.Name;
  6. import com.ms.xml.util.StringInputStream;
  7. import com.ms.xml.util.XMLOutputStream;
  8. import java.io.IOException;
  9. import java.util.Enumeration;
  10.  
  11. public class Entity extends ElementImpl {
  12.    static String nameENTITY = "ENTITY";
  13.    static Atom nameXML = Atom.create("XML");
  14.    static Atom nameSpaceID = Atom.create("//XML/NAMESPACE");
  15.    Name name;
  16.    String url;
  17.    String pubid;
  18.    String text;
  19.    char cdata;
  20.    Name ndata;
  21.    int line;
  22.    int column;
  23.    boolean par;
  24.    boolean sys;
  25.    boolean parsed;
  26.    static Name nameNAME = Name.create("NAME", "XML");
  27.    static Name namePUBLICID = Name.create("PUBLICID", "XML");
  28.    static Name nameSYSTEMID = Name.create("SYSTEMID", "XML");
  29.    static Name nameINTENTITYDCL = Name.create("INTENTITYDCL", "XML");
  30.    static Name nameEXTENTITYDCL = Name.create("EXTENTITYDCL", "XML");
  31.    static Name nameNOTATION = Name.create("NOTATION", "XML");
  32.    static Name namePAR = Name.create("PAR", "XML");
  33.  
  34.    char getChar(int var1) {
  35.       return this.text == null ? this.cdata : this.text.charAt(var1);
  36.    }
  37.  
  38.    public Object getAttribute(Name var1) {
  39.       this.getAttributes();
  40.       return super.getAttribute(var1);
  41.    }
  42.  
  43.    Entity(Name var1, boolean var2) {
  44.       super(Name.create(nameENTITY, nameXML), 7);
  45.       this.name = var1;
  46.       this.par = var2;
  47.       this.parsed = false;
  48.    }
  49.  
  50.    Entity(Name var1, boolean var2, String var3) {
  51.       this(var1, var2);
  52.       this.setText(var3);
  53.       this.setPosition(0, 0);
  54.    }
  55.  
  56.    Entity(Name var1, boolean var2, int var3) {
  57.       this(var1, var2);
  58.       this.cdata = (char)var3;
  59.       super.setText(String.valueOf(this.cdata));
  60.       this.setPosition(0, 0);
  61.    }
  62.  
  63.    void setNDATA(Name var1) {
  64.       this.ndata = var1;
  65.    }
  66.  
  67.    EntityReader getReader(EntityReader var1) {
  68.       return new EntityReader(new StringInputStream(this.text), this.line, this.column, var1, this);
  69.    }
  70.  
  71.    public Enumeration getAttributes() {
  72.       if (super.getAttribute(nameNAME) == null) {
  73.          ((ElementImpl)this).setAttribute(nameNAME, this.name);
  74.          if (this.pubid != null) {
  75.             ((ElementImpl)this).setAttribute(namePUBLICID, this.pubid);
  76.          }
  77.  
  78.          if (this.url != null) {
  79.             ((ElementImpl)this).setAttribute(nameSYSTEMID, this.url);
  80.          }
  81.  
  82.          if (this.ndata != null) {
  83.             ((ElementImpl)this).setAttribute(nameNOTATION, this.ndata);
  84.          }
  85.       }
  86.  
  87.       return super.getAttributes();
  88.    }
  89.  
  90.    public void save(XMLOutputStream var1) throws IOException {
  91.       if (var1.savingDTD) {
  92.          var1.writeIndent();
  93.          this.saveEntity(var1);
  94.          var1.writeNewLine();
  95.       } else {
  96.          super.save(var1);
  97.       }
  98.    }
  99.  
  100.    void setURL(String var1) {
  101.       this.url = var1;
  102.       this.sys = true;
  103.    }
  104.  
  105.    String getURL() {
  106.       return this.url;
  107.    }
  108.  
  109.    void setPosition(int var1, int var2) {
  110.       this.line = var1;
  111.       this.column = var2;
  112.    }
  113.  
  114.    public Name getName() {
  115.       return this.name;
  116.    }
  117.  
  118.    public void saveEntity(XMLOutputStream var1) throws IOException {
  119.       var1.writeChars("<!ENTITY ");
  120.       if (this.par) {
  121.          var1.writeChars("% ");
  122.       }
  123.  
  124.       var1.writeQualifiedName(this.name, (Atom)null);
  125.       var1.writeChars(" ");
  126.       if (this.url != null) {
  127.          if (this.pubid == null) {
  128.             var1.writeChars("SYSTEM ");
  129.          } else {
  130.             var1.writeChars("PUBLIC ");
  131.             var1.writeQuotedString(this.pubid);
  132.             var1.write(32);
  133.          }
  134.  
  135.          var1.writeQuotedString(this.url.toString());
  136.          if (this.ndata != null) {
  137.             var1.writeChars(" NDATA ");
  138.             var1.writeQualifiedName(this.ndata, this.name.getNameSpace());
  139.          }
  140.       } else if (this.text != null) {
  141.          var1.writeQuotedString(this.text);
  142.       }
  143.  
  144.       var1.write(62);
  145.    }
  146.  
  147.    int getLength() {
  148.       if (this.cdata > 0) {
  149.          return -1;
  150.       } else {
  151.          return this.text == null ? 0 : this.text.length();
  152.       }
  153.    }
  154.  
  155.    public void setText(String var1) {
  156.       this.text = var1;
  157.       this.sys = false;
  158.    }
  159.  
  160.    public Name getTagName() {
  161.       return this.sys ? nameEXTENTITYDCL : nameINTENTITYDCL;
  162.    }
  163. }
  164.