KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > jsptag > CommunityListTag


1 /*
2  * CommunityListTag.java
3  *
4  * Version: $Revision: 1.9 $
5  *
6  * Date: $Date: 2005/10/14 06:56:22 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.webui.jsptag;
41
42 import java.io.IOException JavaDoc;
43
44 import javax.servlet.http.HttpServletRequest JavaDoc;
45 import javax.servlet.jsp.JspException JavaDoc;
46 import javax.servlet.jsp.JspWriter JavaDoc;
47 import javax.servlet.jsp.jstl.fmt.LocaleSupport;
48 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
49
50 import org.dspace.content.Community;
51
52 /**
53  * Tag for display a list of communities
54  *
55  * @author Robert Tansley
56  * @version $Revision: 1.9 $
57  */

58 public class CommunityListTag extends TagSupport JavaDoc
59 {
60     /** Communities to display */
61     private Community[] communities;
62
63     public CommunityListTag()
64     {
65         super();
66     }
67
68     public int doStartTag() throws JspException JavaDoc
69     {
70         JspWriter JavaDoc out = pageContext.getOut();
71
72         try
73         {
74             out.println("<table align=\"center\" class=\"miscTable\" title=\"Community List\">");
75
76             // Write column headings
77
out.print("<tr><th id=\"t5\" class=\"oddRowOddCol\">"
78                             + LocaleSupport.getLocalizedMessage(pageContext,
79                                     "org.dspace.app.webui.jsptag.CommunityListTag.communityName")
80                     + "</th></tr>");
81
82             // Row: toggles between Odd and Even
83
String JavaDoc row = "even";
84
85             for (int i = 0; i < communities.length; i++)
86             {
87                 // name
88
String JavaDoc name = communities[i].getMetadata("name");
89
90                 // first and only column is 'name'
91
out.print("<tr><td headers=\"t5\" class=\"" + row + "RowEvenCol\">");
92                 out.print("<a HREF=\"");
93
94                 HttpServletRequest JavaDoc hrq = (HttpServletRequest JavaDoc) pageContext
95                         .getRequest();
96                 out.print(hrq.getContextPath() + "/handle/");
97                 out.print(communities[i].getHandle());
98                 out.print("\">");
99                 out.print(name);
100                 out.print("</a>");
101
102                 out.println("</td></tr>");
103
104                 row = (row.equals("odd") ? "even" : "odd");
105             }
106
107             out.println("</table>");
108         }
109         catch (IOException JavaDoc ie)
110         {
111             throw new JspException JavaDoc(ie);
112         }
113
114         return SKIP_BODY;
115     }
116
117     /**
118      * Get the communities to list
119      *
120      * @return the communities
121      */

122     public Community[] getCommunities()
123     {
124         return communities;
125     }
126
127     /**
128      * Set the communities to list
129      *
130      * @param communitiesIn
131      * the communities
132      */

133     public void setCommunities(Community[] communitiesIn)
134     {
135         communities = communitiesIn;
136     }
137
138     public void release()
139     {
140         communities = null;
141     }
142 }
143
Popular Tags