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: bbab38f642c03f4b16b7d2d4d1fec160e754e927 (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
/*******************************************************************************
 * 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.css.core.internal.contentmodel;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

/**
 * 
 */
public class PropCMProperty extends PropCMContainer {

	// static fields
	private static java.util.Hashtable instances = null;
	private static java.util.Hashtable cachedIdMap = null;
	public final static String P_AZIMUTH = "azimuth";//$NON-NLS-1$
	public final static String P_BG = "background";//$NON-NLS-1$
	public final static String P_BG_ATTACHMENT = "background-attachment";//$NON-NLS-1$
	public final static String P_BG_COLOR = "background-color";//$NON-NLS-1$
	public final static String P_BG_IMAGE = "background-image";//$NON-NLS-1$
	public final static String P_BG_POSITION = "background-position";//$NON-NLS-1$
	public final static String P_BG_REPEAT = "background-repeat";//$NON-NLS-1$
	public final static String P_BORDER = "border";//$NON-NLS-1$
	public final static String P_BORDER_COLLAPSE = "border-collapse";//$NON-NLS-1$
	public final static String P_BORDER_COLOR = "border-color";//$NON-NLS-1$
	public final static String P_BORDER_SPACING = "border-spacing";//$NON-NLS-1$
	public final static String P_BORDER_STYLE = "border-style";//$NON-NLS-1$
	public final static String P_BORDER_TOP = "border-top";//$NON-NLS-1$
	public final static String P_BORDER_RIGHT = "border-right";//$NON-NLS-1$
	public final static String P_BORDER_BOTTOM = "border-bottom";//$NON-NLS-1$
	public final static String P_BORDER_LEFT = "border-left";//$NON-NLS-1$
	public final static String P_BORDER_TOP_COLOR = "border-top-color";//$NON-NLS-1$
	public final static String P_BORDER_RIGHT_COLOR = "border-right-color";//$NON-NLS-1$
	public final static String P_BORDER_BOTTOM_COLOR = "border-bottom-color";//$NON-NLS-1$
	public final static String P_BORDER_LEFT_COLOR = "border-left-color";//$NON-NLS-1$
	public final static String P_BORDER_TOP_STYLE = "border-top-style";//$NON-NLS-1$
	public final static String P_BORDER_RIGHT_STYLE = "border-right-style";//$NON-NLS-1$
	public final static String P_BORDER_BOTTOM_STYLE = "border-bottom-style";//$NON-NLS-1$
	public final static String P_BORDER_LEFT_STYLE = "border-left-style";//$NON-NLS-1$
	public final static String P_BORDER_TOP_WIDTH = "border-top-width";//$NON-NLS-1$
	public final static String P_BORDER_RIGHT_WIDTH = "border-right-width";//$NON-NLS-1$
	public final static String P_BORDER_BOTTOM_WIDTH = "border-bottom-width";//$NON-NLS-1$
	public final static String P_BORDER_LEFT_WIDTH = "border-left-width";//$NON-NLS-1$
	public final static String P_BORDER_WIDTH = "border-width";//$NON-NLS-1$
	public final static String P_BOTTOM = "bottom";//$NON-NLS-1$
	public final static String P_CAPTION_SIDE = "caption-side";//$NON-NLS-1$
	public final static String P_CLEAR = "clear";//$NON-NLS-1$
	public final static String P_CLIP = "clip";//$NON-NLS-1$
	public final static String P_COLOR = "color";//$NON-NLS-1$
	public final static String P_CONTENT = "content";//$NON-NLS-1$
	public final static String P_COUNTER_INCREMENT = "counter-increment";//$NON-NLS-1$
	public final static String P_COUNTER_RESET = "counter-reset";//$NON-NLS-1$
	public final static String P_CUE = "cue";//$NON-NLS-1$
	public final static String P_CUE_AFTER = "cue-after";//$NON-NLS-1$
	public final static String P_CUE_BEFORE = "cue-before";//$NON-NLS-1$
	public final static String P_CURSOR = "cursor";//$NON-NLS-1$
	public final static String P_DIRECTION = "direction";//$NON-NLS-1$
	public final static String P_DISPLAY = "display";//$NON-NLS-1$
	public final static String P_ELEVATION = "elevation";//$NON-NLS-1$
	public final static String P_EMPTY_CELLS = "empty-cells";//$NON-NLS-1$
	public final static String P_FLOAT = "float";//$NON-NLS-1$
	public final static String P_FONT = "font";//$NON-NLS-1$
	public final static String P_FONT_FAMILY = "font-family";//$NON-NLS-1$
	public final static String P_FONT_SIZE = "font-size";//$NON-NLS-1$
	public final static String P_FONT_SIZE_ADJUST = "font-size-adjust";//$NON-NLS-1$
	public final static String P_FONT_STRETCH = "font-stretch";//$NON-NLS-1$
	public final static String P_FONT_STYLE = "font-style";//$NON-NLS-1$
	public final static String P_FONT_VARIANT = "font-variant";//$NON-NLS-1$
	public final static String P_FONT_WEIGHT = "font-weight";//$NON-NLS-1$
	public final static String P_HEIGHT = "height";//$NON-NLS-1$
	public final static String P_LEFT = "left";//$NON-NLS-1$
	public final static String P_LETTER_SPACING = "letter-spacing";//$NON-NLS-1$
	public final static String P_LINE_HEIGHT = "line-height";//$NON-NLS-1$
	public final static String P_LIST_STYLE = "list-style";//$NON-NLS-1$
	public final static String P_LIST_STYLE_IMAGE = "list-style-image";//$NON-NLS-1$
	public final static String P_LIST_STYLE_POSITION = "list-style-position";//$NON-NLS-1$
	public final static String P_LIST_STYLE_TYPE = "list-style-type";//$NON-NLS-1$
	public final static String P_MARGIN = "margin";//$NON-NLS-1$
	public final static String P_MARGIN_TOP = "margin-top";//$NON-NLS-1$
	public final static String P_MARGIN_RIGHT = "margin-right";//$NON-NLS-1$
	public final static String P_MARGIN_BOTTOM = "margin-bottom";//$NON-NLS-1$
	public final static String P_MARGIN_LEFT = "margin-left";//$NON-NLS-1$
	public final static String P_MARKER_OFFSET = "marker-offset";//$NON-NLS-1$
	public final static String P_MARKS = "marks";//$NON-NLS-1$
	public final static String P_MAX_HEIGHT = "max-height";//$NON-NLS-1$
	public final static String P_MAX_WIDTH = "max-width";//$NON-NLS-1$
	public final static String P_MIN_HEIGHT = "min-height";//$NON-NLS-1$
	public final static String P_MIN_WIDTH = "min-width";//$NON-NLS-1$
	public final static String P_ORPHANS = "orphans";//$NON-NLS-1$
	public final static String P_OUTLINE = "outline";//$NON-NLS-1$
	public final static String P_OUTLINE_COLOR = "outline-color";//$NON-NLS-1$
	public final static String P_OUTLINE_STYLE = "outline-style";//$NON-NLS-1$
	public final static String P_OUTLINE_WIDTH = "outline-width";//$NON-NLS-1$
	public final static String P_OVERFLOW = "overflow";//$NON-NLS-1$
	public final static String P_PADDING = "padding";//$NON-NLS-1$
	public final static String P_PADDING_TOP = "padding-top";//$NON-NLS-1$
	public final static String P_PADDING_RIGHT = "padding-right";//$NON-NLS-1$
	public final static String P_PADDING_BOTTOM = "padding-bottom";//$NON-NLS-1$
	public final static String P_PADDING_LEFT = "padding-left";//$NON-NLS-1$
	public final static String P_PAGE = "page";//$NON-NLS-1$
	public final static String P_PAGE_BREAK_AFTER = "page-break-after";//$NON-NLS-1$
	public final static String P_PAGE_BREAK_BEFORE = "page-break-before";//$NON-NLS-1$
	public final static String P_PAGE_BREAK_INSIDE = "page-break-inside";//$NON-NLS-1$
	public final static String P_PAUSE = "pause";//$NON-NLS-1$
	public final static String P_PAUSE_AFTER = "pause-after";//$NON-NLS-1$
	public final static String P_PAUSE_BEFORE = "pause-before";//$NON-NLS-1$
	public final static String P_PITCH = "pitch";//$NON-NLS-1$
	public final static String P_PITCH_RANGE = "pitch-range";//$NON-NLS-1$
	public final static String P_PLAY_DURING = "play-during";//$NON-NLS-1$
	public final static String P_POSITION = "position";//$NON-NLS-1$
	public final static String P_QUOTES = "quotes";//$NON-NLS-1$
	public final static String P_RICHNESS = "richness";//$NON-NLS-1$
	public final static String P_RIGHT = "right";//$NON-NLS-1$
	public final static String P_SIZE = "size";//$NON-NLS-1$
	public final static String P_SPEAK = "speak";//$NON-NLS-1$
	public final static String P_SPEAK_HEADER = "speak-header";//$NON-NLS-1$
	public final static String P_SPEAK_NUMERAL = "speak-numeral";//$NON-NLS-1$
	public final static String P_SPEAK_PUNCTUATION = "speak-punctuation";//$NON-NLS-1$
	public final static String P_SPEECH_RATE = "speech-rate";//$NON-NLS-1$
	public final static String P_STRESS = "stress";//$NON-NLS-1$
	public final static String P_TABLE_LAYOUT = "table-layout";//$NON-NLS-1$
	public final static String P_TEXT_ALIGN = "text-align";//$NON-NLS-1$
	public final static String P_TEXT_DECORATION = "text-decoration";//$NON-NLS-1$
	public final static String P_TEXT_INDENT = "text-indent";//$NON-NLS-1$
	public final static String P_TEXT_SHADOW = "text-shadow";//$NON-NLS-1$
	public final static String P_TEXT_TRANSFORM = "text-transform";//$NON-NLS-1$
	public final static String P_TOP = "top";//$NON-NLS-1$
	public final static String P_UNICODE_BIDI = "unicode-bidi";//$NON-NLS-1$
	public final static String P_VERTICAL_ALIGN = "vertical-align";//$NON-NLS-1$
	public final static String P_VISIBILITY = "visibility";//$NON-NLS-1$
	public final static String P_VOICE_FAMILY = "voice-family";//$NON-NLS-1$
	public final static String P_VOLUME = "volume";//$NON-NLS-1$
	public final static String P_WHITE_SPACE = "white-space";//$NON-NLS-1$
	public final static String P_WIDOWS = "widows";//$NON-NLS-1$
	public final static String P_WIDTH = "width";//$NON-NLS-1$
	public final static String P_WORD_SPACING = "word-spacing";//$NON-NLS-1$
	public final static String P_Z_INDEX = "z-index";//$NON-NLS-1$
	// instance fields
	private int fMinValueCount = 1;
	private int fMaxValueCount = 1;
	private Object[] mediaGroups;
	protected List containers;

	/**
	 * 
	 */
	protected PropCMProperty(String name) {
		super(name);
	}

	/**
	 * 
	 */
	Object appendChild(Object node) {
		Object ret = super.appendChild(node);
		if (node instanceof PropCMProperty) {
			// register shorthand container
			PropCMProperty cm = (PropCMProperty) node;
			if (cm.containers == null)
				cm.containers = new Vector();
			if (!cm.containers.contains(this))
				cm.containers.add(this);
		}
		return ret;
	}

	/**
	 * 
	 */
	void appendMediaGroup(Object mg) {
		if (mediaGroups == null)
			mediaGroups = new Object[1];
		else {
			Object[] oldMediaGroups = mediaGroups;
			mediaGroups = new Object[oldMediaGroups.length + 1];
			System.arraycopy(oldMediaGroups, 0, mediaGroups, 0, oldMediaGroups.length);
		}
		mediaGroups[mediaGroups.length - 1] = mg;
	}

	/**
	 * 
	 */
	public static PropCMProperty getInstanceOf(String name) {
		// initialize
		if (instances == null)
			instances = new Hashtable(200);

		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		// query
		Object node = instances.get(name);
		if (node != null)
			return (PropCMProperty) node;

		// register
		if (PropCMNode.isLoading()) {
			node = new PropCMProperty(name);
			instances.put(name, node);
		}

		return (PropCMProperty) node;
	}

	/**
	 * 
	 */
	public int getMaxValueCount() {
		return fMaxValueCount;
	}

	/**
	 * 
	 */
	public List getMediaGroups() {
		if (mediaGroups != null)
			return Arrays.asList(mediaGroups);
		else
			return new ArrayList();
	}

	/**
	 * 
	 */
	public int getMinValueCount() {
		return fMinValueCount;
	}

	/**
	 * 
	 */
	public static Enumeration getNameEnum() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return instances.keys();
	}

	/**
	 * 
	 */
	public static Enumeration getPropertyEnum() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return instances.elements();
	}

	/**
	 * 
	 */
	public int getShorthandContainerCount() {
		return (containers == null) ? 0 : containers.size();
	}

	/**
	 * 
	 */
	public short getType() {
		return VAL_PROPERTY;
	}

	/**
	 * 
	 */
	public boolean isShorthand() {
		int nChild = getNumChild();
		for (int i = 0; i < nChild; i++) {
			Object obj = getChildAt(i);
			if (obj instanceof PropCMProperty && !(obj instanceof PropCMSubProperty))
				return true;
		}
		return false;
	}

	/**
	 * 
	 */
	public static Vector names() {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		return new Vector(instances.keySet());
	}

	/**
	 * 
	 */
	public static List names(Object mediaGroup) {
		if (mediaGroup == null)
			return names();

		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		Vector properties = new Vector();

		Iterator it = instances.values().iterator();
		while (it.hasNext()) {
			PropCMProperty prop = (PropCMProperty) it.next();
			if (prop.getMediaGroups().contains(mediaGroup))
				properties.add(prop.getName());
		}

		return properties;
	}

	/**
	 * If identifier is null, get all properties
	 */
	public static Vector propertiesFor(String identifier, boolean shorthands) {
		// Initialize of DB
		if (isNeedInitialize())
			PropCMNode.initPropertyCM();

		// if identifier is null, get all properties
		if (identifier == null)
			return new Vector(instances.values());

		if (cachedIdMap == null) {
			// start cacheing
			cachedIdMap = new Hashtable();
		}
		else {
			// search cached
			Object ret = cachedIdMap.get(identifier + String.valueOf(shorthands));
			if (ret != null)
				return new Vector((Collection) ret);
		}

		// create
		Enumeration propertyEnum = getPropertyEnum();
		HashSet set = new HashSet();
		while (propertyEnum.hasMoreElements()) {
			PropCMProperty prop = (PropCMProperty) propertyEnum.nextElement();
			if (!shorthands && prop.isShorthand())
				continue;
			if (prop.canHave(identifier))
				set.add(prop);
		}

		// cache
		cachedIdMap.put(identifier + String.valueOf(shorthands), set);

		return new Vector(set);
	}

	/**
	 * 
	 */
	protected void setMaxValueCount(int newMaxValueCount) {
		fMaxValueCount = newMaxValueCount;
	}

	/**
	 * 
	 */
	protected void setMinValueCount(int newMinValueCount) {
		fMinValueCount = newMinValueCount;
	}

	/**
	 * 
	 */
	public PropCMProperty shorthandContainerAt(int i) {
		if (containers == null)
			return null;
		if (i < 0 || containers.size() <= i)
			return null;
		return (PropCMProperty) containers.get(i);
	}

	/**
	 * 
	 */
	public Iterator shorthandContainerIterator() {
		if (containers == null) {
			return new Iterator() {
				public boolean hasNext() {
					return false;
				}

				public Object next() {
					return null;
				}

				public void remove() {
				}
			};
		}
		else
			return containers.iterator();
	}
}

Back to the top