1 19 package org.lucane.webconnector; 20 21 import java.util.Locale ; 22 import java.net.URL ; 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 WEB_DIR = "web/"; 33 public static final String IMAGES_DIR = "images/"; 34 35 public static final String APPNAME_PARAM = "appName"; 36 37 private String name; 38 private LucanePrincipal user; 39 private Locale locale = null; 40 41 public WebApp(String name, LucanePrincipal user) 42 { 43 this.name = name; 44 this.user = user; 45 } 46 47 public String getName() 48 { 49 return name; 50 } 51 52 public String getTitle() 53 { 54 return tr("title"); 55 } 56 57 public String getTooltip() 58 { 59 return tr("tooltip"); 60 } 61 62 public String getCategory() 63 { 64 return tr("category"); 65 } 66 67 public String getIconPath() 68 { 69 return "/" + name + "/images/" + tr("icon"); 70 } 71 72 public String 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 tr(String 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 getLocale() 91 throws Exception 92 { 93 if(this.locale == null) 94 this.locale = new Locale (user.getUser().getLanguage()); 95 96 return this.locale; 97 } 98 99 public boolean hasFile(String path) 100 { 101 try { 102 URL url = new URL (getDirectory() + path); 103 url.openStream(); 104 return true; 105 } catch(Exception e) { 106 return false; 107 } 108 } 109 110 public String getDirectory() 111 { 112 String url = "jar:file:///" + Server.getInstance().getWorkingDirectory() 113 + Server.APPLICATIONS_DIRECTORY + name + ".jar!/"; 114 return url.replace('\\', '/'); 115 } 116 } | Popular Tags |