cjolif      2003/07/09 06:00:46

  Modified:    sources/org/apache/batik/bridge
                        BaseScriptingEnvironment.java
               sources/org/apache/batik/script ScriptHandler.java
  Added:       sources/org/w3c/dom/svg EventListenerInitializer.java
  Log:
  add/modify classes for Batik to be conformant with SVG 1.1 specification
  Appendix D, on Java language binding.
  This is closing BR #21374
  
  Revision  Changes    Path
  1.23      +42 -27    
xml-batik/sources/org/apache/batik/bridge/BaseScriptingEnvironment.java
  
  Index: BaseScriptingEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/BaseScriptingEnvironment.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- BaseScriptingEnvironment.java     8 Jul 2003 00:16:56 -0000       1.22
  +++ BaseScriptingEnvironment.java     9 Jul 2003 13:00:45 -0000       1.23
  @@ -35,6 +35,7 @@
   import org.w3c.dom.events.EventTarget;
   import org.w3c.dom.svg.SVGDocument;
   import org.w3c.dom.svg.SVGSVGElement;
  +import org.w3c.dom.svg.EventListenerInitializer;
   
   /**
    * This class is the base class for SVG scripting.
  @@ -46,7 +47,7 @@
       /**
        * Constant used to describe inline scripts
        */
  -    public static final String INLINE_SCRIPT_DESCRIPTION 
  +    public static final String INLINE_SCRIPT_DESCRIPTION
           = "BaseScriptingEnvironment.constant.inline.script.description";
   
       /**
  @@ -84,7 +85,7 @@
           }
           return false;
       }
  -    
  +
       /**
        * Tells whether the given SVG element is dynamic.
        */
  @@ -153,7 +154,7 @@
                   (null, SVGConstants.SVG_ONMOUSEUP_ATTRIBUTE).length() > 0) {
                   return true;
               }
  -        
  +
               for (Node n = elt.getFirstChild();
                    n != null;
                    n = n.getNextSibling()) {
  @@ -166,7 +167,7 @@
           }
           return false;
       }
  -    
  +
   
       protected final static String EVENT_NAME = "event";
       protected final static String ALTERNATE_EVENT_NAME = "evt";
  @@ -180,7 +181,7 @@
        * The user-agent.
        */
       protected UserAgent userAgent;
  -    
  +
       /**
        * The document to manage.
        */
  @@ -239,7 +240,7 @@
       public Interpreter getInterpreter(String lang) {
           interpreter = bridgeContext.getInterpreter(lang);
           if (interpreter == null) {
  -            if (languages.contains(lang)) 
  +            if (languages.contains(lang))
                   // Already issued warning so just return null;
                   return null;
   
  @@ -304,33 +305,47 @@
                       URL docURL = null;
                       try {
                           docURL = new URL(docPURL.toString());
  -                    } catch (MalformedURLException mue) { 
  +                    } catch (MalformedURLException mue) {
                           /* nothing just let docURL be null */
                       }
                       cll = new DocumentJarClassLoader
                           (new URL(purl.toString()), docURL);
  -                    
  +
                       // Get the 'Script-Handler' entry in the manifest.
                       URL url = cll.findResource("META-INF/MANIFEST.MF");
                       if (url == null) {
                           continue;
                       }
                       Manifest man = new Manifest(url.openStream());
  +
                       String sh;
  +
                       sh = man.getMainAttributes().getValue("Script-Handler");
  -                    if (sh == null) {
  -                        continue;
  +                    if (sh != null) {
  +                        // Run the script handler.
  +                        ScriptHandler h;
  +                        h = (ScriptHandler)cll.loadClass(sh).newInstance();
  +
  +                        if (window == null) {
  +                            window = createWindow();
  +                        }
  +
  +                        h.run(document, window);
                       }
  -                    
  -                    // Run the script handler.
  -                    ScriptHandler h;
  -                    h = (ScriptHandler)cll.loadClass(sh).newInstance();
  -                    
  -                    if (window == null) {
  -                        window = createWindow();
  +
  +                    sh = man.getMainAttributes().getValue("SVG-Handler-Class");
  +                    if (sh != null) {
  +                        // Run the initializer
  +                        EventListenerInitializer initializer;
  +                        initializer =
  +                            
(EventListenerInitializer)cll.loadClass(sh).newInstance();
  +
  +                        if (window == null) {
  +                            window = createWindow();
  +                        }
  +
  +                        initializer.initializeEventListeners((SVGDocument)document);
                       }
  -                    
  -                    h.run(document, window);
                   } catch (Exception e) {
                       if (userAgent != null) {
                           userAgent.displayError(e);
  @@ -395,11 +410,11 @@
       }
   
       /**
  -     * Checks that the script URLs and the document url are 
  +     * Checks that the script URLs and the document url are
        * compatible. A SecurityException is thrown if loading
        * the script is not allowed.
        */
  -    protected void checkCompatibleScriptURL(String scriptType, 
  +    protected void checkCompatibleScriptURL(String scriptType,
                                             ParsedURL scriptPURL){
           userAgent.checkLoadScript(scriptType, scriptPURL, docPURL);
       }
  @@ -416,8 +431,8 @@
       /**
        * Auxiliary method for dispatchSVGLoad.
        */
  -    protected void dispatchSVGLoad(Element elt, 
  -                                   boolean checkCanRun, 
  +    protected void dispatchSVGLoad(Element elt,
  +                                   boolean checkCanRun,
                                      String lang) {
           for (Node n = elt.getFirstChild();
                n != null;
  @@ -449,7 +464,7 @@
               t.dispatchEvent(ev);
               return;
           }
  -        
  +
           if (checkCanRun) {
               // Check that it is ok to run embeded scripts
               checkCompatibleScriptURL(lang, docPURL);
  @@ -618,8 +633,8 @@
            * @param h A handler called when the data is available.
            * @param enc The character encoding of the data.
            */
  -        public void getURL(String uri, 
  -                           org.apache.batik.script.Window.GetURLHandler h, 
  +        public void getURL(String uri,
  +                           org.apache.batik.script.Window.GetURLHandler h,
                              String enc) {
           }
   
  
  
  
  1.2       +3 -3      xml-batik/sources/org/apache/batik/script/ScriptHandler.java
  
  Index: ScriptHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/ScriptHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScriptHandler.java        10 Apr 2002 07:24:33 -0000      1.1
  +++ ScriptHandler.java        9 Jul 2003 13:00:45 -0000       1.2
  @@ -15,7 +15,7 @@
    * an SVG document.
    *
    * A ScriptHandler instance is called when a 'script' element's 'type'
  - * attribute value is 'application/x-java-jar-file' and when the
  + * attribute value is 'application/java-archive' and when the
    * manifest of the jar file referenced by the 'xlink:href' attribute
    * contains a 'Script-Handler' entry.  The value of this entry must be
    * the classname of the ScriptHandler to call.
  @@ -27,7 +27,7 @@
    * @version $Id$
    */
   public interface ScriptHandler {
  -    
  +
       /**
        * Runs this handler.  This method is called by the SVG viewer
        * when the scripts are loaded.
  
  
  
  1.1                  xml-batik/sources/org/w3c/dom/svg/EventListenerInitializer.java
  
  Index: EventListenerInitializer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.w3c.dom.svg;
  
  /**
   * This interface must be implemented in order to call Java code from
   * an SVG document.
   *
   * A <code>EventListenerInitializer</code> instance is called when
   * a 'script' element's 'type' attribute value is 'application/java-archive' and when
   * the manifest of the jar file referenced by the 'xlink:href' attribute contains
   * a 'SVG-Handler-Class' entry.  The value of this entry must be the classname of the
   * <code>EventListenerInitializer</code> to call.
   *
   * This classes implementing this interface must have a default
   * constructor.
   *
   * @version $Id: EventListenerInitializer.java,v 1.1 2003/07/09 13:00:46 cjolif Exp $
   */
  public interface EventListenerInitializer {
  
      /**
       * This method is called by the SVG viewer
       * when the scripts are loaded to register
       * the listener needed.
       * @param doc The current document.
       */
      public void initializeEventListeners(SVGDocument doc);
  }
  
  
  

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

Reply via email to