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: 3ffb396e50d7396f890690c6fed999ec06cd6d3b (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
/*******************************************************************************
 * 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.internal.contentmodel;

import java.util.Hashtable;

import org.eclipse.wst.html.core.HTMLCMProperties;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;

/**
 * The factory object of PropertyProvider.
 */
final class PropertyProviderFactory {


	/**
	 * DefaultProvider is intended to be used for unknown properties.
	 * It always returns null value for any properties.
	 */
	class DefaultProvider implements PropertyProvider {
		public DefaultProvider() {
			super();
		}

		public boolean supports(HTMLElementDeclaration edecl) {
			return false;
		}

		public Object get(HTMLElementDeclaration edecl) {
			return null;
		}
	}

	abstract class AbstractElementPropertyProvider implements PropertyProvider {
		protected AbstractElementPropertyProvider() {
			super();
		}

		public boolean supports(HTMLElementDeclaration edecl) {
			return (edecl != null);
		}

		public Object get(HTMLElementDeclaration edecl) {
			if (!(edecl instanceof HTMLPropertyDeclaration))
				return null;
			return getElementProperty((HTMLPropertyDeclaration)edecl);
		}

		abstract protected Object getElementProperty(HTMLPropertyDeclaration decl);
	}

	/*
	 * "tagInfo"
	 * gets documentation for the element
	 */
	class PPTagInfo extends AbstractElementPropertyProvider {
		private final static String htmlAnnotationLoc = "platform:/plugin/org.eclipse.wst.html.core/data/htmref.xml"; //$NON-NLS-1$
		protected AnnotationMap fAnnotationMap = null;

		public PPTagInfo() {
			super();
		}

		/**
		 * Gets the annotationMap.
		 * @return Returns a AnnotationMap
		 */
		protected AnnotationMap getAnnotationMap() {
			if (fAnnotationMap == null) {
				fAnnotationMap = new AnnotationMap();
				try {
					fAnnotationMap.load(htmlAnnotationLoc);
				}
				catch (Exception e) {
					// no annotation available
				}
			}
			return fAnnotationMap;
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			if (decl instanceof HTMLElementDeclaration) {
				return getAnnotationMap().getProperty(((HTMLElementDeclaration)decl).getElementName(), "tagInfo"); //$NON-NLS-1$
			} else {
				return null;
			}
		}
	}

	/*
	 * "shouldKeepSpace"
	 */
	class PPShouldKeepSpace extends AbstractElementPropertyProvider {
		public PPShouldKeepSpace() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return new Boolean(decl.shouldKeepSpaces());
		}
	}

	/*
	 * "shouldIndentChildSource"
	 */
	class PPShouldIndentChildSource extends AbstractElementPropertyProvider {
		public PPShouldIndentChildSource() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return new Boolean(decl.shouldIndentChildSource());
		}
	}

	/*
	 * "terminators"
	 */
	class PPTerminators extends AbstractElementPropertyProvider {
		public PPTerminators() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			if (! (decl instanceof HTMLElemDeclImpl)) return null;
			return ((HTMLElemDeclImpl)decl).getTerminators();
		}
	}

	/*
	 * "prohibitedAncestors"
	 */
	class PPProhibitedAncestors extends AbstractElementPropertyProvider {
		public PPProhibitedAncestors() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return decl.getProhibitedAncestors();
		}
	}

	/*
	 * "isJSP"
	 */
	class PPIsJSP extends AbstractElementPropertyProvider {
		public PPIsJSP() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return new Boolean(decl.isJSP());
		}
	}

	/*
	 * "isXHTML"
	 * HTMLElementDeclaration itself never represent any XHTML element declaration.
	 * So, this property must be always false.
	 */
	class PPIsXHTML extends AbstractElementPropertyProvider {
		public PPIsXHTML() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return new Boolean(false);
		}
	}

	/*
	 * "isSSI"
	 * Each declaration class for SSI elements must provide this property itself,
	 * and then return true.  Other declaration must always return false.
	 */
	class PPIsSSI extends AbstractElementPropertyProvider {
		public PPIsSSI() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return new Boolean(false);
		}
	}

	/*
	 * "lineBreakHint"
	 */
	class PPLineBreakHint extends AbstractElementPropertyProvider {
		public PPLineBreakHint() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			String hint = HTMLCMProperties.Values.BREAK_NONE;
			switch (decl.getLineBreakHint()) {
				case HTMLElementDeclaration.BREAK_AFTER_START :
					hint = HTMLCMProperties.Values.BREAK_AFTER_START;
					break;
				case HTMLElementDeclaration.BREAK_BEFORE_START_AND_AFTER_END :
					hint = HTMLCMProperties.Values.BREAK_BEFORE_START_AND_AFTER_END;
					break;
				case HTMLElementDeclaration.BREAK_NONE :
				// nothing to do
				default :
					break;
			}
			return hint;
		}
	}

	/*
	 * "layoutType"
	 */
	class PPLayoutType extends AbstractElementPropertyProvider {
		public PPLayoutType() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			String type = HTMLCMProperties.Values.LAYOUT_NONE;
			switch (decl.getLayoutType()) {
				case HTMLElementDeclaration.LAYOUT_BLOCK :
					type = HTMLCMProperties.Values.LAYOUT_BLOCK;
					break;
				case HTMLElementDeclaration.LAYOUT_BREAK :
					type = HTMLCMProperties.Values.LAYOUT_BREAK;
					break;
				case HTMLElementDeclaration.LAYOUT_HIDDEN :
					type = HTMLCMProperties.Values.LAYOUT_HIDDEN;
					break;
				case HTMLElementDeclaration.LAYOUT_OBJECT :
					type = HTMLCMProperties.Values.LAYOUT_OBJECT;
					break;
				case HTMLElementDeclaration.LAYOUT_WRAP :
					type = HTMLCMProperties.Values.LAYOUT_WRAP;
					break;
				case HTMLElementDeclaration.LAYOUT_NONE :
				// nothing to do.
				default :
					break;
			}
			return type;
		}
	}

	/*
	 * "omitType"
	 */
	class PPOmitType extends AbstractElementPropertyProvider {
		public PPOmitType() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			String type = HTMLCMProperties.Values.OMIT_NONE;
			switch (decl.getOmitType()) {
				case HTMLElementDeclaration.OMIT_BOTH :
					type = HTMLCMProperties.Values.OMIT_BOTH;
					break;
				case HTMLElementDeclaration.OMIT_END :
					type = HTMLCMProperties.Values.OMIT_END;
					break;
				case HTMLElementDeclaration.OMIT_END_DEFAULT :
					type = HTMLCMProperties.Values.OMIT_END_DEFAULT;
					break;
				case HTMLElementDeclaration.OMIT_END_MUST :
					type = HTMLCMProperties.Values.OMIT_END_MUST;
					break;
				case HTMLElementDeclaration.OMIT_NONE :
				// nothing to do.
				default :
					break;
			}
			return type;
		}
	}

	/*
	 * "inclusion"
	 */
	class PPInclusion extends AbstractElementPropertyProvider {
		public PPInclusion() {
			super();
		}

		protected Object getElementProperty(HTMLPropertyDeclaration decl) {
			return decl.getInclusion();
		}
	}

	public static PropertyProvider getProvider(String propName) {
		PropertyProviderFactory factory = getInstance();
		PropertyProvider pp = (PropertyProvider) factory.registry.get(propName);
		if (pp != null)
			return pp;

		pp = factory.create(propName);
		if (pp == null)
			return factory.defaultProvider;

		factory.registry.put(propName, pp);
		return pp;
	}

	private static PropertyProviderFactory instance = null;

	private synchronized static PropertyProviderFactory getInstance() {
		if (instance != null)
			return instance;
		instance = new PropertyProviderFactory();
		return instance;
	}

	private Hashtable registry = new Hashtable();
	private PropertyProvider defaultProvider = new DefaultProvider();

	private PropertyProviderFactory() {
		super();
	}

	private PropertyProvider create(String propName) {
		PropertyProvider pp = null;
		if (propName.equals(HTMLCMProperties.IS_JSP))
			pp = new PPIsJSP();
		else if (propName.equals(HTMLCMProperties.IS_XHTML))
			pp = new PPIsXHTML();
		else if (propName.equals(HTMLCMProperties.IS_SSI))
			pp = new PPIsSSI();
		else if (propName.equals(HTMLCMProperties.LAYOUT_TYPE))
			pp = new PPLayoutType();
		else if (propName.equals(HTMLCMProperties.LINE_BREAK_HINT))
			pp = new PPLineBreakHint();
		else if (propName.equals(HTMLCMProperties.PROHIBITED_ANCESTORS))
			pp = new PPProhibitedAncestors();
		else if (propName.equals(HTMLCMProperties.SHOULD_KEEP_SPACE))
			pp = new PPShouldKeepSpace();
		else if (propName.equals(HTMLCMProperties.SHOULD_INDENT_CHILD_SOURCE))
			pp = new PPShouldIndentChildSource();
		else if (propName.equals(HTMLCMProperties.TERMINATORS))
			pp = new PPTerminators();
		else if (propName.equals(HTMLCMProperties.TAGINFO))
			pp = new PPTagInfo();
		else if (propName.equals(HTMLCMProperties.OMIT_TYPE))
			pp = new PPOmitType();
		else if (propName.equals(HTMLCMProperties.INCLUSION))
			pp = new PPInclusion();

		return pp;
	}
}

Back to the top