Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1c2ca806d510c987c8bed373835e84a214657f6f (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
/*******************************************************************************
 * 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.document;



import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue;
import org.w3c.dom.DOMException;
import org.w3c.dom.css.Counter;
import org.w3c.dom.css.RGBColor;
import org.w3c.dom.css.Rect;


/**
 * 
 */
class CSSPrimitiveValueImpl extends CSSRegionContainer implements ICSSPrimitiveValue {

	protected short fPrimitiveType = CSS_UNKNOWN;
	private float fFloatValue = 0.0f;
	private String fStringValue = null;

	CSSPrimitiveValueImpl(CSSPrimitiveValueImpl that) {
		super(that);

		this.fPrimitiveType = that.fPrimitiveType;
		this.fFloatValue = that.fFloatValue;
		this.fStringValue = that.fStringValue;
	}

	CSSPrimitiveValueImpl(short primitiveType) {
		super();
		fPrimitiveType = primitiveType;
	}

	public ICSSNode cloneNode(boolean deep) {
		CSSPrimitiveValueImpl cloned = new CSSPrimitiveValueImpl(this);

		return cloned;
	}

	/**
	 * This method is used to get the Counter value. If this CSS value doesn't
	 * contain a counter value, a <code>DOMException</code> is raised.
	 * Modification to the corresponding style property can be achieved using
	 * the <code>Counter</code> interface.
	 * 
	 * @return The Counter value.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the CSS value doesn't
	 *                contain a Counter value (e.g. this is not
	 *                <code>CSS_COUNTER</code>).
	 */
	public Counter getCounterValue() throws DOMException {
		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
	}

	/**
	 * @return java.lang.String
	 */
	public java.lang.String getCSSValueText() {
		return getCssText();
	}

	/**
	 * A code defining the type of the value as defined above.
	 */
	public short getCssValueType() {
		if (getPrimitiveType() == CSS_INHERIT_PRIMITIVE) {
			return CSS_INHERIT;
		}
		else {
			return CSS_PRIMITIVE_VALUE;
		}
	}

	/**
	 * This method is used to get a float value in a specified unit. If this
	 * CSS value doesn't contain a float value or can't be converted into the
	 * specified unit, a <code>DOMException</code> is raised.
	 * 
	 * @param unitType
	 *            A unit code to get the float value. The unit code can only
	 *            be a float unit type (i.e. <code>CSS_NUMBER</code>,
	 *            <code>CSS_PERCENTAGE</code>,<code>CSS_EMS</code>,
	 *            <code>CSS_EXS</code>,<code>CSS_PX</code>,
	 *            <code>CSS_CM</code>,<code>CSS_MM</code>,
	 *            <code>CSS_IN</code>,<code>CSS_PT</code>,
	 *            <code>CSS_PC</code>,<code>CSS_DEG</code>,
	 *            <code>CSS_RAD</code>,<code>CSS_GRAD</code>,
	 *            <code>CSS_MS</code>,<code>CSS_S</code>,
	 *            <code>CSS_HZ</code>,<code>CSS_KHZ</code>,
	 *            <code>CSS_DIMENSION</code>).
	 * @return The float value in the specified unit.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the CSS value doesn't
	 *                contain a float value or if the float value can't be
	 *                converted into the specified unit.
	 */
	public float getFloatValue(short unitType) throws DOMException {
		switch (fPrimitiveType) {
			case CSS_NUMBER :
			case CSS_PERCENTAGE :
			case CSS_EMS :
			case CSS_EXS :
			case CSS_PX :
			case CSS_CM :
			case CSS_MM :
			case CSS_IN :
			case CSS_PT :
			case CSS_PC :
			case CSS_DEG :
			case CSS_RAD :
			case CSS_GRAD :
			case CSS_MS :
			case CSS_S :
			case CSS_HZ :
			case CSS_KHZ :
			case CSS_DIMENSION :
			case CSS_INTEGER :
			case CSS_HASH :
				return fFloatValue;
			default :
				throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
		}
	}

	/**
	 * Insert the method's description here. Creation date: (2001/01/17
	 * 12:12:18)
	 * 
	 * @return short
	 */
	public short getNodeType() {
		return PRIMITIVEVALUE_NODE;
	}

	/**
	 * The type of the value as defined by the constants specified above.
	 */
	public short getPrimitiveType() {
		return fPrimitiveType;
	}

	/**
	 * This method is used to get the Rect value. If this CSS value doesn't
	 * contain a rect value, a <code>DOMException</code> is raised.
	 * Modification to the corresponding style property can be achieved using
	 * the <code>Rect</code> interface.
	 * 
	 * @return The Rect value.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the CSS value doesn't
	 *                contain a Rect value. (e.g. this is not
	 *                <code>CSS_RECT</code>).
	 */
	public Rect getRectValue() throws DOMException {
		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
	}

	/**
	 * This method is used to get the RGB color. If this CSS value doesn't
	 * contain a RGB color value, a <code>DOMException</code> is raised.
	 * Modification to the corresponding style property can be achieved using
	 * the <code>RGBColor</code> interface.
	 * 
	 * @return the RGB color value.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the attached property
	 *                can't return a RGB color value (e.g. this is not
	 *                <code>CSS_RGBCOLOR</code>).
	 */
	public RGBColor getRGBColorValue() throws DOMException {
		throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
	}

	/**
	 * This method is used to get the string value. If the CSS value doesn't
	 * contain a string value, a <code>DOMException</code> is raised. Some
	 * properties (like 'font-family' or 'voice-family') convert a whitespace
	 * separated list of idents to a string.
	 * 
	 * @return The string value in the current unit. The current
	 *         <code>primitiveType</code> can only be a string unit type
	 *         (i.e. <code>CSS_STRING</code>,<code>CSS_URI</code>,
	 *         <code>CSS_IDENT</code> and <code>CSS_ATTR</code>).
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the CSS value doesn't
	 *                contain a string value.
	 */
	public String getStringValue() throws DOMException {
		switch (fPrimitiveType) {
			case CSS_STRING :
			case CSS_URI :
			case CSS_IDENT :
			case CSS_ATTR :
			case CSS_URANGE :
			case CSS_FORMAT :
			case CSS_LOCAL :
			case CSS_HASH :
			case CSS_COMMA :
			case CSS_SLASH :
			case CSS_INHERIT_PRIMITIVE :
				return fStringValue;
			default :
				throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
		}
	}

	/**
	 * 
	 */
	protected void notifyValueChanged(String oldValue) {
		// for model
		ICSSDocument doc = getContainerDocument();
		if (doc == null)
			return;
		CSSModelImpl model = (CSSModelImpl) doc.getModel();
		if (model == null)
			return;
		model.valueChanged(this, oldValue);

		// for adapters
		notify(CHANGE, new Short(fPrimitiveType), null, null, getStartOffset());
	}

	/**
	 * A method to set the float value with a specified unit. If the property
	 * attached with this value can not accept the specified unit or the float
	 * value, the value will be unchanged and a <code>DOMException</code>
	 * will be raised.
	 * 
	 * @param unitType
	 *            A unit code as defined above. The unit code can only be a
	 *            float unit type (i.e. <code>CSS_NUMBER</code>,
	 *            <code>CSS_PERCENTAGE</code>,<code>CSS_EMS</code>,
	 *            <code>CSS_EXS</code>,<code>CSS_PX</code>,
	 *            <code>CSS_CM</code>,<code>CSS_MM</code>,
	 *            <code>CSS_IN</code>,<code>CSS_PT</code>,
	 *            <code>CSS_PC</code>,<code>CSS_DEG</code>,
	 *            <code>CSS_RAD</code>,<code>CSS_GRAD</code>,
	 *            <code>CSS_MS</code>,<code>CSS_S</code>,
	 *            <code>CSS_HZ</code>,<code>CSS_KHZ</code>,
	 *            <code>CSS_DIMENSION</code>).
	 * @param floatValue
	 *            The new float value.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the attached property
	 *                doesn't support the float value or the unit type. <br>
	 *                NO_MODIFICATION_ALLOWED_ERR: Raised if this property is
	 *                readonly.
	 */
	public void setFloatValue(short unitType, float floatValue) throws DOMException {
		switch (unitType) {
			case CSS_NUMBER :
			case CSS_PERCENTAGE :
			case CSS_EMS :
			case CSS_EXS :
			case CSS_PX :
			case CSS_CM :
			case CSS_MM :
			case CSS_IN :
			case CSS_PT :
			case CSS_PC :
			case CSS_DEG :
			case CSS_RAD :
			case CSS_GRAD :
			case CSS_MS :
			case CSS_S :
			case CSS_HZ :
			case CSS_KHZ :
			case CSS_DIMENSION :
			case CSS_INTEGER :
				String oldValue = getCSSValueText();
				fPrimitiveType = unitType;
				fFloatValue = floatValue;
				notifyValueChanged(oldValue);
				break;
			default :
				throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
		}
	}

	/**
	 * A method to set the string value with the specified unit. If the
	 * property attached to this value can't accept the specified unit or the
	 * string value, the value will be unchanged and a
	 * <code>DOMException</code> will be raised.
	 * 
	 * @param stringType
	 *            A string code as defined above. The string code can only be
	 *            a string unit type (i.e. <code>CSS_STRING</code>,
	 *            <code>CSS_URI</code>,<code>CSS_IDENT</code>, and
	 *            <code>CSS_ATTR</code>).
	 * @param stringValue
	 *            The new string value.
	 * @exception DOMException
	 *                INVALID_ACCESS_ERR: Raised if the CSS value doesn't
	 *                contain a string value or if the string value can't be
	 *                converted into the specified unit. <br>
	 *                NO_MODIFICATION_ALLOWED_ERR: Raised if this property is
	 *                readonly.
	 */
	public void setStringValue(short stringType, String stringValue) throws DOMException {
		switch (stringType) {
			case CSS_STRING :
			case CSS_URI :
			case CSS_IDENT :
			case CSS_ATTR :
			case CSS_URANGE :
			case CSS_FORMAT :
			case CSS_LOCAL :
			case CSS_HASH :
			case CSS_COMMA :
			case CSS_SLASH :
			case CSS_INHERIT_PRIMITIVE :
				String oldValue = getCSSValueText();
				fPrimitiveType = stringType;
				fStringValue = stringValue;
				notifyValueChanged(oldValue);
				break;
			default :
				throw new DOMException(DOMException.INVALID_ACCESS_ERR, "");//$NON-NLS-1$
		}
	}

	/**
	 * Insert the method's description here. Creation date: (2001/01/24
	 * 15:06:25)
	 * 
	 * @param floatValue
	 *            float
	 * @exception org.w3c.dom.DOMException
	 *                The exception description.
	 */
	public void setValue(float floatValue) throws org.w3c.dom.DOMException {
		setFloatValue(getPrimitiveType(), floatValue);
	}

	/**
	 * Insert the method's description here. Creation date: (2001/01/24
	 * 15:06:25)
	 * 
	 * @param stringValue
	 *            java.lang.String
	 * @exception org.w3c.dom.DOMException
	 *                The exception description.
	 */
	public void setValue(java.lang.String stringValue) throws org.w3c.dom.DOMException {
		setStringValue(getPrimitiveType(), stringValue);
	}
}

Back to the top