1 /* Entity.java -- Stores information, obtained by parsing SGML DTL
2 * <!ENTITY % .. > tag
3 Copyright (C) 2005 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package javax
.swing
.text
.html
.parser
;
42 import gnu
.javax
.swing
.text
.html
.parser
.support
.gnuStringIntMapper
;
44 import java
.io
.Serializable
;
47 * <p>Stores information, obtained by parsing SGML DTL
48 * <!ENTITY % .. > tag.</p>
50 * The entity defines some kind of macro that can be used elsewhere in
52 * When the macro is referred to by the name in the DTD, it is expanded into
54 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
56 public final class Entity
57 implements DTDConstants
, Serializable
60 * Package level mapper between type names and they string values.
62 final static gnuStringIntMapper mapper
=
63 new gnuStringIntMapper()
65 protected void create()
67 add("ANY", DTDConstants
.ANY
);
68 add("CDATA", DTDConstants
.CDATA
);
69 add("PUBLIC", DTDConstants
.PUBLIC
);
70 add("SDATA", DTDConstants
.SDATA
);
71 add("PI", DTDConstants
.PI
);
72 add("STARTTAG", DTDConstants
.STARTTAG
);
73 add("ENDTAG", DTDConstants
.ENDTAG
);
74 add("MS", DTDConstants
.MS
);
75 add("MD", DTDConstants
.MD
);
76 add("SYSTEM", DTDConstants
.SYSTEM
);
96 * String representation of the entity data.
101 * Create a new entity
102 * @param a_name the entity name
103 * @param a_type the entity type
104 * @param a_data the data replacing the entity reference
106 public Entity(String a_name
, int a_type
, char[] a_data
)
114 * Converts a given string to the corresponding entity type.
115 * @return a value, defined in DTDConstants (one of
116 * PUBLIC, CDATA, SDATA, PI, STARTTAG, ENDTAG, MS, MD, SYSTEM)
117 * or CDATA if the parameter is not a valid entity type.
119 public static int name2type(String an_entity
)
121 int r
= mapper
.get(an_entity
);
122 return (r
== 0) ? DTDConstants
.CDATA
: r
;
126 * Get the entity data.
128 public char[] getData()
134 * Returns true for general entities. Each general entity can be
135 * referenced as <code>&entity-name;</code>. Such entities are
136 * defined by the SGML DTD tag
137 * <code><!ENTITY <i>name</i> "<i>value</i>"></code>. The general
138 * entities can be used anywhere in the document.
140 public boolean isGeneral()
142 return (type
& DTDConstants
.GENERAL
) != 0;
146 * Get the entity name.
148 public String
getName()
154 * Returns true for parameter entities. Each parameter entity can be
155 * referenced as <code>&entity-name;</code>. Such entities are
156 * defined by the SGML DTD tag
157 * <code><!ENTITY % <i>name</i> "<i>value</i>"></code>. The parameter
158 * entities can be used only in SGML context.
160 public boolean isParameter()
162 return (type
& DTDConstants
.PARAMETER
) != 0;
166 * Returns a data as String
168 public String
getString()
171 sdata
= new String(data
);
177 * Get the entity type.
178 * @return the value of the {@link #type}.