KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > LinkPortlet


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.portal.portlets;
18
19
20 import org.apache.jetspeed.capability.CapabilityMap;
21 import org.apache.jetspeed.util.MimeType;
22 import org.apache.jetspeed.services.rundata.JetspeedRunData;
23 import org.apache.ecs.*;
24
25
26 /**
27  * Portlet for rendering HTML links
28  * Can also be used for WML but no output will be created so
29  * redering for wml is done in by the /wml/column.vm file
30  *
31  * @author <a HREF="mailto:A.Kempf@web.de">Andreas Kempf</a>
32  * @version $Id: LinkPortlet.java,v 1.7 2004/02/23 04:03:34 jford Exp $
33  */

34 public class LinkPortlet extends AbstractPortlet
35 {
36
37   // Define parameter name for a image
38
public static final String JavaDoc L_IMAGE = "image";
39   // Define parameter name for the link name
40
public static final String JavaDoc L_NAME = "anchor";
41   // Define parameter name for the link url
42
public static final String JavaDoc L_URL = "link";
43   // Define parameter name for the link description
44
public static final String JavaDoc L_DESC = "description";
45   // Define the image for opening the link in an external window
46
public static final String JavaDoc EXT_LINK_IMG = "exlink.gif";
47
48
49 /**
50  * Render HTML links like:
51  * <bullet> <open_new_window_link+image> <link_image> <link_name> <link_description>.
52  * @return org.apache.ecs.ConcreteElement
53  * @param data org.apache.turbine.util.RunData
54  */

55 public org.apache.ecs.ConcreteElement getContent(org.apache.turbine.util.RunData data)
56 {
57
58   CapabilityMap cap = ((JetspeedRunData)data).getCapability();
59
60   // only for HTML mimetype!!!
61
if (cap.getPreferredType().getCode().equals(MimeType.HTML.getCode()))
62   {
63     String JavaDoc link;
64     String JavaDoc image;
65     String JavaDoc name;
66     String JavaDoc desc;
67     String JavaDoc res = "";
68     String JavaDoc cstr = "";
69     int contains = 0;
70     int i = 0;
71
72     do
73     {
74       if (i>0)
75         cstr=String.valueOf(i);
76
77       link = getPortletConfig().getInitParameter(L_URL+cstr);
78
79       // Link available?
80
if ((link!=null) && (link.length()>0))
81       {
82
83         // start Linklist
84
if (i==0)
85           res = "<ul>";
86
87         image = getPortletConfig().getInitParameter(L_IMAGE+cstr);
88         name = getPortletConfig().getInitParameter(L_NAME+cstr);
89         desc = getPortletConfig().getInitParameter(L_DESC+cstr);
90
91         // set description
92
if ((desc==null) || (desc.length()<1))
93           desc = "follow this link";
94
95         // add new entry
96
res += "<li>";
97
98         // add open in new window link
99
res += "<A HREF=\""+link+"\" TARGET=\"_new\"><IMG SRC=\"images/"+EXT_LINK_IMG+"\" BORDER=\"0\" ALT=\""+name+"\"></A>";
100
101         // add link
102
res += "<A HREF=\""+link+"\">";
103
104         // add image
105
if ((image != null) && (image.length()>0))
106           res += "&nbsp;<IMG SRC=\""+image+"\" HSPACES=\"5\" ALT=\""+name+"\" BORDER=\"0\">&nbsp;&nbsp;";
107
108         // add name and description
109
res += name+"</A>&nbsp;&nbsp;&nbsp;&nbsp;<SMALL>"+desc+"</SMALL></li>";
110         contains++;
111       }
112       else
113         link = null;
114
115       i++;
116     }
117     while (link != null);
118     {
119     }
120
121     // close list
122
if (contains > 0)
123       res += "</ul>";
124
125     return(new StringElement(res));
126   }
127
128
129
130     return new org.apache.jetspeed.util.JetspeedClearElement( " " );
131 }
132
133 }
134
Popular Tags