1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
38 public static final String L_IMAGE = "image";
39
40 public static final String L_NAME = "anchor";
41
42 public static final String L_URL = "link";
43
44 public static final String L_DESC = "description";
45
46 public static final String 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
61 if (cap.getPreferredType().getCode().equals(MimeType.HTML.getCode()))
62 {
63 String link;
64 String image;
65 String name;
66 String desc;
67 String res = "";
68 String 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
80 if ((link!=null) && (link.length()>0))
81 {
82
83
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
92 if ((desc==null) || (desc.length()<1))
93 desc = "follow this link";
94
95
96 res += "<li>";
97
98
99 res += "<A HREF=\""+link+"\" TARGET=\"_new\"><IMG SRC=\"images/"+EXT_LINK_IMG+"\" BORDER=\"0\" ALT=\""+name+"\"></A>";
100
101
102 res += "<A HREF=\""+link+"\">";
103
104
105 if ((image != null) && (image.length()>0))
106 res += " <IMG SRC=\""+image+"\" HSPACES=\"5\" ALT=\""+name+"\" BORDER=\"0\"> ";
107
108
109 res += name+"</A> <SMALL>"+desc+"</SMALL></li>";
110 contains++;
111 }
112 else
113 link = null;
114
115 i++;
116 }
117 while (link != null);
118 {
119 }
120
121
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 }