* @param ctx the context to use
* @param svgDocument the DOM tree that represents an SVG document
*/
public GraphicsNode build(BridgeContext ctx, Document svgDocument){
RootGraphicsNode root = ctx.getGVTFactory().createRootGraphicsNode();
Element svgRoot = svgDocument.getDocumentElement();
// Now, build corresponding canvas
Bridge bridge = ctx.getBridge(svgRoot);
if (bridge == null || !(bridge instanceof GraphicsNodeBridge)) {
return root;
}
GraphicsNode treeRoot = null;
GraphicsNodeBridge graphicsNodeBridge = (GraphicsNodeBridge) bridge;
try {
treeRoot = graphicsNodeBridge.createGraphicsNode(ctx, svgRoot);
buildComposite(ctx,
(CompositeGraphicsNode)treeRoot,
svgRoot.getFirstChild());
graphicsNodeBridge.buildGraphicsNode(treeRoot, ctx, svgRoot);
// <!> TODO this should be done only if we want binding !!!!
BridgeEventSupport.loadScripts(ctx, svgDocument);
EventTarget target = (EventTarget) svgRoot;
target.addEventListener("DOMAttrModified",
new BridgeDOMAttrModifiedListener
((ConcreteBridgeContext)ctx),
true);
EventListener listener =
new BridgeDOMInsertedRemovedListener((ConcreteBridgeContext)ctx);
// Adds the Listener on Attr Modified event.
target.addEventListener("DOMNodeInserted", listener, true);
// Adds the Listener on Attr Modified event.
target.addEventListener("DOMNodeRemoved", listener, true);
BridgeEventSupport.addGVTListener(ctx, svgRoot);
// <!> END TODO
} catch (BuilderException ex) {
ex.setRootGraphicsNode(root);
throw ex;
} finally {
if (treeRoot != null) {
root.getChildren().add(treeRoot);
}
}
return root;
}