home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML in Action / Dynamicke-HTML-v-akci-covermount.bin / XML / PARSER / XMLINST.EXE / classes / com / ms / xml / parser / Notation.java < prev    next >
Encoding:
Java Source  |  1997-11-03  |  2.5 KB  |  111 lines

  1. /*
  2.  * @(#)Notation.java 1.0 6/3/97
  3.  * 
  4.  * Copyright (c) 1997 Microsoft, Corp. All Rights Reserved.
  5.  * 
  6.  */
  7.  
  8. package com.ms.xml.parser;
  9.  
  10. import com.ms.xml.om.ElementImpl;
  11. import com.ms.xml.om.Element;
  12.  
  13. import com.ms.xml.util.Name;
  14. import com.ms.xml.util.XMLOutputStream;
  15. import java.io.*;
  16.  
  17. /**
  18.  * This class implements an entity object representing an XML notation.
  19.  *
  20.  * @version 1.0, 6/3/97
  21.  */
  22. public class Notation extends ElementImpl
  23. {
  24.     Notation(Name name)
  25.     {
  26.         super(name,Element.NOTATION);
  27.         this.name = name;
  28.     }
  29.  
  30.     void setURL(String url)
  31.     {
  32.         this.url = url;
  33.     }
  34.  
  35.     public Element toSchema()
  36.     {
  37.         if( schema == null )
  38.         {
  39.             Element notationElement = new ElementImpl( nameNOTATION, Element.ELEMENT );
  40.             notationElement.setAttribute( nameNAME, name.toString() );
  41.             if( url != null )
  42.             {
  43.                 notationElement.setAttribute( nameSYSTEMID, url );
  44.             }
  45.             if( pubid != null )
  46.             {
  47.                 notationElement.setAttribute( namePUBLICID, pubid );
  48.             }
  49.             schema = notationElement;
  50.         }         
  51.  
  52.         return schema;
  53.     }
  54.    
  55.     /**
  56.     * Saves the notation to the given output stream with indenting and new lines.
  57.     * @param o The output stream.
  58.     * @exception IOException if there is a problem writing to the output stream. 
  59.     */
  60.     public void save(XMLOutputStream o) throws IOException
  61.     {
  62.         o.writeIndent();
  63.         o.writeChars("<!NOTATION ");
  64.         o.writeQualifiedName(name, null);
  65.         o.writeChars(" ");
  66.  
  67.         if (type == Parser.PUBLIC) {
  68.             o.writeChars("PUBLIC ");
  69.             o.writeQuotedString(pubid);
  70.             o.write(' ');
  71.             o.writeQuotedString(url);
  72.         } else {
  73.             o.writeChars("SYSTEM ");
  74.             o.writeQuotedString(url);
  75.         }
  76.         o.write('>');
  77.         o.writeNewLine();
  78.     }
  79.  
  80.     /**
  81.      * Name of Notation
  82.      */
  83.     Name name;
  84.  
  85.     /**
  86.      * Url 
  87.      */
  88.     String url;
  89.  
  90.     /**
  91.      * pubid
  92.      */
  93.     String pubid; 
  94.  
  95.     /**
  96.      * Type of notation (Parser.SYSTEM or Parser.PUBLIC)
  97.      */
  98.     int type;
  99.  
  100.     /**
  101.      * Schema representation
  102.      */
  103.     Element schema = null;
  104.  
  105.     static Name nameNAME         = Name.create("NAME");
  106.     static Name nameSYSTEMID     = Name.create("SYSTEMID");
  107.     static Name namePUBLICID     = Name.create("PUBLICID");
  108.     static Name nameNOTATION     = Name.create("NOTATION");
  109.  
  110. }
  111.