1 16 package org.apache.pluto.portlet.admin.util; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import java.util.Properties ; 23 24 import org.apache.pluto.portlet.admin.PlutoAdminConstants; 25 import org.apache.pluto.portlet.admin.PlutoAdminException; 26 import org.apache.pluto.portlet.admin.PlutoAdminLogger; 27 28 38 public class PlutoAdminContext { 39 40 private static final String CLASS_NAME = "PlutoAdminContext"; 41 43 private static String _containerHome = null; 44 private static String _plutoHome = null; 45 private static String _plutoContext = null; 46 private static String _deploymentPath = null; 47 private static Map _cache = new HashMap (); 48 private static PlutoAdminContext _instance = new PlutoAdminContext(); 49 50 53 private PlutoAdminContext() { 54 } 55 56 public static PlutoAdminContext getInstance(){ 57 return _instance; 58 } 59 60 67 public String getPageRegistryPath() { 68 String path = getPlutoHome() + PlutoAdminConstants.FS + getRelDataDir() + PlutoAdminConstants.FS + getProperties().getProperty("pageregistry-file"); 69 return path; 70 } 71 72 79 public String getPortletEntityRegistryPath() { 80 String path = getPlutoHome() + PlutoAdminConstants.FS + getRelDataDir() + PlutoAdminConstants.FS + getProperties().getProperty("portletentityregistry-file"); 81 return path; 82 } 83 84 91 public String getPlutoHome(){ 92 final String METHOD_NAME = "getPlutoHome()"; 93 return _plutoHome; 106 } 107 108 115 123 135 public static Properties getProperties(String propFileName){ 136 final String METHOD_NAME = "getProperties(propFileName)"; 137 Properties props = null; 138 props = (Properties )_cache.get(propFileName); 140 if ( props == null) { 141 InputStream stream = PlutoAdminContext.class.getClassLoader().getResourceAsStream(propFileName); 143 if (stream == null) { 144 String logMsg = "Null InputStream." + 145 " Please make sure the properties file exists and is in the classpath."; 146 NullPointerException e = new NullPointerException (logMsg); 147 PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e); 148 throw e; 149 } 150 props = new Properties (); 151 try { 152 props.load(stream); 153 } catch (IOException e) { 154 PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e); 155 throw new PlutoAdminException(e); 156 } 157 _cache.put(propFileName, props); 159 return props; 160 } else { 161 return props; 162 } 163 } 164 165 public static Properties getProperties(){ 166 return getProperties(PlutoAdminConstants.PROP_FILENAME); 167 } 168 169 private String getRelDataDir(){ 170 String dir = getProperties().getProperty("data-dir-relative-path"); 171 return dir; 172 } 173 174 178 public String getPortletContextsPath() { 179 String path = getPlutoHome() + PlutoAdminConstants.FS + getRelDataDir() + PlutoAdminConstants.FS + getProperties().getProperty("portletcontexts-file"); 180 return path; 181 } 182 183 188 public static String getContainerHome(){ 189 final String METHOD_NAME = "getContainerHome()"; 190 return _containerHome; 191 } 192 193 199 public static void parseDeploymentPaths(String plutoHome) { 200 final String METHOD_NAME = "parseDeploymentPaths(plutoHome)"; 201 int lastSlash = 0; 203 if (plutoHome == null) { 204 _plutoHome = getProperties().getProperty("pluto-home"); 205 if (_plutoHome == null || _plutoHome.equals("")) { 206 throw new PlutoAdminException("pluto-home needs to be set in pluto-admin.properties."); 207 } 208 } else if (plutoHome.lastIndexOf(PlutoAdminConstants.FS) == plutoHome.length()-1) { 210 lastSlash = plutoHome.lastIndexOf(PlutoAdminConstants.FS); 211 _plutoHome = plutoHome.substring(0, lastSlash); 212 } else { 213 _plutoHome = plutoHome; 214 } 215 PlutoAdminLogger.logDebug(CLASS_NAME, METHOD_NAME, "Pluto home: " + _plutoHome); 216 lastSlash = _plutoHome.lastIndexOf(PlutoAdminConstants.FS); 218 _plutoContext = _plutoHome.substring(lastSlash + 1); 219 PlutoAdminLogger.logDebug(CLASS_NAME, METHOD_NAME, "Pluto web context: " + _plutoContext); 220 _deploymentPath = _plutoHome.substring(0, lastSlash); 222 PlutoAdminLogger.logDebug(CLASS_NAME, METHOD_NAME, "Portlet deployment path: " + _deploymentPath); 223 lastSlash = _deploymentPath.lastIndexOf(PlutoAdminConstants.FS); 225 _containerHome = _deploymentPath.substring(0, lastSlash); 226 PlutoAdminLogger.logDebug(CLASS_NAME, METHOD_NAME, "Container (Tomcat) home: " + _containerHome); 227 } 228 229 233 public static String getDeploymentPath(){ 234 return _deploymentPath; 235 } 236 237 241 public static String getPlutoWebContext(){ 242 return _plutoContext; 243 } 244 } 245 | Popular Tags |