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