b0VIM 5.4      l_9P
 /4  mark                                    spot.wutka.com                          ~mark/jprogs/dtdparser-1.0.1/source/com/wutka/dtd/DTDParser.java                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    3210#"! U                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tp       P            V   A                                           L   5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ad  1       P                 y  ^  Z  C  A  "    
        r  Y  S  R        w  s  D  >                        g  f  4  3                    y  x  +    
  
  
  
  
  }
  s
  C
  B
  
  
  	  	  	  	  c	   	  	  	                y  h  Z  3  %                  s  i  F  <  6  5                l  ^            z  0  "                      =  <              w  q  p  '              {  m                   {             if (token.value.equals("EMPTY"))         {         if (token.type == Scanner.IDENTIFIER)          Token token = scanner.get();     {         throws IOException     protected void parseContentSpec(Scanner scanner, DTDElement element)      }         parseContentSpec(scanner, element);          }             dtd.elements.put(element.name, element);             element = new DTDElement(name.value);         {         if (element == null)          DTDElement element = (DTDElement) dtd.elements.get(name.value);          Token name = expect(Scanner.IDENTIFIER);     {         throws IOException     protected void parseElement()      }         return token;          }             }                     " instead of "+ token.type.name+"("+token.value+")");                 throw new IOException("Expected "+expected.name+             {             else             }                     " instead of "+token.type.name);                 throw new IOException("Expected "+expected.name+             {             if (token.value == null)         {         if (token.type != expected)          Token token = scanner.get();     {         throws IOException     protected Token expect(TokenType expected)      }         }             token = scanner.get();         {         while (token.type != stopToken)          Token token = scanner.get();     {         throws IOException     protected void skipUntil(TokenType stopToken)      }         }             }                 skipUntil(Scanner.GT);             {             else                     }             // Don't need to do anything for this token         {         else if (token.type == Scanner.ENDCONDITIONAL)         }             }                     "Invalid token in conditional: "+token.value);                 throw new IOException(             {             else if (!token.value.equals("INCLUDE"))             }                 scanner.skipConditional();             {             if (token.value.equals("IGNORE"))              token = expect(Scanner.IDENTIFIER);         {         else if (token.type == Scanner.CONDITIONAL)         }             return;              skipUntil(Scanner.QUESGT);         {         if (token.type == Scanner.LTQUES) // Is <? xxx ?> even valid in a DTD?  I'll ignore it just in case it's there          Token token = scanner.get();     {         throws IOException     protected void parseTopLevelElement()      }         return dtd;          }             parseTopLevelElement();              if (token.type == Scanner.EOF) break;              token = scanner.peek();         {         for (;;)          Token token;     {         throws IOException     public DTD parse()      }         dtd = new DTD();         scanner = new Scanner(in, trace);     {     public DTDParser(Reader in, boolean trace)  */  *  (used for debugging the parser)  * @param trace True if the parser should print out tokens as it reads them  * @param in The input stream to read /** Creates a parser that will read from the specified Reader object      }         dtd = new DTD();         scanner = new Scanner(in, false);     {     public DTDParser(Reader in) /** Creates a parser that will read from the specified Reader object */      protected DTD dtd;     protected Scanner scanner; { public class DTDParser  */  * @version 1.0 06/28/2000  * @author Mark Wutka  * /** Parses a DTD file and returns a DTD object  import java.io.*; import java.util.*;  package com.wutka.dtd; ad         L       y  O  A  0  "            p  :  (        s  ]  %              t  j  i  M  G  F  #               o  n  :  9      
  
  
  
  ~
  X
  1
  '
  	  	  	  	  	  q	  R	  Q	  	  	        z  P  B  A                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  }     }         expect(Scanner.GT);         }             notation.externalID = pub;              }                 pub.system = token.value;                 token = scanner.get();             {             if (token.type == Scanner.STRING)             token = scanner.peek(); // a SystemLiteral // For <!NOTATION>, you can have PUBLIC PubidLiteral without              pub.system = null;             pub.pub = token.value;              token = expect(Scanner.STRING);             DTDPublic pub = new DTDPublic();         {         else if (token.value.equals("PUBLIC"))         }             notation.externalID = sys;             sys.system = token.value;              token = expect(Scanner.STRING);             DTDSystem sys = new DTDSystem();         {         if (token.value.equals("SYSTEM"))          token = expect(Scanner.IDENTIFIER);          dtd.notations.put(notation.name, notation);          notation.name = token.value;          Token token = expect(Scanner.IDENTIFIER);          DTDNotation notation = new DTDNotation();     {         throws java.io.IOException     protected void parseNotation()      }         expect(Scanner.GT);          }             throw new IOException("Invalid entity definition");         {         else         }             }                 }                     entity.ndata = token.value;                     token = expect(Scanner.IDENTIFIER);                     }                             "Invalid NData declaration");                         throw new IOException(                     {                     if (!token.value.equals("NDATA"))                 {                 if (token.type == Scanner.IDENTIFIER)                 token = scanner.peek();             {             if (entity.isParsed)              }                 throw new IOException("Invalid External ID specification");             {             else             }                 pub.system = token.value;                 token = expect(Scanner.STRING);                 pub.pub = token.value;                 token = expect(Scanner.STRING); ad  b       V             f  X  8  *            y  Z  L    	              |  v  u  C  (  "                  g  L  F  !             ~  I  ;  *    
  
  
  y
  x
  b
  \
  [
  9
  
  
  	  	  	  	  	  v	  D	  	  	  	          m  g  B  A    	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {             if (token.value.equals("EMPTY"))         {         if (token.type == Scanner.IDENTIFIER)          Token token = scanner.get();     {         throws IOException     protected void parseContentSpec(Scanner scanner, DTDElement element)      }         parseContentSpec(scanner, element);          }             dtd.elements.put(element.name, element);             element = new DTDElement(name.value);         {         if (element == null)          DTDElement element = (DTDElement) dtd.elements.get(name.value);          Token name = expect(Scanner.IDENTIFIER);     {         throws IOException     protected void parseElement()      }         return token;          }             }                     " instead of "+ token.type.name+"("+token.value+")");                 throw new IOException("Expected "+expected.name+             {             else             }                     " instead of "+token.type.name);                 throw new IOException("Expected "+expected.name+             {             if (token.value == null)         {         if (token.type != expected)          Token token = scanner.get();     {         throws IOException     protected Token expect(TokenType expected)      }         }             token = scanner.get();         {         while (token.type != stopToken)          Token token = scanner.get();     {         throws IOException     protected void skipUntil(TokenType stopToken)      }         }             }                 skipUntil(Scanner.GT);             {             else             }                 parseNotation();             {             else if (token.value.equals("NOTATION"))             }                 parseEntity();             {             else if (token.value.equals("ENTITY"))             }                 parseAttlist();             {             else if (token.value.equals("ATTLIST"))             }                 parseElement();             {             if (token.value.equals("ELEMENT"))              token = expect(Scanner.IDENTIFIER);          {         else if (token.type == Scanner.LTBANG) ad     V                R  D  :              i  W  .              v  h  @  2  (  "  !                h  g  F  E  4  *               W  E  "  
  
  
  
  w
  e
  d
  L
  >
  
  	  	  	  	  	  	  u	  &	   	                S  R  ,  +              U  K    
            |  I  ?  >                  {  z  i  _  9  8            [  I            }  k  7  !          ~  h  V  U                                            }                     }                         cs = new DTDSequence();                     {                     else                     }                         cs = new DTDChoice();                     {                     if (token.type == Scanner.PIPE)                 {                 if (cs == null)                  separator = token.type;                 }                         "Can't mix separators in a choice/sequence");                     throw new IOException(                 {                 if ((separator != null) && (separator != token.type))             {                 (token.type == Scanner.COMMA))             if ((token.type == Scanner.PIPE) ||              Token token = scanner.get();              DTDItem item = parseCP();         {         for (;;)          DTDContainer cs = null;          TokenType separator = null;     {         throws IOException     protected DTDContainer parseChoiceSequence()      }         element.content = choiceSeq;          }             choiceSeq.cardinal = DTDCardinal.NONE;         {         else         }             choiceSeq.cardinal = DTDCardinal.ONEMANY;         {         else if (token.type == Scanner.PLUS)         }             choiceSeq.cardinal = DTDCardinal.ZEROMANY;         {         else if (token.type == Scanner.ASTERISK)         }             choiceSeq.cardinal = DTDCardinal.OPTIONAL;         {         if (token.type == Scanner.QUES)          choiceSeq.cardinal = parseCardinality();          Token token = scanner.peek();          DTDContainer choiceSeq = parseChoiceSequence();     {         throws IOException     protected void parseChildren(DTDElement element)      }         }             }                     token.type.name);                 throw new IOException("Invalid token in Mixed content type: "+             {             else             }                 mixed.add(new DTDName(token.value));                  token = scanner.get();             {             else if (token.type == Scanner.PIPE)             }                 return;                  }                     mixed.cardinal = DTDCardinal.NONE;                 {                 else                 }                     mixed.cardinal = DTDCardinal.ZEROMANY;                     scanner.get();                 {                 if (token.type == Scanner.ASTERISK)                                  token = scanner.peek();             {             if (token.type == Scanner.RPAREN)              Token token = scanner.get();         {         for (;;)          element.content = mixed;          scanner.get();          mixed.add(new DTDPCData());          DTDMixed mixed = new DTDMixed();     {         throws IOException     protected void parseMixed(DTDElement element)      }         }             }                 parseChildren(element);             {             else if (token.type == Scanner.LPAREN)             }                 }                     parseChildren(element);                 {                 else                 }                     parseMixed(element);                 {                 if (token.value.equals("#PCDATA"))             {             if (token.type == Scanner.IDENTIFIER)              token = scanner.peek();         {         else if (token.type == Scanner.LPAREN)         }             }                 element.content = new DTDAny();             {             else if (token.value.equals("ANY"))             }                 element.content = new DTDEmpty(); ad     `                s  a  7  %            t  N  @  6  0  /                |  r  E  ;              p  N  D  C                  {  z  R  H  -    
  
  
  
  {
  q
  D
  :
  
  	  	  	  	  	  	  	  	  ~	  c	  ]	  +	  *	            R  H  G  '  &                O  4  .              l  k  =  3              n  `  V  '                  r  D  6    
        n  `  2  $              `  _                              throw new IOException(             {             else             }                 attr.decl = DTDDecl.IMPLIED;             {             else if (token.value.equals("#IMPLIED"))             }                 attr.decl = DTDDecl.REQUIRED;             {             else if (token.value.equals("#REQUIRED"))             }                 attr.defaultValue = token.value;                 token = scanner.get();                  attr.decl = DTDDecl.FIXED;             {             if (token.value.equals("#FIXED"))             scanner.get();         {         if (token.type == Scanner.IDENTIFIER)          token = scanner.peek();          }             attr.type = parseEnumeration();         {         else if (token.type == Scanner.LPAREN)         }             }                 attr.type = token.value;             {             else             }                 attr.type = parseNotationList();             {             if (token.value.equals("NOTATION"))         {         if (token.type == Scanner.IDENTIFIER)          token = scanner.get();          element.attributes.put(token.value, attr);          DTDAttribute attr = new DTDAttribute(token.value);          Token token = expect(Scanner.IDENTIFIER);     {         throws IOException     protected void parseAttdef(Scanner scanner, DTDElement element)      }         }             token = scanner.peek();             parseAttdef(scanner, element);         {         while (token.type != Scanner.GT)          token = scanner.peek();          }             dtd.elements.put(token.value, element);             element = new DTDElement(token.value);         {         if (element == null)          DTDElement element = (DTDElement) dtd.elements.get(token.value);          Token token = expect(Scanner.IDENTIFIER);     {         throws IOException     protected void parseAttlist()      }         }             return DTDCardinal.NONE;         {         else         }             return DTDCardinal.ONEMANY;             scanner.get();         {         else if (token.type == Scanner.PLUS)         }             return DTDCardinal.ZEROMANY;             scanner.get();         {         else if (token.type == Scanner.ASTERISK)         }             return DTDCardinal.OPTIONAL;             scanner.get();         {         if (token.type == Scanner.QUES)          Token token = scanner.peek();                {         throws IOException     protected DTDCardinal parseCardinality()      }         return item;          item.cardinal = parseCardinality();          }                 token.type.name);             throw new IOException("Found invalid token in sequence: "+         {         else         }             item = parseChoiceSequence();         {         else if (token.type == Scanner.LPAREN)         }             item = new DTDName(token.value);         {         if (token.type == Scanner.IDENTIFIER)          DTDItem item = null;          Token token = scanner.get();     {         throws IOException     protected DTDItem parseCP()      }         }             }                     token.type.name);                 throw new IOException("Found invalid token in sequence: "+             {             else             }                 return cs;                 cs.add(item);                 }                     cs = new DTDChoice();                 {                 if (cs == null)             {             else if (token.type == Scanner.RPAREN)             }                 cs.add(item); ad     :                W  M  2                z  @  ?  .  $          u  O  A  @                w  i  8  *          |  v  u  E  *  $  
  
  
  
  
  
  q
  c
  
  	  	  	  	  	  	  	  h	  Z	  ;	  	  		        \  N  #                      ^  T  7            w  v  1  0    
          x  w  W  V                {  u  P  O  %            ~  p  ?            z  l  ;  :  9                     DTDPublic pub = new DTDPublic();             {             else if (token.value.equals("PUBLIC"))             }                 entity.externalID = sys;                 sys.system = token.value;                  token = expect(Scanner.STRING);                 DTDSystem sys = new DTDSystem();             {             if (token.value.equals("SYSTEM"))         {         else if (token.type == Scanner.IDENTIFIER)         }             entity.value = token.value;         {         if (token.type == Scanner.STRING)          Token token = scanner.get();     {         throws IOException     protected void parseEntityDef(DTDEntity entity)      }         }             scanner.addEntity(entity.name, entity.value);         {         if (entity.isParsed && (entity.value != null))          parseEntityDef(entity);          entity.isParsed = isParsed;          }             dtd.entities.put(entity.name, entity);             entity = new DTDEntity(name.value);         {         if (entity == null)          DTDEntity entity = (DTDEntity) dtd.entities.get(name.value);          }             throw new IOException("Invalid entity declaration");         {         else if (name.type != Scanner.IDENTIFIER)         }             name = expect(Scanner.IDENTIFIER);             isParsed = true;         {         if (name.type == Scanner.PERCENT)          Token name = scanner.get();          boolean isParsed = false;     {         throws IOException     protected void parseEntity()      }         }             scanner.get(); // eat the pipe             }                     token.type.name);                 throw new IOException("Invalid token in enumeration: "+             {             else if (token.type != Scanner.PIPE)             }                 return enumeration;                 scanner.get();             {             if (token.type == Scanner.RPAREN)              token = scanner.peek();              enumeration.add(token.value);              }                     token.type.name);                 throw new IOException("Invalid token in enumeration: "+             {             if (token.type != Scanner.IDENTIFIER)              Token token = scanner.get();         {         for (;;)          DTDEnumeration enumeration = new DTDEnumeration();     {         throws IOException     protected DTDEnumeration parseEnumeration()      }         }             scanner.get(); // eat the pipe             }                     token.type.name);                 throw new IOException("Invalid token in notation: "+             {             else if (token.type != Scanner.PIPE)             }                 return notation;                 scanner.get();             {             if (token.type == Scanner.RPAREN)              token = scanner.peek();              notation.add(token.value);              }                     token.type.name);                 throw new IOException("Invalid token in notation: "+             {             if (token.type != Scanner.IDENTIFIER)              Token token = scanner.get();         {         for (;;)          DTDNotationList notation = new DTDNotationList();     {         throws IOException     protected DTDNotationList parseNotationList()      }         }             attr.defaultValue = token.value;             attr.decl = DTDDecl.VALUE;             scanner.get();         {         else if (token.type == Scanner.STRING)         }             }                     token.value);                     "Invalid token in attribute declaration: "+ 