Author: woonsan
Date: Thu Oct 25 22:32:32 2007
New Revision: 588531

URL: http://svn.apache.org/viewvc?rev=588531&view=rev
Log:
[PB-75] GroovyPortlet need to support Jetspeed's new feature, auto-dispatching 
for edit_defaults mode option.

Fixed.
So, now every bridge-based portlets can support edit_defaults mode 
automatically if they support just edit mode.

Modified:
    
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java

Modified: 
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?rev=588531&r1=588530&r2=588531&view=diff
==============================================================================
--- 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
 (original)
+++ 
portals/bridges/trunk/groovy/src/java/org/apache/portals/bridges/groovy/GroovyPortlet.java
 Thu Oct 25 22:32:32 2007
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 
 import javax.portlet.Portlet;
 import javax.portlet.PortletConfig;
@@ -29,6 +31,7 @@
 import javax.portlet.ActionResponse;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+import javax.portlet.GenericPortlet;
 
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyCodeSource;
@@ -43,7 +46,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Woonsan Ko</a>
  * @Id@
  */
-public class GroovyPortlet implements Portlet
+public class GroovyPortlet extends GenericPortlet
 {
     public static final String SCRIPT_SOURCE_INIT_PARAM = "script-source";
 
@@ -65,10 +68,15 @@
 
     protected Portlet scriptPortletInstance;
 
+    protected GenericPortlet scriptGenericPortletInstance;
+
+    protected Method portletDoEditMethod;
+
     protected GroovyClassLoader groovyClassLoader;
 
     public GroovyPortlet()
     {
+        super();
     }
 
     public void init(PortletConfig config) throws PortletException
@@ -158,6 +166,14 @@
         }
     }
 
+    public void destroy()
+    {
+        if (this.scriptPortletInstance != null)
+        {
+            this.scriptPortletInstance.destroy();
+        }
+    }
+
     public void processAction(ActionRequest request, ActionResponse response) 
throws PortletException, IOException
     {
         refreshPortletInstance();
@@ -180,17 +196,31 @@
         {
             throw new PortletException("Groovy script portlet is not 
available!");
         }
-        else
-        {
-            this.scriptPortletInstance.render(request, response);
-        }
+
+        this.scriptPortletInstance.render(request, response);
     }
 
-    public void destroy()
+    public PortletConfig getPortletConfig ()
     {
-        if (this.scriptPortletInstance != null)
+        return this.portletConfig;
+    }
+    
+    public void doEdit(RenderRequest request, RenderResponse response) throws 
PortletException, IOException
+    {
+        if (this.scriptGenericPortletInstance != null && 
this.portletDoEditMethod != null)
         {
-            this.scriptPortletInstance.destroy();
+            try
+            {
+                
this.portletDoEditMethod.invoke(this.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.");
         }
     }
 
@@ -233,6 +263,27 @@
     {
         Class scriptPortletClass = 
this.groovyClassLoader.parseClass(this.groovyCodeSource);
         this.scriptPortletInstance = (Portlet) 
scriptPortletClass.newInstance();
+        this.scriptGenericPortletInstance = null;
+        this.portletDoEditMethod = null;
+        
+        if (this.scriptPortletInstance instanceof GenericPortlet)
+        {
+            this.scriptGenericPortletInstance = (GenericPortlet) 
this.scriptPortletInstance;
+            
+            try
+            {
+                Method doEditMethod = 
this.scriptGenericPortletInstance.getClass().getMethod("doEdit", new Class [] { 
RenderRequest.class, RenderResponse.class });
+                
+                if (Modifier.isPublic(doEditMethod.getModifiers()))
+                {
+                    this.portletDoEditMethod = doEditMethod;
+                }
+            }
+            catch (NoSuchMethodException e)
+            {
+            }
+        }
+        
         this.parsedFileLastModified = 
this.groovyCodeSource.getFile().lastModified();
         this.scriptPortletInstance.init(this.portletConfig);
     }



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

Reply via email to