Hi Thomas.

I have a patch here for your consideration that adds a function to the
BridgeExtension interface that returns a true/false if a given element
is dynamic.  This is so that the
BaseScriptingEnvironment.isDynamicDocument method can return true if an
extension element's presence should cause a document to be dynamic.

This is useful for my project, as it would let me not modify
BaseScriptingEnvironment and keep all my code as an extension.

Thanks,

Cameron

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922
Index: sources/org/apache/batik/bridge/BaseScriptingEnvironment.java
===================================================================
RCS file: 
/home/cvspublic/xml-batik/sources/org/apache/batik/bridge/BaseScriptingEnvironment.java,v
retrieving revision 1.27
diff -u -r1.27 BaseScriptingEnvironment.java
--- sources/org/apache/batik/bridge/BaseScriptingEnvironment.java       9 Aug 2003 
16:58:37 -0000       1.27
+++ sources/org/apache/batik/bridge/BaseScriptingEnvironment.java       10 Feb 2004 
02:28:40 -0000
@@ -57,6 +57,8 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 import java.util.jar.Manifest;
 
@@ -144,14 +146,15 @@
      * Tells whether the given SVG element is dynamic.
      */
     public static boolean isDynamicElement(Element elt) {
-        if (SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
-            String name = elt.getLocalName();
-            if (name.equals(SVGConstants.SVG_SCRIPT_TAG)) {
-                return true;
-            }
-            if (name.startsWith("animate") || name.equals("set")) {
+        List bridgeExtensions = BridgeContext.getBridgeExtensions();
+        Iterator i = bridgeExtensions.iterator();
+        while (i.hasNext()) {
+            BridgeExtension bridgeExtension = (BridgeExtension) i.next();
+            if (bridgeExtension.isDynamicElement(elt)) {
                 return true;
             }
+        }
+        if (SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
             if (elt.getAttributeNS
                 (null, SVGConstants.SVG_ONKEYUP_ATTRIBUTE).length() > 0) {
                 return true;
@@ -208,14 +211,14 @@
                 (null, SVGConstants.SVG_ONMOUSEUP_ATTRIBUTE).length() > 0) {
                 return true;
             }
+        }
 
-            for (Node n = elt.getFirstChild();
-                 n != null;
-                 n = n.getNextSibling()) {
-                if (n.getNodeType() == Node.ELEMENT_NODE) {
-                    if (isDynamicElement((Element)n)) {
-                        return true;
-                    }
+        for (Node n = elt.getFirstChild();
+             n != null;
+             n = n.getNextSibling()) {
+            if (n.getNodeType() == Node.ELEMENT_NODE) {
+                if (isDynamicElement((Element)n)) {
+                    return true;
                 }
             }
         }
Index: sources/org/apache/batik/bridge/BridgeExtension.java
===================================================================
RCS file: 
/home/cvspublic/xml-batik/sources/org/apache/batik/bridge/BridgeExtension.java,v
retrieving revision 1.3
diff -u -r1.3 BridgeExtension.java
--- sources/org/apache/batik/bridge/BridgeExtension.java        8 Aug 2003 11:38:50 
-0000       1.3
+++ sources/org/apache/batik/bridge/BridgeExtension.java        10 Feb 2004 02:28:40 
-0000
@@ -52,6 +52,8 @@
 
 import java.util.Iterator;
 
+import org.w3c.dom.Element;
+
 /**
  * This is a Service interface for classes that want to extend the
  * functionality of the Bridge, to support new tags in the rendering tree.
@@ -109,4 +111,13 @@
      * @param ctx The BridgeContext instance to be updated
      */
     public void registerTags(BridgeContext ctx);
+
+    /**
+     * Whether the presence of the specified element should cause
+     * the document to be dynamic.  If this element isn't handled
+     * by this BridgeExtension, just return false.
+     *
+     * @param e The element to check.
+     */
+    public boolean isDynamicElement(Element e);
 }
Index: sources/org/apache/batik/bridge/SVGBridgeExtension.java
===================================================================
RCS file: 
/home/cvspublic/xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java,v
retrieving revision 1.8
diff -u -r1.8 SVGBridgeExtension.java
--- sources/org/apache/batik/bridge/SVGBridgeExtension.java     8 Aug 2003 11:38:51 
-0000       1.8
+++ sources/org/apache/batik/bridge/SVGBridgeExtension.java     10 Feb 2004 02:28:40 
-0000
@@ -53,6 +53,9 @@
 import java.util.Collections;
 import java.util.Iterator;
 
+import org.apache.batik.util.SVGConstants;
+import org.w3c.dom.Element;
+
 /**
  * This is a Service interface for classes that want to extend the
  * functionality of the Bridge, to support new tags in the rendering tree.
@@ -191,5 +194,26 @@
         ctx.putBridge(new SVGUseElementBridge());
         ctx.putBridge(new SVGVKernElementBridge());
 
+    }
+
+    /**
+     * Whether the presence of the specified element should cause
+     * the document to be dynamic.  If this element isn't handled
+     * by this BridgeExtension, just return false.
+     *
+     * @param e The element to check.
+     */
+    public boolean isDynamicElement(Element e) {
+        String ns = e.getNamespaceURI();
+        if (!SVGConstants.SVG_NAMESPACE_URI.equals(ns)) {
+            return false;
+        }
+        String ln = e.getLocalName();
+        if (ln.equals(SVGConstants.SVG_SCRIPT_TAG)
+                || ln.startsWith("animate")
+                || ln.equals("set")) {
+            return true;
+        }
+        return false;
     }
 }
Index: sources/org/apache/batik/extension/svg/BatikBridgeExtension.java
===================================================================
RCS file: 
/home/cvspublic/xml-batik/sources/org/apache/batik/extension/svg/BatikBridgeExtension.java,v
retrieving revision 1.7
diff -u -r1.7 BatikBridgeExtension.java
--- sources/org/apache/batik/extension/svg/BatikBridgeExtension.java    8 Aug 2003 
11:39:10 -0000       1.7
+++ sources/org/apache/batik/extension/svg/BatikBridgeExtension.java    10 Feb 2004 
02:28:40 -0000
@@ -56,6 +56,7 @@
 
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.BridgeExtension;
+import org.w3c.dom.Element;
 
 /**
  * This is a Service interface for classes that want to extend the
@@ -142,5 +143,16 @@
         ctx.putBridge(new SolidColorBridge());
         ctx.putBridge(new ColorSwitchBridge());
         ctx.putBridge(new SVGFlowTextElementBridge());
+    }
+
+    /**
+     * Whether the presence of the specified element should cause
+     * the document to be dynamic.  If this element isn't handled
+     * by this BridgeExtension, just return false.
+     *
+     * @param e The element to check.
+     */
+    public boolean isDynamicElement(Element e) {
+        return false;
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to