KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > html > parser > Entity


1 /*
2  * @(#)Entity.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.text.html.parser;
9
10 import java.util.Hashtable JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.io.InputStreamReader JavaDoc;
14 import java.io.Reader JavaDoc;
15 import java.io.CharArrayReader JavaDoc;
16 import java.net.URL JavaDoc;
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.10, 12/19/03
24  * @author Arthur van Hoff
25  */

26 public final
27 class Entity implements DTDConstants JavaDoc {
28     public String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getString() {
89     return new String JavaDoc(data, 0, data.length);
90     }
91
92
93     static Hashtable JavaDoc entityTypes = new Hashtable JavaDoc();
94
95     static {
96     entityTypes.put("PUBLIC", new Integer JavaDoc(PUBLIC));
97     entityTypes.put("CDATA", new Integer JavaDoc(CDATA));
98     entityTypes.put("SDATA", new Integer JavaDoc(SDATA));
99     entityTypes.put("PI", new Integer JavaDoc(PI));
100     entityTypes.put("STARTTAG", new Integer JavaDoc(STARTTAG));
101     entityTypes.put("ENDTAG", new Integer JavaDoc(ENDTAG));
102     entityTypes.put("MS", new Integer JavaDoc(MS));
103     entityTypes.put("MD", new Integer JavaDoc(MD));
104     entityTypes.put("SYSTEM", new Integer JavaDoc(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 JavaDoc nm) {
119     Integer JavaDoc i = (Integer JavaDoc)entityTypes.get(nm);
120     return (i == null) ? CDATA : i.intValue();
121     }
122 }
123
124
Popular Tags