Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/hexidec/ekit/component/parser/Entity.java


1   /*
2    * @(#)Entity.java  1.8 01/12/03
3    *
4    * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
5    * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6    */
7   
8   package com.hexidec.ekit.component.parser;
9   
10  import java.util.Hashtable;
11  import java.io.IOException;
12  import java.io.InputStream;
13  import java.io.InputStreamReader;
14  import java.io.Reader;
15  import java.io.CharArrayReader;
16  import java.net.URL;
17  
18  /**
19   * An entity is described in a DTD using the ENTITY construct.
20   * It defines the type and value of the the entity.
21   *
22   * @see DTD
23   * @version 1.8, 12/03/01
24   * @author Arthur van Hoff
25   */
26  public final
27  class Entity implements DTDConstants {
28      public String name;
29      public int type;
30      public char data[];
31  
32      /**
33       * Creates an entity.
34       * @param name the name of the entity
35       * @param type the type of the entity
36       * @param data the char array of data
37       */
38      public Entity(String name, int type, char data[]) {
39    this.name = name;
40    this.type = type;
41    this.data = data;
42      }
43  
44      /**
45       * Gets the name of the entity.
46       * @return the name of the entity, as a <code>String</code>
47       */
48      public String getName() {
49    return name;
50      }
51  
52      /**
53       * Gets the type of the entity.
54       * @return the type of the entity
55       */
56      public int getType() {
57    return type & 0xFFFF;
58      }
59  
60      /**
61       * Returns <code>true</code> if it is a parameter entity.
62       * @return <code>true</code> if it is a parameter entity
63       */
64      public boolean isParameter() {
65    return (type & PARAMETER) != 0;
66      }
67  
68      /**
69       * Returns <code>true</code> if it is a general entity.
70       * @return <code>true</code> if it is a general entity
71       */
72      public boolean isGeneral() {
73    return (type & GENERAL) != 0;
74      }
75  
76      /**
77       * Returns the <code>data</code>.
78       * @return the <code>data</code>
79       */
80      public char getData()[] {
81    return data;
82      }
83  
84      /**
85       * Returns the data as a <code>String</code>.
86       * @return the data as a <code>String</code>
87       */
88      public String getString() {
89    return new String(data, 0, data.length);
90      }
91  
92  
93      static Hashtable entityTypes = new Hashtable();
94  
95      static {
96    entityTypes.put("PUBLIC", new Integer(PUBLIC));
97    entityTypes.put("CDATA", new Integer(CDATA));
98    entityTypes.put("SDATA", new Integer(SDATA));
99    entityTypes.put("PI", new Integer(PI));
100   entityTypes.put("STARTTAG", new Integer(STARTTAG));
101   entityTypes.put("ENDTAG", new Integer(ENDTAG));
102   entityTypes.put("MS", new Integer(MS));
103   entityTypes.put("MD", new Integer(MD));
104   entityTypes.put("SYSTEM", new Integer(SYSTEM));
105     }
106 
107     /**
108      * Converts <code>nm</code> string to the corresponding
109      * entity type.  If the string does not have a corresponding
110      * entity type, returns the type corresponding to "CDATA".
111      * Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI",
112      * "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM".
113      *
114      * @param nm the string to be converted
115      * @return the corresponding entity type, or the type corresponding
116      *   to "CDATA", if none exists
117      */
118     public static int name2type(String nm) {
119   Integer i = (Integer)entityTypes.get(nm);
120   return (i == null) ? CDATA : i.intValue();
121     }
122 }
123