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