Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 854806427da0d1cb18391b604a08bb220c417065 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.html.core.contentmodel.chtml;



import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;

import org.eclipse.wst.common.contentmodel.CMNode;

/**
 * Factory for element declarations.
 */
final class ElementCollection extends DeclCollection implements org.eclipse.wst.html.core.HTML40Namespace.ElementName {


	// Element IDs
	private static class Ids {
		public static final int ID_A = 0;
		public static final int ID_ADDRESS = 1;
		public static final int ID_BASE = 2;
		public static final int ID_BLOCKQUOTE = 3;
		public static final int ID_BODY = 4;
		public static final int ID_BR = 5;
		public static final int ID_CENTER = 6;
		public static final int ID_DD = 7;
		public static final int ID_DIR = 8;
		public static final int ID_DIV = 9;
		public static final int ID_DL = 10;
		public static final int ID_DT = 11;
		public static final int ID_FORM = 12;
		public static final int ID_H1 = 13;
		public static final int ID_H2 = 14;
		public static final int ID_H3 = 15;
		public static final int ID_H4 = 16;
		public static final int ID_H5 = 17;
		public static final int ID_H6 = 18;
		public static final int ID_HEAD = 19;
		public static final int ID_HR = 20;
		public static final int ID_HTML = 21;
		public static final int ID_IMG = 22;
		public static final int ID_INPUT = 23;
		public static final int ID_LI = 24;
		public static final int ID_MENU = 25;
		public static final int ID_META = 26;
		public static final int ID_OL = 27;
		public static final int ID_OPTION = 28;
		public static final int ID_P = 29;
		public static final int ID_PRE = 30;
		public static final int ID_SELECT = 31;
		public static final int ID_TEXTAREA = 32;
		public static final int ID_TITLE = 33;
		public static final int ID_UL = 34;
		public static final int ID_SSI_CONFIG = 35;
		public static final int ID_SSI_ECHO = 36;
		public static final int ID_SSI_EXEC = 37;
		public static final int ID_SSI_FSIZE = 38;
		public static final int ID_SSI_FLASTMOD = 39;
		public static final int ID_SSI_INCLUDE = 40;
		public static final int ID_SSI_PRINTENV = 41;
		public static final int ID_SSI_SET = 42;

		public static int getNumOfIds() {
			if (numofids != -1)
				return numofids;

			// NOTE: If the reflection is too slow, this method should
			// just return the literal value, like 105.
			// -- 5/25/2001
			Class clazz = Ids.class;
			Field[] fields = clazz.getFields();
			numofids = 0;
			for (int i = 0; i < fields.length; i++) {
				String name = fields[i].getName();
				if (name.startsWith("ID_"))//$NON-NLS-1$
					numofids++;
			}
			return numofids;
		}

		// chache the result of the reflection.
		private static int numofids = -1;
	}

	/** %formctl;. INPUT | SELECT | TEXTAREA */
	private static final String[] FORMCTL = {INPUT, SELECT, TEXTAREA};
	/** %phrase;.
	 * DFN
	 */
	private static final String[] PHRASE = {DFN};
	/** %special;.
	 * A | IMG | BR
	 */
	private static final String[] SPECIAL = {A, IMG, BR};
	/** %heading;. H[1-6] */
	private static final String[] HEADING = {H1, H2, H3, H4, H5, H6};
	/** %list;. UL | OL | DIR | MENU */
	private static final String[] LIST = {UL, OL, DIR, MENU};
	/** %preformatted;. PRE */
	private static final String[] PREFORMATTED = {PRE};
	private AttributeCollection attributeCollection = null;
	private static String[] names = null;

	static {
		names = new String[Ids.getNumOfIds()];
		names[Ids.ID_A] = A;
		names[Ids.ID_ADDRESS] = ADDRESS;
		names[Ids.ID_BASE] = BASE;
		names[Ids.ID_BLOCKQUOTE] = BLOCKQUOTE;
		names[Ids.ID_BODY] = BODY;
		names[Ids.ID_BR] = BR;
		names[Ids.ID_CENTER] = CENTER;
		names[Ids.ID_DD] = DD;
		names[Ids.ID_DIR] = DIR;
		names[Ids.ID_DIV] = DIV;
		names[Ids.ID_DL] = DL;
		names[Ids.ID_DT] = DT;
		names[Ids.ID_FORM] = FORM;
		names[Ids.ID_H1] = H1;
		names[Ids.ID_H2] = H2;
		names[Ids.ID_H3] = H3;
		names[Ids.ID_H4] = H4;
		names[Ids.ID_H5] = H5;
		names[Ids.ID_H6] = H6;
		names[Ids.ID_HEAD] = HEAD;
		names[Ids.ID_HR] = HR;
		names[Ids.ID_HTML] = HTML;
		names[Ids.ID_IMG] = IMG;
		names[Ids.ID_INPUT] = INPUT;
		names[Ids.ID_LI] = LI;
		names[Ids.ID_MENU] = MENU;
		names[Ids.ID_META] = META;
		names[Ids.ID_OL] = OL;
		names[Ids.ID_OPTION] = OPTION;
		names[Ids.ID_P] = P;
		names[Ids.ID_PRE] = PRE;
		names[Ids.ID_SELECT] = SELECT;
		names[Ids.ID_TEXTAREA] = TEXTAREA;
		names[Ids.ID_TITLE] = TITLE;
		names[Ids.ID_UL] = UL;
		names[Ids.ID_SSI_CONFIG] = SSI_CONFIG;
		names[Ids.ID_SSI_ECHO] = SSI_ECHO;
		names[Ids.ID_SSI_EXEC] = SSI_EXEC;
		names[Ids.ID_SSI_FSIZE] = SSI_FSIZE;
		names[Ids.ID_SSI_FLASTMOD] = SSI_FLASTMOD;
		names[Ids.ID_SSI_INCLUDE] = SSI_INCLUDE;
		names[Ids.ID_SSI_PRINTENV] = SSI_PRINTENV;
		names[Ids.ID_SSI_SET] = SSI_SET;
	}

	/**
	 */
	public ElementCollection(AttributeCollection collection) {
		super(names, TOLERANT_CASE);
		attributeCollection = collection;
	}

	/**
	 * Actually creates HTMLElementDeclaration instance.
	 * @return HTMLElementDeclaration
	 */
	protected CMNode create(String elementName) {
		HTMLElemDeclImpl edec = null;

		if (elementName.equalsIgnoreCase(A)) {
			edec = new HedA(this);

		}
		else if (elementName.equalsIgnoreCase(ADDRESS)) {
			edec = new HedADDRESS(this);

		}
		else if (elementName.equalsIgnoreCase(BASE)) {
			edec = new HedBASE(this);

		}
		else if (elementName.equalsIgnoreCase(BLOCKQUOTE)) {
			edec = new HedBLOCKQUOTE(this);

		}
		else if (elementName.equalsIgnoreCase(BODY)) {
			edec = new HedBODY(this);

		}
		else if (elementName.equalsIgnoreCase(BR)) {
			edec = new HedBR(this);

		}
		else if (elementName.equalsIgnoreCase(CENTER)) {
			edec = new HedCENTER(this);

		}
		else if (elementName.equalsIgnoreCase(DD)) {
			edec = new HedDD(this);

		}
		else if (elementName.equalsIgnoreCase(DIR)) {
			edec = new HedMENU(DIR, this);

		}
		else if (elementName.equalsIgnoreCase(DIV)) {
			edec = new HedDIV(this);

		}
		else if (elementName.equalsIgnoreCase(DL)) {
			edec = new HedDL(this);

		}
		else if (elementName.equalsIgnoreCase(DT)) {
			edec = new HedDT(this);

		}
		else if (elementName.equalsIgnoreCase(FORM)) {
			edec = new HedFORM(this);

		}
		else if (elementName.equalsIgnoreCase(H1)) {
			edec = new HedHeading(H1, this);

		}
		else if (elementName.equalsIgnoreCase(H2)) {
			edec = new HedHeading(H2, this);

		}
		else if (elementName.equalsIgnoreCase(H3)) {
			edec = new HedHeading(H3, this);

		}
		else if (elementName.equalsIgnoreCase(H4)) {
			edec = new HedHeading(H4, this);

		}
		else if (elementName.equalsIgnoreCase(H5)) {
			edec = new HedHeading(H5, this);

		}
		else if (elementName.equalsIgnoreCase(H6)) {
			edec = new HedHeading(H6, this);

		}
		else if (elementName.equalsIgnoreCase(HEAD)) {
			edec = new HedHEAD(this);

		}
		else if (elementName.equalsIgnoreCase(HR)) {
			edec = new HedHR(this);

		}
		else if (elementName.equalsIgnoreCase(HTML)) {
			edec = new HedHTML(this);

		}
		else if (elementName.equalsIgnoreCase(IMG)) {
			edec = new HedIMG(this);

		}
		else if (elementName.equalsIgnoreCase(INPUT)) {
			edec = new HedINPUT(this);

		}
		else if (elementName.equalsIgnoreCase(LI)) {
			edec = new HedLI(this);

		}
		else if (elementName.equalsIgnoreCase(MENU)) {
			edec = new HedMENU(MENU, this);

		}
		else if (elementName.equalsIgnoreCase(META)) {
			edec = new HedMETA(this);

		}
		else if (elementName.equalsIgnoreCase(OL)) {
			edec = new HedOL(this);

		}
		else if (elementName.equalsIgnoreCase(OPTION)) {
			edec = new HedOPTION(this);

		}
		else if (elementName.equalsIgnoreCase(P)) {
			edec = new HedP(this);

		}
		else if (elementName.equalsIgnoreCase(PRE)) {
			edec = new HedPRE(this);

		}
		else if (elementName.equalsIgnoreCase(SELECT)) {
			edec = new HedSELECT(this);

		}
		else if (elementName.equalsIgnoreCase(TEXTAREA)) {
			edec = new HedTEXTAREA(this);

		}
		else if (elementName.equalsIgnoreCase(TITLE)) {
			edec = new HedTITLE(this);

		}
		else if (elementName.equalsIgnoreCase(UL)) {
			edec = new HedUL(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_CONFIG)) {
			edec = new HedSSIConfig(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_ECHO)) {
			edec = new HedSSIEcho(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_EXEC)) {
			edec = new HedSSIExec(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_FSIZE)) {
			edec = new HedSSIFsize(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_FLASTMOD)) {
			edec = new HedSSIFlastmod(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_INCLUDE)) {
			edec = new HedSSIInclude(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_PRINTENV)) {
			edec = new HedSSIPrintenv(this);

		}
		else if (elementName.equalsIgnoreCase(SSI_SET)) {
			edec = new HedSSISet(this);

		} // unknown
		else {
			// NOTE: We don't define the UNKNOWN element declaration.
			// <code>null</code> for a declaration is a sign of
			// the target element is unknown.
			// -- 3/9/2001
			edec = null;
		}
		return edec;
	}

	/**
	 * @return com.ibm.sed.contentmodel.html.AttributeCollection
	 */
	public AttributeCollection getAttributeCollection() {
		return attributeCollection;
	}

	/**
	 */
	public final Collection getNamesOfBlock() {
		// P | %list | %preformatted | DL | DIV | CENTER | BLOCKQUOTE | FORM | HR
		String[] blockMisc = {P, DL, DIV, CENTER, BLOCKQUOTE, FORM, HR,};
		Vector blockNames = new Vector(Arrays.asList(blockMisc));
		// %heading;
		blockNames.addAll(Arrays.asList(HEADING));
		// %list;
		blockNames.addAll(Arrays.asList(LIST));
		// %preformatted;
		blockNames.addAll(Arrays.asList(PREFORMATTED));

		return blockNames;
	}

	/**
	 * %block;.
	 * %block; is:
	 * P | %heading; | %list; | %preformatted; | DL | DIV | CENTER |
	 * NOSCRIPT | NOFRAMES | BLOCKQUOTE | FORM | ISINDEX | HR |
	 * TABLE | FIELDSET | ADDRESS.<br>
	 * @param group CMGroupImpl Return values.
	 */
	public final void getBlock(CMGroupImpl group) {
		if (group == null)
			return;
		getDeclarations(group, getNamesOfBlock().iterator());
	}

	/**
	 * Create element declarations and store them
	 * into a <code>CMGroupImpl</code> instance.
	 * @param group CMGroupImpl Return values.
	 */
	public final void getFlow(CMGroupImpl group) {
		if (group == null)
			return;
		getBlock(group);
		getInline(group);
	}

	/**
	 * Create element declarations and store them into a <code>CMGroupImpl</code>
	 * instance.<br>
	 * @param group CMGroupImpl Return values.
	 */
	public final void getFontstyle(CMGroupImpl group) {
		return;
	}

	/**
	 * Create element declarations and store them into a <code>CMGroupImpl</code>
	 * instance.<br>
	 * @param group CMGroupImpl Return values.
	 */
	public final void getFormctrl(CMGroupImpl group) {
		if (group == null)
			return;
		getDeclarations(group, Arrays.asList(FORMCTL).iterator());
	}

	/**
	 * %heading;.
	 * @param group CMGroupImpl Return values.
	 */
	public final void getHeading(CMGroupImpl group) {
		if (group == null)
			return;

		getDeclarations(group, Arrays.asList(HEADING).iterator());
	}

	/**
	 * Create element declarations and store them
	 * into a <code>CMGroupImpl</code> instance.
	 * @param group CMGroupImpl Return values.
	 */
	public final void getInline(CMGroupImpl group) {
		if (group == null)
			return;
		getFontstyle(group);
		getPhrase(group);
		getSpecial(group);
		getFormctrl(group);
	}

	/**
	 * %list;.
	 * @param group CMGroupImpl Return values.
	 */
	public final void getList(CMGroupImpl group) {
		if (group == null)
			return;

		getDeclarations(group, Arrays.asList(LIST).iterator());
	}

	/**
	 * Create element declarations and store them into a <code>CMGroupImpl</code>
	 * instance.<br>
	 * @param group CMGroupImpl Return values.
	 */
	public final void getPhrase(CMGroupImpl group) {
		if (group == null)
			return;
		getDeclarations(group, Arrays.asList(PHRASE).iterator());
	}

	/**
	 * %preformatted;
	 * @param group CMGroupImpl Return values.
	 */
	public final void getPreformatted(CMGroupImpl group) {
		if (group == null)
			return;

		getDeclarations(group, Arrays.asList(PREFORMATTED).iterator());
	}

	/**
	 * Create element declarations and store them into a <code>CMGroupImpl</code>
	 * instance.<br>
	 * @param group CMGroupImpl Return values.
	 */
	public final void getSpecial(CMGroupImpl group) {
		if (group == null)
			return;
		getDeclarations(group, Arrays.asList(SPECIAL).iterator());
	}
}

Back to the top