You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bridges-commits@portals.apache.org by wo...@apache.org on 2010/04/21 19:48:46 UTC

svn commit: r936400 - in /portals/bridges/bridges-script/trunk: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/portals/ src/main/java/org/apache/portals/bridges/ src/main/java/org/apache/portals/bridges/script/ src/test/java/o...

Author: woonsan
Date: Wed Apr 21 17:48:45 2010
New Revision: 936400

URL: http://svn.apache.org/viewvc?rev=936400&view=rev
Log:
PB-104: Adding a generic script support bridge portlet with test cases (groovy, jruby, jython, beanshell and rhino).

Added:
    portals/bridges/bridges-script/trunk/src/main/java/org/
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java   (with props)
    portals/bridges/bridges-script/trunk/src/test/resources/org/
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloBeanShell.bsh
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloGroovy.groovy
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb   (with props)
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py   (with props)
    portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js   (with props)
Modified:
    portals/bridges/bridges-script/trunk/pom.xml

Modified: portals/bridges/bridges-script/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/pom.xml?rev=936400&r1=936399&r2=936400&view=diff
==============================================================================
--- portals/bridges/bridges-script/trunk/pom.xml (original)
+++ portals/bridges/bridges-script/trunk/pom.xml Wed Apr 21 17:48:45 2010
@@ -30,27 +30,202 @@
     <javax.servlet.version>2.4</javax.servlet.version>
     <portals.portlet2-api-spec.version>1.0</portals.portlet2-api-spec.version>
     <org.apache.portals.bridges.common.version>2.0</org.apache.portals.bridges.common.version>
+    <javax.script.version>1.0</javax.script.version>
+    <javax.script.groovy-engine.version>20080611</javax.script.groovy-engine.version>
+    <javax.script.js-engine.version>20080611</javax.script.js-engine.version>
+    <javax.script.jython-engine.version>20080611</javax.script.jython-engine.version>
+    <javax.script.jruby-engine.version>20080611</javax.script.jruby-engine.version>
+    <javax.script.bsh-engine.version>20080611</javax.script.bsh-engine.version>
+    <groovy.version>1.7.2</groovy.version>
+    <rhino.version>1.6R7</rhino.version>
+    <jython.version>2.2.1</jython.version>
+    <jruby.version>1.4.0</jruby.version>
+    <bsh.version>2.0b5</bsh.version>
+    <slf4j.version>1.5.6</slf4j.version>
+    <junit.version>3.8.1</junit.version>
+    <spring.version>2.5.6</spring.version>
+    <commons-lang.version>2.4</commons-lang.version>
   </properties>
-
+  
+  <repositories>
+    <repository>
+      <id>servicemix</id>
+      <name>ServiceMix Repository</name>
+      <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
+    </repository>
+  </repositories>
+  
   <dependencies>
+    
     <dependency>
       <groupId>org.apache.portals</groupId>
       <artifactId>portlet-api_2.0_spec</artifactId>
       <version>${portals.portlet2-api-spec.version}</version>
       <scope>provided</scope>
     </dependency>
+    
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>${javax.servlet.version}</version>
       <scope>provided</scope>
     </dependency>
+    
     <dependency>
       <groupId>org.apache.portals.bridges</groupId>
       <artifactId>portals-bridges-common</artifactId>
       <version>${org.apache.portals.bridges.common.version}</version>
       <scope>provided</scope>
     </dependency>
+    
+    <dependency>
+      <groupId>javax.script</groupId>
+      <artifactId>script-api</artifactId>
+      <version>${javax.script.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    
+    <!-- ServiceMix Repo Script Engines -->
+    
+    <dependency>
+      <groupId>com.sun.script</groupId>
+      <artifactId>groovy-engine</artifactId>
+      <version>${javax.script.groovy-engine.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.sun.script</groupId>
+      <artifactId>js-engine</artifactId>
+      <version>${javax.script.js-engine.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.sun.script</groupId>
+      <artifactId>jython-engine</artifactId>
+      <version>${javax.script.jython-engine.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.sun.script</groupId>
+      <artifactId>jruby-engine</artifactId>
+      <version>${javax.script.jruby-engine.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.sun.script</groupId>
+      <artifactId>bsh-engine</artifactId>
+      <version>${javax.script.bsh-engine.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- Script Libraries -->
+    
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-all</artifactId>
+      <version>${groovy.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>rhino</groupId>
+      <artifactId>js</artifactId>
+      <version>${rhino.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.python</groupId>
+      <artifactId>jython</artifactId>
+      <version>${jython.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jruby</groupId>
+      <artifactId>jruby</artifactId>
+      <version>${jruby.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.beanshell</groupId>
+      <artifactId>bsh</artifactId>
+      <version>${bsh.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>junit-addons</groupId>
+          <artifactId>junit-addons-runner</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-core</artifactId>
+      <version>${spring.version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <version>${spring.version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>${commons-lang.version}</version>
+      <scope>test</scope>
+    </dependency>
+    
   </dependencies>
 
   <scm>

Added: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,517 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventPortlet;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceServingPortlet;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+/**
+ * ScriptPortlet evaluates a script source to create a delegatee portlet instance
+ * and delegate invocations to the delegatee scripted portlet instance.
+ * <P>
+ * The final evaluated object from the scripted portlet source must be a portlet instance or portlet class
+ * based on the Java Portlet Specifications.
+ * </P>
+ * <P>
+ * Here's an example portlet definition with descriptions on init parameters.
+ * </P>
+ * <PRE><CODE><XMP>
+ * <portlet>
+ *   <portlet-name>HelloGroovy</portlet-name>
+ *   <display-name>Hello Groovy</display-name>
+ *   <portlet-class>org.apache.portals.bridges.script.ScriptPortlet</portlet-class>
+ *   
+ *   <!-- Optional init parameter for script engine 
+ *   If this init parameter is not set, the ScriptPortlet will look up a script engine automatically
+ *   by the mimeType or the extension of the script source file. -->
+ *   <init-param>
+ *     <name>script-engine</name>
+ *     <!-- 
+ *       Note: You can set other script engine which support JSR-223 ScriptEngine
+ *       such as 'groovy', 'jruby', 'jython'.
+ *     --> 
+ *     <value>groovy</value>
+ *   </init-param>
+ *   
+ *   <!-- Optional init parameter for the key for portlet class or portlet instance which is evaluated and returned by the script.
+ *   By default, when this init parameter is not set, ScriptPortlet retrieves the last evaluated object from the script.
+ *   If you set this to 'portlet', then ScriptPortlet retrieves an object named 'portlet' from the script engine.
+ *   Depending on script engines, this init parameter should be properly configured because some script engines do not return the last evaluated object. -->
+ *   <init-param>
+ *     <name>eval-portlet-key</name>
+ *     <value>portlet</value>
+ *   </init-param>
+ *   
+ *   <!-- Required init parameter for script source path -->
+ *   <init-param>
+ *     <name>script-source</name>
+ *     <!--
+ *       Note: You can set script source in three ways. 
+ *       The first is to use context relative path,
+ *       the second is to use file: url, 
+ *       and the third is to classpath: uri.
+ *       Here are the examples for each way.
+ *     -->
+ *     <!--
+ *       <value>/WEB-INF/groovy/HelloGroovy.groovy</value>
+ *       <value>file:/C:/Program Files/Apache Software Foundation/Tomcat/webapps/demo/WEB-INF/groovy/HelloGroovy.groovy</value>
+ *       <value>classpath:org/apache/portals/bridges/script/HelloGroovy.groovy</value>
+ *     -->
+ *     <value>classpath:org/apache/portals/bridges/script/HelloGroovy.groovy</value>
+ *   </init-param>
+ *   
+ *   <!-- Optional init parameter for script file content encoding. The default value is 'UTF-8'. -->
+ *   <init-param>
+ *     <name>script-source-encoding</name>
+ *     <value>UTF-8</value>
+ *   </init-param>
+ *   
+ *   <!-- Optional init parameter for auto-refresh option.
+ *   If auto-refresh is true, then a modification of script source applies instantly.
+ *   By default, this option is not set to true. -->
+ *   <init-param>
+ *     <name>auto-refresh</name>
+ *     <value>true</value>
+ *   </init-param>
+ *   
+ *   <!-- The followings are not special for ScriptPortlet, but normal configurations for a portlet. -->
+ *   <supports>
+ *     <mime-type>text/html</mime-type>
+ *     <portlet-mode>VIEW</portlet-mode>
+ *     <portlet-mode>EDIT</portlet-mode>
+ *     <portlet-mode>HELP</portlet-mode>
+ *   </supports>
+ *   <supported-locale>en</supported-locale>
+ *   <portlet-info>
+ *     <title>Hello Groovy</title>
+ *     <short-title>Hello Groovy</short-title>
+ *     <keywords>demo,groovy</keywords>
+ *   </portlet-info>
+ *   <portlet-preferences>
+ *     <preference>
+ *       <name>message</name>
+ *       <value>Hello, Groovy!</value>
+ *     </preference>
+ *   </portlet-preferences>
+ *   
+ * </portlet>
+ * </XMP></CODE></PRE>
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class ScriptPortlet extends GenericPortlet
+{
+    public static final String SCRIPT_ENGINE_INIT_PARAM = "script-engine";
+    
+    public static final String EVAL_PORTLET_KEY_INIT_PARAM = "eval-portlet-key";
+    
+    public static final String SCRIPT_SOURCE_INIT_PARAM = "script-source";
+    
+    public static final String SCRIPT_SOURCE_URL_ENCODING_INIT_PARAM = "script-source-uri-encoding";
+    
+    public static final String SCRIPT_SOURCE_ENCODING_INIT_PARAM = "script-source-encoding";
+    
+    public static final String AUTO_REFRESH_INIT_PARAM = "auto-refresh";
+    
+    protected PortletConfig portletConfig;
+    
+    protected String scriptEngineName;
+    
+    protected String evalPortletKey;
+    
+    protected ScriptEngine scriptEngine;
+    
+    protected String scriptSourceUri;
+    
+    protected String scriptSourceUriEncoding = "UTF-8";
+    
+    protected String scriptSourceEncoding = "UTF-8";
+    
+    protected boolean autoRefresh;
+    
+    protected ScriptSource scriptSource;
+    
+    protected long scriptSourceLastModified;
+    
+    protected long scriptSourceLastEvaluated;
+    
+    protected Portlet scriptPortletInstance;
+    
+    protected GenericPortlet scriptGenericPortletInstance;
+    
+    protected Method portletDoEditMethod;
+    
+    public ScriptPortlet()
+    {
+        super();
+    }
+    
+    @Override
+    public void init(PortletConfig config) throws PortletException
+    {
+        portletConfig = config;
+        
+        autoRefresh = "true".equals(config.getInitParameter(AUTO_REFRESH_INIT_PARAM));
+        
+        String param = config.getInitParameter(SCRIPT_ENGINE_INIT_PARAM);
+        
+        if (param != null && !"".equals(param.trim()))
+        {
+            scriptEngineName = param;
+        }
+        
+        param = config.getInitParameter(EVAL_PORTLET_KEY_INIT_PARAM);
+        
+        if (param != null && !"".equals(param.trim()))
+        {
+            evalPortletKey = param;
+        }
+        
+        param = config.getInitParameter(SCRIPT_SOURCE_URL_ENCODING_INIT_PARAM);
+        
+        if (param != null && !"".equals(param.trim()))
+        {
+            scriptSourceUriEncoding = param;
+        }
+        
+        scriptSourceUri = config.getInitParameter(SCRIPT_SOURCE_INIT_PARAM);
+
+        if (scriptSourceUri == null)
+        {
+            throw new PortletException("Configuration failed: " + SCRIPT_SOURCE_INIT_PARAM + " should be set properly!");
+        }
+        else
+        {
+            try
+            {
+                if (scriptSourceUri.startsWith("/"))
+                {
+                    scriptSource = new ScriptSource(new File(config.getPortletContext().getRealPath(scriptSourceUri)).toURL().toString(), scriptSourceUriEncoding);
+                }
+                else
+                {
+                    scriptSource = new ScriptSource(scriptSourceUri, scriptSourceUriEncoding);
+                }
+            }
+            catch (Exception e)
+            {
+                throw new PortletException("File not found: " + this.scriptSourceUri, e);
+            }
+        }
+        
+        param = config.getInitParameter(SCRIPT_SOURCE_ENCODING_INIT_PARAM);
+        
+        if (param != null && !"".equals(param.trim()))
+        {
+            scriptSourceEncoding = param;
+        }
+        
+        refreshPortletInstance();
+
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+    }
+    
+    @Override
+    public void destroy()
+    {
+        if (scriptPortletInstance != null)
+        {
+            scriptPortletInstance.destroy();
+        }
+    }
+    
+    @Override
+    public PortletConfig getPortletConfig ()
+    {
+        return portletConfig;
+    }
+    
+    @Override
+    public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        refreshPortletInstance();
+
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+
+        scriptPortletInstance.render(request, response);
+    }
+    
+    @Override
+    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+    {
+        refreshPortletInstance();
+
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+        else
+        {
+            scriptPortletInstance.processAction(request, response);
+        }
+    }
+    
+    @Override
+    public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException
+    {
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+        
+        if (scriptPortletInstance instanceof EventPortlet)
+        {
+            ((EventPortlet) scriptPortletInstance).processEvent(request, response);
+        }
+    }
+    
+    @Override
+    public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException
+    {
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+        
+        if (scriptPortletInstance instanceof ResourceServingPortlet)
+        {
+            ((ResourceServingPortlet) scriptPortletInstance).serveResource(request, response);
+        }
+    }
+    
+    @Override
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        if (scriptPortletInstance == null)
+        {
+            throw new PortletException("Script portlet is not available!");
+        }
+        
+        if (scriptGenericPortletInstance != null && portletDoEditMethod != null)
+        {
+            try
+            {
+                portletDoEditMethod.invoke(scriptGenericPortletInstance, new Object [] { request, response });
+            }
+            catch (Exception e)
+            {
+                throw new PortletException("Failed to invoke doEdit method.", e);
+            }
+        }
+        else
+        {
+            throw new PortletException("doEdit method not implemented or not public.");
+        }
+    }
+    
+    protected void refreshPortletInstance() throws PortletException
+    {
+        if (scriptPortletInstance == null)
+        {
+            try
+            {
+                createScriptPortletInstance();
+            }
+            catch (Exception ex)
+            {
+                throw new PortletException("Could not evaluate script: " + scriptSourceUri, ex);
+            }
+        }
+        else if (autoRefresh && isScriptFileModified())
+        {
+            synchronized (scriptPortletInstance)
+            {
+                try
+                {
+                    createScriptPortletInstance();
+                }
+                catch (Exception ex)
+                {
+                    throw new PortletException("Could not evaluate script: " + scriptSourceUri, ex);
+                }
+            }
+        }
+    }
+    
+    protected boolean isScriptFileModified()
+    {
+        return (scriptSource.lastModified() > scriptSourceLastModified);
+    }
+    
+    protected void createScriptPortletInstance() throws Exception
+    {
+        if (scriptEngine == null)
+        {
+            ScriptEngineManager manager = new ScriptEngineManager();
+            
+            if (scriptEngineName != null)
+            {
+                scriptEngine = manager.getEngineByName(scriptEngineName);
+            }
+            else
+            {
+                String mimeType = portletConfig.getPortletContext().getMimeType(scriptSource.getName());
+                
+                if (mimeType != null)
+                {
+                    scriptEngine = manager.getEngineByMimeType(mimeType);
+                }
+                
+                if (scriptEngine == null)
+                {
+                    String extension = scriptSource.getExtension();
+                    
+                    if (extension != null)
+                    {
+                        scriptEngine = manager.getEngineByExtension(extension);
+                    }
+                }
+            }
+        }
+        
+        if (scriptEngine == null)
+        {
+            throw new ScriptException("Cannot create script engine. { scriptEngineName: " + scriptEngineName + ", scriptSource: " + scriptSource);
+        }
+        
+        InputStream input = null;
+        InputStreamReader isr = null;
+        BufferedReader br = null;
+        
+        try
+        {
+            input = scriptSource.getInputStream();
+            isr = new InputStreamReader(input, scriptSourceEncoding);
+            br = new BufferedReader(isr);
+            
+            Object evalPortlet = null;
+            Object ret = scriptEngine.eval(br);
+            
+            if (evalPortletKey != null)
+            {
+                evalPortlet = scriptEngine.get(evalPortletKey);
+            }
+            
+            if (evalPortlet == null)
+            {
+                evalPortlet = ret;
+            }
+            
+            if (evalPortlet == null)
+            {
+                throw new ScriptException("The evaluated return is null. (" + evalPortletKey + ")");
+            }
+            
+            scriptSourceLastEvaluated = System.currentTimeMillis();
+            
+            if (evalPortlet instanceof Portlet)
+            {
+                scriptPortletInstance = (Portlet) evalPortlet;
+            }
+            else if (evalPortlet instanceof Class)
+            {
+                Class<? extends Portlet> scriptPortletClass = (Class<? extends Portlet>) evalPortlet;
+                scriptPortletInstance = (Portlet) scriptPortletClass.newInstance();
+            }
+            else
+            {
+                throw new ScriptException("The evaluated return is neither class nor instance of javax.portlet.Portlet. " + evalPortlet);
+            }
+        }
+        finally
+        {
+            if (br != null)
+            {
+                try
+                {
+                    br.close();
+                }
+                catch (Exception ignore) { }
+            }
+            if (isr != null)
+            {
+                try
+                {
+                    isr.close();
+                }
+                catch (Exception ignore) { }
+            }
+            if (input != null)
+            {
+                try
+                {
+                    input.close();
+                }
+                catch (Exception ignore) { }
+            }
+        }
+        
+        scriptGenericPortletInstance = null;
+        portletDoEditMethod = null;
+        
+        if (scriptPortletInstance instanceof GenericPortlet)
+        {
+            scriptGenericPortletInstance = (GenericPortlet) scriptPortletInstance;
+            
+            try
+            {
+                Method doEditMethod = scriptGenericPortletInstance.getClass().getMethod("doEdit", new Class [] { RenderRequest.class, RenderResponse.class });
+                
+                if (Modifier.isPublic(doEditMethod.getModifiers()))
+                {
+                    portletDoEditMethod = doEditMethod;
+                }
+            }
+            catch (NoSuchMethodException e)
+            {
+            }
+        }
+        
+        scriptSourceLastModified = scriptSource.lastModified();
+        scriptPortletInstance.init(portletConfig);
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java (added)
+++ portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLDecoder;
+
+public class ScriptSource
+{
+    private String uri;
+    private String name;
+    private String extension;
+    
+    private File scriptFile;
+    private byte [] scriptBytes;
+    
+    public ScriptSource(String uri) throws IOException
+    {
+        this(uri, null);
+    }
+    
+    public ScriptSource(String uri, String uriEncoding) throws IOException
+    {
+        this.uri = uri;
+        
+        if (uri.startsWith("file:"))
+        {
+            String decodedUri = uri;
+            
+            if (uriEncoding != null)
+            {
+                decodedUri = URLDecoder.decode(uri, uriEncoding);
+            }
+            
+            scriptFile = new File(decodedUri.substring(5));
+        }
+        else if (uri.startsWith("classpath:"))
+        {
+            URL resourceURL = Thread.currentThread().getContextClassLoader().getResource(uri.substring(10));
+            String resourceURLString = resourceURL.toString();
+
+            if (resourceURLString.startsWith("file:"))
+            {
+                String decodedUri = resourceURLString;
+                
+                if (uriEncoding != null)
+                {
+                    decodedUri = URLDecoder.decode(resourceURLString, uriEncoding);
+                }
+                
+                scriptFile = new File(decodedUri.substring(5));
+            }
+            else
+            {
+                InputStream is = null;
+                BufferedInputStream bis = null;
+                ByteArrayOutputStream baos = null;
+                
+                try
+                {
+                    is = resourceURL.openStream();
+                    bis = new BufferedInputStream(is);
+                    baos = new ByteArrayOutputStream(4096);
+                    
+                    byte [] bytes = new byte[4096];
+                    
+                    int readLen = bis.read(bytes, 0, 4096);
+                    while (readLen != -1)
+                    {
+                        baos.write(bytes, 0, readLen);
+                        readLen = bis.read(bytes, 0, 4096);
+                    }
+                    
+                    scriptBytes = baos.toByteArray();
+                }
+                finally
+                {
+                    if (baos != null)
+                    {
+                        try
+                        {
+                            baos.close();
+                        }
+                        catch (Exception ignore) { }
+                    }
+                    if (bis != null)
+                    {
+                        try
+                        {
+                            bis.close();
+                        }
+                        catch (Exception ignore) { }
+                    }
+                    if (is != null)
+                    {
+                        try
+                        {
+                            is.close();
+                        }
+                        catch (Exception ignore) { }
+                    }
+                }
+            }
+        }
+        else
+        {
+            String relPath = uri;
+            scriptFile = new File(relPath);
+        }
+        
+        if (scriptFile != null)
+        {
+            name = scriptFile.getName();
+        }
+        else
+        {
+            name = uri;
+            int offset = name.lastIndexOf('/');
+            if (offset != -1)
+            {
+                name = name.substring(offset + 1);
+            }
+        }
+        
+        int offset = name.lastIndexOf('.');
+        
+        if (offset != -1)
+        {
+            extension = name.substring(offset + 1);
+        }
+    }
+    
+    public String getUri()
+    {
+        return uri;
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+    
+    public String getExtension()
+    {
+        return extension;
+    }
+    
+    public long lastModified()
+    {
+        if (scriptFile != null)
+        {
+            return scriptFile.lastModified();
+        }
+        else
+        {
+            return 0L;
+        }
+    }
+    
+    public InputStream getInputStream() throws IOException
+    {
+        if (scriptFile != null)
+        {
+            return new FileInputStream(scriptFile);
+        }
+        else
+        {
+            return new ByteArrayInputStream(scriptBytes);
+        }
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/main/java/org/apache/portals/bridges/script/ScriptSource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import javax.portlet.Portlet;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+
+import junit.framework.TestCase;
+
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.mock.web.portlet.MockPortletConfig;
+import org.springframework.mock.web.portlet.MockPortletContext;
+import org.springframework.mock.web.portlet.MockPortletPreferences;
+import org.springframework.mock.web.portlet.MockRenderRequest;
+import org.springframework.mock.web.portlet.MockRenderResponse;
+
+/**
+ * AbstractSimpleScriptPortletTestCase
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public abstract class AbstractSimpleScriptPortletTestCase extends TestCase
+{
+    private PortletContext portletContext;
+    private MockPortletConfig portletConfig;
+    private ScriptPortlet scriptPortlet;
+    private Portlet scriptPortletInstance;
+    private long scriptSourceLastEvaluated;
+    
+    abstract protected Map<String, String> getPortletInitParameters();
+    
+    abstract protected ResourceBundle getPortletResourceBundle();
+    
+    abstract protected String getScriptMimeType();
+    
+    public void setUp() throws Exception
+    {
+        portletContext = new MockPortletContext(new DefaultResourceLoader());
+        portletConfig = new MockPortletConfig(portletContext);
+        
+        for (Map.Entry<String, String> entry : getPortletInitParameters().entrySet())
+        {
+            portletConfig.addInitParameter(entry.getKey(), entry.getValue());
+        }
+        
+        portletConfig.setResourceBundle(Locale.ENGLISH, getPortletResourceBundle());
+        
+        scriptPortlet = new ScriptPortlet();
+        
+        try
+        {
+            scriptPortlet.init(portletConfig);
+            scriptPortletInstance = scriptPortlet.scriptPortletInstance;
+            scriptSourceLastEvaluated = scriptPortlet.scriptSourceLastEvaluated;
+            assertTrue(scriptPortlet.scriptSourceLastEvaluated > 0L);
+        }
+        catch (PortletException e)
+        {
+            e.printStackTrace();
+            fail("Failed to initialize portlet: " + e);
+        }
+    }
+    
+    @Override
+    public void tearDown()
+    {
+        if (scriptPortlet != null)
+        {
+            scriptPortlet.destroy();
+        }
+    }
+    
+    public void testInitialization() throws Exception
+    {
+        String scriptEngine = getPortletInitParameters().get("script-engine");
+        String evalPortletKey = getPortletInitParameters().get("eval-portlet-key");
+        String scriptSource = getPortletInitParameters().get("script-source");
+        
+        /*
+         * 1. initialize script engine by script engine name
+         */
+        
+        PortletContext portletContext = new MockPortletContext(new DefaultResourceLoader());
+        MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
+        portletConfig.addInitParameter("script-engine", scriptEngine);
+        if (evalPortletKey != null)
+        {
+            portletConfig.addInitParameter("eval-portlet-key", evalPortletKey);
+        }
+        portletConfig.addInitParameter("script-source", scriptSource);
+        
+        ScriptPortlet helloScriptPortlet = new ScriptPortlet();
+        
+        try
+        {
+            helloScriptPortlet.init(portletConfig);
+            assertTrue(helloScriptPortlet.scriptSourceLastEvaluated > 0L);
+        }
+        catch (PortletException e)
+        {
+            e.printStackTrace();
+            fail("Failed to initialize portlet: " + e);
+        }
+        
+        /*
+         * 2. initialize script engine by script file extension
+         */
+        
+        portletContext = new MockPortletContext(new DefaultResourceLoader());
+        portletConfig = new MockPortletConfig(portletContext);
+        if (evalPortletKey != null)
+        {
+            portletConfig.addInitParameter("eval-portlet-key", evalPortletKey);
+        }
+        portletConfig.addInitParameter("script-source", scriptSource);
+        
+        helloScriptPortlet = new ScriptPortlet();
+        
+        try
+        {
+            helloScriptPortlet.init(portletConfig);
+            assertTrue(helloScriptPortlet.scriptSourceLastEvaluated > 0L);
+        }
+        catch (PortletException e)
+        {
+            e.printStackTrace();
+            fail("Failed to initialize portlet: " + e);
+        }
+        
+        /*
+         * 3. initialize script engine by script mime type
+         */
+        
+        portletContext = new MockPortletContext(new DefaultResourceLoader())
+        {
+            @Override
+            public String getMimeType(String filePath)
+            {
+                return getScriptMimeType();
+            }
+        };
+        portletConfig = new MockPortletConfig(portletContext);
+        if (evalPortletKey != null)
+        {
+            portletConfig.addInitParameter("eval-portlet-key", evalPortletKey);
+        }
+        portletConfig.addInitParameter("script-source", scriptSource);
+        
+        helloScriptPortlet = new ScriptPortlet();
+        
+        try
+        {
+            helloScriptPortlet.init(portletConfig);
+            assertTrue(helloScriptPortlet.scriptSourceLastEvaluated > 0L);
+        }
+        catch (PortletException e)
+        {
+            e.printStackTrace();
+            fail("Failed to initialize portlet: " + e);
+        }
+    }
+    
+    public void testHelloScriptPortlet() throws Exception
+    {
+        MockRenderRequest request = new MockRenderRequest(portletContext);
+        MockPortletPreferences preferences = new MockPortletPreferences();
+        request.setPreferences(preferences);
+        request.addLocale(Locale.ENGLISH);
+        
+        MockRenderResponse response = new MockRenderResponse();
+        
+        scriptPortlet.render(request, response);
+        
+        String content = response.getContentAsString();
+        assertNotNull(content);
+        //System.out.println("### content: " + content);
+        String greeting = "<H1>" + portletConfig.getResourceBundle(Locale.ENGLISH).getString("javax.portlet.title") + "</H1>";
+        assertEquals(greeting, content.trim());
+
+        // to force to refresh...
+        Thread.sleep(10);
+        scriptPortlet.scriptSourceLastModified = 0L;
+        scriptPortlet.render(request, response);
+        
+        assertNotSame(scriptPortletInstance, scriptPortlet.scriptPortletInstance);
+        
+        assertTrue("The script is not refreshed " +
+                   "(scriptSourceLastEvaluated: " + scriptPortlet.scriptSourceLastEvaluated + ", " +
+                   "initial-scriptSourceLastEvaluated: " + scriptSourceLastEvaluated + ")",
+                   scriptPortlet.scriptSourceLastEvaluated > scriptSourceLastEvaluated);
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/AbstractSimpleScriptPortletTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.HashMap;
+import java.util.ListResourceBundle;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * TestHelloBeanShellScriptPortlet
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class TestHelloBeanShellScriptPortlet extends AbstractSimpleScriptPortletTestCase
+{
+    @Override
+    protected Map<String, String> getPortletInitParameters()
+    {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("script-engine", "beanshell");
+        initParams.put("script-source", "classpath:org/apache/portals/bridges/script/HelloBeanShell.bsh");
+        initParams.put("auto-refresh", "true");
+        return initParams;
+    }
+    
+    @Override
+    protected ResourceBundle getPortletResourceBundle()
+    {
+        return new ListResourceBundle()
+        {
+            protected Object[][] getContents() 
+            {
+                return new Object[][] {
+                    {"javax.portlet.title", "Hello BeanShell Portlet"},
+                    {"javax.portlet.short-title", "Hello BeanShell"},
+                    {"javax.portlet.keywords", "hello,beanshell"}
+                };
+            }
+        };
+    }
+
+    @Override
+    protected String getScriptMimeType()
+    {
+        return "application/x-beanshell";
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloBeanShellScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.HashMap;
+import java.util.ListResourceBundle;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * TestGroovyScriptPortlet
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class TestHelloGroovyScriptPortlet extends AbstractSimpleScriptPortletTestCase
+{
+    @Override
+    protected Map<String, String> getPortletInitParameters()
+    {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("script-engine", "groovy");
+        initParams.put("script-source", "classpath:org/apache/portals/bridges/script/HelloGroovy.groovy");
+        initParams.put("auto-refresh", "true");
+        return initParams;
+    }
+    
+    @Override
+    protected ResourceBundle getPortletResourceBundle()
+    {
+        return new ListResourceBundle()
+        {
+            protected Object[][] getContents() 
+            {
+                return new Object[][] {
+                    {"javax.portlet.title", "Hello Groovy Portlet"},
+                    {"javax.portlet.short-title", "Hello Groovy"},
+                    {"javax.portlet.keywords", "hello,groovy"}
+                };
+            }
+        };
+    }
+
+    @Override
+    protected String getScriptMimeType()
+    {
+        return "application/x-groovy";
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloGroovyScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.HashMap;
+import java.util.ListResourceBundle;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * TestHelloJRubyScriptPortlet
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class TestHelloJRubyScriptPortlet extends AbstractSimpleScriptPortletTestCase
+{
+    @Override
+    protected Map<String, String> getPortletInitParameters()
+    {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("script-engine", "jruby");
+        initParams.put("script-source", "classpath:org/apache/portals/bridges/script/HelloJRuby.rb");
+        initParams.put("auto-refresh", "true");
+        return initParams;
+    }
+    
+    @Override
+    protected ResourceBundle getPortletResourceBundle()
+    {
+        return new ListResourceBundle()
+        {
+            protected Object[][] getContents() 
+            {
+                return new Object[][] {
+                    {"javax.portlet.title", "Hello JRuby Portlet"},
+                    {"javax.portlet.short-title", "Hello JRuby"},
+                    {"javax.portlet.keywords", "hello,jruby"}
+                };
+            }
+        };
+    }
+
+    @Override
+    protected String getScriptMimeType()
+    {
+        return "application/x-ruby";
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJRubyScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.HashMap;
+import java.util.ListResourceBundle;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * TestHelloJythonScriptPortlet
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class TestHelloJythonScriptPortlet extends AbstractSimpleScriptPortletTestCase
+{
+    @Override
+    protected Map<String, String> getPortletInitParameters()
+    {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("script-engine", "jython");
+        initParams.put("eval-portlet-key", "portlet");
+        initParams.put("script-source", "classpath:org/apache/portals/bridges/script/HelloJython.py");
+        initParams.put("auto-refresh", "true");
+        return initParams;
+    }
+    
+    @Override
+    protected ResourceBundle getPortletResourceBundle()
+    {
+        return new ListResourceBundle()
+        {
+            protected Object[][] getContents() 
+            {
+                return new Object[][] {
+                    {"javax.portlet.title", "Hello Jython Portlet"},
+                    {"javax.portlet.short-title", "Hello Jython"},
+                    {"javax.portlet.keywords", "hello,jython"}
+                };
+            }
+        };
+    }
+
+    @Override
+    protected String getScriptMimeType()
+    {
+        return "application/x-jython";
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloJythonScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java (added)
+++ portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java Wed Apr 21 17:48:45 2010
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import java.util.HashMap;
+import java.util.ListResourceBundle;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import org.apache.commons.lang.SystemUtils;
+
+/**
+ * TestHelloRhinoScriptPortlet
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class TestHelloRhinoScriptPortlet extends AbstractSimpleScriptPortletTestCase
+{
+    @Override
+    public void setUp() throws Exception
+    {
+        if (SystemUtils.isJavaVersionAtLeast(160))
+        {
+            System.out.println("[WARNING] Rhino script engine embedded in the default Java 1.6+ has not fully tested yet.");
+            return;
+        }
+        
+        super.setUp();
+    }
+    
+    @Override
+    protected Map<String, String> getPortletInitParameters()
+    {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("script-engine", "rhino");
+        initParams.put("script-source", "classpath:org/apache/portals/bridges/script/HelloRhino.js");
+        initParams.put("auto-refresh", "true");
+        return initParams;
+    }
+    
+    @Override
+    protected ResourceBundle getPortletResourceBundle()
+    {
+        return new ListResourceBundle()
+        {
+            protected Object[][] getContents() 
+            {
+                return new Object[][] {
+                    {"javax.portlet.title", "Hello Rhino Portlet"},
+                    {"javax.portlet.short-title", "Hello Rhino"},
+                    {"javax.portlet.keywords", "hello,rhino,js"}
+                };
+            }
+        };
+    }
+
+    @Override
+    protected String getScriptMimeType()
+    {
+        return "application/x-javascript";
+    }
+    
+    @Override
+    public void testInitialization() throws Exception
+    {
+        if (SystemUtils.isJavaVersionAtLeast(160))
+        {
+            System.out.println("[WARNING] Rhino script engine embedded in the default Java 1.6+ has not fully tested yet.");
+            return;
+        }
+        
+        super.testInitialization();
+    }
+    
+    @Override
+    public void testHelloScriptPortlet() throws Exception
+    {
+        if (SystemUtils.isJavaVersionAtLeast(160))
+        {
+            System.out.println("[WARNING] Rhino script engine embedded in the default Java 1.6+ has not fully tested yet.");
+            return;
+        }
+        
+        super.testHelloScriptPortlet();
+    }
+}

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/java/org/apache/portals/bridges/script/TestHelloRhinoScriptPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloBeanShell.bsh
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloBeanShell.bsh?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloBeanShell.bsh (added)
+++ portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloBeanShell.bsh Wed Apr 21 17:48:45 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+class HelloBeanShell extends GenericPortlet
+{
+    public void doView(RenderRequest request, RenderResponse response)
+    {
+        String greeting = "<H1>" + getTitle(request) + "</H1>";
+        response.getWriter().println(greeting);
+    }
+}
+
+// Return portlet instance as a last evaluated object
+// because ScriptPortlet expects the evaluated result object as a portlet class or non-initialized portlet instance.
+new HelloBeanShell();

Added: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloGroovy.groovy
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloGroovy.groovy?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloGroovy.groovy (added)
+++ portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloGroovy.groovy Wed Apr 21 17:48:45 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.bridges.script;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class HelloGroovy extends GenericPortlet
+{
+    public void doView(RenderRequest request, RenderResponse response)
+    {
+        String greeting = "<H1>" + getTitle(request) + "</H1>";
+        response.getWriter().println(greeting);
+    }
+}
+
+// Return portlet instance as a last evaluated object
+// because ScriptPortlet expects the evaluated result object as a portlet class or non-initialized portlet instance.
+new HelloGroovy();

Added: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb (added)
+++ portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb Wed Apr 21 17:48:45 2010
@@ -0,0 +1,35 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#      http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'java'
+
+#
+# @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+# @version $Id$
+#
+class HelloJRuby < javax.portlet.GenericPortlet
+    
+    def doView(request, response)
+        greeting = "<H1>" + getTitle(request) + "</H1>"
+        response.writer.println(greeting)
+    end
+    
+end
+
+# Return portlet instance as a last evaluated object
+# because ScriptPortlet expects the evaluated result object as a portlet class or non-initialized portlet instance.
+HelloJRuby.new

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJRuby.rb
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py (added)
+++ portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py Wed Apr 21 17:48:45 2010
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#      http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from javax.portlet import GenericPortlet
+
+#
+# @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+# @version $Id$
+#
+class HelloJython(GenericPortlet):
+    def doView(self, request, response):
+        greeting = "<H1>" + self.getTitle(request) + "</H1>"
+        response.writer.println(greeting)
+        
+
+# Return portlet instance as a last evaluated object
+# because ScriptPortlet expects the evaluated result object as a portlet class or non-initialized portlet instance.
+portlet = HelloJython()

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloJython.py
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js
URL: http://svn.apache.org/viewvc/portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js?rev=936400&view=auto
==============================================================================
--- portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js (added)
+++ portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js Wed Apr 21 17:48:45 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+importPackage(Packages.javax.portlet);
+
+/**
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+
+// Return portlet instance as a last evaluated object
+// because ScriptPortlet expects the evaluated result object as a portlet class or non-initialized portlet instance.
+new GenericPortlet(
+    {
+        doView: function(request, response) {
+            greeting = "<H1>Hello Rhino Portlet</H1>";
+            response.getWriter().println(greeting);
+        }
+    }
+);

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/bridges/bridges-script/trunk/src/test/resources/org/apache/portals/bridges/script/HelloRhino.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: bridges-commits-unsubscribe@portals.apache.org
For additional commands, e-mail: bridges-commits-help@portals.apache.org