54 55 /** 56 * The char array of data. 57 */ 58 public char data[]; 59 60 /** 61 * Creates an entity. 62 * @param name the name of the entity 63 * @param type the type of the entity 64 * @param data the char array of data 65 */ 66 public Entity(String name, int type, char data[]) { 67 this.name = name; 68 this.type = type; 69 this.data = data; 70 } 71 72 /** 73 * Gets the name of the entity. 74 * @return the name of the entity, as a <code>String</code> 75 */ 76 public String getName() { 77 return name; 78 } 79 80 /** 81 * Gets the type of the entity. 82 * @return the type of the entity 83 */ 84 public int getType() { 85 return type & 0xFFFF; 86 } 87 88 /** 89 * Returns <code>true</code> if it is a parameter entity. 90 * @return <code>true</code> if it is a parameter entity 91 */ 92 public boolean isParameter() { 93 return (type & PARAMETER) != 0; 94 } 95 96 /** 97 * Returns <code>true</code> if it is a general entity. 98 * @return <code>true</code> if it is a general entity 99 */ 100 public boolean isGeneral() { 101 return (type & GENERAL) != 0; 102 } 103 104 /** 105 * Returns the <code>data</code>. 106 * @return the <code>data</code> 107 */ 108 public char getData()[] { 109 return data; 110 } 111 112 /** 113 * Returns the data as a <code>String</code>. 114 * @return the data as a <code>String</code> 115 */ 116 public String getString() { 117 return new String(data, 0, data.length); 118 } 119 120 121 static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>(); 122 123 static { 124 entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC)); 125 entityTypes.put("CDATA", Integer.valueOf(CDATA)); 126 entityTypes.put("SDATA", Integer.valueOf(SDATA)); 127 entityTypes.put("PI", Integer.valueOf(PI)); 128 entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG)); 129 entityTypes.put("ENDTAG", Integer.valueOf(ENDTAG)); 130 entityTypes.put("MS", Integer.valueOf(MS)); 131 entityTypes.put("MD", Integer.valueOf(MD)); 132 entityTypes.put("SYSTEM", Integer.valueOf(SYSTEM)); 133 } 134 135 /** 136 * Converts <code>nm</code> string to the corresponding 137 * entity type. If the string does not have a corresponding 138 * entity type, returns the type corresponding to "CDATA". 139 * Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI", 140 * "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM". 141 * 142 * @param nm the string to be converted 143 * @return the corresponding entity type, or the type corresponding 144 * to "CDATA", if none exists 145 */ 146 public static int name2type(String nm) { 147 Integer i = entityTypes.get(nm); 148 return (i == null) ? CDATA : i.intValue(); 149 } 150 } | 54 55 /** 56 * The char array of data. 57 */ 58 public char data[]; 59 60 /** 61 * Creates an entity. 62 * @param name the name of the entity 63 * @param type the type of the entity 64 * @param data the char array of data 65 */ 66 public Entity(String name, int type, char data[]) { 67 this.name = name; 68 this.type = type; 69 this.data = data; 70 } 71 72 /** 73 * Gets the name of the entity. 74 * @return the name of the entity, as a {@code String} 75 */ 76 public String getName() { 77 return name; 78 } 79 80 /** 81 * Gets the type of the entity. 82 * @return the type of the entity 83 */ 84 public int getType() { 85 return type & 0xFFFF; 86 } 87 88 /** 89 * Returns {@code true} if it is a parameter entity. 90 * @return {@code true} if it is a parameter entity 91 */ 92 public boolean isParameter() { 93 return (type & PARAMETER) != 0; 94 } 95 96 /** 97 * Returns {@code true} if it is a general entity. 98 * @return {@code true} if it is a general entity 99 */ 100 public boolean isGeneral() { 101 return (type & GENERAL) != 0; 102 } 103 104 /** 105 * Returns the {@code data}. 106 * @return the {@code data} 107 */ 108 public char getData()[] { 109 return data; 110 } 111 112 /** 113 * Returns the data as a {@code String}. 114 * @return the data as a {@code String} 115 */ 116 public String getString() { 117 return new String(data, 0, data.length); 118 } 119 120 121 static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>(); 122 123 static { 124 entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC)); 125 entityTypes.put("CDATA", Integer.valueOf(CDATA)); 126 entityTypes.put("SDATA", Integer.valueOf(SDATA)); 127 entityTypes.put("PI", Integer.valueOf(PI)); 128 entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG)); 129 entityTypes.put("ENDTAG", Integer.valueOf(ENDTAG)); 130 entityTypes.put("MS", Integer.valueOf(MS)); 131 entityTypes.put("MD", Integer.valueOf(MD)); 132 entityTypes.put("SYSTEM", Integer.valueOf(SYSTEM)); 133 } 134 135 /** 136 * Converts {@code nm} string to the corresponding 137 * entity type. If the string does not have a corresponding 138 * entity type, returns the type corresponding to "CDATA". 139 * Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI", 140 * "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM". 141 * 142 * @param nm the string to be converted 143 * @return the corresponding entity type, or the type corresponding 144 * to "CDATA", if none exists 145 */ 146 public static int name2type(String nm) { 147 Integer i = entityTypes.get(nm); 148 return (i == null) ? CDATA : i.intValue(); 149 } 150 } |