1 /* |
1 /* |
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
100 return name; |
100 return name; |
101 } |
101 } |
102 |
102 |
103 /** |
103 /** |
104 * Gets an entity by name. |
104 * Gets an entity by name. |
|
105 * @param name the entity name |
105 * @return the <code>Entity</code> corresponding to the |
106 * @return the <code>Entity</code> corresponding to the |
106 * <code>name</code> <code>String</code> |
107 * <code>name</code> <code>String</code> |
107 */ |
108 */ |
108 public Entity getEntity(String name) { |
109 public Entity getEntity(String name) { |
109 return entityHash.get(name); |
110 return entityHash.get(name); |
110 } |
111 } |
111 |
112 |
112 /** |
113 /** |
113 * Gets a character entity. |
114 * Gets a character entity. |
|
115 * @param ch the character |
114 * @return the <code>Entity</code> corresponding to the |
116 * @return the <code>Entity</code> corresponding to the |
115 * <code>ch</code> character |
117 * <code>ch</code> character |
116 */ |
118 */ |
117 public Entity getEntity(int ch) { |
119 public Entity getEntity(int ch) { |
118 return entityHash.get(Integer.valueOf(ch)); |
120 return entityHash.get(Integer.valueOf(ch)); |
191 /** |
193 /** |
192 * Returns the <code>Element</code> which matches the |
194 * Returns the <code>Element</code> which matches the |
193 * specified parameters. If one doesn't exist, a new |
195 * specified parameters. If one doesn't exist, a new |
194 * one is created and returned. |
196 * one is created and returned. |
195 * |
197 * |
196 * @param name the name of the <code>Element</code> |
198 * @param name the name of the <code>Element</code> |
197 * @param type the type of the <code>Element</code> |
199 * @param type the type of the <code>Element</code> |
198 * @param omitStart <code>true</code> if start should be omitted |
200 * @param omitStart <code>true</code> if start should be omitted |
199 * @param omitEnd <code>true</code> if end should be omitted |
201 * @param omitEnd <code>true</code> if end should be omitted |
200 * @param content the <code>ContentModel</code> |
202 * @param content the <code>ContentModel</code> |
201 * @param atts the <code>AttributeList</code> specifying the |
203 * @param exclusions the set of elements that must not occur inside the element |
202 * <code>Element</code> |
204 * @param inclusions the set of elements that can occur inside the element |
|
205 * @param atts the <code>AttributeList</code> specifying the |
|
206 * <code>Element</code> |
203 * @return the <code>Element</code> specified |
207 * @return the <code>Element</code> specified |
204 */ |
208 */ |
205 public Element defineElement(String name, int type, |
209 public Element defineElement(String name, int type, |
206 boolean omitStart, boolean omitEnd, ContentModel content, |
210 boolean omitStart, boolean omitEnd, ContentModel content, |
207 BitSet exclusions, BitSet inclusions, AttributeList atts) { |
211 BitSet exclusions, BitSet inclusions, AttributeList atts) { |
229 } |
233 } |
230 |
234 |
231 /** |
235 /** |
232 * Creates and returns a character <code>Entity</code>. |
236 * Creates and returns a character <code>Entity</code>. |
233 * @param name the entity's name |
237 * @param name the entity's name |
|
238 * @param type the entity's type |
|
239 * @param ch the entity's value (character) |
234 * @return the new character <code>Entity</code> |
240 * @return the new character <code>Entity</code> |
235 */ |
241 */ |
236 public Entity defEntity(String name, int type, int ch) { |
242 public Entity defEntity(String name, int type, int ch) { |
237 char data[] = {(char)ch}; |
243 char data[] = {(char)ch}; |
238 return defineEntity(name, type, data); |
244 return defineEntity(name, type, data); |
239 } |
245 } |
240 |
246 |
241 /** |
247 /** |
242 * Creates and returns an <code>Entity</code>. |
248 * Creates and returns an <code>Entity</code>. |
243 * @param name the entity's name |
249 * @param name the entity's name |
|
250 * @param type the entity's type |
|
251 * @param str the entity's data section |
244 * @return the new <code>Entity</code> |
252 * @return the new <code>Entity</code> |
245 */ |
253 */ |
246 protected Entity defEntity(String name, int type, String str) { |
254 protected Entity defEntity(String name, int type, String str) { |
247 int len = str.length(); |
255 int len = str.length(); |
248 char data[] = new char[len]; |
256 char data[] = new char[len]; |
250 return defineEntity(name, type, data); |
258 return defineEntity(name, type, data); |
251 } |
259 } |
252 |
260 |
253 /** |
261 /** |
254 * Creates and returns an <code>Element</code>. |
262 * Creates and returns an <code>Element</code>. |
255 * @param name the element's name |
263 * @param name the element's name |
|
264 * @param type the element's type |
|
265 * @param omitStart {@code true} if the element needs no starting tag |
|
266 * @param omitEnd {@code true} if the element needs no closing tag |
|
267 * @param content the element's content |
|
268 * @param exclusions the elements that must be excluded from the content of the element |
|
269 * @param inclusions the elements that can be included as the content of the element |
|
270 * @param atts the attributes of the element |
256 * @return the new <code>Element</code> |
271 * @return the new <code>Element</code> |
257 */ |
272 */ |
258 protected Element defElement(String name, int type, |
273 protected Element defElement(String name, int type, |
259 boolean omitStart, boolean omitEnd, ContentModel content, |
274 boolean omitStart, boolean omitEnd, ContentModel content, |
260 String[] exclusions, String[] inclusions, AttributeList atts) { |
275 String[] exclusions, String[] inclusions, AttributeList atts) { |
278 } |
293 } |
279 return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts); |
294 return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts); |
280 } |
295 } |
281 |
296 |
282 /** |
297 /** |
283 * Creates and returns an <code>AttributeList</code>. |
298 * Creates and returns an <code>AttributeList</code> responding to a new attribute. |
284 * @param name the attribute list's name |
299 * @param name the attribute's name |
|
300 * @param type the attribute's type |
|
301 * @param modifier the attribute's modifier |
|
302 * @param value the default value of the attribute |
|
303 * @param values the allowed values for the attribute (multiple values could be separated by '|') |
|
304 * @param atts the previous attribute of the element; to be placed to {@code AttributeList.next}, |
|
305 * creating a linked list |
285 * @return the new <code>AttributeList</code> |
306 * @return the new <code>AttributeList</code> |
286 */ |
307 */ |
287 protected AttributeList defAttributeList(String name, int type, int modifier, String value, String values, AttributeList atts) { |
308 protected AttributeList defAttributeList(String name, int type, int modifier, |
|
309 String value, String values, AttributeList atts) { |
288 Vector<String> vals = null; |
310 Vector<String> vals = null; |
289 if (values != null) { |
311 if (values != null) { |
290 vals = new Vector<String>(); |
312 vals = new Vector<String>(); |
291 for (StringTokenizer s = new StringTokenizer(values, "|") ; s.hasMoreTokens() ;) { |
313 for (StringTokenizer s = new StringTokenizer(values, "|") ; s.hasMoreTokens() ;) { |
292 String str = s.nextToken(); |
314 String str = s.nextToken(); |
299 } |
321 } |
300 |
322 |
301 /** |
323 /** |
302 * Creates and returns a new content model. |
324 * Creates and returns a new content model. |
303 * @param type the type of the new content model |
325 * @param type the type of the new content model |
|
326 * @param obj the content of the content model |
|
327 * @param next pointer to the next content model |
304 * @return the new <code>ContentModel</code> |
328 * @return the new <code>ContentModel</code> |
305 */ |
329 */ |
306 protected ContentModel defContentModel(int type, Object obj, ContentModel next) { |
330 protected ContentModel defContentModel(int type, Object obj, ContentModel next) { |
307 return new ContentModel(type, obj, next); |
331 return new ContentModel(type, obj, next); |
308 } |
332 } |
330 * and returned. Any uppercase characters in the name |
354 * and returned. Any uppercase characters in the name |
331 * are converted to lowercase. |
355 * are converted to lowercase. |
332 * |
356 * |
333 * @param name the name of the DTD |
357 * @param name the name of the DTD |
334 * @return the DTD which corresponds to <code>name</code> |
358 * @return the DTD which corresponds to <code>name</code> |
|
359 * @throws IOException if an I/O error occurs |
335 */ |
360 */ |
336 public static DTD getDTD(String name) throws IOException { |
361 public static DTD getDTD(String name) throws IOException { |
337 name = name.toLowerCase(); |
362 name = name.toLowerCase(); |
338 DTD dtd = getDtdHash().get(name); |
363 DTD dtd = getDtdHash().get(name); |
339 if (dtd == null) |
364 if (dtd == null) |