Frames | No Frames |
1: /* Entity.java -- Stores information, obtained by parsing SGML DTL 2: * <!ENTITY % .. > tag 3: Copyright (C) 2005 Free Software Foundation, Inc. 4: 5: This file is part of GNU Classpath. 6: 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) 10: any later version. 11: 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. 16: 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 20: 02110-1301 USA. 21: 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 25: combination. 26: 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. */ 38: 39: 40: package javax.swing.text.html.parser; 41: 42: import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper; 43: 44: /** 45: * <p>Stores information, obtained by parsing SGML DTL 46: * <!ENTITY % .. > tag.</p> 47: * <p> 48: * The entity defines some kind of macro that can be used elsewhere in 49: * the document. 50: * When the macro is referred to by the name in the DTD, it is expanded into 51: * a string 52: * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 53: */ 54: public final class Entity 55: implements DTDConstants 56: { 57: /** 58: * Package level mapper between type names and they string values. 59: */ 60: final static gnuStringIntMapper mapper = 61: new gnuStringIntMapper() 62: { 63: protected void create() 64: { 65: add("ANY", DTDConstants.ANY); 66: add("CDATA", DTDConstants.CDATA); 67: add("PUBLIC", DTDConstants.PUBLIC); 68: add("SDATA", DTDConstants.SDATA); 69: add("PI", DTDConstants.PI); 70: add("STARTTAG", DTDConstants.STARTTAG); 71: add("ENDTAG", DTDConstants.ENDTAG); 72: add("MS", DTDConstants.MS); 73: add("MD", DTDConstants.MD); 74: add("SYSTEM", DTDConstants.SYSTEM); 75: } 76: }; 77: 78: /** 79: * The entity name. 80: */ 81: public String name; 82: 83: /** 84: * The entity data 85: */ 86: public char[] data; 87: 88: /** 89: * The entity type. 90: */ 91: public int type; 92: 93: /** 94: * String representation of the entity data. 95: */ 96: private String sdata; 97: 98: /** 99: * Create a new entity 100: * @param a_name the entity name 101: * @param a_type the entity type 102: * @param a_data the data replacing the entity reference 103: */ 104: public Entity(String a_name, int a_type, char[] a_data) 105: { 106: name = a_name; 107: type = a_type; 108: data = a_data; 109: } 110: 111: /** 112: * Converts a given string to the corresponding entity type. 113: * @return a value, defined in DTDConstants (one of 114: * PUBLIC, CDATA, SDATA, PI, STARTTAG, ENDTAG, MS, MD, SYSTEM) 115: * or CDATA if the parameter is not a valid entity type. 116: */ 117: public static int name2type(String an_entity) 118: { 119: int r = mapper.get(an_entity); 120: return (r == 0) ? DTDConstants.CDATA : r; 121: } 122: 123: /** 124: * Get the entity data. 125: */ 126: public char[] getData() 127: { 128: return data; 129: } 130: 131: /** 132: * Returns true for general entities. Each general entity can be 133: * referenced as <code>&entity-name;</code>. Such entities are 134: * defined by the SGML DTD tag 135: * <code><!ENTITY <i>name</i> "<i>value</i>"></code>. The general 136: * entities can be used anywhere in the document. 137: */ 138: public boolean isGeneral() 139: { 140: return (type & DTDConstants.GENERAL) != 0; 141: } 142: 143: /** 144: * Get the entity name. 145: */ 146: public String getName() 147: { 148: return name; 149: } 150: 151: /** 152: * Returns true for parameter entities. Each parameter entity can be 153: * referenced as <code>&entity-name;</code>. Such entities are 154: * defined by the SGML DTD tag 155: * <code><!ENTITY % <i>name</i> "<i>value</i>"></code>. The parameter 156: * entities can be used only in SGML context. 157: */ 158: public boolean isParameter() 159: { 160: return (type & DTDConstants.PARAMETER) != 0; 161: } 162: 163: /** 164: * Returns a data as String 165: */ 166: public String getString() 167: { 168: if (sdata == null) 169: sdata = new String(data); 170: 171: return sdata; 172: } 173: 174: /** 175: * Get the entity type. 176: * @return the value of the {@link #type}. 177: */ 178: public int getType() 179: { 180: return type; 181: } 182: 183: }