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: 6bfdfded476bb60079ec868fb5c1a28e0496d422 (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
/*******************************************************************************
 * Copyright (c) 2004, 2008 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.Enumeration;

import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.JSP12TLDNames;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDDocument;
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;

public class CMAttributeDeclarationImpl implements TLDAttributeDeclaration {

	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170556
	private static final CMDataType attrType = new CMDataTypeImpl(CMDataType.CDATA);
	
	private String fDescription;

	//
	private boolean fIsFragment = false;

	private CMDocument fOwnerDocument;
	// optional id
	private String id = null;

	// required name
	private String name = null;
	// optional "required" element present, defaults to not present
	private boolean required = false;

	// optional run-time (scriplet derived) value of attributes, defaults to
	// none/false
	private String rtexprvalue = null;

	private String type = null;

	/**
	 * CMAttributeDeclarationImpl constructor comment.
	 */
	public CMAttributeDeclarationImpl(CMDocument owner) {
		super();
		fOwnerDocument = owner;
	}

	/**
	 * getAttrName method
	 * 
	 * @return java.lang.String
	 */
	public String getAttrName() {
		return getNodeName();
	}

	/**
	 * getAttrType method
	 * 
	 * @return CMDataType
	 */
	public CMDataType getAttrType() {
		return attrType;
	}

	/**
	 * @deprecated in superclass
	 */
	public String getDefaultValue() {
		return ""; //$NON-NLS-1$
	}

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

	/**
	 * @deprecated in superclass
	 */
	public Enumeration getEnumAttr() {
		return null;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getId() {
		return id;
	}

	/**
	 * getNodeName method
	 * 
	 * @return java.lang.String
	 */
	public String getNodeName() {
		return name;
	}

	/**
	 * getNodeType method
	 * 
	 * @return int
	 * 
	 * Returns one of :
	 * 
	 */
	public int getNodeType() {
		return CMNode.ATTRIBUTE_DECLARATION;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.jsp.core.contentmodel.tld.TLDAttributeDeclaration#getOwnerDocument()
	 */
	public CMDocument getOwnerDocument() {
		return fOwnerDocument;
	}

	/**
	 * getProperty method
	 * 
	 * @return java.lang.Object
	 * 
	 * Returns the object property described by the propertyName
	 * 
	 */
	public Object getProperty(String propertyName) {
		if (propertyName != null && propertyName.equals(JSP12TLDNames.DESCRIPTION)) {
			return getDescription(); // return attribute description
		}
		else if (propertyName.equals(TLDDocument.CM_KIND)) {
			return TLDDocument.JSP_TLD;
		}
		else if (propertyName.equals(JSP12TLDNames.SMALL_ICON) || propertyName.equals(JSP12TLDNames.LARGE_ICON)) {
			return getOwnerDocument().getProperty(propertyName);
		}
		return null;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public java.lang.String getRtexprvalue() {
		return rtexprvalue;
	}

	public String getType() {
		return type;
	}

	/**
	 * getUsage method
	 * 
	 * @return int OPTIONAL|REQUIRED
	 */
	public int getUsage() {
		return required ? REQUIRED : OPTIONAL;
	}

	/**
	 * @return Returns the isFragment.
	 */
	public boolean isFragment() {
		return fIsFragment;
	}

	/**
	 * 
	 * @return boolean
	 */
	public boolean isRequired() {
		return required;
	}

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

	/**
	 * @param isFragment
	 *            The isFragment to set.
	 */
	public void setFragment(boolean isFragment) {
		fIsFragment = isFragment;
	}

	/**
	 * 
	 * @param newId
	 *            java.lang.String
	 */
	public void setId(String newId) {
		id = newId;
	}

	public void setNodeName(String string) {
		name = string;
	}

	/**
	 * 
	 * @param newRequired
	 *            boolean
	 */
	public void setRequired(boolean newRequired) {
		required = newRequired;
	}

	/**
	 * 
	 * @param newRequired
	 *            boolean
	 */
	public void setRequiredString(String newRequired) {
		if (newRequired != null) {
			if (newRequired.equalsIgnoreCase(JSP12TLDNames.TRUE) || newRequired.equalsIgnoreCase(JSP12TLDNames.YES))
				setRequired(true);
			else if (newRequired.equalsIgnoreCase(JSP12TLDNames.FALSE) || newRequired.equalsIgnoreCase(JSP12TLDNames.NO))
				setRequired(false);
		}
	}

	/**
	 * 
	 * @param newRtexprvalue
	 *            java.lang.String
	 */
	public void setRtexprvalue(String newRtexprvalue) {
		rtexprvalue = newRtexprvalue;
	}

	public void setType(String type) {
		this.type = type;
	}

	/**
	 * supports method
	 * 
	 * @return boolean
	 * 
	 * Returns true if the CMNode supports a specified property
	 * 
	 */
	public boolean supports(String propertyName) {
		return propertyName == null || propertyName.equals(JSP12TLDNames.DESCRIPTION) || propertyName.equals(TLDDocument.CM_KIND) || propertyName.equals(JSP12TLDNames.SMALL_ICON) || propertyName.equals(JSP12TLDNames.LARGE_ICON);
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("\n\t " + super.toString()); //$NON-NLS-1$
		buffer.append("\n\t name:" + StringUtils.escape(getNodeName())); //$NON-NLS-1$
		// Boolean.toString(boolean) is introduced in 1.4
		// buffer.append("\n\t required:" +
		// StringUtils.escape(Boolean.toString(isRequired())));
		buffer.append("\n\t required:" + StringUtils.toString(isRequired())); //$NON-NLS-1$
		buffer.append("\n\t rtexpr:" + StringUtils.escape(getRtexprvalue())); //$NON-NLS-1$
		if (getId() != null)
			buffer.append("\n\t id:" + StringUtils.escape(getId())); //$NON-NLS-1$
		return buffer.toString();
	}
}

Back to the top