You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by sg...@apache.org on 2002/03/05 13:26:33 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util/template JetspeedTemplateLink.java PortletTemplateLink.java

sgala       02/03/05 04:26:33

  Modified:    src/java/org/apache/jetspeed/portal/portlets
                        VelocityPortlet.java
               src/java/org/apache/jetspeed/util/template
                        JetspeedTemplateLink.java PortletTemplateLink.java
  Log:
  Change the mechanism to have jlink in the toolbox. Instead of instantiating a new one for each request, leave the work to turbine, and setPortlet() of the right one in the rendering code. This deprecates the whole PortletTemplateLink class (I should have removed it, but...) as now JetspeedTemplateLink is able to deliver context sensitive links for Panes. I hope I won't break anything.
  
  Revision  Changes    Path
  1.12      +5 -2      jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java
  
  Index: VelocityPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- VelocityPortlet.java	28 Jan 2002 11:25:50 -0000	1.11
  +++ VelocityPortlet.java	5 Mar 2002 12:26:33 -0000	1.12
  @@ -65,7 +65,7 @@
   import org.apache.jetspeed.portal.portlets.AbstractPortlet;
   import org.apache.jetspeed.portal.PortletException;
   import org.apache.jetspeed.services.TemplateLocator;
  -import org.apache.jetspeed.util.template.PortletTemplateLink;
  +import org.apache.jetspeed.util.template.JetspeedTemplateLink;
   import org.apache.jetspeed.services.JetspeedSecurity;
   import org.apache.jetspeed.services.security.JetspeedSecurityService;
   
  @@ -119,7 +119,10 @@
           // Put the request and session based contexts
           TurbinePull.populateContext(context, rundata);
           
  -        context.put( "jlink", new PortletTemplateLink(rundata,this) );
  +        //We need to initialize the jlink tool with ourselves to
  +        // enable links between portlets.
  +        JetspeedTemplateLink jlink = (JetspeedTemplateLink) context.get( "jlink" );
  +        jlink.setPortlet( this );
   
           String actionName = getPortletConfig().getInitParameter("action");
           
  
  
  
  1.6       +88 -15    jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/JetspeedTemplateLink.java
  
  Index: JetspeedTemplateLink.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/JetspeedTemplateLink.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JetspeedTemplateLink.java	22 Jul 2001 20:31:11 -0000	1.5
  +++ JetspeedTemplateLink.java	5 Mar 2002 12:26:33 -0000	1.6
  @@ -60,16 +60,25 @@
   import org.apache.turbine.util.template.TemplateLink;
   import org.apache.turbine.services.pull.ApplicationTool;
   
  +import org.apache.jetspeed.portal.Portlet;
  +import org.apache.jetspeed.portal.PortletController;
  +import org.apache.jetspeed.portal.PanedPortletController;
  +
   import org.apache.jetspeed.services.rundata.JetspeedRunData;
   
   
   /**
  - * A customized version of the TemplateLink which can handle portlet
  - * references.
  - * It is inserted into the template context by the JetspeedVelocityPage.
  + * <p>A customized version of the TemplateLink which can handle portlet
  + * references.</p>
  + *
  + * <p>It is inserted into the template context by Turbine, via request tools.</p>
  + *
  + * <p>Each portlet must call setPortlet(this) on it before entering the template
  + * rendering code. This is done currently in VelocityPortlet.</p>
    *
    * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
  - * @version $Id: JetspeedTemplateLink.java,v 1.5 2001/07/22 20:31:11 raphael Exp $
  + * @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
  + * @version $Id: JetspeedTemplateLink.java,v 1.6 2002/03/05 12:26:33 sgala Exp $
    */
   public class JetspeedTemplateLink
       extends TemplateLink implements ApplicationTool
  @@ -82,8 +91,22 @@
       public static final String TEMPLATE_KEY = "template";
       public static final String PANEL_KEY = "select-panel";        
       
  -    private String portlet = null;
  +    /**
  +     *<p>The name of the portlet for which a URL will be generated.</p>
  +     */
  +    private String portletName = null;
  +
  +    /**
  +     *<p>Request to which we refer.</p>
  +     */
       private JetspeedRunData data = null;
  +
  +    /**
  +     *<p>The portlet that will be used to build the reference.</p>
  +     */
  +    protected Portlet activePortlet = null;
  +
  +
       
       /**
        * Empty constructor.for introspection
  @@ -95,7 +118,7 @@
       /**
        * Constructor.
        *
  -     * @param data A Turbine RunData object.
  +     * @param data A Jetspeed RunData object.
        */
       public JetspeedTemplateLink(RunData data)
       {
  @@ -129,6 +152,17 @@
       }
   
       /**
  +     * <p> Set the portlet giving context to this Link object.</p>
  +     *
  +     */
  +    public void setPortlet(Portlet portlet)
  +    {
  +        this.activePortlet=portlet;
  +    }
  +    
  +
  +
  +    /**
        * Refresh method - does nothing
        */
       public void refresh()
  @@ -143,25 +177,37 @@
       }
   
       /** 
  -     * Add a portlet reference in the link
  +     * Return a URI that refers to the named portlet.
        *
        * @param portlet the name of the portlet to link to
  -     * @return a self reference for easy link construction in template
  +     * @return a DynamicURI referencing the named portlet for easy link construction in template
        */
  -    public DynamicURI setPortlet(String portlet)
  +    public DynamicURI forPortlet(String portlet)
       {
  -        this.portlet=portlet;
  +        this.portletName = portlet;
           removePathInfo(getPortletKey());
           removeQueryData(getPortletKey());
           return addPathInfo(getPortletKey(), portlet);
       }
       
       /** 
  +     * Add a portlet reference in the link.
  +     *
  +     * @param portlet the name of the portlet to link to
  +     * @deprecated the name is confusing. Use @see(#forPortlet()) instead.
  +     * @return a DynamicURI referencing the named portlet for easy link construction in template
  +     */
  +    public DynamicURI setPortlet(String portlet)
  +    {
  +        return this.forPortlet( portlet ); 
  +    }
  +    
  +    /** 
        * @return the portlet parameter value
        */
       public String getPortlet()
       {
  -        return this.portlet;
  +        return this.portletName;
       }
       
       /** 
  @@ -204,28 +250,55 @@
        */
       public DynamicURI setPanel(String panel)
       {
  +        Log.debug("JetspeedTemplateLink: setPanel(String):" + panel );
           removePathInfo(getPanelKey());
           removeQueryData(getPanelKey());
           return addPathInfo(getPanelKey(), panel);
       }
       
  -     /** 
  +    /** 
  +     * <p>Use the activePortlet to get the current Panel name (key).</p>
  +     *
        * @return the panel parameter name
        */
       public String getPanelKey()
       {
  -        return PANEL_KEY;
  +        String panelName = PANEL_KEY;
  +        try
  +        {
  +            PortletController controller = activePortlet.getPortletConfig()
  +                                                        .getPortletSet()
  +                                                        .getController();
  +
  +            if (controller instanceof PanedPortletController)
  +            {
  +                panelName=((PanedPortletController)controller).getParameterName();
  +            }
  +            
  +        }
  +        catch (Exception e)
  +        {
  +            panelName = PANEL_KEY;
  +        }
  +        
  +        return panelName;
       }    
  -    
  +
  +    /**
  +     *
  +     *
  +     */
       public String toString()
       {
  -        String buf = super.toString();
           String tmpl = this.data.getRequestedTemplate();
           if (tmpl!=null)
           {
               setPage(tmpl);
           }
           
  +        String buf = super.toString();
           return buf;
       }
  +
  +
   }
  
  
  
  1.2       +3 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/PortletTemplateLink.java
  
  Index: PortletTemplateLink.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/PortletTemplateLink.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PortletTemplateLink.java	27 Aug 2001 15:52:22 -0000	1.1
  +++ PortletTemplateLink.java	5 Mar 2002 12:26:33 -0000	1.2
  @@ -72,7 +72,9 @@
    * if it exists.
    *
    * @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
  - * @version $Id: PortletTemplateLink.java,v 1.1 2001/08/27 15:52:22 raphael Exp $
  + * @deprecated Since 2002-03-05. Use JetspeedTemplateLink with the setPortlet(Portlet) method to give
  + * it the right context.
  + * @version $Id: PortletTemplateLink.java,v 1.2 2002/03/05 12:26:33 sgala Exp $
    */
   public class PortletTemplateLink extends JetspeedTemplateLink
   {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>