Skip to main content
summaryrefslogtreecommitdiffstats
blob: 936684b6519cf1b1b414365e2eceda7ad5a3ec43 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.jst.jsp.core.internal.contentmodel.tld;



import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.jst.jsp.core.internal.Logger;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDDocument;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDValidator;
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileInfo;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileParser;

public class CMDocumentImpl implements TLDDocument {
	
	/** Contains taginfo and/or any other misc properties*/
	private AnnotationMap fAnnotationMap = null;
	
	private Map fProperties = new HashMap(0);

	/**
	 * Records from where this document was created
	 */
	private String fBaseLocation;
	/** 
	 * since JSP 1.2
	 */
	private String fDescription;
	
	private String fDisplayName;

	/**
	 * NOT public API
	 */
	public CMNamedNodeMapImpl fElements = new CMNamedNodeMapImpl();

	private List fFunctions = new ArrayList(0);
	
	// id of the taglib
	private String fId = null;
	/**
	 * Children of "taglib" within a .tld file each allow
	 * one Text node (#PCDATA) beneath them.  Store the values
	 * here for simplicity.
	 */
	// The JSP specification required for this taglib to function
	private String fJSPVersion = null;
	
	private String fLargeIcon;

	private List fListeners;
	
	private String fParentURI = null;
	// A short name suggested as the default prefix for tags within the lib
	private String fShortName = null;
	
	private String fSmallIcon;
	
	/**
	 * since JSP 2.0
	 * 
	 * The entire element is stored here since its layout is undefined 
	 */
	private List fTaglibExtensions = new ArrayList(0);
	
	// Version information for the taglib itself
	private String fTLibVersion = null;
	
	// A unique public URI describing this taglib.  Recommended to be the URL
	// to the descriptor
	private String fURI = null;
	
	private String fLocationString;

	protected TLDValidator validator;
	
	/**
	 * CMDocumentImpl constructor comment.
	 */
	public CMDocumentImpl() {
		super();
	}

	/**
	 * Get the annotation map associated with this document.  Lazily creates
	 * and loads annotation map.
	 * @return AnnotationMap
	 */
	private AnnotationMap getAnnotationMap() {
		// create a new annotation map and load it up
		if (fAnnotationMap == null) {
			fAnnotationMap = new AnnotationMap();
			
			List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(getUri());
		    for (Iterator i = annotationFiles.iterator(); i.hasNext();) {
		    	try {
		    		AnnotationFileInfo fileInfo = (AnnotationFileInfo) i.next();
		    		AnnotationFileParser parser = new AnnotationFileParser();
		    		parser.parse(fAnnotationMap, fileInfo);
		        } catch (Exception e) {
		        	Logger.log(Logger.WARNING_DEBUG, "Exception thrown in CMDocumentImpl#getAnnotationMap", e); //$NON-NLS-1$
		        }
		    }
		}
		return fAnnotationMap;
	}
	/**
	 * @return Returns the baseLocation.
	 */
	public String getBaseLocation() {
		return fBaseLocation;
	}

	/**
	 * Gets the description.
	 * @return Returns a String
	 */
	public String getDescription() {
		return fDescription;
	}

	/**
	 * Gets the displayName.
	 * @return Returns a String
	 */
	public String getDisplayName() {
		return fDisplayName;
	}

	/**
	 * getElements method
	 * @return CMNamedNodeMap
	 *
	 * Returns CMNamedNodeMap of ElementDeclaration
	 */
	public CMNamedNodeMap getElements() {
		return fElements;
	}

	/**
	 * getEntities method
	 * @return CMNamedNodeMap
	 *
	 * Returns CMNamedNodeMap of EntityDeclaration
	 */
	public CMNamedNodeMap getEntities() {
		return null;
	}
	
	public List getExtensions() {
		return fTaglibExtensions;
	}
	/**
	 * @return Returns the functions.
	 */
	public List getFunctions() {
		return fFunctions;
	}

	/**
	 * Gets the id.
	 * @return Returns a String
	 */
	public String getId() {
		return fId;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getInfo() {
		return getDescription();
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getJspversion() {
		return fJSPVersion;
	}

	/**
	 * Gets the largeIcon.
	 * @return Returns a String
	 */
	public String getLargeIcon() {
		return fLargeIcon;
	}

	public List getListeners() {
		if (fListeners == null)
			fListeners = new ArrayList();
		return fListeners;
	}

	/**
	 * getNamespace method
	 * @return CMNamespace
	 */
	public CMNamespace getNamespace() {
		return null;
	}

	/**
	 * getNodeName method
	 * @return java.lang.String
	 */
	public String getNodeName() {
		return "#cmdocument"; //$NON-NLS-1$
	}

	/**
	 * getNodeType method
	 * @return int
	 *
	 * Returns one of :
	 *
	 */
	public int getNodeType() {
		return CMNode.DOCUMENT;
	}
	/**
	 * @return Returns the parentURI.
	 */
	public String getParentURI() {
		return fParentURI;
	}

	/**
	 * getProperty method
	 * @return java.lang.Object
	 *
	 * Returns the object property desciped by the propertyName
	 *
	 */
	public Object getProperty(String propertyName) {
		if (propertyName.equals(TLDDocument.CM_KIND)) {
			return TLDDocument.JSP_TLD;
		}
		else if (propertyName.equals("annotationMap")) { //$NON-NLS-1$
			return getAnnotationMap();
		}
		return fProperties.get(propertyName);
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getShortname() {
		return fShortName;
	}

	/**
	 * Gets the smallIcon.
	 * @return Returns a String
	 */
	public String getSmallIcon() {
		return fSmallIcon;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getTlibversion() {
		return fTLibVersion;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getUri() {
		return fURI;
	}

	/*
	 * @see TLDDocument#getValidator()
	 */
	public TLDValidator getValidator() {
		return validator;
	}
	/**
	 * @param baseLocation The baseLocation to set.
	 */
	public void setBaseLocation(String baseLocation) {
		fBaseLocation = baseLocation;
	}

	/**
	 * Sets the description.
	 * @param description The description to set
	 */
	public void setDescription(String description) {
		this.fDescription = description;
	}

	/**
	 * Sets the displayName.
	 * @param displayName The displayName to set
	 */
	public void setDisplayName(String displayName) {
		this.fDisplayName = displayName;
	}

	/**
	 * Sets the id.
	 * @param id The id to set
	 */
	public void setId(String id) {
		this.fId = id;
	}

	/**
	 * 
	 * @param newInfo java.lang.String
	 */
	public void setInfo(String newInfo) {
		setDescription(newInfo);
	}

	/**
	 * 
	 * @param newJspversion java.lang.String
	 */
	public void setJspversion(String newJspversion) {
		fJSPVersion = newJspversion;
	}

	/**
	 * Sets the largeIcon.
	 * @param largeIcon The largeIcon to set
	 */
	public void setLargeIcon(String largeIcon) {
		this.fLargeIcon = largeIcon;
	}

	public void setListeners(List listeners) {
		this.fListeners = listeners;
	}
	/**
	 * @param parentURI The parentURI to set.
	 */
	public void setParentURI(String parentURI) {
		fParentURI = parentURI;
	}
	
	public void setProperty(String property, Object value) {
		fProperties.put(property, value);
	}

	/**
	 * 
	 * @param newShortname java.lang.String
	 */
	public void setShortname(String newShortname) {
		fShortName = newShortname;
	}

	/**
	 * Sets the smallIcon.
	 * @param smallIcon The smallIcon to set
	 */
	public void setSmallIcon(String smallIcon) {
		this.fSmallIcon = smallIcon;
	}

	/**
	 * 
	 * @param newTlibversion java.lang.String
	 */
	public void setTlibversion(String newTlibversion) {
		fTLibVersion = newTlibversion;
	}

	/**
	 * 
	 * @param newUri java.lang.String
	 */
	public void setUri(String newUri) {
		fURI = newUri;
	}

	public void setValidator(TLDValidator validator) {
		this.validator = validator;
	}

	/**
	 * supports method
	 * @return boolean
	 *
	 * Returns true if the CMNode supports a specified property
	 *
	 */
	public boolean supports(String propertyName) {
		if (TLDDocument.CM_KIND.equals(propertyName) || "annotationMap".equals(propertyName)) //$NON-NLS-1$
			return true;
		return fProperties.containsKey(propertyName);
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(super.toString());
		buffer.append("\n\t short name:" + StringUtils.escape(getShortname())); //$NON-NLS-1$
		buffer.append("\n\t display name:" + StringUtils.escape(getDisplayName())); //$NON-NLS-1$
		buffer.append("\n\t description (info):" + StringUtils.escape(getDescription())); //$NON-NLS-1$
		buffer.append("\n\t URI:" + StringUtils.escape(getUri())); //$NON-NLS-1$
		buffer.append("\n\t jsp version:" + StringUtils.escape(getJspversion())); //$NON-NLS-1$
		buffer.append("\n\t taglib version:" + StringUtils.escape(getTlibversion())); //$NON-NLS-1$
		buffer.append("\n\t small icon:" + StringUtils.escape(getSmallIcon())); //$NON-NLS-1$
		buffer.append("\n\t large icon:" + StringUtils.escape(getLargeIcon())); //$NON-NLS-1$
		if (getValidator() != null)
			buffer.append("\n\t validator:" + StringUtils.replace(getValidator().toString(), "\n", "\n\t\t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		buffer.append("\n\t listeners:"); //$NON-NLS-1$
		for (int i = 0; i < getListeners().size(); i++) {
			buffer.append("\n" + StringUtils.replace(getListeners().get(i).toString(), "\n", "\n\t\t")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}
		buffer.append("\n\t elements:"); //$NON-NLS-1$
		CMNamedNodeMap elements = getElements();
		for (int i = 0; i < elements.getLength(); i++) {
			buffer.append(StringUtils.replace(elements.item(i).toString(), "\n", "\n\t\t")); //$NON-NLS-1$ //$NON-NLS-2$
		}
		return buffer.toString();
	}

	public String getLocationString() {
		return fLocationString;
	}

	public void setLocationString(String url) {
		fLocationString = url;
	}
}

Back to the top