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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.portal.portlets;
181920import org.apache.jetspeed.capability.CapabilityMap;
21import org.apache.jetspeed.util.MimeType;
22import org.apache.jetspeed.services.rundata.JetspeedRunData;
23import org.apache.ecs.*;
242526/***27 * Portlet for rendering HTML links28 * Can also be used for WML but no output will be created so29 * redering for wml is done in by the /wml/column.vm file30 * 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 */34publicclassLinkPortletextendsAbstractPortlet35 {
3637// Define parameter name for a image38publicstaticfinal String L_IMAGE = "image";
39// Define parameter name for the link name40publicstaticfinal String L_NAME = "anchor";
41// Define parameter name for the link url42publicstaticfinal String L_URL = "link";
43// Define parameter name for the link description44publicstaticfinal String L_DESC = "description";
45// Define the image for opening the link in an external window46publicstaticfinal String EXT_LINK_IMG = "exlink.gif";
474849/***50 * Render HTML links like:51 * <bullet> <open_new_window_link+image> <link_image> <link_name> <link_description>.52 * @return org.apache.ecs.ConcreteElement53 * @param data org.apache.turbine.util.RunData54 */55public org.apache.ecs.ConcreteElement getContent(org.apache.turbine.util.RunData data)
56 {
5758CapabilityMap cap = ((JetspeedRunData)data).getCapability();
5960// only for HTML mimetype!!!61if (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 = "";
69int contains = 0;
70int i = 0;
7172do73 {
74if (i>0)
75 cstr=String.valueOf(i);
7677 link = getPortletConfig().getInitParameter(L_URL+cstr);
7879// Link available?80if ((link!=null) && (link.length()>0))
81 {
8283// start Linklist84if (i==0)
85 res = "<ul>";
8687 image = getPortletConfig().getInitParameter(L_IMAGE+cstr);
88 name = getPortletConfig().getInitParameter(L_NAME+cstr);
89 desc = getPortletConfig().getInitParameter(L_DESC+cstr);
9091// set description92if ((desc==null) || (desc.length()<1))
93 desc = "follow this link";
9495// add new entry96 res += "<li>";
9798// add open in new window link99 res += "<A HREF=\""+link+"\" TARGET=\"_new\"><IMG SRC=\"images/"+EXT_LINK_IMG+"\" BORDER=\"0\" ALT=\""+name+"\"></A>";
100101// add link102 res += "<A HREF=\""+link+"\">";
103104// add image105if ((image != null) && (image.length()>0))
106 res += " <IMG SRC=\""+image+"\" HSPACES=\"5\" ALT=\""+name+"\" BORDER=\"0\"> ";
107108// add name and description109 res += name+"</A> <SMALL>"+desc+"</SMALL></li>";
110 contains++;
111 }
112else113 link = null;
114115 i++;
116 }
117while (link != null);
118 {
119 }
120121// close list122if (contains > 0)
123 res += "</ul>";
124125return(new StringElement(res));
126 }
127128129130returnnew org.apache.jetspeed.util.JetspeedClearElement( " " );
131 }
132133 }