|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.microedition.m2g; |
|
20 |
|
21 import org.w3c.dom.*; |
|
22 import org.w3c.dom.svg.*; |
|
23 import org.w3c.dom.events.*; |
|
24 import com.nokia.mj.impl.rt.legacy.ToolkitInvoker; |
|
25 import java.io.IOException; |
|
26 import org.eclipse.swt.widgets.*; |
|
27 import org.eclipse.swt.widgets.Display; |
|
28 import com.nokia.mj.impl.rt.legacy.LegacyRtPort; |
|
29 import com.nokia.mj.impl.utils.Logger; |
|
30 |
|
31 public class M2GSVGElement extends M2GObject implements SVGElement |
|
32 { |
|
33 //-------------------------------------------------- |
|
34 // STATIC CONSTANTS |
|
35 //-------------------------------------------------- |
|
36 // Error constants |
|
37 static final String TYPE_IS_NULL_ESTR = |
|
38 "The type is null."; |
|
39 static final String LISTENER_IS_NULL_ESTR = |
|
40 "The listener is null."; |
|
41 static final String CAPTURE_NOT_SUPPORTED_ESTR = |
|
42 "The capture phase is not supported in SVG Tiny."; |
|
43 static final String ESWT_PACKAGE = |
|
44 "org.eclipse.swt.widgets.Display" ; |
|
45 static boolean iIsToolkitAvailable = false; |
|
46 static boolean iStaticUIToolkit = LCDUI_TOOLKIT; |
|
47 /* Optimization: static finals changed to local variables |
|
48 static final String TRAIT_IS_NULL_ESTR = |
|
49 "The trait is null."; |
|
50 static final String TRAIT_NOT_SUPPORTED_ON_ELEM_ESTR = |
|
51 "The trait is not supported on this element."; |
|
52 static final String TRAIT_NOT_SUPPORTED_IN_NS_ESTR = |
|
53 "The trait is not supported in this namespace."; |
|
54 static final String GET_FLOAT_MISMATCH_ESTR = |
|
55 "Trait's computed value cannot be converted to a float."; |
|
56 static final String SET_FLOAT_MISMATCH_ESTR = |
|
57 "Trait's value cannot be specified as a float."; |
|
58 static final String GET_MATRIX_MISMATCH_ESTR = |
|
59 "Trait's computed value cannot be converted to a SVGMatrix."; |
|
60 static final String SET_MATRIX_MISMATCH_ESTR = |
|
61 "Trait's value cannot be specified as a SVGMatrix."; |
|
62 static final String GET_PATH_MISMATCH_ESTR = |
|
63 "Trait's computed value cannot be converted to a SVGPath."; |
|
64 static final String SET_PATH_MISMATCH_ESTR = |
|
65 "Trait's value cannot be specified as a SVGPath."; |
|
66 static final String GET_RECT_MISMATCH_ESTR = |
|
67 "Trait's computed value cannot be converted to a SVGRect."; |
|
68 static final String SET_RECT_MISMATCH_ESTR = |
|
69 "Trait's value cannot be specified as a SVGRect."; |
|
70 static final String GET_RGB_MISMATCH_ESTR = |
|
71 "Trait's computed value cannot be converted to a SVGRGBColor."; |
|
72 static final String SET_RGB_MISMATCH_ESTR = |
|
73 "Trait's value cannot be specified as a SVGRGBColor."; |
|
74 static final String NS_NOT_SUPPORTED_ESTR = |
|
75 "The namespace is not supported."; |
|
76 static final String GET_TRAIT_NS_STRING_MISMATCH_ESTR = |
|
77 "Trait's computed value cannot be converted to a String."; |
|
78 static final String SET_TRAIT_NS_STRING_MISMATCH_ESTR = |
|
79 "Trait's value cannot be specified as a String."; |
|
80 static final String ID_IS_NULL_ESTR = |
|
81 "The id is null."; |
|
82 static final String EXISTING_ELEM_ID_CHANGE_ESTR = |
|
83 "Existing element id cannot be changed."; |
|
84 static final String ELEM_ID_EXIST_IN_DOCUMENT_ESTR = |
|
85 "Element id already exists in the document."; |
|
86 static final String INVALID_INPUT_VALUE_ESTR = |
|
87 "The input value is an invalid value for the given trait."; |
|
88 static final String VALUE_IS_NULL_ESTR = |
|
89 "Value cannot be set to null."; |
|
90 static final String SET_READONLY_MISMATCH_ESTR = |
|
91 "Attempt to change readonly trait."; |
|
92 static final String INVALID_VALUE_ESTR = |
|
93 "The value is invalid."; |
|
94 static final String INVALID_USE_ELEMENT_ESTR = |
|
95 "The <use> element is hooked into the document tree and the the value of xlink:href is set invalid."; |
|
96 static final String CANNOT_REMOVE_NODE_ESTR = |
|
97 "Cannot remove this type of node."; |
|
98 static final String CANNOT_REMOVE_NOT_CHILD_ESTR = |
|
99 "Not a child of this node."; |
|
100 static final String CANNOT_REMOVE_NON_NULL_ID_ESTR = |
|
101 "The element being removed or one of its decendants have non-null id."; |
|
102 static final String INSERT_NODE_OF_THAT_TYPE_ESTR = |
|
103 "Cannot insert node of that type."; |
|
104 static final String APPEND_DOCUMENT_ESTR = |
|
105 "Cannot append Document elements."; |
|
106 static final String DOCUMENT_HIERARCHY_ESTR = |
|
107 "Hierarchy request error in Document."; |
|
108 static final String CHILD_IS_WRONG_TYPE_ESTR = |
|
109 "Child is wrong type (Document)."; |
|
110 static final String CHILD_BELONG_TO_DIFFERENT_DOCUMENT_ESTR = |
|
111 "Child belongs to different document."; |
|
112 static final String CHILD_NOT_FOUND_ESTR = |
|
113 "The child to insert before doesn't exist in this current node."; |
|
114 static final String INVALID_ELEMENT_ID_VALUE = |
|
115 "Invalid element id value."; |
|
116 */ |
|
117 |
|
118 //-------------------------------------------------- |
|
119 // VARIABLES |
|
120 //-------------------------------------------------- |
|
121 protected M2GDocument iDocument; |
|
122 protected short iElementTypeId; |
|
123 |
|
124 //-------------------------------------------------- |
|
125 // METHODS |
|
126 //-------------------------------------------------- |
|
127 /** |
|
128 * Constructor |
|
129 * @param aHandle is native element handle |
|
130 * @param aDocument is a reference to a document that owns this element. |
|
131 */ |
|
132 M2GSVGElement(int aElementHandle, M2GDocument aDocument) |
|
133 { |
|
134 super(aElementHandle); |
|
135 iDocument = aDocument; |
|
136 doConstruct(); |
|
137 } |
|
138 |
|
139 |
|
140 /** |
|
141 * @see org.w3c.dom.events.EventTarget#addEventListener() |
|
142 */ |
|
143 public void addEventListener(String type, EventListener listener, boolean useCapture) |
|
144 { |
|
145 if (type == null || type.equals("")) |
|
146 { |
|
147 throw new NullPointerException(TYPE_IS_NULL_ESTR); |
|
148 } |
|
149 if (listener == null) |
|
150 { |
|
151 throw new NullPointerException(LISTENER_IS_NULL_ESTR); |
|
152 } |
|
153 if (useCapture == true) |
|
154 { |
|
155 throw new DOMException( |
|
156 DOMException.NOT_SUPPORTED_ERR, |
|
157 CAPTURE_NOT_SUPPORTED_ESTR); |
|
158 } |
|
159 iDocument.register(this, type, listener); |
|
160 } |
|
161 |
|
162 /** |
|
163 * @see org.w3c.dom.Node#appendChild() |
|
164 */ |
|
165 public Node appendChild(Node newChild) |
|
166 { |
|
167 // If refChild is null, newChild is inserted at the end of the list |
|
168 return insertBefore(newChild, null); // will inform about DOM changes |
|
169 } |
|
170 |
|
171 /** |
|
172 * Checks attribute validity |
|
173 * @param aAttributeTypeName |
|
174 * @return attribute's type id |
|
175 * @throws DOMException |
|
176 */ |
|
177 protected short check(String aAttributeTypeName) throws DOMException |
|
178 { |
|
179 short attributeTypeId = M2GSVGConstants.AT_UNDEFINED; |
|
180 if (aAttributeTypeName == null || aAttributeTypeName.equals("")) |
|
181 { |
|
182 Logger.ELOG(Logger.EJavaUI, |
|
183 "check() exception: " + /*SF*/"The trait is null."/*SF*/); |
|
184 throw new DOMException( |
|
185 DOMException.NOT_SUPPORTED_ERR, |
|
186 /*SF*/"The trait is null."/*SF*/); |
|
187 } |
|
188 // Converts attribute's name |
|
189 attributeTypeId = M2GSVGConstants.parseAttributeTypeId(aAttributeTypeName); |
|
190 // Checks that element has this attribute |
|
191 if (!M2GSVGConstants.checkElementAttribute(attributeTypeId, iElementTypeId)) |
|
192 { |
|
193 Logger.ELOG(Logger.EJavaUI, |
|
194 "check() exception: " + /*SF*/"The trait is not supported on this element."/*SF*/); |
|
195 throw new DOMException( |
|
196 DOMException.NOT_SUPPORTED_ERR, |
|
197 /*SF*/"The trait is not supported on this element."/*SF*/); |
|
198 } |
|
199 return attributeTypeId; |
|
200 } |
|
201 |
|
202 /** |
|
203 * @see com.nokia.microedition.m2g.M2GObject#doCheckValidity() |
|
204 */ |
|
205 public boolean doCheckValidity() |
|
206 { |
|
207 try |
|
208 { |
|
209 if (super.doCheckValidity() && |
|
210 (iDocument != null) && |
|
211 (iElementTypeId != M2GSVGConstants.EL_UNDEFINED)) |
|
212 { |
|
213 return true; |
|
214 } |
|
215 } |
|
216 catch (IOException e) |
|
217 { |
|
218 } |
|
219 return false; |
|
220 } |
|
221 |
|
222 /** |
|
223 * @see com.nokia.microedition.m2g.M2GObject#doCleanup() |
|
224 */ |
|
225 protected void doCleanup() |
|
226 { |
|
227 iDocument = null; |
|
228 iElementTypeId = M2GSVGConstants.EL_UNDEFINED; |
|
229 resetHandles(); |
|
230 } |
|
231 |
|
232 /** |
|
233 * @see com.nokia.microedition.m2g.M2GObject#doConstruct() |
|
234 */ |
|
235 public void doConstruct() |
|
236 { |
|
237 // No need to register for finalization |
|
238 // super.doConstruct(); |
|
239 iElementTypeId = _getElementTypeId( |
|
240 getNativeEventSourceHandle(), |
|
241 getNativeSVGProxyHandle(), getHandle(), iUIToolkit); |
|
242 } |
|
243 |
|
244 /** |
|
245 * Returns a document |
|
246 */ |
|
247 public M2GDocument getDocument() |
|
248 { |
|
249 return iDocument; |
|
250 } |
|
251 |
|
252 /* |
|
253 * Retuns element's type id |
|
254 * @return element's type id |
|
255 */ |
|
256 public short getElementTypeId() |
|
257 { |
|
258 return iElementTypeId; |
|
259 } |
|
260 |
|
261 /** |
|
262 * @see org.w3c.dom.svg.SVGElement#getFirstElementChild() |
|
263 */ |
|
264 public Element getFirstElementChild() throws DOMException |
|
265 { |
|
266 // Get child element's handle |
|
267 int childHandle = _getFirstElementChild( |
|
268 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), getHandle(), iUIToolkit); |
|
269 if (M2GObject.checkHandle(childHandle)) |
|
270 { |
|
271 return (Element)M2GSVGElement.buildElement(childHandle, iDocument); |
|
272 } |
|
273 return null; |
|
274 } |
|
275 |
|
276 /** |
|
277 * @see org.w3c.dom.svg.SVGElement#getFloatTrait() |
|
278 */ |
|
279 public float getFloatTrait(String name) throws DOMException |
|
280 { |
|
281 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
282 if (!iDocument.iConnectionRight) |
|
283 { |
|
284 Logger.ELOG(Logger.EJavaUI, "getFloatTrait() - access rights failure"); |
|
285 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
286 } |
|
287 short attributeTypeId = check(name); |
|
288 if (!M2GSVGConstants.isGetFloatTraitAllowed(attributeTypeId)) |
|
289 { |
|
290 throw new DOMException( |
|
291 DOMException.TYPE_MISMATCH_ERR, |
|
292 /*SF*/"Trait's computed value cannot be converted to a float."/*SF*/); |
|
293 } |
|
294 return _getFloatTrait( |
|
295 getNativeEventSourceHandle(), |
|
296 getNativeSVGProxyHandle(), getHandle(), attributeTypeId, iUIToolkit); |
|
297 } |
|
298 |
|
299 /** |
|
300 * @see org.w3c.dom.svg.SVGElement#getId() |
|
301 */ |
|
302 public String getId() |
|
303 { |
|
304 return _getStringTrait( |
|
305 getNativeEventSourceHandle(), |
|
306 getNativeSVGProxyHandle(), getHandle(), M2GSVGConstants.AT_ID, iUIToolkit); |
|
307 } |
|
308 |
|
309 /** |
|
310 * @see org.w3c.dom.Node#getLocalName() |
|
311 */ |
|
312 public String getLocalName() |
|
313 { |
|
314 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
315 if (!iDocument.iConnectionRight) |
|
316 { |
|
317 Logger.ELOG(Logger.EJavaUI, |
|
318 "getLocalName() - access rights failure"); |
|
319 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
320 } |
|
321 return M2GSVGConstants.parseElementTypeName(iElementTypeId); |
|
322 } |
|
323 |
|
324 /** |
|
325 * @see org.w3c.dom.svg.SVGElement#getMatrixTrait() |
|
326 */ |
|
327 public SVGMatrix getMatrixTrait(String name) |
|
328 { |
|
329 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
330 if (!iDocument.iConnectionRight) |
|
331 { |
|
332 Logger.ELOG(Logger.EJavaUI, |
|
333 "getMatrixTrait() - access rights failure"); |
|
334 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
335 } |
|
336 short attributeTypeId = check(name); |
|
337 if (!M2GSVGConstants.isGetMatrixTraitAllowed(attributeTypeId)) |
|
338 { |
|
339 throw new DOMException( |
|
340 DOMException.TYPE_MISMATCH_ERR, |
|
341 /*SF*/"Trait's computed value cannot be converted to a SVGMatrix."/*SF*/); |
|
342 } |
|
343 M2GSVGMatrix matrix = new M2GSVGMatrix(); |
|
344 // If an error is occurred, then no values are put in the |
|
345 // matrix array by the native method |
|
346 _getMatrixTrait( |
|
347 getNativeEventSourceHandle(), |
|
348 getNativeSVGProxyHandle(), |
|
349 getHandle(), |
|
350 attributeTypeId, |
|
351 matrix.getComponents(), |
|
352 iUIToolkit); |
|
353 return matrix; |
|
354 } |
|
355 |
|
356 /** |
|
357 * @see org.w3c.dom.Node#getNamespaceURI() |
|
358 */ |
|
359 public String getNamespaceURI() |
|
360 { |
|
361 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
362 if (!iDocument.iConnectionRight) |
|
363 { |
|
364 Logger.ELOG(Logger.EJavaUI, |
|
365 "getNamespaceURI() - access rights failure"); |
|
366 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
367 } |
|
368 return M2GSVGConstants.SVG_NAMESPACE_URI; |
|
369 /* |
|
370 return _getStringTrait( |
|
371 getNativeEventSourceHandle(), |
|
372 getNativeSVGProxyHandle(), |
|
373 getHandle(), |
|
374 id); |
|
375 */ |
|
376 } |
|
377 |
|
378 /** |
|
379 * @see org.w3c.dom.svg.SVGElement#getNextElementSibling() |
|
380 */ |
|
381 public Element getNextElementSibling() |
|
382 { |
|
383 int elementHandle = _getNextElementSibling( |
|
384 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), getHandle(),iUIToolkit); |
|
385 if (M2GObject.checkHandle(elementHandle)) |
|
386 { |
|
387 return M2GSVGElement.buildElement(elementHandle, iDocument); |
|
388 } |
|
389 return null; |
|
390 } |
|
391 |
|
392 /** |
|
393 * @see org.w3c.dom.svg.SVGElement#getParentNode() |
|
394 */ |
|
395 public Node getParentNode() |
|
396 { |
|
397 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
398 if (!iDocument.iConnectionRight) |
|
399 { |
|
400 Logger.ELOG(Logger.EJavaUI, |
|
401 "getParentNode() - access rights failure"); |
|
402 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
403 } |
|
404 int parentHandle = _getParent( |
|
405 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), getHandle(), iUIToolkit); |
|
406 if (M2GObject.checkHandle(parentHandle)) |
|
407 { |
|
408 return M2GSVGElement.buildElement(parentHandle, iDocument); |
|
409 } |
|
410 return null; |
|
411 } |
|
412 |
|
413 /** |
|
414 * @see org.w3c.dom.svg.SVGElement#getPathTrait() |
|
415 */ |
|
416 public SVGPath getPathTrait(String name) |
|
417 { |
|
418 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
419 if (!iDocument.iConnectionRight) |
|
420 { |
|
421 Logger.ELOG(Logger.EJavaUI, |
|
422 "getPathTrait() - access rights failure"); |
|
423 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
424 } |
|
425 short attributeTypeId = check(name); |
|
426 if (!M2GSVGConstants.isGetPathTraitAllowed(attributeTypeId)) |
|
427 { |
|
428 throw new DOMException( |
|
429 DOMException.TYPE_MISMATCH_ERR, |
|
430 /*SF*/"Trait's computed value cannot be converted to a SVGPath."/*SF*/); |
|
431 } |
|
432 int pathHandle = _getPathTrait( |
|
433 getNativeEventSourceHandle(), |
|
434 getNativeSVGProxyHandle(), |
|
435 getHandle(), |
|
436 attributeTypeId, |
|
437 iUIToolkit); |
|
438 if (pathHandle != 0) |
|
439 { |
|
440 // Path doesn't own the native object |
|
441 return new M2GSVGPath(pathHandle); |
|
442 } |
|
443 else |
|
444 { |
|
445 return null; |
|
446 } |
|
447 } |
|
448 |
|
449 /** |
|
450 * @see org.w3c.dom.svg.SVGElement#getRectTrait() |
|
451 */ |
|
452 public SVGRect getRectTrait(String name) |
|
453 { |
|
454 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
455 if (!iDocument.iConnectionRight) |
|
456 { |
|
457 Logger.ELOG(Logger.EJavaUI, |
|
458 "getRectTrait() - access rights failure"); |
|
459 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
460 } |
|
461 short attributeTypeId = check(name); |
|
462 if (!M2GSVGConstants.isGetRectTraitAllowed(attributeTypeId)) |
|
463 { |
|
464 throw new DOMException( |
|
465 DOMException.TYPE_MISMATCH_ERR, |
|
466 /*SF*/"Trait's computed value cannot be converted to a SVGRect."/*SF*/); |
|
467 } |
|
468 M2GSVGRect rect = new M2GSVGRect(); |
|
469 if (_getRectTrait( |
|
470 getNativeEventSourceHandle(), |
|
471 getNativeSVGProxyHandle(), |
|
472 getHandle(), |
|
473 attributeTypeId, |
|
474 rect.getComponents(),iUIToolkit) == -1) |
|
475 { |
|
476 Logger.LOG(Logger.EJavaUI, Logger.EInfo, |
|
477 "getRectTrait() - returns null!!"); |
|
478 return null; |
|
479 } |
|
480 else |
|
481 { |
|
482 return rect; |
|
483 } |
|
484 } |
|
485 |
|
486 /** |
|
487 * @see org.w3c.dom.svg.SVGElement#getRGBColorTrait() |
|
488 */ |
|
489 public SVGRGBColor getRGBColorTrait(String name) |
|
490 { |
|
491 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
492 if (!iDocument.iConnectionRight) |
|
493 { |
|
494 Logger.ELOG(Logger.EJavaUI, |
|
495 "getRGBColorTrait() - access rights failure"); |
|
496 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
497 } |
|
498 |
|
499 short attributeTypeId = check(name); |
|
500 if (!M2GSVGConstants.isGetRgbColorTraitAllowed(attributeTypeId)) |
|
501 { |
|
502 throw new DOMException( |
|
503 DOMException.TYPE_MISMATCH_ERR, |
|
504 /*SF*/"Trait's computed value cannot be converted to a SVGRGBColor."/*SF*/); |
|
505 } |
|
506 M2GSVGRGBColor rgb = new M2GSVGRGBColor(0, 0, 0); |
|
507 int result = _getColorTrait( |
|
508 getNativeEventSourceHandle(), |
|
509 getNativeSVGProxyHandle(), |
|
510 getHandle(), |
|
511 attributeTypeId, |
|
512 rgb.getComponents(), iUIToolkit); |
|
513 if (result == -1) |
|
514 { |
|
515 if ((attributeTypeId == M2GSVGConstants.AT_FILL) || |
|
516 (attributeTypeId == M2GSVGConstants.AT_COLOR)) |
|
517 { |
|
518 return new M2GSVGRGBColor(0, 0, 0); |
|
519 } |
|
520 else |
|
521 { |
|
522 return null; |
|
523 } |
|
524 } |
|
525 else if (result == 0) |
|
526 { |
|
527 return null; |
|
528 } |
|
529 return rgb; |
|
530 } |
|
531 |
|
532 /** |
|
533 * Get trait |
|
534 * @see org.w3c.dom.svg.SVGElement#getTrait() |
|
535 */ |
|
536 public String getTrait(String name) |
|
537 { |
|
538 return getTraitNS(null, name); |
|
539 } |
|
540 |
|
541 /** |
|
542 * Get trait |
|
543 * @see org.w3c.dom.svg.SVGElement#getTraitNS() |
|
544 */ |
|
545 public String getTraitNS(String namespaceURI, String name) |
|
546 { |
|
547 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
548 if (!iDocument.iConnectionRight) |
|
549 { |
|
550 Logger.ELOG(Logger.EJavaUI, |
|
551 "getTraitNS() - access rights failure"); |
|
552 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
553 } |
|
554 |
|
555 // Checks name validity |
|
556 short id = check(name); |
|
557 String value = null; |
|
558 |
|
559 // SVG traits are in the so-called element's 'per-element type partitions namespaces' |
|
560 // namespace must be always null |
|
561 // except for HREF traits which are from XLINK namespace? |
|
562 |
|
563 // XLINK_NAMESPACE |
|
564 if (namespaceURI != null && |
|
565 namespaceURI.equals(M2GSVGConstants.XLINK_NAMESPACE_URI)) |
|
566 { |
|
567 if (!M2GSVGConstants.isGetTraitNSAllowed(id)) |
|
568 { |
|
569 Logger.ELOG(Logger.EJavaUI, "getTraitNS() XLINK eception: " + |
|
570 "Trait's computed value cannot be converted to a String."); |
|
571 throw new DOMException( |
|
572 DOMException.TYPE_MISMATCH_ERR, |
|
573 "Trait's computed value cannot be converted to a String."); |
|
574 } |
|
575 |
|
576 value = _getStringTrait( |
|
577 getNativeEventSourceHandle(), |
|
578 getNativeSVGProxyHandle(), |
|
579 getHandle(), |
|
580 id, iUIToolkit); |
|
581 |
|
582 if (value == null) |
|
583 { |
|
584 value = ""; |
|
585 } |
|
586 |
|
587 return value; |
|
588 } |
|
589 |
|
590 // Checks namespace validity: namespace must be null |
|
591 if (namespaceURI != null) |
|
592 { |
|
593 Logger.ELOG(Logger.EJavaUI, |
|
594 "getTraitNS() - namespace IS NOT xlink but something else."); |
|
595 Logger.ELOG(Logger.EJavaUI, |
|
596 "getTraitNS() exception: " + /*SF*/"The namespace is not supported."/*SF*/); |
|
597 |
|
598 throw new DOMException( |
|
599 DOMException.NOT_SUPPORTED_ERR, |
|
600 "The namespace is not supported."); |
|
601 } |
|
602 |
|
603 // Checks that attribute is obtaineable as a string |
|
604 if (!M2GSVGConstants.isGetTraitNSStringAllowed(id)) |
|
605 { |
|
606 Logger.ELOG(Logger.EJavaUI, "getTraitNS() exception: " + |
|
607 "Trait's computed value cannot be converted to a String."); |
|
608 |
|
609 throw new DOMException( |
|
610 DOMException.TYPE_MISMATCH_ERR, |
|
611 "Trait's computed value cannot be converted to a String."); |
|
612 } |
|
613 |
|
614 if (id == M2GSVGConstants.AT_XLINKHREF) |
|
615 { |
|
616 Logger.ELOG(Logger.EJavaUI, "getTraitNS() exception: " |
|
617 + "The trait is not supported in this namespace."); |
|
618 |
|
619 throw new DOMException( |
|
620 DOMException.NOT_SUPPORTED_ERR, |
|
621 "The trait is not supported in this namespace."); |
|
622 } |
|
623 |
|
624 // Checks if attribute is in string format |
|
625 if ((id == M2GSVGConstants.AT_STRING) || |
|
626 (id == M2GSVGConstants.AT_VERSION) || |
|
627 (id == M2GSVGConstants.AT_BASEPROFILE) || |
|
628 (id == M2GSVGConstants.AT_TARGET) || |
|
629 (id == M2GSVGConstants.AT_FONTFAMILY)) |
|
630 { |
|
631 value = _getStringTrait( |
|
632 getNativeEventSourceHandle(), |
|
633 getNativeSVGProxyHandle(), |
|
634 getHandle(), |
|
635 id,iUIToolkit); |
|
636 } |
|
637 // Reads enum attribute |
|
638 else |
|
639 { |
|
640 short valueId = _getEnumTrait( |
|
641 getNativeEventSourceHandle(), |
|
642 getNativeSVGProxyHandle(), |
|
643 getHandle(), |
|
644 id, |
|
645 iUIToolkit); |
|
646 |
|
647 // Convert value id to string |
|
648 value = M2GSVGConstants.parseAttributeValueName(id, valueId); |
|
649 } |
|
650 |
|
651 if (value == null) |
|
652 { |
|
653 value = ""; |
|
654 } |
|
655 return value; |
|
656 } |
|
657 |
|
658 /* |
|
659 * Get element used from this element |
|
660 * @return Element. |
|
661 */ |
|
662 public SVGElement getUsedFromElement() |
|
663 { |
|
664 int elementHandle = _getUsedFromElement( |
|
665 getNativeEventSourceHandle(), |
|
666 getNativeSVGProxyHandle(), |
|
667 getHandle(),iUIToolkit); |
|
668 if (M2GObject.checkHandle(elementHandle)) |
|
669 { |
|
670 return M2GSVGElement.buildElement(elementHandle, iDocument); |
|
671 } |
|
672 return null; |
|
673 } |
|
674 |
|
675 |
|
676 /** |
|
677 * @see org.w3c.dom.Node#insertBefore |
|
678 */ |
|
679 public Node insertBefore(Node newChild, Node refChild) |
|
680 { |
|
681 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
682 if (!iDocument.iConnectionRight) |
|
683 { |
|
684 Logger.ELOG(Logger.EJavaUI, |
|
685 "insertBefore() - access rights failure"); |
|
686 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
687 } |
|
688 |
|
689 if (newChild == null) |
|
690 { |
|
691 Logger.ELOG(Logger.EJavaUI, |
|
692 "insertBefore() exception - new child is null"); |
|
693 throw new NullPointerException(); |
|
694 } |
|
695 if (newChild instanceof M2GDocument) |
|
696 { |
|
697 Logger.ELOG(Logger.EJavaUI, |
|
698 "insertBefore() exception - child is document"); |
|
699 throw new DOMException( |
|
700 DOMException.HIERARCHY_REQUEST_ERR, |
|
701 /*SF*/"Child is wrong type (Document)."/*SF*/); |
|
702 } |
|
703 |
|
704 if (!M2GSVGConstants.isAllowedToInsertElement(((M2GSVGElement)newChild).iElementTypeId)) |
|
705 { |
|
706 Logger.ELOG(Logger.EJavaUI, |
|
707 "insertBefore() exception - cannot insert this node type"); |
|
708 throw new DOMException( |
|
709 DOMException.NOT_SUPPORTED_ERR, |
|
710 /*SF*/"Cannot insert node of that type."/*SF*/); |
|
711 } |
|
712 |
|
713 if (!M2GSVGConstants.checkElementAsChild( |
|
714 iElementTypeId, ((M2GSVGElement)newChild).iElementTypeId)) |
|
715 { |
|
716 Logger.ELOG(Logger.EJavaUI, |
|
717 "insertBefore() exception - invalid parent-child relation"); |
|
718 throw new DOMException( |
|
719 DOMException.HIERARCHY_REQUEST_ERR, |
|
720 /*SF*/"Cannot insert node of that type."/*SF*/); |
|
721 } |
|
722 // Ensure that the new child candidate wouldn't be an ancestor of this element |
|
723 if (IsAncestor(newChild, this)) |
|
724 { |
|
725 Logger.ELOG(Logger.EJavaUI, |
|
726 "insertBefore() exception - is ancestor"); |
|
727 throw new DOMException( |
|
728 DOMException.HIERARCHY_REQUEST_ERR, |
|
729 /*SF*/"Hierarchy request error in Document."/*SF*/); |
|
730 } |
|
731 // Check that the child and this element belong to the same Document |
|
732 if (((M2GSVGElement)newChild).getDocument().getHandle() != iDocument.getHandle()) |
|
733 { |
|
734 Logger.ELOG(Logger.EJavaUI, |
|
735 "insertBefore() exception - document is not the same"); |
|
736 throw new DOMException( |
|
737 DOMException.WRONG_DOCUMENT_ERR, |
|
738 /*SF*/"Child belongs to different document."/*SF*/); |
|
739 } |
|
740 if ((refChild != null) && |
|
741 (((M2GSVGElement)refChild.getParentNode()).getHandle() != getHandle())) |
|
742 { |
|
743 Logger.ELOG(Logger.EJavaUI, |
|
744 "insertBefore() exception - ref child is not found"); |
|
745 throw new DOMException( |
|
746 DOMException.NOT_FOUND_ERR, |
|
747 /*SF*/"The child to insert before doesn't exist in this current node."/*SF*/); |
|
748 } |
|
749 // check that if <use> then xlink:href is an existing element id |
|
750 if (((M2GSVGElement)newChild).iElementTypeId == M2GSVGConstants.EL_USE) |
|
751 { |
|
752 String value = ((M2GSVGElement)newChild).getTraitNS( |
|
753 M2GSVGConstants.XLINK_NAMESPACE_URI, "href"); |
|
754 if (value.length() != 0) |
|
755 { |
|
756 if (!value.startsWith("#") || |
|
757 ((M2GSVGElement)newChild).iDocument.getElementById(value.substring(1)) == null) |
|
758 { |
|
759 Logger.ELOG(Logger.EJavaUI, |
|
760 "insertBefore() exception - \"href\" trait value=" |
|
761 + value + " is invalid"); |
|
762 throw new DOMException( |
|
763 DOMException.INVALID_STATE_ERR, |
|
764 /*SF*/"Invalid element id value."/*SF*/); |
|
765 } |
|
766 } |
|
767 } |
|
768 if (refChild == null) |
|
769 { |
|
770 _appendChild( |
|
771 getNativeEventSourceHandle(), |
|
772 getNativeSVGProxyHandle(), |
|
773 getHandle(), |
|
774 ((M2GSVGElement)newChild).getHandle(), iUIToolkit); |
|
775 } |
|
776 else |
|
777 { |
|
778 _insertBefore( |
|
779 getNativeEventSourceHandle(), |
|
780 getNativeSVGProxyHandle(), |
|
781 getHandle(), |
|
782 ((M2GSVGElement)newChild).getHandle(), |
|
783 ((M2GSVGElement) refChild).getHandle(),iUIToolkit); |
|
784 } |
|
785 String href = _getStringTrait( |
|
786 getNativeEventSourceHandle(), |
|
787 getNativeSVGProxyHandle(), |
|
788 ((M2GSVGElement)newChild).getHandle(), |
|
789 M2GSVGConstants.AT_XLINKHREF,iUIToolkit); |
|
790 // Need to call resource handler if element is elementindom, image, |
|
791 // and if it has an href attribute |
|
792 if ((href != null) && |
|
793 (((M2GSVGElement)newChild).iElementTypeId == M2GSVGConstants.EL_IMAGE) && |
|
794 iDocument.isElementInDOM(((M2GSVGElement)newChild).getHandle())) |
|
795 { |
|
796 // Call resource handler here |
|
797 iDocument.invokeResourceHandler(href); |
|
798 } |
|
799 |
|
800 // inform observer about changes in DOM only if element is in DOM |
|
801 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
802 |
|
803 return newChild; |
|
804 } |
|
805 |
|
806 /* |
|
807 * Check if used |
|
808 * @return True if used. |
|
809 */ |
|
810 public boolean isUsed() |
|
811 { |
|
812 return (_isUsed( |
|
813 getNativeEventSourceHandle(), |
|
814 getNativeSVGProxyHandle(), |
|
815 getHandle(),iUIToolkit) > 0 ? true : false); |
|
816 } |
|
817 |
|
818 /** |
|
819 * @see org.w3c.dom.events.EventTarget#removeEventListener() |
|
820 */ |
|
821 public void removeEventListener(String type, EventListener listener, boolean useCapture) |
|
822 { |
|
823 if (type == null || type.equals("") || listener == null) |
|
824 { |
|
825 throw new NullPointerException(); |
|
826 } |
|
827 if (useCapture == true) |
|
828 { |
|
829 throw new DOMException( |
|
830 DOMException.NOT_SUPPORTED_ERR, |
|
831 CAPTURE_NOT_SUPPORTED_ESTR); |
|
832 } |
|
833 iDocument.unregister(this, type, listener); |
|
834 } |
|
835 |
|
836 /** |
|
837 * @see org.w3c.dom.svg.SVGElement#setId() |
|
838 */ |
|
839 public void setId(String id) throws DOMException |
|
840 { |
|
841 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
842 if (!iDocument.iConnectionRight) |
|
843 { |
|
844 Logger.ELOG(Logger.EJavaUI, |
|
845 "setId() - access rights failure"); |
|
846 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
847 } |
|
848 if (id == null) |
|
849 { |
|
850 throw new NullPointerException(/*SF*/"The id is null."/*SF*/); |
|
851 } |
|
852 if (getId() != null) |
|
853 { |
|
854 throw new DOMException( |
|
855 DOMException.NO_MODIFICATION_ALLOWED_ERR, |
|
856 /*SF*/"Existing element id cannot be changed."/*SF*/); |
|
857 } |
|
858 if (iDocument.containsElement(id)) |
|
859 { |
|
860 throw new DOMException( |
|
861 DOMException.INVALID_ACCESS_ERR, |
|
862 /*SF*/"Element id already exists in the document."/*SF*/); |
|
863 } |
|
864 else |
|
865 { |
|
866 _setStringTrait( |
|
867 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), |
|
868 getHandle(), M2GSVGConstants.AT_ID, id,iUIToolkit); |
|
869 } |
|
870 } |
|
871 |
|
872 /** |
|
873 * @see org.w3c.dom.svg.SVGElement#setFloatTrait() |
|
874 */ |
|
875 public void setFloatTrait(String name, float value) |
|
876 { |
|
877 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
878 if (!iDocument.iConnectionRight) |
|
879 { |
|
880 Logger.ELOG(Logger.EJavaUI, |
|
881 "setFloatTrait() - access rights failure"); |
|
882 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
883 } |
|
884 |
|
885 short id = check(name); |
|
886 if (!M2GSVGConstants.isSetFloatTraitAllowed(id)) |
|
887 { |
|
888 Logger.ELOG(Logger.EJavaUI, |
|
889 "setFloatTrait() exception - set float (id=" + id + ") not allowed"); |
|
890 throw new DOMException( |
|
891 DOMException.TYPE_MISMATCH_ERR, |
|
892 /*SF*/"Trait's value cannot be specified as a float."/*SF*/); |
|
893 } |
|
894 if ((Float.isNaN(value)) || |
|
895 // value must be >= 1 |
|
896 (value < 1 && (id == M2GSVGConstants.AT_STROKEMITERLIMIT)) || |
|
897 // value must be >= 0 |
|
898 (value < 0 && (id == M2GSVGConstants.AT_FONTSIZE || |
|
899 id == M2GSVGConstants.AT_STROKEWIDTH || |
|
900 id == M2GSVGConstants.AT_HEIGHT || |
|
901 id == M2GSVGConstants.AT_WIDTH || |
|
902 id == M2GSVGConstants.AT_RX || |
|
903 id == M2GSVGConstants.AT_RY || |
|
904 id == M2GSVGConstants.AT_R))) |
|
905 { |
|
906 Logger.ELOG(Logger.EJavaUI, |
|
907 "setFloatTrait() exception - invalid value=" + value); |
|
908 throw new DOMException( |
|
909 DOMException.INVALID_ACCESS_ERR, |
|
910 /*SF*/"The input value is an invalid value for the given trait."/*SF*/); |
|
911 } |
|
912 _setFloatTrait(getNativeEventSourceHandle(), getNativeSVGProxyHandle(), |
|
913 getHandle(), id, value,iUIToolkit); |
|
914 |
|
915 // inform observer about changes in DOM only if element is in DOM |
|
916 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
917 } |
|
918 |
|
919 /** |
|
920 * @see org.w3c.dom.svg.SVGElement#setMatrixTrait() |
|
921 */ |
|
922 public void setMatrixTrait(String name, SVGMatrix matrix) |
|
923 { |
|
924 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
925 if (!iDocument.iConnectionRight) |
|
926 { |
|
927 Logger.ELOG(Logger.EJavaUI, |
|
928 "setMatrixTrait() - access rights failure"); |
|
929 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
930 } |
|
931 short id = check(name); |
|
932 if (!M2GSVGConstants.isSetMatrixTraitAllowed(id)) |
|
933 { |
|
934 throw new DOMException( |
|
935 DOMException.TYPE_MISMATCH_ERR, |
|
936 /*SF*/"Trait's value cannot be specified as a SVGMatrix."/*SF*/); |
|
937 } |
|
938 if ((matrix == null) || |
|
939 !(matrix instanceof M2GSVGMatrix)) |
|
940 { |
|
941 throw new DOMException( |
|
942 DOMException.INVALID_ACCESS_ERR, |
|
943 /*SF*/"The input value is an invalid value for the given trait."/*SF*/); |
|
944 } |
|
945 |
|
946 _setMatrixTrait(getNativeEventSourceHandle(), getNativeSVGProxyHandle(), |
|
947 getHandle(), id, |
|
948 ((M2GSVGMatrix)matrix).getComponents(),iUIToolkit); |
|
949 |
|
950 // inform observer about changes in DOM only if element is in DOM |
|
951 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
952 } |
|
953 |
|
954 /** |
|
955 * @see org.w3c.dom.svg.SVGElement#setPathTrait() |
|
956 */ |
|
957 public void setPathTrait(String name, SVGPath path) |
|
958 { |
|
959 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
960 if (!iDocument.iConnectionRight) |
|
961 { |
|
962 Logger.ELOG(Logger.EJavaUI, |
|
963 "setPathTrait() - access rights failure"); |
|
964 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
965 } |
|
966 short id = check(name); |
|
967 if (!M2GSVGConstants.isSetPathTraitAllowed(id)) |
|
968 { |
|
969 throw new DOMException( |
|
970 DOMException.TYPE_MISMATCH_ERR, |
|
971 /*SF*/"Trait's value cannot be specified as a SVGPath."/*SF*/); |
|
972 } |
|
973 if ((path == null) || |
|
974 !(path instanceof M2GSVGPath) || |
|
975 !((M2GSVGPath)path).doCheckValidity()) |
|
976 { |
|
977 Logger.ELOG(Logger.EJavaUI, |
|
978 "setPathTrait() - exception M2GSVGPath not valid"); |
|
979 throw new DOMException( |
|
980 DOMException.INVALID_ACCESS_ERR, |
|
981 /*SF*/"The input value is an invalid value for the given trait."/*SF*/); |
|
982 } |
|
983 |
|
984 _setPathTrait(getNativeEventSourceHandle(), getNativeSVGProxyHandle(), |
|
985 getHandle(), id, ((M2GSVGPath)path).getHandle(),iUIToolkit); |
|
986 |
|
987 // inform observer about changes in DOM only if element is in DOM |
|
988 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
989 } |
|
990 |
|
991 |
|
992 /** |
|
993 * @see org.w3c.dom.svg.SVGElement#setPathTrait() |
|
994 */ |
|
995 public void setRectTrait(String name, SVGRect rect) |
|
996 { |
|
997 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
998 if (!iDocument.iConnectionRight) |
|
999 { |
|
1000 Logger.ELOG(Logger.EJavaUI, |
|
1001 "setRectTrait() - access rights failure"); |
|
1002 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
1003 } |
|
1004 short id = check(name); |
|
1005 if (!M2GSVGConstants.isSetRectTraitAllowed(id)) |
|
1006 { |
|
1007 throw new DOMException( |
|
1008 DOMException.TYPE_MISMATCH_ERR, |
|
1009 /*SF*/"Trait's value cannot be specified as a SVGRect."/*SF*/); |
|
1010 } |
|
1011 if ((rect == null) || |
|
1012 (rect.getWidth() < 0 || rect.getHeight() < 0)) |
|
1013 { |
|
1014 throw new DOMException( |
|
1015 DOMException.INVALID_ACCESS_ERR, |
|
1016 /*SF*/"The input value is an invalid value for the given trait."/*SF*/); |
|
1017 } |
|
1018 |
|
1019 _setRectTrait( |
|
1020 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), getHandle(), id, |
|
1021 rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),iUIToolkit); |
|
1022 |
|
1023 // inform observer about changes in DOM only if element is in DOM |
|
1024 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
1025 } |
|
1026 |
|
1027 /** |
|
1028 * @see org.w3c.dom.svg.SVGElement#setRGBColorTrait() |
|
1029 */ |
|
1030 public void setRGBColorTrait(String name, SVGRGBColor color) |
|
1031 { |
|
1032 |
|
1033 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
1034 if (!iDocument.iConnectionRight) |
|
1035 { |
|
1036 Logger.ELOG(Logger.EJavaUI, |
|
1037 "setRGBColorTrait() - access rights failure"); |
|
1038 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
1039 } |
|
1040 short id = check(name); |
|
1041 if (!M2GSVGConstants.isSetRgbColorTraitAllowed(id)) |
|
1042 { |
|
1043 Logger.ELOG(Logger.EJavaUI, |
|
1044 "setRGBColorTrait() - exception: " + DOMException.TYPE_MISMATCH_ERR); |
|
1045 throw new DOMException( |
|
1046 DOMException.TYPE_MISMATCH_ERR, |
|
1047 /*SF*/"Trait's value cannot be specified as a SVGRGBColor."/*SF*/); |
|
1048 } |
|
1049 if (color == null) |
|
1050 { |
|
1051 Logger.ELOG(Logger.EJavaUI, |
|
1052 "setRGBColorTrait() - exception: " + DOMException.INVALID_ACCESS_ERR); |
|
1053 throw new DOMException( |
|
1054 DOMException.INVALID_ACCESS_ERR, |
|
1055 /*SF*/"The trait is null."/*SF*/); |
|
1056 } |
|
1057 |
|
1058 _setColorTrait( |
|
1059 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), getHandle(), id, |
|
1060 color.getRed(), color.getGreen(), color.getBlue(),iUIToolkit); |
|
1061 |
|
1062 // inform observer about changes in DOM only if element is in DOM |
|
1063 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
1064 } |
|
1065 |
|
1066 /** |
|
1067 * @see org.w3c.dom.svg.SVGElement#setTrait() |
|
1068 */ |
|
1069 public void setTrait(String name, String value) |
|
1070 { |
|
1071 setTraitNS(null, name, value); |
|
1072 } |
|
1073 |
|
1074 /** |
|
1075 * @see org.w3c.dom.svg.SVGElement#setTraitNS() |
|
1076 */ |
|
1077 public void setTraitNS(String namespaceURI, String name, String value) |
|
1078 { |
|
1079 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
1080 if (!iDocument.iConnectionRight) |
|
1081 { |
|
1082 Logger.ELOG(Logger.EJavaUI, |
|
1083 "setTraitNS() - access rights failure"); |
|
1084 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
1085 } |
|
1086 if (value == null) |
|
1087 { |
|
1088 throw new DOMException( |
|
1089 DOMException.INVALID_ACCESS_ERR, |
|
1090 /*SF*/"Value cannot be set to null."/*SF*/); |
|
1091 } |
|
1092 |
|
1093 short id = check(name); |
|
1094 |
|
1095 // SVG traits are in the so-called element's 'per-element type partitions namespaces' |
|
1096 // namespace must be always null |
|
1097 // except for HREF traits which are from XLINK namespace? |
|
1098 |
|
1099 if (namespaceURI != null && |
|
1100 namespaceURI.equals(M2GSVGConstants.XLINK_NAMESPACE_URI)) |
|
1101 { |
|
1102 if (!M2GSVGConstants.isGetTraitNSAllowed(id)) |
|
1103 { |
|
1104 throw new DOMException( |
|
1105 DOMException.TYPE_MISMATCH_ERR, |
|
1106 "Trait's value cannot be specified as a String."); |
|
1107 } |
|
1108 |
|
1109 // check that if <use> then xlink:href is an existing element id |
|
1110 if ((iElementTypeId == M2GSVGConstants.EL_USE) && |
|
1111 (iDocument.isElementInDOM(getHandle()))) |
|
1112 { |
|
1113 if ((value.length() <= 1) || |
|
1114 !value.startsWith("#") || |
|
1115 (iDocument.getElementById(value.substring(1)) == null)) |
|
1116 { |
|
1117 Logger.ELOG(Logger.EJavaUI, |
|
1118 "setTraitNS() - DOMException"); |
|
1119 throw new DOMException( |
|
1120 DOMException.INVALID_ACCESS_ERR, |
|
1121 /*SF*/"The <use> element is hooked into the document tree and the the value of xlink:href is set invalid."/*SF*/); |
|
1122 } |
|
1123 } |
|
1124 |
|
1125 _setStringTrait( |
|
1126 getNativeEventSourceHandle(), |
|
1127 getNativeSVGProxyHandle(), getHandle(), id, value,iUIToolkit); |
|
1128 |
|
1129 // inform observer about changes in DOM only if element is in DOM |
|
1130 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
1131 |
|
1132 // Check if element is in DOM and in that case invokes |
|
1133 // resource handler |
|
1134 if ((iElementTypeId == M2GSVGConstants.EL_IMAGE) && |
|
1135 (id == M2GSVGConstants.AT_XLINKHREF) && |
|
1136 (iDocument.isElementInDOM(getHandle()))) |
|
1137 { |
|
1138 if (!iDocument.containsExternalResourceURI(value)) |
|
1139 { |
|
1140 iDocument.invokeResourceHandler(value); |
|
1141 } |
|
1142 } |
|
1143 |
|
1144 return; |
|
1145 } // namespaceURI != null && namespaceURI.equals(M2GSVGConstants.XLINK_NAMESPACE_URI) |
|
1146 |
|
1147 // all traits except HREF must have no namespace |
|
1148 if (namespaceURI != null) |
|
1149 { |
|
1150 throw new DOMException( |
|
1151 DOMException.NOT_SUPPORTED_ERR, |
|
1152 "The namespace is not supported."); |
|
1153 } |
|
1154 |
|
1155 if ((id == M2GSVGConstants.AT_VERSION) || |
|
1156 (id == M2GSVGConstants.AT_BASEPROFILE)) |
|
1157 { |
|
1158 throw new DOMException( |
|
1159 DOMException.NO_MODIFICATION_ALLOWED_ERR, |
|
1160 /*SF*/"Attempt to change readonly trait."/*SF*/); |
|
1161 } |
|
1162 |
|
1163 if (id == M2GSVGConstants.AT_XLINKHREF) |
|
1164 { |
|
1165 throw new DOMException( |
|
1166 DOMException.NOT_SUPPORTED_ERR, |
|
1167 /*SF*/"The trait is not supported in this namespace."/*SF*/); |
|
1168 } |
|
1169 |
|
1170 if (!M2GSVGConstants.isSetTraitNSStringAllowed(id)) |
|
1171 { |
|
1172 throw new DOMException( |
|
1173 DOMException.TYPE_MISMATCH_ERR, |
|
1174 /*SF*/"Trait's value cannot be specified as a String."/*SF*/); |
|
1175 } |
|
1176 |
|
1177 short valueId = M2GSVGConstants.parseAttributeValueNameId(id, value); |
|
1178 |
|
1179 if (valueId == M2GSVGConstants.SVG_ERROR) |
|
1180 { |
|
1181 throw new DOMException( |
|
1182 DOMException.INVALID_ACCESS_ERR, |
|
1183 /*SF*/"The value is invalid."/*SF*/); |
|
1184 } |
|
1185 else if (valueId == M2GSVGConstants.TEXT_NOT_SHORT) |
|
1186 { |
|
1187 _setStringTrait( |
|
1188 getNativeEventSourceHandle(), |
|
1189 getNativeSVGProxyHandle(), getHandle(), id, value,iUIToolkit); |
|
1190 } |
|
1191 else |
|
1192 { |
|
1193 _setEnumTrait( |
|
1194 getNativeEventSourceHandle(), |
|
1195 getNativeSVGProxyHandle(), getHandle(), id, valueId,iUIToolkit); |
|
1196 } |
|
1197 |
|
1198 // inform observer about changes in DOM only if element is in DOM |
|
1199 iDocument.notifyDOMChangeObserver(iNativeHandle); |
|
1200 } |
|
1201 |
|
1202 /** |
|
1203 * @see org.w3c.dom.Node#removeChild |
|
1204 */ |
|
1205 public Node removeChild(Node oldChild) throws DOMException |
|
1206 { |
|
1207 // Optimization: if(!getDocument().getConnectionPolicy().getAccessRight()) |
|
1208 if (!iDocument.iConnectionRight) |
|
1209 { |
|
1210 Logger.ELOG(Logger.EJavaUI, |
|
1211 "removeChild() - access rights failure"); |
|
1212 throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR); |
|
1213 } |
|
1214 if (oldChild == null) |
|
1215 { |
|
1216 throw new NullPointerException(); |
|
1217 } |
|
1218 if (oldChild instanceof M2GDocument) |
|
1219 { |
|
1220 throw new DOMException( |
|
1221 DOMException.NOT_SUPPORTED_ERR, |
|
1222 /*SF*/"Cannot remove this type of node."/*SF*/); |
|
1223 } |
|
1224 |
|
1225 M2GSVGElement removableChild = (M2GSVGElement)oldChild; |
|
1226 |
|
1227 if (!M2GSVGConstants.isAllowedToRemoveElement( |
|
1228 removableChild.iElementTypeId)) |
|
1229 { |
|
1230 throw new DOMException( |
|
1231 DOMException.NOT_SUPPORTED_ERR, |
|
1232 /*SF*/"Cannot remove this type of node."/*SF*/); |
|
1233 } |
|
1234 M2GSVGElement parent = (M2GSVGElement)removableChild.getParentNode(); |
|
1235 if ((parent == null) || |
|
1236 (parent.getHandle() != getHandle())) |
|
1237 { |
|
1238 throw new DOMException( |
|
1239 DOMException.NOT_FOUND_ERR, |
|
1240 /*SF*/"Not a child of this node."/*SF*/); |
|
1241 } |
|
1242 // Check if removable |
|
1243 int result = _checkRemoveable( |
|
1244 getNativeEventSourceHandle(), |
|
1245 getNativeSVGProxyHandle(), |
|
1246 removableChild.getHandle(), iUIToolkit); |
|
1247 if (result <= 0) |
|
1248 { |
|
1249 throw new DOMException( |
|
1250 DOMException.INVALID_ACCESS_ERR, |
|
1251 /*SF*/"The element being removed or one of its decendants have non-null id."/*SF*/); |
|
1252 } |
|
1253 // The removedChildHandle handle should be same as the removableChild handle |
|
1254 int removedChildHandle = removedChildHandle = _removeChild( |
|
1255 getNativeEventSourceHandle(), getNativeSVGProxyHandle(), |
|
1256 getHandle(), removableChild.getHandle(), iUIToolkit); |
|
1257 // Remove the element from the live elements |
|
1258 removableChild.getDocument().unregisterLiveElement( |
|
1259 new Integer(removableChild.getHandle())); |
|
1260 |
|
1261 iDocument.notifyDOMChangeObserver(getHandle()); |
|
1262 |
|
1263 return removableChild; |
|
1264 } |
|
1265 |
|
1266 //-------------------------------------------------- |
|
1267 // STATIC METHODS |
|
1268 //-------------------------------------------------- |
|
1269 |
|
1270 /** |
|
1271 * Gets the current Ui toolkit using RuntimeInfoFactory object. |
|
1272 */ |
|
1273 public static boolean getCurrentUiToolkit() |
|
1274 { |
|
1275 if (!iIsToolkitAvailable) |
|
1276 { |
|
1277 String toolkit = LegacyRtPort.getRegisteredToolkit(); |
|
1278 if (ESWT_PACKAGE.equals(toolkit)) |
|
1279 { |
|
1280 // Current UITOOLKIT is eSWT |
|
1281 iStaticUIToolkit = eSWT_TOOLKIT; |
|
1282 } |
|
1283 else |
|
1284 { |
|
1285 // Current UITOOLKIT is LCDUI |
|
1286 iStaticUIToolkit = LCDUI_TOOLKIT; |
|
1287 } |
|
1288 iIsToolkitAvailable = true; |
|
1289 } |
|
1290 return iStaticUIToolkit; |
|
1291 } |
|
1292 /** |
|
1293 * Creates SVGElement instance according to the element type. |
|
1294 * Possible element types are: SVGElement, SVGLocatableElement, |
|
1295 * SVGSVGElement, SVGAnimationElement |
|
1296 */ |
|
1297 public static SVGElement buildElement(int aElementHandle, M2GDocument aDocument) |
|
1298 { |
|
1299 // Check native handle |
|
1300 if (!M2GObject.checkHandle(aElementHandle) || (aDocument == null)) |
|
1301 { |
|
1302 return null; |
|
1303 } |
|
1304 |
|
1305 // Check if the element already exists |
|
1306 SVGElement svgElement = aDocument.findLiveElement(new Integer(aElementHandle)); |
|
1307 if (svgElement != null) |
|
1308 { |
|
1309 return svgElement; |
|
1310 } |
|
1311 |
|
1312 String typeName = M2GSVGElement.getElementTypeName(aElementHandle, aDocument); |
|
1313 |
|
1314 if (M2GSVGConstants.isRootElement(typeName)) |
|
1315 { |
|
1316 svgElement = M2GSVGSVGElement.buildRootElement(aDocument); |
|
1317 } |
|
1318 else if (M2GSVGConstants.isLocatableElement(typeName)) |
|
1319 { |
|
1320 svgElement = new M2GSVGLocatableElement(aElementHandle, aDocument); |
|
1321 } |
|
1322 else if (M2GSVGConstants.isAnimatableElement(typeName)) |
|
1323 { |
|
1324 svgElement = new M2GSVGAnimationElement(aElementHandle, aDocument); |
|
1325 } |
|
1326 else |
|
1327 { |
|
1328 boolean lUIToolkit = getCurrentUiToolkit(); |
|
1329 String id = M2GSVGElement._getStringTrait( |
|
1330 M2GManager.getInstance(lUIToolkit).getEventSourceHandle(), |
|
1331 M2GManager.getInstance(lUIToolkit).getSVGProxyHandle(), |
|
1332 aElementHandle, |
|
1333 M2GSVGConstants.AT_ID, |
|
1334 lUIToolkit); |
|
1335 if ((id != null) && id.equals("text_use_svg_default_font")) |
|
1336 { |
|
1337 return buildElement( |
|
1338 M2GSVGElement._getNextElementSibling( |
|
1339 aDocument.getNativeEventSourceHandle(), |
|
1340 aDocument.getNativeSVGProxyHandle(), aElementHandle, lUIToolkit), |
|
1341 aDocument); |
|
1342 } |
|
1343 else |
|
1344 { |
|
1345 svgElement = new M2GSVGElement(aElementHandle, aDocument); |
|
1346 } |
|
1347 } |
|
1348 aDocument.registerLiveElement(svgElement, new Integer(aElementHandle)); |
|
1349 return svgElement; |
|
1350 } |
|
1351 |
|
1352 /** |
|
1353 * Helper function for appendChild and insertBefore |
|
1354 * returns true if "ancestor" is the same node as "child" or |
|
1355 * if "ancestor" is parent/ancestor of "child" else returns false |
|
1356 */ |
|
1357 private static final boolean IsAncestor(Node aAncestor, Node aChild) throws DOMException |
|
1358 { |
|
1359 boolean result = false; |
|
1360 if (aAncestor != null && aChild != null) |
|
1361 { |
|
1362 if (aChild instanceof M2GDocument) |
|
1363 { |
|
1364 throw new DOMException( |
|
1365 DOMException.HIERARCHY_REQUEST_ERR, |
|
1366 /*SF*/"Cannot append Document elements."/*SF*/); |
|
1367 } |
|
1368 if ((aChild instanceof M2GSVGElement) && (aAncestor instanceof M2GSVGElement)) |
|
1369 { |
|
1370 // Should check all types or just parent type??? |
|
1371 if (((M2GSVGElement)aAncestor).getHandle() == ((M2GSVGElement)aChild).getHandle()) |
|
1372 { |
|
1373 result = true; |
|
1374 } |
|
1375 else |
|
1376 { |
|
1377 result = IsAncestor(aAncestor, aChild.getParentNode()); |
|
1378 } |
|
1379 } |
|
1380 } |
|
1381 return result; |
|
1382 } |
|
1383 |
|
1384 |
|
1385 /** |
|
1386 * Helper function for removeChild. |
|
1387 * @returns false if the node "child" and all its children have non-null ids |
|
1388 * else returns true |
|
1389 */ |
|
1390 private static final boolean IsReadOnly(Node aChild) |
|
1391 { |
|
1392 if (aChild != null) |
|
1393 { |
|
1394 // Should check all types or just parent type??? |
|
1395 if ((aChild instanceof M2GSVGElement) || |
|
1396 (aChild instanceof SVGLocatableElement) || |
|
1397 (aChild instanceof SVGSVGElement)) |
|
1398 { |
|
1399 if (M2GSVGConstants.isElementReadOnly(((M2GSVGElement)aChild).getLocalName())) |
|
1400 { |
|
1401 return true; |
|
1402 } |
|
1403 return IsReadOnly(aChild.getParentNode()); |
|
1404 } |
|
1405 } |
|
1406 return false; |
|
1407 } |
|
1408 |
|
1409 /** |
|
1410 * Get element's type name |
|
1411 * @param aElementHandle |
|
1412 * @param aDocument |
|
1413 * @return element's type name |
|
1414 */ |
|
1415 public static String getElementTypeName(int aElementHandle, M2GDocument aDocument) |
|
1416 { |
|
1417 short elemenTypeId = M2GSVGConstants.EL_UNDEFINED; |
|
1418 boolean lUIToolkit = getCurrentUiToolkit(); |
|
1419 if (aDocument != null) |
|
1420 { |
|
1421 elemenTypeId = M2GSVGElement._getElementTypeId( |
|
1422 aDocument.getNativeEventSourceHandle(), |
|
1423 aDocument.getNativeSVGProxyHandle(), |
|
1424 aElementHandle, lUIToolkit); |
|
1425 } |
|
1426 else |
|
1427 { |
|
1428 elemenTypeId = M2GSVGElement._getElementTypeId( |
|
1429 M2GManager.getInstance(lUIToolkit).getEventSourceHandle(), |
|
1430 M2GManager.getInstance(lUIToolkit).getSVGProxyHandle(), |
|
1431 aElementHandle, |
|
1432 lUIToolkit); |
|
1433 } |
|
1434 |
|
1435 return M2GSVGConstants.parseElementTypeName(elemenTypeId); |
|
1436 } |
|
1437 |
|
1438 //-------------------------------------------------- |
|
1439 // NATIVE METHODS |
|
1440 //-------------------------------------------------- |
|
1441 private static native void _appendChild( |
|
1442 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, int aNewChild, boolean iUIToolkit); |
|
1443 |
|
1444 private static native int _checkRemoveable( |
|
1445 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, boolean iUIToolkit); |
|
1446 |
|
1447 static native int _getBBox( |
|
1448 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1449 short aAttributeTypeId, float[] aComponents, boolean iUIToolkit); |
|
1450 |
|
1451 private static native int _getColorTrait( |
|
1452 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1453 short aAttributeTypeId, int[] aColorComponents, boolean iUIToolkit); |
|
1454 |
|
1455 private static native short _getElementTypeId( |
|
1456 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, boolean iUIToolkit); |
|
1457 |
|
1458 static native short _getEnumTrait( |
|
1459 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, boolean iUIToolkit); |
|
1460 |
|
1461 private static native int _getFirstElementChild( |
|
1462 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, boolean iUIToolkit); |
|
1463 |
|
1464 private static native float _getFloatTrait( |
|
1465 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, boolean iUIToolkit); |
|
1466 |
|
1467 static native int _getMatrixTrait( |
|
1468 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1469 short aAttributeTypeId, float[] aComponents, boolean iUIToolkit); |
|
1470 |
|
1471 private static native int _getNextElementSibling( |
|
1472 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, boolean iUIToolkit); |
|
1473 |
|
1474 private static native int _getParent( |
|
1475 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle,boolean iUIToolkit); |
|
1476 |
|
1477 private static native int _getPathTrait( |
|
1478 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, boolean iUIToolkit); |
|
1479 |
|
1480 static native int _getRectTrait( |
|
1481 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1482 short aAttributeTypeId, float[] aComponents, boolean iUIToolkit); |
|
1483 |
|
1484 native static int _getRootElement( |
|
1485 int aEventSourceHandle, int aSvgProxyHandle, int aDocumentHandle,boolean iUIToolkit); |
|
1486 |
|
1487 static native void _getScreenBBox( |
|
1488 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, float[] aComponents, boolean iUIToolkit); |
|
1489 |
|
1490 protected static native String _getStringTrait( |
|
1491 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, boolean iUIToolkit); |
|
1492 |
|
1493 private static native int _getUsedFromElement( |
|
1494 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, boolean iUIToolkit); |
|
1495 |
|
1496 private static native void _insertBefore( |
|
1497 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1498 int aChildElementHandle, int aReferenceElementHandle, boolean iUIToolkit); |
|
1499 |
|
1500 private static native int _isUsed( |
|
1501 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle,boolean iUIToolkit); |
|
1502 |
|
1503 private static native int _removeChild( |
|
1504 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, int aChildElementHandle,boolean iUIToolkit); |
|
1505 |
|
1506 private static native void _setColorTrait( |
|
1507 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, |
|
1508 int aRed, int aGreen, int aBlue, boolean iUIToolkit); |
|
1509 |
|
1510 private static native void _setEnumTrait( |
|
1511 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, |
|
1512 short aValue,boolean iUIToolkit); |
|
1513 |
|
1514 private static native void _setFloatTrait( |
|
1515 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, float aValue, boolean iUIToolkit); |
|
1516 |
|
1517 static native void _setMatrixTrait( |
|
1518 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, |
|
1519 short aAttributeTypeId, float[] aComponents, boolean iUIToolkit); |
|
1520 |
|
1521 private static native void _setPathTrait( |
|
1522 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, int aPathHandle, boolean iUIToolkit); |
|
1523 |
|
1524 private static native void _setRectTrait( |
|
1525 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, |
|
1526 float aX, float aY, float aWidth, float aHeight, boolean iUIToolkit); |
|
1527 |
|
1528 private static native void _setStringTrait( |
|
1529 int aEventSourceHandle, int aSvgProxyHandle, int aElementHandle, short aAttributeTypeId, String aValue,boolean iUIToolkit); |
|
1530 |
|
1531 } |