cjolif      2003/03/14 03:15:52

  Added:       sources/org/apache/batik/script/rhino
                        BatikSecurityController.java BatikWrapFactory.java
  Log:
  replacement for BatikSecuritySupport and EventTargetWrapHandler for new APIs
  introduced in Rhino15R4.
  
  Revision  Changes    Path
  1.1                  
xml-batik/sources/org/apache/batik/script/rhino/BatikSecurityController.java
  
  Index: BatikSecurityController.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.apache.batik.script.rhino;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  
  import org.apache.batik.util.BatikSecurityManager;
  
  import org.mozilla.javascript.Context;
  import org.mozilla.javascript.GeneratedClassLoader;
  import org.mozilla.javascript.JavaScriptException;
  import org.mozilla.javascript.SecurityController;
  import org.mozilla.javascript.Script;
  import org.mozilla.javascript.Scriptable;
  
  /**
   * This implementation of the Rhino <tt>SecurityController</tt> interface is
   * meant for use within the context of Batik only. It is a partial
   * implementation of the interface that does what is needed by Batik and
   * no more.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a>
   * @version $Id: BatikSecurityController.java,v 1.1 2003/03/14 11:15:52 cjolif Exp $
   */
  public class BatikSecurityController extends SecurityController {
  
      /**
       * Default constructor
       */
      public GeneratedClassLoader createClassLoader(final ClassLoader parentLoader,
                                                    Object securityDomain) {
          return (RhinoClassLoader)securityDomain;
      }
  
      /**
       * Get dynamic security domain that allows an action only if it is allowed
       * by the current Java stack and <i>securityDomain</i>. If
       * <i>securityDomain</i> is null, return domain representing permissions
       * allowed by the current stack.
       */
      public Object getDynamicSecurityDomain(Object securityDomain) {
          return securityDomain;
      }
  
      /**
       * Call [EMAIL PROTECTED] Script#exec(Context cx, Scriptable scope)} of
       * <i>script</i> under restricted security domain where an action is
       * allowed only if it is allowed according to the Java stack on the
       * moment of the <i>execWithDomain</i> call and <i>securityDomain</i>.
       * Any call to [EMAIL PROTECTED] #getDynamicSecurityDomain(Object)} during
       * execution of [EMAIL PROTECTED] Script#exec(Context cx, Scriptable scope)}
       * should return a domain incorporate restrictions imposed by
       * <i>securityDomain</i>.
       */
      public Object execWithDomain(final Context cx, final Scriptable scope,
                                   final Script script, Object securityDomain)
          throws JavaScriptException {
          return script.exec(cx, scope);
      }
  }
  
  
  
  1.1                  
xml-batik/sources/org/apache/batik/script/rhino/BatikWrapFactory.java
  
  Index: BatikWrapFactory.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.apache.batik.script.rhino;
  
  import org.mozilla.javascript.Context;
  import org.mozilla.javascript.WrapFactory;
  import org.mozilla.javascript.Scriptable;
  
  import org.w3c.dom.events.EventTarget;
  
  /**
   * This is an utility class allowing to pass an ECMAScript function
   * as a parameter of the <code>addEventListener</code> method of
   * <code>EventTarget</code> objects as DOM Level 2 recommendation
   * required.
   * @author <a href="mailto:[EMAIL PROTECTED]">Christophe Jolif</a>
   * @version $Id: BatikWrapFactory.java,v 1.1 2003/03/14 11:15:52 cjolif Exp $
   */
  class BatikWrapFactory extends WrapFactory {
      private RhinoInterpreter interpreter;
  
      public BatikWrapFactory(RhinoInterpreter interp) {
          interpreter = interp;
          setJavaPrimitiveWrap(false);
      }
  
      public Object wrap(Context ctx, Scriptable scope,
                         Object obj, Class staticType) {
          if (obj instanceof EventTarget) {
              return interpreter.buildEventTargetWrapper((EventTarget)obj);
          }
          return super.wrap(ctx, scope, obj, staticType);
      }
  }
  
  
  

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

Reply via email to