Author: ate
Date: Thu Jun 14 01:41:54 2007
New Revision: 547171

URL: http://svn.apache.org/viewvc?view=rev&rev=547171
Log:
PB-69: Groovy Portlet Bridge for rapid dev: Parse, instantiate, invoke and 
auto-refresh a groovy script portlet
New Groovy bridge contributed by Woonsan Ko, cool!

I will also provide the documented example out-of-the-box with the jetspeed-2 
demo portlet application :) 

See: https://issues.apache.org/jira/browse/PB-69

Added:
    portals/bridges/trunk/groovy/   (with props)
    portals/bridges/trunk/groovy/pom.xml   (with props)
    portals/bridges/trunk/groovy/project.properties   (with props)
    portals/bridges/trunk/groovy/project.xml   (with props)
    portals/bridges/trunk/groovy/src/
    portals/bridges/trunk/groovy/src/java/
    portals/bridges/trunk/groovy/src/java/org/
    portals/bridges/trunk/groovy/src/java/org/apache/
    portals/bridges/trunk/groovy/src/java/org/apache/portals/
    portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/
    portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/
    
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
   (with props)
    portals/bridges/trunk/groovy/xdocs/
    portals/bridges/trunk/groovy/xdocs/index.xml   (with props)
    portals/bridges/trunk/groovy/xdocs/navigation.xml   (with props)
Modified:
    portals/bridges/trunk/.classpath
    portals/bridges/trunk/pom.xml
    portals/bridges/trunk/project.properties
    portals/bridges/trunk/project.xml

Modified: portals/bridges/trunk/.classpath
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/.classpath?view=diff&rev=547171&r1=547170&r2=547171
==============================================================================
--- portals/bridges/trunk/.classpath (original)
+++ portals/bridges/trunk/.classpath Thu Jun 14 01:41:54 2007
@@ -9,6 +9,7 @@
        <classpathentry excluding="**/.svn/*" kind="src" 
path="portletfilter/src/java"/>
        <classpathentry excluding="**/.svn/*" kind="src" 
path="struts/src/java"/>
        <classpathentry excluding="**/.svn/*" kind="src" 
path="velocity/src/java"/>
+       <classpathentry excluding="**/.svn/*" kind="src" 
path="groovy/src/java"/>
        <classpathentry excluding="**/.svn/*" kind="src" 
path="applications/jpetstore/src/java"/>
        <classpathentry excluding="**/.svn/*" kind="src" 
path="applications/jsf-demo/src/java"/>
        <classpathentry excluding="**/.svn/*" kind="src" 
path="applications/springmvc/src/java"/>
@@ -27,6 +28,7 @@
        <classpathentry kind="var" 
path="MAVEN_REPO/commons-validator/jars/commons-validator-1.3.1.jar"/>
        <classpathentry kind="var" 
path="MAVEN_REPO/velocity/jars/velocity-1.5.jar"/>
        <classpathentry kind="var" 
path="MAVEN_REPO/velocity-tools/jars/velocity-tools-1.3.jar"/>
+       <classpathentry kind="var" 
path="MAVEN_REPO/groovy/jars/groovy-1.0.jar"/>
        <classpathentry kind="var" 
path="MAVEN_REPO/ibatis/jars/ibatis-common-2.0.8.jar"/>
        <classpathentry kind="var" 
path="MAVEN_REPO/ibatis/jars/ibatis-dao-2.0.8.jar"/>
        <classpathentry kind="var" 
path="MAVEN_REPO/ibatis/jars/ibatis-sqlmap-2.0.8.jar"/>

Propchange: portals/bridges/trunk/groovy/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 14 01:41:54 2007
@@ -0,0 +1 @@
+target

Added: portals/bridges/trunk/groovy/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/pom.xml?view=auto&rev=547171
==============================================================================
--- portals/bridges/trunk/groovy/pom.xml (added)
+++ portals/bridges/trunk/groovy/pom.xml Thu Jun 14 01:41:54 2007
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+
+  $Id$
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+    <modelVersion>4.0.0</modelVersion>
+    <prerequisites>
+        <maven>2.0.4</maven>
+    </prerequisites>
+
+    <!-- POM Identification -->
+
+    <artifactId>portals-bridges-groovy</artifactId>
+    <parent>
+        <groupId>org.apache.portals.bridges</groupId>
+        <artifactId>portals-bridges</artifactId>
+        <version>1.0.2-dev</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <packaging>jar</packaging>
+    <name>Apache Portals Groovy Framework Bridge</name>
+    <description>
+        Apache Portals Groovy Framework Bridge
+    </description>
+
+    <developers>
+        <developer>
+            <name>Ate Douma</name>
+            <id>ate</id>
+            <email>[EMAIL PROTECTED]</email>
+            <timezone>+2</timezone>
+            <organization>Hippo</organization>
+            <roles>
+                <role>Java Developer</role>
+            </roles>
+        </developer>
+    </developers>
+    <contributors>
+        <contributor>
+            <name>Woonsan Ko</name>
+            <email>[EMAIL PROTECTED]</email>
+            <roles>
+                <role>Java Developer</role>
+            </roles>
+        </contributor>    
+    </contributors>
+    
+    <!-- Dependencies -->
+
+    <dependencies>
+        <dependency>
+            <groupId>groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>1.0</version>
+        </dependency>                           
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>             
+       <dependency>
+         <groupId>org.apache.portals.bridges</groupId>
+         <artifactId>portals-bridges-common</artifactId>
+         <version>${pom.version}</version>
+      </dependency>        
+    </dependencies>
+    
+    <!-- Build Configuration -->
+
+    <build>
+        <sourceDirectory>src/java</sourceDirectory>
+        <resources>
+            <resource>
+                <directory>.</directory>
+                <targetPath>META-INF</targetPath>
+                <includes>
+                    <include>NOTICE.txt</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${basedir}/../</directory>
+                <targetPath>META-INF</targetPath>
+                <includes>
+                    <include>LICENSE.TXT</include>
+                </includes>
+            </resource>
+        </resources>
+    </build>
+    
+    <!-- Project Information -->
+
+    <scm>
+        
<connection>scm:svn:http://svn.apache.org/repos/asf/portals/bridges/trunk/groovy</connection>
+        
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/bridges/trunk/groovy</developerConnection>
+        
<url>http://svn.apache.org/viewcvs.cgi/portals/bridges/trunk/groovy/</url>
+    </scm>
+
+</project>

Propchange: portals/bridges/trunk/groovy/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/trunk/groovy/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/trunk/groovy/project.properties
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/project.properties?view=auto&rev=547171
==============================================================================
--- portals/bridges/trunk/groovy/project.properties (added)
+++ portals/bridges/trunk/groovy/project.properties Thu Jun 14 01:41:54 2007
@@ -0,0 +1,20 @@
+# 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.
+#
+# $Id$
+
+maven.multiproject.type=jar
+maven.license.licenseFile=${basedir}/../LICENSE.TXT
+

Propchange: portals/bridges/trunk/groovy/project.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/trunk/groovy/project.properties
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/trunk/groovy/project.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/project.xml?view=auto&rev=547171
==============================================================================
--- portals/bridges/trunk/groovy/project.xml (added)
+++ portals/bridges/trunk/groovy/project.xml Thu Jun 14 01:41:54 2007
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+
+    $Id$
+-->
+<project>
+  <extend>${basedir}/../project.xml</extend>
+  <pomVersion>3</pomVersion>
+  <id>portals-bridges-groovy</id>
+  <name>Groovy Bridge</name>
+  <currentVersion>${portals.bridges.groovy.version}</currentVersion>
+  <package>org.apache.portals.bridges.groovy</package>
+    <description>Apache Portals Groovy Framework Bridge</description>
+  <shortDescription>Apache Portals Groovy Framework Bridge</shortDescription>
+  <repository>
+    
<connection>scm:svn:http://svn.apache.org/repos/asf/portals/bridges/trunk/groovy</connection>
+    
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/bridges/trunk/groovy</developerConnection>
+    
<url>http://svn.apache.org/viewcvs.cgi/portals/bridges/trunk/bridges/groovy/</url>
+  </repository>
+  <developers>
+    <developer>
+      <name>Ate Douma</name>
+      <id>ate</id>
+      <email>[EMAIL PROTECTED]</email>
+      <timezone>+2</timezone>
+      <organization>Hippo</organization>
+      <roles>
+        <role>Java Developer</role>
+      </roles>
+    </developer>
+  </developers>
+  <contributors>
+    <contributor>
+      <name>Woonsan Ko</name>
+      <email>[EMAIL PROTECTED]</email>
+      <roles>
+        <role>Java Developer</role>
+      </roles>
+    </contributor>    
+  </contributors>
+  <dependencies>
+  <dependency>
+      <id>groovy:groovy</id>
+      <version>1.0</version>
+      <type>jar</type>
+      <properties>
+        <war.bundle.jar>true</war.bundle.jar>
+      </properties>
+    </dependency>      
+    <dependency>
+      <id>commons-logging</id>
+      <version>${commons.logging.version}</version>
+    </dependency>
+    <dependency>
+      <id>org.apache.portals.bridges:portals-bridges-common</id>
+      <version>${portals.bridges.common.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <sourceDirectory>src/java</sourceDirectory>
+    <resources>
+      <resource>
+        <directory>.</directory>
+        <targetPath>META-INF</targetPath>
+        <includes>
+          <include>NOTICE.txt</include>
+        </includes>
+      </resource>
+    </resources>
+  </build>
+</project>

Propchange: portals/bridges/trunk/groovy/project.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/trunk/groovy/project.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java?view=auto&rev=547171
==============================================================================
--- 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
 (added)
+++ 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
 Thu Jun 14 01:41:54 2007
@@ -0,0 +1,239 @@
+/*
+ * 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.groovy;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyCodeSource;
+import org.codehaus.groovy.control.CompilationFailedException;
+
+/**
+ * <p>
+ * GroovyPortlet parses and invokes a groovy-scripted portlet. A 
groovy-scripted
+ * portlet just need to be implemented like any other Java-based portlet. So, a
+ * groovy-scripted portlet can support full features of JSR-168 portlet.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Woonsan Ko</a>
+ * @Id@
+ */
+public class GroovyPortlet implements Portlet
+{
+    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 AUTO_REFRESH_INIT_PARAM = "auto-refresh";
+
+    protected PortletConfig portletConfig;
+
+    protected String scriptSourceUri;
+
+    protected String scriptSourceUriEncoding = "UTF-8";
+
+    protected boolean autoRefresh;
+
+    protected long parsedFileLastModified;
+
+    protected GroovyCodeSource groovyCodeSource;
+
+    protected Portlet scriptPortletInstance;
+
+    protected GroovyClassLoader groovyClassLoader;
+
+    public GroovyPortlet()
+    {
+    }
+
+    public void init(PortletConfig config) throws PortletException
+    {
+        this.portletConfig = config;
+        this.groovyClassLoader = new GroovyClassLoader();
+
+        this.autoRefresh = 
"true".equals(config.getInitParameter(AUTO_REFRESH_INIT_PARAM));
+
+        String param = 
config.getInitParameter(SCRIPT_SOURCE_URL_ENCODING_INIT_PARAM);
+
+        if (param != null)
+        {
+            this.scriptSourceUriEncoding = param;
+        }
+
+        this.scriptSourceUri = 
config.getInitParameter(SCRIPT_SOURCE_INIT_PARAM);
+
+        if (this.scriptSourceUri == null)
+        {
+            throw new PortletException("Configuration failed: " + 
SCRIPT_SOURCE_INIT_PARAM + " should be set properly!");
+        }
+        else
+        {
+            try
+            {
+                if (this.scriptSourceUri.startsWith("file:"))
+                {
+                    String decodedScriptSourceUri = this.scriptSourceUri;
+
+                    try
+                    {
+                        decodedScriptSourceUri = 
URLDecoder.decode(this.scriptSourceUri, this.scriptSourceUriEncoding);
+                    }
+                    catch (UnsupportedEncodingException encodingEx)
+                    {
+                        throw new PortletException("Unsupported encoding: " + 
this.scriptSourceUriEncoding);
+                    }
+
+                    this.groovyCodeSource = new GroovyCodeSource(new 
File(decodedScriptSourceUri.substring(5)));
+                }
+                else if (this.scriptSourceUri.startsWith("classpath:"))
+                {
+                    String resourceURL = 
this.groovyClassLoader.getResource(this.scriptSourceUri.substring(10))
+                            .toString();
+
+                    if (resourceURL.startsWith("file:"))
+                    {
+                        String decodedScriptSourceUri = resourceURL;
+
+                        try
+                        {
+                            decodedScriptSourceUri = 
URLDecoder.decode(resourceURL, this.scriptSourceUriEncoding);
+                        }
+                        catch (UnsupportedEncodingException encodingEx)
+                        {
+                            throw new PortletException("Unsupported encoding: 
" + this.scriptSourceUriEncoding);
+                        }
+
+                        this.groovyCodeSource = new GroovyCodeSource(new 
File(decodedScriptSourceUri.substring(5)));
+                    }
+                    else
+                    {
+                        throw new PortletException(SCRIPT_SOURCE_INIT_PARAM
+                                + " with 'classpath:' prefix should indicate 
to a local resource");
+                    }
+                }
+                else
+                {
+                    this.groovyCodeSource = new GroovyCodeSource(new 
File(config.getPortletContext().getRealPath(
+                            this.scriptSourceUri)));
+                }
+            }
+            catch (FileNotFoundException e)
+            {
+                throw new PortletException("File not found: " + 
this.scriptSourceUri, e);
+            }
+
+            this.groovyCodeSource.setCachable(!this.autoRefresh);
+        }
+
+        refreshPortletInstance();
+
+        if (this.scriptPortletInstance == null)
+        {
+            throw new PortletException("Groovy script portlet is not 
available!");
+        }
+    }
+
+    public void processAction(ActionRequest request, ActionResponse response) 
throws PortletException, IOException
+    {
+        refreshPortletInstance();
+
+        if (this.scriptPortletInstance == null)
+        {
+            throw new PortletException("Groovy script portlet is not 
available!");
+        }
+        else
+        {
+            this.scriptPortletInstance.processAction(request, response);
+        }
+    }
+
+    public void render(RenderRequest request, RenderResponse response) throws 
PortletException, IOException
+    {
+        refreshPortletInstance();
+
+        if (this.scriptPortletInstance == null)
+        {
+            throw new PortletException("Groovy script portlet is not 
available!");
+        }
+        else
+        {
+            this.scriptPortletInstance.render(request, response);
+        }
+    }
+
+    public void destroy()
+    {
+        if (this.scriptPortletInstance != null)
+        {
+            this.scriptPortletInstance.destroy();
+        }
+    }
+
+    protected void refreshPortletInstance() throws PortletException
+    {
+        if (this.scriptPortletInstance == null)
+        {
+            try
+            {
+                createScriptPortletInstance();
+            }
+            catch (Exception ex)
+            {
+                throw new PortletException("Could not compile script: " + 
this.scriptSourceUri, ex);
+            }
+        }
+        else if (this.autoRefresh && isScriptFileModified())
+        {
+            synchronized (this.scriptPortletInstance)
+            {
+                try
+                {
+                    createScriptPortletInstance();
+                }
+                catch (Exception ex)
+                {
+                    throw new PortletException("Could not compile script: " + 
this.scriptSourceUri, ex);
+                }
+            }
+        }
+    }
+
+    protected boolean isScriptFileModified()
+    {
+        return (this.groovyCodeSource.getFile().lastModified() > 
this.parsedFileLastModified);
+    }
+
+    protected void createScriptPortletInstance() throws 
CompilationFailedException, InstantiationException,
+            IOException, IllegalAccessException, PortletException
+    {
+        Class scriptPortletClass = 
this.groovyClassLoader.parseClass(this.groovyCodeSource);
+        this.scriptPortletInstance = (Portlet) 
scriptPortletClass.newInstance();
+        this.parsedFileLastModified = 
this.groovyCodeSource.getFile().lastModified();
+        this.scriptPortletInstance.init(this.portletConfig);
+    }
+}

Propchange: 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/trunk/groovy/xdocs/index.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/xdocs/index.xml?view=auto&rev=547171
==============================================================================
--- portals/bridges/trunk/groovy/xdocs/index.xml (added)
+++ portals/bridges/trunk/groovy/xdocs/index.xml Thu Jun 14 01:41:54 2007
@@ -0,0 +1,238 @@
+<?xml version="1.0"?>
+<!--
+       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.
+-->
+<document>
+       <properties>
+               <title>Jetspeed Groovy Portlet Guide</title>
+               <subtitle>Documentation for Creating a Groovy Portlet</subtitle>
+               <authors>
+                       <person name="Woonsan Ko" email="[EMAIL PROTECTED]" />
+               </authors>
+       </properties>
+       <body>
+               <section name="Jetspeed Groovy Portlet Guide">
+                       <p>
+                               This guide provides a tutorial for creating a 
Groovy portlet 
+                with full-featured portlet modes.
+                       </p>
+                       <subsection name="1. The Portlet Class">
+                               <p>
+                               Create the file HelloGroovy.groovy in a 
directory called
+                               groovy-simplest/WEB-INF/classes:
+                               <source><![CDATA[
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletPreferences;
+
+public class HelloGroovy extends GenericPortlet
+{
+    public void doView(RenderRequest request, RenderResponse response)
+    {
+        PortletContext context = getPortletContext();
+        PortletRequestDispatcher rd = 
+            
context.getRequestDispatcher("/WEB-INF/view/hello-groovy-view.jsp");
+        rd.include(request, response);
+    }
+    
+    public void doEdit(RenderRequest request, RenderResponse response)
+    {
+        PortletContext context = getPortletContext();
+        PortletRequestDispatcher rd = 
+            
context.getRequestDispatcher("/WEB-INF/view/hello-groovy-edit.jsp");
+        rd.include(request, response);
+    }
+
+    public void doHelp(RenderRequest request, RenderResponse response)
+    {
+        PortletContext context = getPortletContext();
+        PortletRequestDispatcher rd = 
+            
context.getRequestDispatcher("/WEB-INF/view/hello-groovy-help.html");
+        rd.include(request,response);
+    }
+    
+    public void processAction(ActionRequest request, ActionResponse response)
+    {
+        String message = request.getParameter("message");
+        
+        if (null != message && !"".equals(message)) {
+            PortletPreferences prefs = request.getPreferences();
+            prefs.setValue("message", message);
+            prefs.store();
+        }
+    }
+}
+                               ]]></source>
+                               </p>
+                               <p>
+                               You don't have to compile the source because 
it's groovy.
+                               </p>
+                       </subsection>
+                       <subsection name="2. The portlet.xml">
+                       <p>
+                       Create the file portlet.xml in the 
groovy-simplest/WEB-INF directory.
+                       <source><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<portlet-app id="velocitysimplest" version="1.0">
+  <portlet id="HelloGroovy">
+    <portlet-name>HelloGroovy</portlet-name>
+    <display-name>Hello Groovy Display Name</display-name>
+    
<portlet-class>org.apache.portals.bridges.groovy.GroovyPortlet</portlet-class>
+    <init-param>
+      <name>script-source</name>
+      <!-- Note: You can set script source in three ways.
+                 The first is to use relative path uri,
+                 the second is to use file: url,
+                 and the last is to classpath: uri -->
+      <!--
+      <value>/WEB-INF/groovy/HelloGroovy.groovy</value>
+      <value>file:/C:/Program Files/Apache Software Foundation/Tomcat 
5.5/webapps/demo/WEB-INF/groovy/HelloGroovy.groovy</value>
+      -->
+      <value>classpath:HelloGroovy.groovy</value>
+    </init-param>
+    <!-- If auto-refresh is true, then a modification of script source applies 
instantly. -->
+    <init-param>
+      <name>auto-refresh</name>
+      <value>true</value>
+    </init-param>
+    <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</title>
+      <short-title>Hello Groovy Short Title</short-title>
+    </portlet-info>
+  </portlet>
+</portlet-app>]]>
+                       </source>
+                       </p>
+                       </subsection>
+                       <subsection name="3. The web.xml">
+                       <p>
+            You don't have to add any special tags for this simple example,
+            but you can add some tags for supporting Groovlet or Groovy 
template as a view page.
+            Please see the groovy documentation for those.
+<source><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN"
+                         "http://java.sun.com/dtd/web-app_2_3.dtd";>
+<web-app>
+  <display-name>Groovy Simplest</display-name>
+  <description>The world's simplest Groovy portlet</description>
+
+</web-app>
+]]></source>
+                       </p>
+                       </subsection>
+                       <subsection name="4. The View pages for view, edit and 
help mode">
+                       <p>
+                        Create the hello-groovy-view.jsp file in the 
groovy-simplest/WEB-INF/view directory. Put whatever content you desire in it. 
Here is an example: 
+<source><![CDATA[
+<%@ page session="false" %>                            
+<%@ page import="javax.portlet.*"%>
+<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
+
+<portlet:defineObjects/>                            
+
+<%
+String message = renderRequest.getPreferences().getValue("message", "Hello, 
Groovy!");
+%>
+
+<h1><%=message%>!</h1>
+]]></source>
+
+                        Create the hello-groovy-edit.jsp file in the 
groovy-simplest/WEB-INF/view directory. Put whatever content you desire in it. 
Here is an example: 
+<source><![CDATA[
+<%@ page session="false" %>                            
+<%@ page import="javax.portlet.*"%>
+<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
+
+<portlet:defineObjects/>                            
+
+<%
+String message = renderRequest.getPreferences().getValue("message", "Hello, 
Groovy!");
+%>
+
+<form method="post" action="<portlet:actionURL/>">
+    Message: <input type="text" name="message" value="<%=message%>">
+    <input type="submit" value="Submit">
+</form>
+]]></source>
+                        Last, create the hello-groovy-help.html file in the 
groovy-simplest/WEB-INF/view directory. Put whatever content you desire in it. 
Here is an example:
+<source><![CDATA[
+<H1>Hello Groovy Help</H1>
+<HR>
+
+<P>Groovy Portlet support rapid portlet application development.</P>
+]]></source>
+                       </p>
+                       </subsection>
+                       <subsection name="5. The Dependency JARs">
+                       <p>
+                        Copy the portals-bridges-groovy-1.0.jar,
+                        groovy-1.0.jar, antlr-2.7.5.jar, and asm-2.2.jar to 
the groovy-simplest/WEB-INF/lib
+                        directory. IMPORTANT: 
+                        Do NOT put the portlet-api-1.0.jar in the war file. If 
you have already built Jetspeed some of the jars should be in your Maven 
repository. If so executing these commands in the lib directory will set up the 
dependencies for you.
+                        <source><![CDATA[
+ln -s 
~/.maven/repository/org.apache.portals.bridges/jars/portals-bridges-groovy-1.0.jar
+                        ]]></source>
+                        And, if you download from <a 
href="http://groovy.codehaus.org";>http://groovy.codehaus.org</a> and install 
groovy,
+                        you can find groovy-1.0.jar, antlr-2.7.5.jar, and 
asm-2.2.jar in the lib directory under groovy home directory.
+                        Also, copy the portlet.tld to the 
groovy-simplest/WEB-INF directory. You can find the portlet.tld file in 
jetspeed-2/src/webapps/WEB-INF/ source directory. Or you can copy  that from 
the WEB-INF/ directory of the demo portlet.
+                       </p>
+                       </subsection>
+                       <subsection name="6. The WAR file">
+                       <p>
+                       From the directory groovy-simplest combine the files 
above into a war file using the command,
+                       <source>
+jar cvf ../groovy-simplest.war .
+                       </source>
+                       </p>
+                       </subsection>
+                       <subsection name="7. Deploy the WAR file">
+                       <p>
+                       Copy the war file to 
<code>$CATALINA_HOME/webapps/jetspeed/WEB-INF/deploy</code>.
+                        Jetspeed-2 will deploy the webapp.
+                       </p>
+                       </subsection>
+                       <subsection name="8. The PSML">
+                       <p>
+                        Create the PSML page using the Jetspeed portlet 
chooser. Login and click on the
+                        edit page icon.
+                        Your user must have the permission to edit pages. The 
user <code>admin</code>
+                        password
+                        <code>admin</code> has permission to edit all pages.
+                       </p>
+                       </subsection>
+            <subsection name="9. Additional Notes">
+                <ul>
+                    <li>In this example, JSP and JSTL is used for view pages. 
However, you can use other technologies such as Velocity, Groovlet or Groovy 
template.</li>
+                    <li>GroovyPortlet instantiates a groovy-scripted portlet 
instance just like any Java portlet, and so you can use any techniques used in 
Java portlet programming. For example, your groovy script portlet can extend 
org.apache.portals.bridges.common.GenericServletPortlet to simplify 
implementation.</li>
+                    <li>You can make the script source simpler than Java. See 
the groovy documentation.</li>
+                </ul>
+                       </subsection>
+               </section>
+       </body>
+</document>

Propchange: portals/bridges/trunk/groovy/xdocs/index.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/trunk/groovy/xdocs/index.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/bridges/trunk/groovy/xdocs/navigation.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/groovy/xdocs/navigation.xml?view=auto&rev=547171
==============================================================================
--- portals/bridges/trunk/groovy/xdocs/navigation.xml (added)
+++ portals/bridges/trunk/groovy/xdocs/navigation.xml Thu Jun 14 01:41:54 2007
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+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.
+-->
+<project>
+  <title>Portals Bridges - Groovy Bridge</title>
+
+  <body>
+    <links>
+      <item name="Jetspeed 2" href="http://portals.apache.org/jetspeed-2"; 
target="_nw"/>
+      <item name="Bridges Home" href="../../index.html"/>
+    </links>
+
+    <menu name="Groovy Bridge">
+      <item name="Guide" href="index.html"/>
+    </menu>      
+                  
+  </body>
+</project>

Propchange: portals/bridges/trunk/groovy/xdocs/navigation.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/bridges/trunk/groovy/xdocs/navigation.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/bridges/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/pom.xml?view=diff&rev=547171&r1=547170&r2=547171
==============================================================================
--- portals/bridges/trunk/pom.xml (original)
+++ portals/bridges/trunk/pom.xml Thu Jun 14 01:41:54 2007
@@ -109,6 +109,7 @@
         
<org.apache.portals.bridges.perl.version>1.0.2-dev</org.apache.portals.bridges.perl.version>
         
<org.apache.portals.bridges.php.version>1.0.2-dev</org.apache.portals.bridges.php.version>
         
<org.apache.portals.bridges.velocity.version>1.0.2-dev</org.apache.portals.bridges.velocity.version>
+        
<org.apache.portals.bridges.groovy.version>1.0.2-dev</org.apache.portals.bridges.groovy.version>
         
<org.apache.portals.bridges.portletfilter.version>1.0.2-dev</org.apache.portals.bridges.portletfilter.version>
        
         
<portals.bridges.struts.version>1.0.2-dev</portals.bridges.struts.version>
     </properties>
@@ -126,6 +127,7 @@
         <module>jsf</module>
         <module>perl</module>        
         <module>php</module>        
+        <module>groovy</module>
         <module>portletfilter</module>                
         <module>mapserver</module>
         
@@ -255,6 +257,11 @@
             <groupId>velocity</groupId>
             <artifactId>velocity</artifactId>
             <version>${velocity.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>${groovy.version}</version>
         </dependency>
         <dependency>
             <groupId>velocity-tools</groupId>

Modified: portals/bridges/trunk/project.properties
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/project.properties?view=diff&rev=547171&r1=547170&r2=547171
==============================================================================
--- portals/bridges/trunk/project.properties (original)
+++ portals/bridges/trunk/project.properties Thu Jun 14 01:41:54 2007
@@ -94,6 +94,7 @@
 portals.bridges.python.version=1.0.2-dev
 portals.bridges.struts.version=1.0.2-dev
 portals.bridges.velocity.version=1.0.2-dev
+portals.bridges.groovy.version=1.0.2-dev
 portals.bridges.portletfilter.version=1.0.2-dev
 portals.bridges.mapserver.version=1.0.2-dev
 

Modified: portals/bridges/trunk/project.xml
URL: 
http://svn.apache.org/viewvc/portals/bridges/trunk/project.xml?view=diff&rev=547171&r1=547170&r2=547171
==============================================================================
--- portals/bridges/trunk/project.xml (original)
+++ portals/bridges/trunk/project.xml Thu Jun 14 01:41:54 2007
@@ -31,7 +31,7 @@
     <package>org.apache.portals.bridges</package>
     <description>
       Portals Bridges provides support for JSR-168 compliant Portlet 
development
-      using common web frameworks like Struts, JSF, PHP, Perl and Velocity
+      using common web frameworks like Struts, JSF, PHP, Perl, Velocity and 
Groovy
     </description>
     <shortDescription>JSR-168 Portlet development support for common web 
frameworks</shortDescription>
     <url>http://portals.apache.org/bridges</url>



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

Reply via email to