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 ta...@apache.org on 2001/12/10 18:29:50 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets LinkPortlet.java

taylor      01/12/10 09:29:50

  Added:       src/java/org/apache/jetspeed/portal/portlets
                        LinkPortlet.java
  Log:
  - Renders links for HTML (no output for wml because rendering is done in the column.vm file)
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/LinkPortlet.java
  
  Index: LinkPortlet.java
  ===================================================================
  package org.apache.jetspeed.portal.portlets;
  
  
   /** LinkPortlet
    * Portlet for rendering HTML links
    * Can also be used for WML but no output will be created so
    * redering for wml is done in by the /wml/column.vm file
    * @author <a href="mailto:A.Kempf@web.de">Andreas Kempf</a>
    */
  import org.apache.jetspeed.capability.*;
  import org.apache.jetspeed.util.MimeType;
  import org.apache.jetspeed.services.resources.JetspeedResources;
  import org.apache.ecs.*;
  import org.apache.turbine.util.RunData;
  
  
  public class LinkPortlet extends AbstractPortlet 
  {
  
    // Define parameter name for a image 
    public static final String L_IMAGE = "image";
    // Define parameter name for the link name
    public static final String L_NAME  = "anchor";
    // Define parameter name for the link url
    public static final String L_URL   = "link";
    // Define parameter name for the link description
    public static final String L_DESC  = "description";
    // Define the image for opening the link in an external window
    public static final String EXT_LINK_IMG  = "exlink.gif";
  
  
  /**
   * Render HTML links like:
   * <bullet> <open_new_window_link+image> <link_image> <link_name> <link_description>.
   * @return org.apache.ecs.ConcreteElement
   * @param data org.apache.turbine.util.RunData
   */
  public org.apache.ecs.ConcreteElement getContent(org.apache.turbine.util.RunData data) 
  {
  
    CapabilityMap cap = CapabilityMapFactory.getCapabilityMap(data);
  
    // only for HTML mimetype!!!
    if (cap.getPreferredType().equals(MimeType.HTML))
    {
      String link;
      String image;
      String name;
      String desc;
      String res = "";
      String cstr = "";
      int contains = 0;
      int i = 0;
  
      do
      {
        if (i>0)
          cstr=String.valueOf(i);
          
        link = getPortletConfig().getInitParameter(L_URL+cstr);
                
        // Link available?
        if ((link!=null) && (link.length()>0))
        {
  
          // start Linklist
          if (i==0)
            res = "<ul>";
  
          image = getPortletConfig().getInitParameter(L_IMAGE+cstr);
          name = getPortletConfig().getInitParameter(L_NAME+cstr);
          desc = getPortletConfig().getInitParameter(L_DESC+cstr);
  
          // set description
          if ((desc==null) || (desc.length()<1))
            desc = "follow this link";
      
          // add new entry
          res += "<li>";
  
          // add open in new window link
          res += "<A HREF=\""+link+"\" TARGET=\"_new\"><IMG SRC=\"images/"+EXT_LINK_IMG+"\" BORDER=\"0\" ALT=\""+name+"\"></A>";
  
          // add link
          res += "<A HREF=\""+link+"\">";
    
          // add image
          if ((image != null) && (image.length()>0))
            res += "&nbsp;<IMG SRC=\"images/html/"+image+"\" HSPACES=\"5\" ALT=\""+name+"\" BORDER=\"0\">&nbsp;&nbsp;";
  
          // add name and description  
          res += name+"</A>&nbsp;&nbsp;&nbsp;&nbsp;<SMALL>"+desc+"</SMALL></li>";
          contains++;
        }
        else
          link = null;
        
        i++;  
      }
      while (link != null);
      {
      }
      
      // close list
      if (contains > 0)
        res += "</ul>"; 
  
      return(new StringElement(res));
    }
    
  
  
  	return new org.apache.ecs.ClearElement( " " );
  }
  
  }
  
  
  

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