KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > ui > render > LinkRenderer


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.list.ui.render;
25
26 import java.io.PrintWriter JavaDoc;
27
28 import org.riotfamily.common.beans.PropertyUtils;
29 import org.riotfamily.common.markup.Html;
30 import org.riotfamily.common.markup.TagWriter;
31 import org.riotfamily.common.web.util.ServletUtils;
32 import org.riotfamily.riot.list.command.core.LinkCommand;
33
34 /**
35  * @deprecated Please use the {@link LinkCommand} instead.
36  */

37 public class LinkRenderer implements CellRenderer {
38
39     private String JavaDoc prefix;
40     
41     private String JavaDoc suffix;
42     
43     private String JavaDoc target;
44     
45     private String JavaDoc messageKey;
46     
47     private String JavaDoc titleMessageKey;
48     
49     /**
50      * @deprecated No longer used.
51      */

52     public void setProperty(String JavaDoc property) {
53     }
54
55     public void setTarget(String JavaDoc target) {
56         this.target = target;
57     }
58
59     public void setPrefix(String JavaDoc prefix) {
60         this.prefix = prefix;
61     }
62
63     public void setSuffix(String JavaDoc suffix) {
64         this.suffix = suffix;
65     }
66     
67     public void setMessageKey(String JavaDoc messageKey) {
68         this.messageKey = messageKey;
69     }
70
71     public void setTitleMessageKey(String JavaDoc titleMessageKey) {
72         this.titleMessageKey = titleMessageKey;
73     }
74     
75     public void render(String JavaDoc propertyName, Object JavaDoc item, RenderContext context,
76             PrintWriter JavaDoc writer) {
77         
78         if (item != null) {
79             StringBuffer JavaDoc url = new StringBuffer JavaDoc();
80             if (prefix != null) {
81                 url.append(prefix);
82             }
83             if (propertyName != null) {
84                 url.append(PropertyUtils.getProperty(item, propertyName));
85             }
86             else {
87                 url.append(item);
88             }
89             if (suffix != null) {
90                 url.append(suffix);
91             }
92             String JavaDoc href = url.toString();
93             if (!ServletUtils.isAbsoluteUrl(href) && href.startsWith("/")) {
94                 href = context.getContextPath() + href;
95             }
96             TagWriter tag = new TagWriter(writer);
97             tag.start(Html.A);
98             
99             tag.attribute(Html.A_HREF, href);
100             if (target != null) {
101                 tag.attribute(Html.A_TARGET, target);
102             }
103             if (titleMessageKey != null) {
104                 tag.attribute(Html.TITLE, context.getMessageResolver()
105                         .getMessage(titleMessageKey));
106             }
107             if (messageKey != null) {
108                 tag.body(context.getMessageResolver().getMessage(messageKey));
109             }
110             tag.end();
111         }
112     }
113 }
114
Popular Tags