1 /*
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.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
220 * @param index the requested index
221 * @return the <code>Element</code> corresponding to
222 * <code>index</code>
223 */
224 public Element getElement(int index) {
225 return elements.elementAt(index);
226 }
227
228 /**
229 * Defines an entity. If the <code>Entity</code> specified
230 * by <code>name</code>, <code>type</code>, and <code>data</code>
231 * exists, it is returned; otherwise a new <code>Entity</code>
232 * is created and is returned.
233 *
234 * @param name the name of the <code>Entity</code> as a <code>String</code>
235 * @param type the type of the <code>Entity</code>
236 * @param data the <code>Entity</code>'s data
237 * @return the <code>Entity</code> requested or a new <code>Entity</code>
238 * if not found
239 */
240 public Entity defineEntity(String name, int type, char data[]) {
241 Entity ent = entityHash.get(name);
242 if (ent == null) {
243 ent = new Entity(name, type, data);
244 entityHash.put(name, ent);
245 if (((type & GENERAL) != 0) && (data.length == 1)) {
246 switch (type & ~GENERAL) {
247 case CDATA:
248 case SDATA:
249 entityHash.put(Integer.valueOf(data[0]), ent);
250 break;
251 }
252 }
253 }
254 return ent;
255 }
256
257 /**
258 * Returns the <code>Element</code> which matches the
259 * specified parameters. If one doesn't exist, a new
260 * one is created and returned.
287 /**
288 * Defines attributes for an {@code Element}.
289 *
290 * @param name the name of the <code>Element</code>
291 * @param atts the <code>AttributeList</code> specifying the
292 * <code>Element</code>
293 */
294 public void defineAttributes(String name, AttributeList atts) {
295 Element e = getElement(name);
296 e.atts = atts;
297 }
298
299 /**
300 * Creates and returns a character <code>Entity</code>.
301 * @param name the entity's name
302 * @param type the entity's type
303 * @param ch the entity's value (character)
304 * @return the new character <code>Entity</code>
305 */
306 public Entity defEntity(String name, int type, int ch) {
307 char data[] = {(char)ch};
308 return defineEntity(name, type, data);
309 }
310
311 /**
312 * Creates and returns an <code>Entity</code>.
313 * @param name the entity's name
314 * @param type the entity's type
315 * @param str the entity's data section
316 * @return the new <code>Entity</code>
317 */
318 protected Entity defEntity(String name, int type, String str) {
319 int len = str.length();
320 char data[] = new char[len];
321 str.getChars(0, len, data, 0);
322 return defineEntity(name, type, data);
323 }
324
325 /**
326 * Creates and returns an <code>Element</code>.
327 * @param name the element's name
328 * @param type the element's type
329 * @param omitStart {@code true} if the element needs no starting tag
330 * @param omitEnd {@code true} if the element needs no closing tag
331 * @param content the element's content
332 * @param exclusions the elements that must be excluded from the content of the element
333 * @param inclusions the elements that can be included as the content of the element
334 * @param atts the attributes of the element
335 * @return the new <code>Element</code>
336 */
337 protected Element defElement(String name, int type,
338 boolean omitStart, boolean omitEnd, ContentModel content,
339 String[] exclusions, String[] inclusions, AttributeList atts) {
340 BitSet excl = null;
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
220 * @param index the requested index
221 * @return the <code>Element</code> corresponding to
222 * <code>index</code>
223 */
224 public Element getElement(int index) {
225 return elements.elementAt(index);
226 }
227
228 /**
229 * Defines an entity. If the <code>Entity</code> specified
230 * by <code>name</code>, <code>type</code>, and <code>data</code>
231 * exists, it is returned; otherwise a new <code>Entity</code>
232 * is created and is returned.
233 *
234 * @param name the name of the <code>Entity</code> as a <code>String</code>
235 * @param type the type of the <code>Entity</code>
236 * @param data the <code>Entity</code>'s data
237 * @return the <code>Entity</code> requested or a new <code>Entity</code>
238 * if not found
239 */
240 public Entity defineEntity(String name, int type, char[] data) {
241 Entity ent = entityHash.get(name);
242 if (ent == null) {
243 ent = new Entity(name, type, data);
244 entityHash.put(name, ent);
245 if (((type & GENERAL) != 0) && (data.length == 1)) {
246 switch (type & ~GENERAL) {
247 case CDATA:
248 case SDATA:
249 entityHash.put(Integer.valueOf(data[0]), ent);
250 break;
251 }
252 }
253 }
254 return ent;
255 }
256
257 /**
258 * Returns the <code>Element</code> which matches the
259 * specified parameters. If one doesn't exist, a new
260 * one is created and returned.
287 /**
288 * Defines attributes for an {@code Element}.
289 *
290 * @param name the name of the <code>Element</code>
291 * @param atts the <code>AttributeList</code> specifying the
292 * <code>Element</code>
293 */
294 public void defineAttributes(String name, AttributeList atts) {
295 Element e = getElement(name);
296 e.atts = atts;
297 }
298
299 /**
300 * Creates and returns a character <code>Entity</code>.
301 * @param name the entity's name
302 * @param type the entity's type
303 * @param ch the entity's value (character)
304 * @return the new character <code>Entity</code>
305 */
306 public Entity defEntity(String name, int type, int ch) {
307 char[] data = {(char)ch};
308 return defineEntity(name, type, data);
309 }
310
311 /**
312 * Creates and returns an <code>Entity</code>.
313 * @param name the entity's name
314 * @param type the entity's type
315 * @param str the entity's data section
316 * @return the new <code>Entity</code>
317 */
318 protected Entity defEntity(String name, int type, String str) {
319 int len = str.length();
320 char[] data = new char[len];
321 str.getChars(0, len, data, 0);
322 return defineEntity(name, type, data);
323 }
324
325 /**
326 * Creates and returns an <code>Element</code>.
327 * @param name the element's name
328 * @param type the element's type
329 * @param omitStart {@code true} if the element needs no starting tag
330 * @param omitEnd {@code true} if the element needs no closing tag
331 * @param content the element's content
332 * @param exclusions the elements that must be excluded from the content of the element
333 * @param inclusions the elements that can be included as the content of the element
334 * @param atts the attributes of the element
335 * @return the new <code>Element</code>
336 */
337 protected Element defElement(String name, int type,
338 boolean omitStart, boolean omitEnd, ContentModel content,
339 String[] exclusions, String[] inclusions, AttributeList atts) {
340 BitSet excl = null;
|