KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > webconnector > widgets > BannerWidget


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.webconnector.widgets;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.text.DateFormat JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Locale JavaDoc;
26
27 import org.lucane.common.concepts.UserConcept;
28 import org.lucane.webconnector.WebApp;
29 import org.lucane.webconnector.security.LucanePrincipal;
30
31 public class BannerWidget implements Widget
32 {
33     private WebApp app;
34     private LucanePrincipal user;
35     
36     public BannerWidget(WebApp app, LucanePrincipal user)
37     {
38         this.app = app;
39         this.user = user;
40     }
41     
42     public void render(Writer JavaDoc out) throws IOException JavaDoc
43     {
44         UserConcept concept;
45         try {
46             concept = user.getUser();
47         } catch (Exception JavaDoc e) {
48             throw new RuntimeException JavaDoc("Unable to get user concept !");
49         }
50         
51         Locale JavaDoc locale = new Locale JavaDoc(concept.getLanguage());
52         DateFormat JavaDoc format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale);
53         
54         out.write("<!-- BannerWidget start -->\n");
55         out.write("<div id='banner'>\n");
56         
57         out.write("<a id='bannerHome' HREF='/'>Lucane</a>\n");
58         
59         //link to application if needed
60
if(!app.getName().equals("org.lucane.applications.maininterface")
61                 && !app.getName().equals(concept.getStartupPlugin()))
62         {
63             out.write("<a id='bannerAppName' HREF='/");
64             out.write(app.getName());
65             out.write("/'>");
66             out.write(app.getTitle());
67             out.write("</a>\n");
68         }
69         
70         out.write("<p id='bannerUser'>");
71         out.write(concept.getRealName());
72         out.write("</p>\n");
73         
74         out.write("<p id='bannerDate'>");
75         out.write(format.format(new Date JavaDoc()));
76         out.write("</p>\n");
77         
78         out.write("</div>\n");
79
80         if(app.getCategory().equalsIgnoreCase("invisible"))
81         {
82             out.write("<h1>&nbsp;</h1>\n");
83         }
84         else
85         {
86             out.write("<h1>[");
87             out.write(app.getCategory());
88             out.write("] - ");
89             out.write(app.getTitle());
90             out.write("</h1>\n");
91         }
92         out.write("<!-- BannerWidget end -->");
93     }
94 }
Popular Tags