80
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
80
|
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.events.*;
|
|
23 |
import org.w3c.dom.svg.SVGElement;
|
|
24 |
import java.io.IOException;
|
|
25 |
import java.util.Hashtable;
|
|
26 |
import java.lang.ref.WeakReference;
|
|
27 |
import java.util.Vector;
|
|
28 |
import java.util.Enumeration;
|
|
29 |
import javax.microedition.m2g.*;
|
|
30 |
import com.nokia.microedition.m2g.connection.*;
|
|
31 |
import com.nokia.mj.impl.utils.Logger;
|
|
32 |
|
|
33 |
public class M2GDocument extends M2GObject
|
|
34 |
implements Document, M2GConnectionPolicyHandler
|
|
35 |
{
|
|
36 |
//--------------------------------------------------
|
|
37 |
// STATIC CONSTANTS
|
|
38 |
//--------------------------------------------------
|
|
39 |
// Error constants
|
87
|
40 |
|
80
|
41 |
|
|
42 |
//--------------------------------------------------
|
|
43 |
// VARIABLES
|
|
44 |
//--------------------------------------------------
|
|
45 |
private M2GEventDispatcher iEventDispatcher = null;
|
|
46 |
private ExternalResourceHandler iResourceHandler = null;
|
|
47 |
private M2GSVGImage iImage = null;
|
|
48 |
private M2GSVGSVGElement iRootElement = null;
|
|
49 |
private final M2GLiveElements iLiveElements = new M2GLiveElements(true);
|
|
50 |
private M2GConnectionPolicy iConnectionPolicy =
|
|
51 |
M2GConnectionFactory.getDefaultPolicy();
|
|
52 |
boolean iConnectionRight = true;
|
|
53 |
Vector iExternalResources = new Vector();
|
|
54 |
|
|
55 |
/** A base url from where a document was downloaded */
|
|
56 |
String iBaseUrl;
|
|
57 |
|
|
58 |
/** The suffix of the url from where the document was open*/
|
|
59 |
String iSuffixUrl;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Observer to be notified about changes in DOM
|
|
63 |
* @see M2GDOMChangeObserver.notifyDOMChange()
|
|
64 |
*/
|
|
65 |
private M2GDOMChangeObserver iDOMChangeObserver = null;
|
|
66 |
|
|
67 |
//--------------------------------------------------
|
|
68 |
// METHODS
|
|
69 |
//--------------------------------------------------
|
|
70 |
/**
|
|
71 |
* Creates new document object. If aData is null or empty then
|
|
72 |
* an empty document is create.
|
|
73 |
* @param aImage Svg image
|
87
|
74 |
* @param aBaseUrl A base url from where a document is downloaded.
|
80
|
75 |
* @param aSuffixUrl A suffix url from where a document is downloaded
|
|
76 |
* @param aData Plain text svg data
|
|
77 |
*/
|
|
78 |
public M2GDocument(M2GSVGImage aImage, String aBaseUrl, String aSuffixUrl,
|
|
79 |
String aData)
|
|
80 |
{
|
|
81 |
super();
|
87
|
82 |
|
80
|
83 |
iImage = aImage;
|
|
84 |
iBaseUrl = aBaseUrl;
|
|
85 |
iSuffixUrl = aSuffixUrl;
|
|
86 |
|
|
87 |
setHandle(_createDocument(
|
|
88 |
getNativeSVGProxyHandle(),
|
|
89 |
aData)
|
|
90 |
);
|
|
91 |
|
|
92 |
doConstruct();
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* @see org.w3c.dom.Node#appendChild()
|
|
97 |
*/
|
|
98 |
public Node appendChild(Node newChild) throws DOMException
|
|
99 |
{
|
|
100 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
101 |
if (!iConnectionRight)
|
|
102 |
{
|
|
103 |
Logger.ELOG(Logger.EJavaUI, "appendChild() - access rights failure");
|
|
104 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
105 |
}
|
|
106 |
Logger.ELOG(Logger.EJavaUI, "appendChild() - exception: "
|
|
107 |
+ /*SF*/"Cannot appendChild to a Document node."/*SF*/);
|
|
108 |
throw new DOMException(
|
|
109 |
DOMException.HIERARCHY_REQUEST_ERR,
|
|
110 |
/*SF*/"Cannot appendChild to a Document node."/*SF*/);
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Appends external resource uri to internal container
|
|
115 |
* @param aUri External resource uri
|
|
116 |
* @return true if succeeds
|
|
117 |
*/
|
|
118 |
boolean appendExternalResourceURI(String aUri)
|
|
119 |
{
|
|
120 |
boolean result = false;
|
|
121 |
if (aUri != null && !aUri.equals(""))
|
|
122 |
{
|
|
123 |
synchronized (iExternalResources)
|
|
124 |
{
|
|
125 |
if (!iExternalResources.contains(aUri))
|
|
126 |
{
|
|
127 |
iExternalResources.addElement(aUri);
|
|
128 |
result = true;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, "appendExternalResourceURI() uri=" +
|
|
133 |
((aUri != null) ? aUri : "null") + ", result=" + result + " - end");
|
|
134 |
return result;
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Checks if document contains the element
|
|
139 |
* @param id
|
|
140 |
* @return true if document contains the element
|
|
141 |
*/
|
|
142 |
public boolean containsElement(String id)
|
|
143 |
{
|
|
144 |
if (id == null || id.equals(""))
|
|
145 |
{
|
|
146 |
return false;
|
|
147 |
}
|
|
148 |
int handle = _getElementById(
|
|
149 |
getNativeSVGProxyHandle(),
|
|
150 |
getHandle(), id);
|
|
151 |
return M2GObject.checkHandle(handle);
|
|
152 |
}
|
|
153 |
|
|
154 |
/**
|
|
155 |
* Check if external resource uri exists in internal container
|
|
156 |
* @param aUri External resource uri
|
|
157 |
* @return true if uri exists in container
|
|
158 |
*/
|
|
159 |
boolean containsExternalResourceURI(String aUri)
|
|
160 |
{
|
|
161 |
boolean result = false;
|
|
162 |
if (aUri != null && !aUri.equals(""))
|
|
163 |
{
|
|
164 |
synchronized (iExternalResources)
|
|
165 |
{
|
|
166 |
result = iExternalResources.contains(aUri);
|
|
167 |
}
|
|
168 |
}
|
|
169 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, "containsExternalResourceURI() uri=" +
|
|
170 |
((aUri != null) ? aUri : "null") + ", result=" + result + " - end");
|
|
171 |
return result;
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
/**
|
|
176 |
* @see org.w3c.dom.Document#createElementNS()
|
|
177 |
*/
|
|
178 |
public Element createElementNS(String namespaceURI, String qualifiedName)
|
|
179 |
{
|
|
180 |
if (namespaceURI == null || namespaceURI.equals(""))
|
|
181 |
{
|
|
182 |
Logger.ELOG(Logger.EJavaUI,
|
|
183 |
"createElementNS() exception because namespace is null. qualifiedName="
|
|
184 |
+ qualifiedName);
|
|
185 |
throw new NullPointerException(/*SF*/"The namespace URI is null."/*SF*/);
|
|
186 |
}
|
|
187 |
if (qualifiedName == null || qualifiedName.equals(""))
|
|
188 |
{
|
|
189 |
Logger.ELOG(Logger.EJavaUI,
|
|
190 |
"createElementNS() exception - " + namespaceURI + ", "
|
|
191 |
+ qualifiedName);
|
|
192 |
throw new NullPointerException(/*SF*/"The qualifiedName is null."/*SF*/);
|
|
193 |
}
|
|
194 |
// Checks element validity
|
|
195 |
if (!M2GSVGConstants.isQualifiedElement(qualifiedName))
|
|
196 |
{
|
|
197 |
Logger.ELOG(Logger.EJavaUI, "createElementNS() exception - "
|
|
198 |
+ namespaceURI + ", " + qualifiedName);
|
|
199 |
throw new DOMException(
|
|
200 |
DOMException.NOT_SUPPORTED_ERR,
|
|
201 |
/*SF*/"The type of element is not supported by the implementation."/*SF*/);
|
|
202 |
}
|
|
203 |
// Checks namespace validity
|
|
204 |
if (!namespaceURI.equals(M2GSVGConstants.SVG_NAMESPACE_URI))
|
|
205 |
{
|
|
206 |
Logger.ELOG(Logger.EJavaUI, "createElementNS() exception - "
|
|
207 |
+ namespaceURI + ", " + qualifiedName);
|
|
208 |
throw new DOMException(
|
|
209 |
DOMException.NOT_SUPPORTED_ERR,
|
|
210 |
/*SF*/"The URI is not the SVG namespace URI."/*SF*/);
|
|
211 |
}
|
|
212 |
// Creates native element. A native document owns the new element.
|
|
213 |
// NOTE: The element is NOT located in the DOM tree yet.
|
|
214 |
int elementHandle = _createElementNS(
|
|
215 |
getNativeSVGProxyHandle(),
|
|
216 |
M2GSVGConstants.parseElementTypeId(qualifiedName),
|
|
217 |
getHandle());
|
|
218 |
M2GSVGLocatableElement element = null;
|
|
219 |
// Checks native handle validity
|
|
220 |
if (M2GObject.checkHandle(elementHandle))
|
|
221 |
{
|
|
222 |
// Creates java element object
|
|
223 |
element = new M2GSVGLocatableElement(elementHandle, this);
|
|
224 |
registerLiveElement(element, new Integer(elementHandle));
|
|
225 |
}
|
|
226 |
else
|
|
227 |
{
|
|
228 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
229 |
"createElementNS(): " + qualifiedName + " - end, NOK!!!");
|
|
230 |
}
|
|
231 |
return element;
|
|
232 |
}
|
|
233 |
|
|
234 |
/**
|
|
235 |
* Checks document validity.
|
|
236 |
* @return true if valid
|
|
237 |
*/
|
|
238 |
public boolean doCheckValidity() throws IOException
|
|
239 |
{
|
|
240 |
boolean result = false;
|
|
241 |
if (isHandleValid())
|
|
242 |
{
|
|
243 |
M2GSVGSVGElement root = getRootElement();
|
|
244 |
if (root != null)
|
|
245 |
{
|
|
246 |
// Check svg version and base profile
|
|
247 |
root.checkVersionAndProfile();
|
|
248 |
result = true;
|
|
249 |
}
|
|
250 |
}
|
|
251 |
return result;
|
|
252 |
}
|
|
253 |
|
|
254 |
/**
|
|
255 |
* Cleanup
|
|
256 |
* @see com.nokia.microedition.m2g.M2GObject#doCleanup()
|
|
257 |
*/
|
|
258 |
public void doCleanup()
|
|
259 |
{
|
|
260 |
if (isHandleValid())
|
|
261 |
{
|
|
262 |
_deleteDocument(
|
|
263 |
getNativeSVGProxyHandle(),
|
|
264 |
getHandle());
|
|
265 |
}
|
|
266 |
iImage = null;
|
|
267 |
if (iEventDispatcher != null)
|
|
268 |
{
|
|
269 |
iEventDispatcher.clear();
|
|
270 |
iEventDispatcher = null;
|
|
271 |
}
|
|
272 |
resetHandles();
|
|
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* @see com.nokia.microedition.m2g.M2GObject#doConstruct()
|
|
277 |
*/
|
|
278 |
protected void doConstruct()
|
|
279 |
{
|
|
280 |
super.doConstruct();
|
|
281 |
iEventDispatcher = new M2GEventDispatcher();
|
|
282 |
}
|
|
283 |
|
|
284 |
/**
|
|
285 |
* Find an element from the handle-to-element map.
|
|
286 |
* @see M2GLiveElements#findElement()
|
|
287 |
*/
|
|
288 |
public SVGElement findLiveElement(Integer aElementHandle)
|
|
289 |
{
|
|
290 |
return iLiveElements.findElement(aElementHandle);
|
|
291 |
}
|
|
292 |
|
|
293 |
/**
|
|
294 |
* Get connection policy
|
|
295 |
* @see M2GConnectionListener#getConnectionPolicy()
|
|
296 |
*/
|
|
297 |
public M2GConnectionPolicy getConnectionPolicy()
|
|
298 |
{
|
|
299 |
return iConnectionPolicy;
|
|
300 |
}
|
|
301 |
|
|
302 |
/**
|
|
303 |
* @see org.w3c.dom.Document#getDocumentElement()
|
|
304 |
*/
|
|
305 |
public Element getDocumentElement()
|
|
306 |
{
|
|
307 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
308 |
if (!iConnectionRight)
|
|
309 |
{
|
|
310 |
Logger.ELOG(Logger.EJavaUI,
|
|
311 |
"getDocumentElement() - access rights failure");
|
|
312 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
313 |
}
|
|
314 |
return getRootElement();
|
|
315 |
}
|
|
316 |
|
|
317 |
/**
|
|
318 |
* @see org.w3c.dom.Document#getElementById()
|
|
319 |
*/
|
|
320 |
public Element getElementById(String id)
|
|
321 |
{
|
|
322 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
323 |
if (!iConnectionRight)
|
|
324 |
{
|
|
325 |
Logger.ELOG(Logger.EJavaUI, "getElementById() - access rights failure");
|
|
326 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
327 |
}
|
|
328 |
if (id == null || id.equals(""))
|
|
329 |
{
|
|
330 |
Logger.ELOG(Logger.EJavaUI, "getElementById() - exception");
|
|
331 |
throw new NullPointerException(/*SF*/"The ID is null."/*SF*/);
|
|
332 |
}
|
|
333 |
int elementHandle = _getElementById(
|
|
334 |
getNativeSVGProxyHandle(),
|
|
335 |
getHandle(),
|
87
|
336 |
id);
|
80
|
337 |
return M2GSVGElement.buildElement(elementHandle, this);
|
|
338 |
}
|
|
339 |
|
|
340 |
/**
|
|
341 |
* Returns the image
|
|
342 |
*/
|
|
343 |
public M2GSVGImage getImage()
|
|
344 |
{
|
|
345 |
return iImage;
|
|
346 |
}
|
|
347 |
|
|
348 |
/**
|
|
349 |
* @see org.w3c.dom.Node#getLocalName()
|
|
350 |
*/
|
|
351 |
public String getLocalName()
|
|
352 |
{
|
|
353 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
354 |
if (!iConnectionRight)
|
|
355 |
{
|
|
356 |
Logger.ELOG(Logger.EJavaUI, "getLocalName() - access rights failure");
|
|
357 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
358 |
}
|
|
359 |
return null;
|
|
360 |
}
|
|
361 |
|
|
362 |
/**
|
|
363 |
* @see org.w3c.dom.Node#getNamespaceURI()
|
|
364 |
*/
|
|
365 |
public String getNamespaceURI()
|
|
366 |
{
|
|
367 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
368 |
if (!iConnectionRight)
|
|
369 |
{
|
|
370 |
Logger.ELOG(Logger.EJavaUI, "getNamespaceURI() - access rights failure");
|
|
371 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
372 |
}
|
|
373 |
return null;
|
|
374 |
}
|
|
375 |
|
|
376 |
/**
|
|
377 |
* @see org.w3c.dom.Node#getParentNode()
|
|
378 |
*/
|
|
379 |
public Node getParentNode()
|
|
380 |
{
|
|
381 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
382 |
if (!iConnectionRight)
|
|
383 |
{
|
|
384 |
Logger.ELOG(Logger.EJavaUI,
|
|
385 |
"getParentNode() - access rights failure");
|
|
386 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
387 |
}
|
|
388 |
return null;
|
|
389 |
}
|
|
390 |
|
|
391 |
/**
|
|
392 |
* Get root element
|
|
393 |
* @return M2GSVGSVGElement
|
|
394 |
*/
|
|
395 |
public M2GSVGSVGElement getRootElement()
|
|
396 |
{
|
|
397 |
if (iRootElement == null)
|
|
398 |
{
|
|
399 |
iRootElement = M2GSVGSVGElement.buildRootElement(this);
|
|
400 |
}
|
|
401 |
return iRootElement;
|
|
402 |
}
|
|
403 |
|
|
404 |
/**
|
|
405 |
* @see javax.microedition.m2g.ScalableImage#getViewportHeight()
|
|
406 |
*/
|
|
407 |
public int getViewportHeight()
|
|
408 |
{
|
|
409 |
return _getViewportHeight(
|
|
410 |
getNativeSVGProxyHandle(),
|
|
411 |
getHandle());
|
|
412 |
}
|
|
413 |
|
|
414 |
/**
|
|
415 |
* @see javax.microedition.m2g.ScalableImage#getViewportWidth()
|
|
416 |
*/
|
|
417 |
public int getViewportWidth()
|
|
418 |
{
|
|
419 |
return _getViewportWidth(
|
|
420 |
getNativeSVGProxyHandle(),
|
87
|
421 |
getHandle());
|
80
|
422 |
}
|
|
423 |
|
|
424 |
|
|
425 |
/**
|
|
426 |
* Called by SVGImage upon creating an Event instance
|
|
427 |
* Calls the handleEvent() of all the listeners of the event
|
|
428 |
*/
|
|
429 |
public void handleEvent(Event aEvent)
|
|
430 |
{
|
|
431 |
iEventDispatcher.handleEvent(aEvent);
|
|
432 |
}
|
|
433 |
|
|
434 |
/**
|
|
435 |
* @see org.w3c.dom.Node#insertBefore()
|
|
436 |
*/
|
|
437 |
public Node insertBefore(Node newChild, Node refChild)
|
|
438 |
{
|
|
439 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
440 |
if (!iConnectionRight)
|
|
441 |
{
|
|
442 |
Logger.ELOG(Logger.EJavaUI, "insertBefore() - access rights failure");
|
|
443 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
444 |
}
|
|
445 |
|
|
446 |
Logger.ELOG(Logger.EJavaUI, "insertBefore() DOMException");
|
|
447 |
throw new DOMException(
|
|
448 |
DOMException.HIERARCHY_REQUEST_ERR,
|
|
449 |
/*SF*/"Cannot insertBefore a Document node."/*SF*/);
|
|
450 |
}
|
|
451 |
|
|
452 |
/**
|
|
453 |
* Checks if element is in DOM
|
|
454 |
* @param aElementHandle -
|
|
455 |
* @return true if element is in DOM
|
|
456 |
*/
|
|
457 |
public boolean isElementInDOM(int aElementHandle)
|
|
458 |
{
|
|
459 |
if (!M2GObject.checkHandle(aElementHandle))
|
|
460 |
{
|
|
461 |
return false;
|
|
462 |
}
|
|
463 |
return (_isElementInDOM(
|
|
464 |
getNativeSVGProxyHandle(),
|
|
465 |
getHandle(),
|
|
466 |
aElementHandle) > 0 ? true : false);
|
|
467 |
}
|
|
468 |
|
|
469 |
/**
|
|
470 |
* The external resource handler is invoked
|
|
471 |
* for any external resource referenced in the document.
|
|
472 |
* @param aUri External resource referenced in the document
|
|
473 |
*/
|
|
474 |
public void invokeResourceHandler(String aUri)
|
|
475 |
{
|
|
476 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, "invokeResourceHandler() - URI="
|
|
477 |
+ aUri + " - begin");
|
|
478 |
|
|
479 |
if ((iImage != null) && (iResourceHandler != null) &&
|
|
480 |
(aUri != null) && (aUri.length() > 4))
|
|
481 |
{
|
|
482 |
StringBuffer urlBuf = new StringBuffer();
|
|
483 |
// The uri format for external resource must include the base url
|
|
484 |
// from which the document was loaded. It's also checked that the
|
|
485 |
// url read from svg doesn't contain already the base part.
|
|
486 |
if ((iBaseUrl != null) &&
|
|
487 |
!iBaseUrl.equals("") &&
|
|
488 |
(aUri.indexOf(iBaseUrl) == -1))
|
|
489 |
{
|
|
490 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
491 |
"invokeResourceHandler() append base url=" + iBaseUrl);
|
|
492 |
urlBuf.append(iBaseUrl);
|
|
493 |
}
|
|
494 |
|
|
495 |
urlBuf.append(aUri);
|
|
496 |
|
|
497 |
// append the url suffix in case of drm open mode
|
|
498 |
if (iSuffixUrl != null && !iSuffixUrl.equals(""))
|
|
499 |
{
|
|
500 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
501 |
"invokeResourceHandler() append suffix url=" + iSuffixUrl);
|
|
502 |
urlBuf.append(iSuffixUrl);
|
|
503 |
}
|
|
504 |
|
|
505 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
506 |
"invokeResourceHandler() handler uri=" + urlBuf.toString());
|
|
507 |
|
|
508 |
iResourceHandler.requestResource(iImage, urlBuf.toString());
|
|
509 |
appendExternalResourceURI(aUri);
|
|
510 |
}
|
|
511 |
|
|
512 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
513 |
"invokeResourceHandler() - URI:" + aUri + " - end");
|
|
514 |
}
|
|
515 |
|
|
516 |
/**
|
|
517 |
* Registers an event target and an event listener.
|
|
518 |
* @param aTarget Target element
|
|
519 |
* @param aType Event type
|
|
520 |
* @param aListener Event listener
|
|
521 |
*/
|
|
522 |
void register(EventTarget aTarget, String aType, EventListener aListener)
|
|
523 |
{
|
|
524 |
iEventDispatcher.register(aTarget, aType, aListener);
|
|
525 |
}
|
|
526 |
|
|
527 |
/**
|
|
528 |
* Register element
|
|
529 |
* @see M2GLiveElements#registerElement()
|
|
530 |
*/
|
|
531 |
public void registerLiveElement(SVGElement aElement, Integer aElementHandle)
|
|
532 |
{
|
|
533 |
iLiveElements.registerElement(aElement, aElementHandle);
|
|
534 |
}
|
|
535 |
|
|
536 |
/**
|
|
537 |
* @see org.w3c.dom.Node#removeChild()
|
|
538 |
*/
|
|
539 |
public Node removeChild(Node oldChild) throws DOMException
|
|
540 |
{
|
|
541 |
// Optimization: if(!getConnectionPolicy().getAccessRight())
|
|
542 |
if (!iConnectionRight)
|
|
543 |
{
|
|
544 |
Logger.ELOG(Logger.EJavaUI, "removeChild() - access rights failure");
|
|
545 |
throw new SecurityException(M2GSVGConstants.ACCESS_RIGHTS_ESTR);
|
|
546 |
}
|
|
547 |
Logger.ELOG(Logger.EJavaUI, "removeChild() DOMException");
|
|
548 |
throw new DOMException(
|
|
549 |
DOMException.NOT_SUPPORTED_ERR,
|
|
550 |
/*SF*/"Cannot removeChild from a Document node."/*SF*/);
|
|
551 |
}
|
|
552 |
|
|
553 |
/**
|
|
554 |
* Removes external resource uri from internal container
|
|
555 |
* @param aUri External resource uri
|
|
556 |
* @return true if succeeds
|
|
557 |
*/
|
|
558 |
boolean removeExternalResourceURI(String aUri)
|
|
559 |
{
|
|
560 |
boolean result = false;
|
|
561 |
if (aUri != null && !aUri.equals(""))
|
|
562 |
{
|
|
563 |
synchronized (iExternalResources)
|
|
564 |
{
|
|
565 |
result = iExternalResources.removeElement(aUri);
|
|
566 |
}
|
|
567 |
}
|
|
568 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
569 |
"removeExternalResourceURI() uri="
|
|
570 |
+ ((aUri != null) ? aUri : "null") + ", result=" + result + " - end");
|
|
571 |
return result;
|
|
572 |
}
|
|
573 |
|
|
574 |
/*
|
|
575 |
* @see com.nokia.microedition.m2g.M2GSVGImage#requestCompleted()
|
|
576 |
*/
|
|
577 |
public int requestCompleted(String aUri, byte[] aResourceData)
|
|
578 |
{
|
|
579 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
580 |
"requestCompleted() uri=" + aUri + " - begin");
|
|
581 |
// If the aUri contains a base part it will be cut off
|
|
582 |
if (!aUri.equals("") &&
|
|
583 |
(iBaseUrl != null) &&
|
|
584 |
!containsExternalResourceURI(aUri) &&
|
|
585 |
(aUri.indexOf(iBaseUrl, 0) != -1))
|
|
586 |
{
|
|
587 |
aUri = aUri.substring(iBaseUrl.length(), aUri.length());
|
|
588 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
589 |
"requestCompleted() uri when base part is cut off=" + aUri);
|
|
590 |
}
|
|
591 |
|
|
592 |
// Execute tha request command.
|
|
593 |
int status = _requestCompleted(
|
|
594 |
getNativeSVGProxyHandle(),
|
|
595 |
getHandle(), aUri, aResourceData);
|
|
596 |
if ((status == 0) || aUri.equals(""))
|
|
597 |
{
|
|
598 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
599 |
"requestCompleted() remove URI=" + aUri);
|
|
600 |
removeExternalResourceURI(aUri);
|
|
601 |
}
|
|
602 |
return status;
|
|
603 |
}
|
|
604 |
|
|
605 |
/**
|
|
606 |
* Set connection policy
|
|
607 |
* @see M2GConnectionListener#setConnectionPolicy()
|
|
608 |
*/
|
|
609 |
public void setConnectionPolicy(M2GConnectionPolicy aConnectionPolicy)
|
|
610 |
{
|
|
611 |
iConnectionPolicy = aConnectionPolicy;
|
|
612 |
if (iConnectionPolicy != null)
|
|
613 |
{
|
|
614 |
iConnectionRight = iConnectionPolicy.getAccessRight();
|
|
615 |
}
|
|
616 |
else
|
|
617 |
{
|
|
618 |
iConnectionRight = true;
|
|
619 |
}
|
|
620 |
}
|
|
621 |
|
|
622 |
/**
|
|
623 |
* Set image
|
|
624 |
* @param aImage Image
|
|
625 |
*/
|
|
626 |
public void setImage(M2GSVGImage aImage)
|
|
627 |
{
|
|
628 |
iImage = aImage;
|
|
629 |
}
|
|
630 |
|
|
631 |
/**
|
|
632 |
* Set external resource handler
|
|
633 |
* @param aHandler External resource handler
|
|
634 |
*/
|
|
635 |
public void setResourceHandler(ExternalResourceHandler aHandler)
|
|
636 |
{
|
|
637 |
iResourceHandler = aHandler;
|
|
638 |
}
|
|
639 |
|
|
640 |
/**
|
|
641 |
* @see javax.microedition.m2g.ScalableImage#setViewportHeight()
|
|
642 |
*/
|
|
643 |
public void setViewportHeight(int height)
|
|
644 |
{
|
|
645 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
646 |
"setViewportHeight():" + height + " - begin");
|
|
647 |
if (height < 0)
|
|
648 |
{
|
|
649 |
Logger.ELOG(Logger.EJavaUI, "setViewportHeight():"
|
|
650 |
+ height + " - IllegalArgumentException is thrown");
|
|
651 |
throw new IllegalArgumentException(/*SF*/"The height is negative."/*SF*/);
|
|
652 |
}
|
|
653 |
_setViewportHeight(
|
|
654 |
getNativeSVGProxyHandle(),
|
|
655 |
getHandle(),
|
|
656 |
height);
|
|
657 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
658 |
"setViewportHeight():" + height + " - end");
|
|
659 |
}
|
|
660 |
|
|
661 |
/**
|
|
662 |
* @see javax.microedition.m2g.ScalableImage#setViewportWidth()
|
|
663 |
*/
|
|
664 |
public void setViewportWidth(int width)
|
|
665 |
{
|
|
666 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo, "setViewportWidth:" + width + " - begin");
|
|
667 |
if (width < 0)
|
|
668 |
{
|
|
669 |
Logger.ELOG(Logger.EJavaUI, "setViewportWidth():"
|
|
670 |
+ width + " - IllegalArgumentException is thrown");
|
|
671 |
throw new IllegalArgumentException(/*SF*/"The width is negative."/*SF*/);
|
|
672 |
}
|
|
673 |
_setViewportWidth(
|
|
674 |
getNativeSVGProxyHandle(),
|
|
675 |
getHandle(),
|
87
|
676 |
width);
|
80
|
677 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
678 |
"setViewportWidth:" + width + " - end");
|
|
679 |
}
|
|
680 |
|
|
681 |
/**
|
|
682 |
* Unregister event listener
|
|
683 |
* @param aTarget Target element
|
|
684 |
* @param aType Event type
|
|
685 |
* @param aListener Event listener
|
|
686 |
*/
|
|
687 |
void unregister(EventTarget aTarget, String aType, EventListener aListener)
|
|
688 |
{
|
|
689 |
iEventDispatcher.unregister(aTarget, aType, aListener);
|
|
690 |
}
|
|
691 |
|
|
692 |
/**
|
|
693 |
* Unregister an element from the handle-to-element map
|
|
694 |
* @see M2GLiveElements#unregisterElement()
|
|
695 |
*/
|
|
696 |
public void unregisterLiveElement(Integer aElementHandle)
|
|
697 |
{
|
|
698 |
iLiveElements.unregisterElement(aElementHandle);
|
|
699 |
}
|
|
700 |
|
|
701 |
//--------------------------------------------------
|
|
702 |
// INNER CLASSES
|
|
703 |
//--------------------------------------------------
|
|
704 |
/**
|
|
705 |
* M2GLiveElements
|
|
706 |
*/
|
|
707 |
class M2GLiveElements
|
|
708 |
{
|
|
709 |
private Hashtable iLiveElements = new Hashtable();
|
|
710 |
private boolean iUseWeakReference;
|
|
711 |
|
|
712 |
/**
|
|
713 |
* Constructor
|
|
714 |
*/
|
|
715 |
public M2GLiveElements(boolean aUseWeakReference)
|
|
716 |
{
|
|
717 |
iUseWeakReference = aUseWeakReference;
|
|
718 |
}
|
|
719 |
|
|
720 |
/**
|
|
721 |
* Find an element from the handle-to-element map.
|
|
722 |
* @param aElementHandle Handle
|
|
723 |
* @return SVGElement. Null if not found
|
|
724 |
*/
|
|
725 |
public SVGElement findElement(Integer aElementHandle)
|
|
726 |
{
|
|
727 |
SVGElement element = null;
|
|
728 |
Object weakObject = null;
|
|
729 |
Object object = null;
|
|
730 |
|
|
731 |
synchronized (this)
|
|
732 |
{
|
|
733 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
734 |
"** findElement() handle: " + aElementHandle + " - begin **");
|
|
735 |
object = iLiveElements.get(aElementHandle);
|
|
736 |
if (object != null)
|
|
737 |
{
|
|
738 |
if (iUseWeakReference)
|
|
739 |
{
|
|
740 |
weakObject = ((WeakReference)object).get();
|
|
741 |
if (weakObject == null)
|
|
742 |
{
|
|
743 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
744 |
"** findElement() handle: " + aElementHandle
|
|
745 |
+ " is garbage collected. **");
|
|
746 |
iLiveElements.remove(aElementHandle);
|
|
747 |
}
|
|
748 |
else
|
|
749 |
{
|
|
750 |
element = (SVGElement)weakObject;
|
|
751 |
}
|
|
752 |
}
|
|
753 |
else
|
|
754 |
{
|
|
755 |
element = (SVGElement)object;
|
|
756 |
}
|
|
757 |
}
|
|
758 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,"** findElement() handle: " + aElementHandle
|
|
759 |
+ ((element != null) ? " FOUND" : " NOT FOUND") + " - end **");
|
|
760 |
}
|
|
761 |
return element;
|
|
762 |
}
|
|
763 |
|
|
764 |
/**
|
|
765 |
* Register element
|
|
766 |
* @param aElement Element
|
|
767 |
* @param aElementHandle Handle
|
|
768 |
*/
|
|
769 |
public void registerElement(SVGElement aElement, Integer aElementHandle)
|
|
770 |
{
|
|
771 |
if (aElement == null)
|
|
772 |
{
|
|
773 |
return;
|
|
774 |
}
|
|
775 |
synchronized (this)
|
|
776 |
{
|
|
777 |
if (iUseWeakReference)
|
|
778 |
{
|
|
779 |
iLiveElements.put(aElementHandle, new WeakReference(aElement));
|
|
780 |
}
|
|
781 |
else
|
|
782 |
{
|
|
783 |
iLiveElements.put(aElementHandle, aElement);
|
|
784 |
}
|
|
785 |
}
|
|
786 |
}
|
|
787 |
|
|
788 |
/**
|
|
789 |
* Unregister an element from the handle-to-element map
|
|
790 |
* @param aElementHandle Handle
|
|
791 |
*/
|
|
792 |
public void unregisterElement(Integer aElementHandle)
|
|
793 |
{
|
|
794 |
synchronized (this)
|
|
795 |
{
|
|
796 |
iLiveElements.remove(aElementHandle);
|
|
797 |
}
|
|
798 |
}
|
|
799 |
}
|
|
800 |
|
|
801 |
|
|
802 |
/**
|
|
803 |
* M2GEventDispatcher
|
|
804 |
*/
|
|
805 |
protected class M2GEventDispatcher
|
|
806 |
{
|
|
807 |
static public final int INDEX_UNDEFINED = -1;
|
|
808 |
static public final int INDEX_CLICK = 0;
|
|
809 |
static public final int INDEX_ACTIVATE = 1;
|
|
810 |
static public final int INDEX_FOCUS_IN = 2;
|
|
811 |
static public final int INDEX_FOCUS_OUT = 3;
|
|
812 |
|
|
813 |
Hashtable[] iEventTypes;
|
|
814 |
int iCurrentIndex;
|
|
815 |
Hashtable iDelayedRegistrations = new Hashtable();
|
|
816 |
M2GEventData iCurrentEventData = new M2GEventData();
|
|
817 |
|
|
818 |
/**
|
|
819 |
* Constructor
|
|
820 |
*/
|
|
821 |
public M2GEventDispatcher()
|
|
822 |
{
|
|
823 |
iEventTypes = new Hashtable[4];
|
|
824 |
iCurrentIndex = INDEX_UNDEFINED;
|
|
825 |
}
|
|
826 |
|
|
827 |
/**
|
|
828 |
* Clear all
|
|
829 |
*/
|
|
830 |
public void clear()
|
|
831 |
{
|
|
832 |
synchronized (this)
|
|
833 |
{
|
|
834 |
for (int index = 0; index < iEventTypes.length; index++)
|
|
835 |
{
|
|
836 |
if (iEventTypes[index] != null)
|
|
837 |
{
|
|
838 |
iEventTypes[index].clear();
|
|
839 |
iEventTypes[index] = null;
|
|
840 |
}
|
|
841 |
}
|
|
842 |
}
|
|
843 |
}
|
|
844 |
|
|
845 |
/**
|
|
846 |
* Execute delayed registration
|
|
847 |
* If an EventListener is added to an EventTarget while it is
|
|
848 |
* processing an event, it will not be triggered by the current actions.
|
|
849 |
*/
|
|
850 |
private void doDelayedRegistration()
|
|
851 |
{
|
|
852 |
try
|
|
853 |
{
|
|
854 |
Enumeration registrations = iDelayedRegistrations.elements();
|
|
855 |
while (registrations.hasMoreElements())
|
|
856 |
{
|
|
857 |
M2GEventData eventData =
|
|
858 |
(M2GEventData)registrations.nextElement();
|
|
859 |
register(
|
|
860 |
eventData.iTarget, eventData.iType, eventData.iListener);
|
|
861 |
}
|
|
862 |
}
|
|
863 |
catch (NullPointerException e)
|
|
864 |
{
|
|
865 |
}
|
|
866 |
iDelayedRegistrations.clear();
|
|
867 |
}
|
|
868 |
|
|
869 |
|
|
870 |
/**
|
|
871 |
* Handle event
|
|
872 |
* @param aEvent Event
|
|
873 |
*/
|
|
874 |
public void handleEvent(Event aEvent)
|
|
875 |
{
|
|
876 |
synchronized (this)
|
|
877 |
{
|
|
878 |
if ((aEvent == null) || !prepare(aEvent.getType()))
|
|
879 |
{
|
|
880 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
881 |
"handleEvent() FAILED - event invalid");
|
|
882 |
return;
|
|
883 |
}
|
|
884 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
885 |
"handleEvent(): " + aEvent.getType() + " - begin");
|
|
886 |
EventTarget target = aEvent.getCurrentTarget();
|
|
887 |
if (target == null)
|
|
888 |
{
|
|
889 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
890 |
"handleEvent() FAILED - event's target is null");
|
|
891 |
return;
|
|
892 |
}
|
|
893 |
// Check if wrapped event target
|
|
894 |
if (target instanceof M2GSVGElementWrapper)
|
|
895 |
{
|
|
896 |
target = ((M2GSVGElementWrapper)target).getWrappedTarget();
|
|
897 |
if (target == null)
|
|
898 |
{
|
|
899 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
900 |
"handleEvent() FAILED - wrapped event's target is null");
|
|
901 |
return;
|
|
902 |
}
|
|
903 |
}
|
|
904 |
if (iEventTypes[iCurrentIndex].containsKey(target))
|
|
905 |
{
|
|
906 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
907 |
"handleEvent() - target handling begin");
|
|
908 |
iCurrentEventData.set(target, aEvent.getType(), null);
|
|
909 |
Vector listeners =
|
|
910 |
(Vector)iEventTypes[iCurrentIndex].get(iCurrentEventData.iTarget);
|
|
911 |
|
|
912 |
if (listeners != null)
|
|
913 |
{
|
|
914 |
Enumeration index = listeners.elements();
|
|
915 |
while (index.hasMoreElements())
|
|
916 |
{
|
|
917 |
Object listener = index.nextElement();
|
|
918 |
if ((listener != null) && (listener instanceof EventListener))
|
|
919 |
{
|
|
920 |
((EventListener)listener).handleEvent(aEvent);
|
|
921 |
}
|
|
922 |
else
|
|
923 |
{
|
|
924 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
925 |
"handleEvent(): listener is null!");
|
|
926 |
}
|
|
927 |
}
|
|
928 |
}
|
|
929 |
else
|
|
930 |
{
|
|
931 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
932 |
"handleEvent(): listeners is null!");
|
|
933 |
}
|
|
934 |
iCurrentEventData.clear();
|
|
935 |
}
|
|
936 |
else
|
|
937 |
{
|
|
938 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
939 |
"handleEvent(): target not found");
|
|
940 |
}
|
|
941 |
// Execute the delayed registration.
|
|
942 |
doDelayedRegistration();
|
|
943 |
}
|
|
944 |
}
|
|
945 |
|
|
946 |
/**
|
|
947 |
* Check is event targets are equal
|
|
948 |
* @param aLhs Left hand side
|
|
949 |
* @param aRhs Right hand side
|
|
950 |
* @return True if equal
|
|
951 |
*/
|
|
952 |
private boolean isEquals(EventTarget aLhs, EventTarget aRhs)
|
|
953 |
{
|
|
954 |
int lhsHandle = M2GObject.INVALID_NATIVE_HANDLE;
|
|
955 |
int rhsHandle = M2GObject.INVALID_NATIVE_HANDLE;
|
|
956 |
if (aLhs instanceof M2GSVGElement)
|
|
957 |
{
|
|
958 |
lhsHandle = ((M2GSVGElement)aLhs).getHandle();
|
|
959 |
}
|
|
960 |
if (aRhs instanceof M2GSVGElement)
|
|
961 |
{
|
|
962 |
rhsHandle = ((M2GSVGElement)aRhs).getHandle();
|
|
963 |
}
|
|
964 |
if ((lhsHandle == rhsHandle) && (lhsHandle != M2GObject.INVALID_NATIVE_HANDLE))
|
|
965 |
{
|
|
966 |
return true;
|
|
967 |
}
|
|
968 |
return false;
|
|
969 |
}
|
|
970 |
|
|
971 |
/**
|
|
972 |
* Set an index that points to an event type hash table.
|
|
973 |
* The hash table is created if needed.
|
|
974 |
* @param aType Type
|
|
975 |
*/
|
|
976 |
private boolean prepare(String aType)
|
|
977 |
{
|
|
978 |
if (!setIndex(aType))
|
|
979 |
{
|
|
980 |
return false;
|
|
981 |
}
|
|
982 |
if (iEventTypes[iCurrentIndex] == null)
|
|
983 |
{
|
|
984 |
iEventTypes[iCurrentIndex] = new Hashtable();
|
|
985 |
}
|
|
986 |
return true;
|
|
987 |
}
|
|
988 |
|
|
989 |
/**
|
|
990 |
* Register an event target and an event listener pair
|
|
991 |
* @param aTarget Target
|
|
992 |
* @param aType Type
|
|
993 |
* @param aListener Listener
|
|
994 |
*/
|
|
995 |
public void register(EventTarget aTarget,
|
|
996 |
String aType,
|
|
997 |
EventListener aListener)
|
|
998 |
{
|
|
999 |
// NOTE: no need to check validity of aTarget & aListener. It's
|
|
1000 |
// already done.
|
|
1001 |
synchronized (this)
|
|
1002 |
{
|
|
1003 |
if (!prepare(aType))
|
|
1004 |
{
|
|
1005 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
1006 |
"register() - failed: " + aType);
|
|
1007 |
return;
|
|
1008 |
}
|
|
1009 |
// Check if delayed registration is needed
|
|
1010 |
// If an EventListener is added to an EventTarget while it is
|
|
1011 |
// processing an event, it will not be triggered by
|
|
1012 |
// the current actions.
|
|
1013 |
if ((iCurrentEventData.iType == aType) &&
|
|
1014 |
isEquals(iCurrentEventData.iTarget, aTarget))
|
|
1015 |
{
|
|
1016 |
try
|
|
1017 |
{
|
|
1018 |
iDelayedRegistrations.put(
|
|
1019 |
aListener,
|
|
1020 |
new M2GEventData(aTarget, aType, aListener));
|
|
1021 |
}
|
|
1022 |
catch (NullPointerException e)
|
|
1023 |
{
|
|
1024 |
}
|
|
1025 |
return;
|
|
1026 |
}
|
|
1027 |
Vector listeners = null;
|
|
1028 |
if (iEventTypes[iCurrentIndex].containsKey(aTarget))
|
|
1029 |
{
|
|
1030 |
listeners = (Vector)iEventTypes[iCurrentIndex].get(aTarget);
|
|
1031 |
}
|
|
1032 |
else
|
|
1033 |
{
|
|
1034 |
listeners = new Vector();
|
|
1035 |
iEventTypes[iCurrentIndex].put(aTarget, listeners);
|
|
1036 |
}
|
|
1037 |
// Don't add if the event target already contains the same listener
|
|
1038 |
// for the same event.
|
|
1039 |
if (!listeners.contains(aListener))
|
|
1040 |
{
|
|
1041 |
listeners.addElement(aListener);
|
|
1042 |
}
|
|
1043 |
}
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
/**
|
|
1047 |
* Set an event type container index
|
|
1048 |
* @param aType Type
|
|
1049 |
* @return False if the type is invalid
|
|
1050 |
*/
|
|
1051 |
private boolean setIndex(String aType)
|
|
1052 |
{
|
|
1053 |
if (aType.equals(M2GSVGConstants.EVENT_ACTIVATE))
|
|
1054 |
{
|
|
1055 |
iCurrentIndex = INDEX_ACTIVATE;
|
|
1056 |
}
|
|
1057 |
else if (aType.equals(M2GSVGConstants.EVENT_CLICK))
|
|
1058 |
{
|
|
1059 |
iCurrentIndex = INDEX_CLICK;
|
|
1060 |
}
|
|
1061 |
else if (aType.equals(M2GSVGConstants.EVENT_FOCUS_IN))
|
|
1062 |
{
|
|
1063 |
iCurrentIndex = INDEX_FOCUS_IN;
|
|
1064 |
}
|
|
1065 |
else if (aType.equals(M2GSVGConstants.EVENT_FOCUS_OUT))
|
|
1066 |
{
|
|
1067 |
iCurrentIndex = INDEX_FOCUS_OUT;
|
|
1068 |
}
|
|
1069 |
else
|
|
1070 |
{
|
|
1071 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
1072 |
"setIndex() type:" + aType + " FALSE - end");
|
|
1073 |
// Wrong event type
|
|
1074 |
iCurrentIndex = INDEX_UNDEFINED;
|
|
1075 |
return false;
|
|
1076 |
}
|
|
1077 |
return true;
|
|
1078 |
}
|
|
1079 |
|
|
1080 |
/**
|
|
1081 |
* Unregister an event target and an event listener pair
|
|
1082 |
* @param aTarget Target
|
|
1083 |
* @param aType Type
|
|
1084 |
* @param aListener Listener
|
|
1085 |
*/
|
|
1086 |
public void unregister(EventTarget aTarget,
|
|
1087 |
String aType,
|
|
1088 |
EventListener aListener)
|
|
1089 |
{
|
|
1090 |
synchronized (this)
|
|
1091 |
{
|
|
1092 |
if (!prepare(aType))
|
|
1093 |
{
|
|
1094 |
return;
|
|
1095 |
}
|
|
1096 |
// Remove delayed registration
|
|
1097 |
iDelayedRegistrations.remove(aListener);
|
|
1098 |
// Remove real registration
|
|
1099 |
Vector listeners = (Vector)iEventTypes[iCurrentIndex].get(aTarget);
|
|
1100 |
boolean removed = false;
|
|
1101 |
if (listeners != null)
|
|
1102 |
{
|
|
1103 |
removed = listeners.removeElement(aListener);
|
|
1104 |
if (listeners.isEmpty())
|
|
1105 |
{
|
|
1106 |
iEventTypes[iCurrentIndex].remove(aTarget);
|
|
1107 |
}
|
|
1108 |
}
|
|
1109 |
if (removed)
|
|
1110 |
{
|
|
1111 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
1112 |
"unregister() ok - end");
|
|
1113 |
}
|
|
1114 |
else
|
|
1115 |
{
|
|
1116 |
Logger.LOG(Logger.EJavaUI, Logger.EInfo,
|
|
1117 |
"unregister() failed - end");
|
|
1118 |
}
|
|
1119 |
}
|
|
1120 |
}
|
|
1121 |
|
|
1122 |
/**
|
|
1123 |
* Helper class for handling delayed registration
|
|
1124 |
*/
|
|
1125 |
class M2GEventData
|
|
1126 |
{
|
|
1127 |
public EventTarget iTarget = null;
|
|
1128 |
public String iType = null;
|
|
1129 |
public EventListener iListener = null;
|
|
1130 |
|
|
1131 |
/**
|
|
1132 |
* Ctor
|
|
1133 |
*/
|
|
1134 |
public M2GEventData()
|
|
1135 |
{
|
|
1136 |
}
|
|
1137 |
|
|
1138 |
/**
|
|
1139 |
* Ctor
|
|
1140 |
* @param aTarget Target
|
|
1141 |
* @param aType Event type
|
|
1142 |
* @param aListener Event listener
|
|
1143 |
*/
|
|
1144 |
public M2GEventData(
|
|
1145 |
EventTarget aTarget,
|
|
1146 |
String aType,
|
|
1147 |
EventListener aListener)
|
|
1148 |
{
|
|
1149 |
set(aTarget, aType, aListener);
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
/**
|
|
1153 |
* Clearing
|
|
1154 |
*/
|
|
1155 |
public void clear()
|
|
1156 |
{
|
|
1157 |
iTarget = null;
|
|
1158 |
iType = null;
|
|
1159 |
iListener = null;
|
|
1160 |
}
|
|
1161 |
|
|
1162 |
/**
|
|
1163 |
* Setter
|
|
1164 |
* @param aTarget Target
|
|
1165 |
* @param aType Event type
|
|
1166 |
* @param aListener Event listener
|
|
1167 |
*/
|
|
1168 |
public void set(EventTarget aTarget,
|
|
1169 |
String aType,
|
|
1170 |
EventListener aListener)
|
|
1171 |
{
|
|
1172 |
iTarget = aTarget;
|
|
1173 |
iType = aType;
|
|
1174 |
iListener = aListener;
|
|
1175 |
}
|
|
1176 |
}
|
|
1177 |
}
|
|
1178 |
|
|
1179 |
//--------------------------------------------------
|
|
1180 |
// STATIC METHODS
|
|
1181 |
//--------------------------------------------------
|
|
1182 |
|
|
1183 |
/**
|
|
1184 |
* Creates an empty SVG document. The document contains a
|
|
1185 |
* root <svg> element with default viewport size of 100x100.
|
|
1186 |
* @param aImage -
|
|
1187 |
* @param aHander -
|
|
1188 |
* @return document object
|
|
1189 |
* @throws IllegalArgumentException
|
|
1190 |
* @throws IOException
|
|
1191 |
*/
|
|
1192 |
static public M2GDocument buildEmptyDocument(M2GSVGImage aImage,
|
|
1193 |
ExternalResourceHandler aHandler)
|
|
1194 |
throws IllegalArgumentException, IOException
|
|
1195 |
{
|
|
1196 |
return M2GDocument.buildDocument(
|
|
1197 |
aImage,
|
|
1198 |
null,
|
|
1199 |
null,
|
|
1200 |
M2GSVGConstants.getInstance().iEmptySvgDocument,
|
|
1201 |
aHandler);
|
|
1202 |
}
|
|
1203 |
|
|
1204 |
/**
|
|
1205 |
* Builds document
|
|
1206 |
* @param aImage Svg image
|
|
1207 |
* @param aBaseUrl A base url from where a document is downloaded.
|
|
1208 |
* @param aSuffixUrl The suffix url from where a document is downloaded.
|
|
1209 |
* @param aData Plain text svg data
|
|
1210 |
* @param aHandler Resource handler. If null the default resource handler is
|
|
1211 |
* used.
|
|
1212 |
* @return document object
|
|
1213 |
* @throws IllegalArgumentException
|
|
1214 |
* @throws IOException
|
|
1215 |
*/
|
|
1216 |
static public M2GDocument buildDocument(M2GSVGImage aImage,
|
|
1217 |
String aBaseUrl,
|
|
1218 |
String aSuffixUrl,
|
|
1219 |
String aData,
|
|
1220 |
ExternalResourceHandler aHandler)
|
|
1221 |
throws IOException
|
|
1222 |
{
|
87
|
1223 |
|
80
|
1224 |
if ((aData == null) || (aData.equals("")))
|
|
1225 |
{
|
87
|
1226 |
|
80
|
1227 |
throw new IOException(
|
|
1228 |
/*SF*/"The SVG document does not conform to the XML 1.0 specification."/*SF*/);
|
|
1229 |
}
|
|
1230 |
|
|
1231 |
M2GDocument document = new M2GDocument(aImage, aBaseUrl, aSuffixUrl, aData);
|
|
1232 |
|
|
1233 |
if (document.doCheckValidity())
|
|
1234 |
{
|
|
1235 |
document.setResourceHandler(aHandler);
|
|
1236 |
return document;
|
|
1237 |
}
|
|
1238 |
throw new IOException(
|
|
1239 |
/*SF*/"The SVG document does not conform to the XML 1.0 specification."/*SF*/);
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
/**
|
|
1243 |
* Registers an observer to any DOM change
|
|
1244 |
* @since S60 3.2
|
|
1245 |
*/
|
|
1246 |
public void registerDOMChangeObserver(M2GDOMChangeObserver aDOMChangeObserver)
|
|
1247 |
{
|
|
1248 |
iDOMChangeObserver = aDOMChangeObserver;
|
|
1249 |
}
|
|
1250 |
|
|
1251 |
/**
|
|
1252 |
* Notify the observer about any change in DOM
|
|
1253 |
* SVGSVGElement is always part of DOM
|
|
1254 |
* @since S60 3.2
|
|
1255 |
*/
|
|
1256 |
public void notifyDOMChangeObserver()
|
|
1257 |
{
|
|
1258 |
if (iDOMChangeObserver != null)
|
|
1259 |
{
|
|
1260 |
iDOMChangeObserver.notifyDOMChange();
|
|
1261 |
}
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
/**
|
|
1265 |
* Notify the observer about any change in DOM only if the node is in DOM
|
|
1266 |
* @param aNativeHandle the handle of a node
|
|
1267 |
* @since S60 3.2
|
|
1268 |
*/
|
|
1269 |
public void notifyDOMChangeObserver(int aNativeHandle)
|
|
1270 |
{
|
|
1271 |
if (iDOMChangeObserver != null && isElementInDOM(aNativeHandle))
|
|
1272 |
{
|
|
1273 |
iDOMChangeObserver.notifyDOMChange();
|
|
1274 |
}
|
|
1275 |
}
|
|
1276 |
|
|
1277 |
|
|
1278 |
//--------------------------------------------------
|
|
1279 |
// NATIVE METHODS
|
|
1280 |
//--------------------------------------------------
|
|
1281 |
private native static int _createDocument(
|
|
1282 |
int aSvgProxyHandle, String aString);
|
|
1283 |
|
|
1284 |
private native static int _createElementNS(
|
|
1285 |
int aSvgProxyHandle, short aType,
|
|
1286 |
int aDocumentHandle);
|
|
1287 |
|
|
1288 |
private native static void _deleteDocument(
|
|
1289 |
int aSvgProxyHandle, int aDocumentHandle);
|
|
1290 |
|
|
1291 |
private native static int _getElementById(
|
|
1292 |
int aSvgProxyHandle, int aDocumentHandle,
|
|
1293 |
String aId);
|
|
1294 |
|
|
1295 |
private static native int _getViewportHeight(
|
87
|
1296 |
int aSvgProxyHandle, int aDocumentHandle);
|
80
|
1297 |
|
|
1298 |
private static native int _getViewportWidth(
|
87
|
1299 |
int aSvgProxyHandle, int aDocumentHandle);
|
80
|
1300 |
|
|
1301 |
private native static int _isElementInDOM(
|
87
|
1302 |
int aSvgProxyHandle, int aDocumentHandle,
|
80
|
1303 |
int aElementHandle);
|
|
1304 |
|
|
1305 |
private static native int _requestCompleted(
|
|
1306 |
int aSvgProxyHandle, int aDocumentHandle,
|
|
1307 |
String aUri, byte[] aResourceData);
|
|
1308 |
|
|
1309 |
private static native void _setViewportHeight(
|
|
1310 |
int aSvgProxyHandle, int aDocumentHandle, int aHeight);
|
|
1311 |
|
|
1312 |
private static native void _setViewportWidth(
|
|
1313 |
int aSvgProxyHandle, int aDocumentHandle, int aWidth);
|
|
1314 |
}
|
|
1315 |
|