KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > webconnector > WebApp


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;
20
21 import java.util.Locale JavaDoc;
22 import java.net.URL JavaDoc;
23
24 import org.lucane.server.Server;
25 import org.lucane.server.Service;
26 import org.lucane.server.ServiceManager;
27 import org.lucane.webconnector.security.LucanePrincipal;
28 import org.lucane.webconnector.util.Translation;
29
30 public class WebApp
31 {
32     public static final String JavaDoc WEB_DIR = "web/";
33     public static final String JavaDoc IMAGES_DIR = "images/";
34
35     public static final String JavaDoc APPNAME_PARAM = "appName";
36     
37     private String JavaDoc name;
38     private LucanePrincipal user;
39     private Locale JavaDoc locale = null;
40     
41     public WebApp(String JavaDoc name, LucanePrincipal user)
42     {
43         this.name = name;
44         this.user = user;
45     }
46     
47     public String JavaDoc getName()
48     {
49         return name;
50     }
51     
52     public String JavaDoc getTitle()
53     {
54         return tr("title");
55     }
56
57     public String JavaDoc getTooltip()
58     {
59         return tr("tooltip");
60     }
61
62     public String JavaDoc getCategory()
63     {
64         return tr("category");
65     }
66
67     public String JavaDoc getIconPath()
68     {
69         return "/" + name + "/images/" + tr("icon");
70     }
71
72     public String JavaDoc getIcon16Path()
73     {
74         if (tr("icon16")!="icon16")
75             return "/" + name + "/images/" + tr("icon16");
76         else
77             return "/" + name + "/images/" + tr("icon");
78     }
79
80     public String JavaDoc tr(String JavaDoc message)
81     {
82         return Translation.get(this, user).tr(message);
83     }
84     
85     public Service getService()
86     {
87         return ServiceManager.getInstance().getService(name);
88     }
89     
90     public Locale JavaDoc getLocale()
91     throws Exception JavaDoc
92     {
93         if(this.locale == null)
94             this.locale = new Locale JavaDoc(user.getUser().getLanguage());
95         
96         return this.locale;
97     }
98
99     public boolean hasFile(String JavaDoc path)
100     {
101         try {
102             URL JavaDoc url = new URL JavaDoc(getDirectory() + path);
103             url.openStream();
104             return true;
105         } catch(Exception JavaDoc e) {
106             return false;
107         }
108     }
109
110     public String JavaDoc getDirectory()
111     {
112         String JavaDoc url = "jar:file:///" + Server.getInstance().getWorkingDirectory()
113         + Server.APPLICATIONS_DIRECTORY + name + ".jar!/";
114         return url.replace('\\', '/');
115     }
116 }
Popular Tags