portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pau...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util/template JetspeedLink.java
Date Thu, 04 Apr 2002 03:49:23 GMT
paulsp      02/04/03 19:49:23

  Added:       src/java/org/apache/jetspeed/util/template JetspeedLink.java
  Log:
  Part of the PEID implementation. This will replace JetspeedTemplateLink.java
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/JetspeedLink.java
  
  Index: JetspeedLink.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.util.template;
  
  // Jetspeed
  import org.apache.jetspeed.om.profile.Profile;
  import org.apache.jetspeed.om.profile.ProfileException;
  import org.apache.jetspeed.om.profile.ProfileLocator;
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletSet;
  import org.apache.jetspeed.portal.PortletController;
  import org.apache.jetspeed.portal.PanedPortletController;
  import org.apache.jetspeed.services.Profiler;
  import org.apache.jetspeed.services.resources.JetspeedResources;
  import org.apache.jetspeed.services.rundata.JetspeedRunData;
  
  // Turbine
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.DynamicURI;
  import org.apache.turbine.util.template.TemplateLink;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * <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:paulsp@apache.org">Paul Spencer</a>
   * @version $Id: JetspeedLink.java,v 1.1 2002/04/04 03:49:23 paulsp Exp $
   */
  public class JetspeedLink implements ApplicationTool
  {
      
      // parameter names for the Jetspeed framework elements
  //    public static final String PANEID_KEY = "js_pane";
  //    public static final String PORTLETID_KEY = "js_peid";
      
      
      /**
       *<p>Request to which we refer.</p>
       */
      private JetspeedRunData rundata = null;
      
      /**
       * Profile locator from <code>rundata</code>.  This is here
       * for performance reasons.
       */
      private ProfileLocator locator = null;
      
      /**
       * @deprecated Use JetspeedResources.PATH_PANEL_KEY. This is a from JetspeedTemplateLink
       */
      public static final String PANEL_KEY = "select-panel";
      /**
       * @deprecated JetspeedResources.PATH_PORTLET_KEY. This is a from JetspeedTemplateLink
       */
      public static final String PORTLET_KEY = "portlet";
      /**
       *<p>The portlet that will be used to build the reference.</p>
       * @deprecated This is a from JetspeedTemplateLink
       */
      protected Portlet activePortlet = null;
      
      /**
       * Empty constructor.for introspection
       */
      public JetspeedLink()
      {
      }
      
      /**
       * Constructor required by ApplicationTool interface
       *
       * @param data A Jetspeed RunData object.
       */
      public JetspeedLink(RunData data)
      {
          init(data);
      }
      
      /**
       * Return an link to a specific portlet using the portet's id
       *
       * @param peid of the portlet
       * @throws ProfileException if the profile detects an error
       * @return DynamicURI to spedific portlet
       */
      public DynamicURI forPortletById(String peid) throws ProfileException
      {
          DynamicURI uri = Profiler.makeDynamicURI(rundata, locator);
          return uri.addPathInfo( JetspeedResources.PATH_PORTLETID_KEY, peid);
      }
      
      /**
       * Return a link to a specific pane using the pane's id
       *
       * @param paneId of the Pane
       * @throws ProfileException if the profile detects an error
       * @return  URI to specific portlet
       */
      public DynamicURI forPaneById(String paneId) throws ProfileException
      {
          DynamicURI uri = Profiler.makeDynamicURI(rundata, locator);
          return uri.addPathInfo(JetspeedResources.PATH_PANEID_KEY, paneId);
      }
      
      /**
       * Return a link to the root portlet or pane
       * @throws ProfileException if the profile detects an error
       * @return  URI to the root portlet/pane
       */
      public DynamicURI getRoot() throws ProfileException
      {
          return Profiler.makeDynamicURI(rundata, locator);
      }
      
      /**
       * Return a URL, as a string, the the root page or pane.
       *
       * @return a URL, as a string, the the root page or pane.
       */
      public String toString()
      {
          try
          {
              return Profiler.makeDynamicURI(rundata, locator).toString();
          } catch (ProfileException e)
          {
              return new DynamicURI(rundata).toString();
          }
      }
      
      /**
       * Depracated methods from JetspeedTemplateLink.
       */
      
      /**
       * <p> Set the portlet giving context to this Link object.</p>
       *
       * This method is from JetspeeTemplateLink and is only here
       * for backward compatibility. This it should not be used for
       * any new development.  Also any problems with this method will
       * not be fixed
       *
       * @param portlet the name of the active portlet
       * @deprecated the name is confusing. Use @see(#forPaneById()) instead.
       */
      public void setPortlet(Portlet portlet)
      {
          this.activePortlet=portlet;
      }
      
      
      /**
       * Add a portlet reference in the link.
       *
       * This method is from JetspeeTemplateLink and is only here
       * for backward compatibility. This it should not be used for
       * any new development.  Also any problems with this method will
       * not be fixed
       *
       * @param portlet the name of the portlet to link to
       * @deprecated the name is confusing. Use @see(#forPortletById()) instead.
       * @return a DynamicURI referencing the named portlet for easy link construction in
template
       */
      public DynamicURI setPortlet(String portlet)
      {
          return this.forPortlet( portlet );
      }
      
      /**
       * Add a portlet reference in the link.
       *
       * This method is from JetspeeTemplateLink and is only here
       * for backward compatibility. This it should not be used for
       * any new development.  Also any problems with this method will
       * not be fixed
       *
       * @param portlet the name of the portlet to link to
       * @deprecated Use @see(#forPortletById()) instead.
       * @return a DynamicURI referencing the named portlet for easy link construction in
template
       */
      public DynamicURI forPortlet(String portlet)
      {
          try
          {
              DynamicURI uri = Profiler.makeDynamicURI(rundata, locator);
              return uri.addPathInfo(JetspeedResources.PATH_PORTLET_KEY, portlet);
          } catch ( ProfileException e)
          {
              return null;
          }
      }
      
      /**
       * Add a select-panel reference in the link
       *
       * This method is from JetspeeTemplateLink and is only here
       * for backward compatibility. This it should not be used for
       * any new development.  Also any problems with this method will
       * not be fixed
       *
       * @param portlet the name of the portlet to link to
       * @deprecated Use @see(#forPaneById()) instead.
       * @return a self reference for easy link construction in template
       */
      public DynamicURI setPanel(String panel)
      {
          PortletController controller = activePortlet.getPortletConfig().getPortletSet().getController();
          
          String id = null;
          
          if (controller instanceof PanedPortletController)
          {
              PortletSet set = controller.getPortlets();
              Portlet portlet = null;
              if (null != set)
              {
                  portlet = set.getPortletByName(panel);
              }
              if (portlet != null)
                  id = portlet.getID();
          }
          
          try
          {
              DynamicURI uri = Profiler.makeDynamicURI(rundata, locator);
              return uri.addPathInfo(JetspeedResources.PATH_PANEID_KEY, id);
          } catch ( ProfileException e)
          {
              return null;
          }
      }
      
      /**
       * <p>Use the activePortlet to get the current Panel name (key).</p>
       *
       * This method is from JetspeeTemplateLink and is only here
       * for backward compatibility. This it should not be used for
       * any new development.  Also any problems with this method will
       * not be fixed
       *
       * @deprecated Use @see(#forPaneById()) instead.
       * @return the panel parameter name
       */
      public String getPanelKey()
      {
          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;
      }
      
      /**
       * Methods required by ApplictionTool interface
       *
       */
      
      /**
       * This will initialise a JetspeedTool object that was
       * constructed with the default constructor (ApplicationTool
       * method).
       *
       * @param data assumed to be a RunData object
       */
      
      public void init(Object data)
      {
          this.rundata = (JetspeedRunData)data;
          
          Profile profile = null;
          try
          {
              profile = Profiler.getProfile(rundata);
          }
          catch (Exception e)
          {
              locator = null;
              return;
          }
          
          // Get ProfileLocator for path info.
          if ((profile instanceof ProfileLocator) == false)
          {
              locator = null;
              return;
          }
          locator = (ProfileLocator) profile;
          
          return;
      }
      /**
       * Refresh method - does nothing
       */
      public void refresh()
      {
          // empty
      }
      
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message