1 21 package net.sf.packtag.util; 22 23 import javax.servlet.ServletContext ; 24 25 26 27 33 public class ContextConfiguration { 34 35 private final static String EMPTY_STRING = ""; 36 private static final String SLASH = "/"; 37 38 public final static String CACHE_TYPE_FILE = "file"; 39 public final static String CACHE_TYPE_SERVLET = "servlet"; 40 public final static String CACHE_TYPE_DISABLED = "disabled"; 41 42 private static String cacheType; 43 44 45 private static String cacheServletPath; 46 47 48 private static String cacheFilePath; 49 50 51 private static Boolean fileCheckTimestamps; 52 53 54 private static Boolean hideErrors; 55 56 57 public static String getCacheType(ServletContext context) { 58 if (cacheType == null) { 59 synchronized (ContextConfiguration.class) { 60 if (cacheType == null) { 61 String type = context.getInitParameter("packtag.cache.type"); 62 if (type == null) { 63 type = CACHE_TYPE_FILE; 64 } 65 cacheType = type; 66 } 67 } 68 } 69 return cacheType; 70 } 71 72 73 public static boolean isCachetypeDisabled(ServletContext context) { 74 return CACHE_TYPE_DISABLED.equalsIgnoreCase(getCacheType(context)); 75 } 76 77 78 public static boolean isCachetypeServlet(ServletContext context) { 79 return CACHE_TYPE_SERVLET.equalsIgnoreCase(getCacheType(context)); 80 } 81 82 83 public static boolean isCachetypeFile(ServletContext context) { 84 return CACHE_TYPE_FILE.equalsIgnoreCase(getCacheType(context)); 85 } 86 87 88 public static boolean isFileCheckTimestamps(ServletContext context) { 89 if (fileCheckTimestamps == null) { 90 synchronized (ContextConfiguration.class) { 91 if (fileCheckTimestamps == null) { 92 String parameter = context.getInitParameter("packtag.resources.checktimestamps"); 93 if (parameter == null || parameter.equals(EMPTY_STRING)) { 94 fileCheckTimestamps = Boolean.TRUE; } 96 else { 97 fileCheckTimestamps = new Boolean (parameter); 98 } 99 } 100 } 101 } 102 return fileCheckTimestamps.booleanValue(); 103 } 104 105 106 107 public static boolean isHideErros(ServletContext context) { 108 if (hideErrors == null) { 109 synchronized (ContextConfiguration.class) { 110 if (hideErrors == null) { 111 hideErrors = new Boolean (context.getInitParameter("packtag.hide.errors")); 112 } 113 } 114 } 115 return hideErrors.booleanValue(); 116 } 117 118 119 public static String getPackStrategyClassName(ServletContext context, String resourceType) { 120 return context.getInitParameter("packtag." + resourceType + ".strategy"); 121 } 122 123 124 public static String getCacheServletPath(ServletContext context) { 125 if (cacheServletPath == null) { 126 synchronized (ContextConfiguration.class) { 127 if (cacheServletPath == null) { 128 String path = context.getInitParameter("packtag.cache.servlet.path"); 129 if ((path == null) || (path.length() == 0)) { 130 path = "/pack"; 131 } 132 if (!path.startsWith(SLASH)) { 133 path = SLASH + path; 134 } 135 if (path.endsWith(SLASH)) { 136 path = path.substring(0, path.length() - 1); 137 } 138 cacheServletPath = path; 139 } 140 } 141 } 142 return cacheServletPath; 143 } 144 145 146 public static String getCacheFilePath(ServletContext context) { 147 if (cacheFilePath == null) { 148 synchronized (ContextConfiguration.class) { 149 if (cacheFilePath == null) { 150 String path = context.getInitParameter("packtag.cache.file.path"); 151 if ((path == null) || (path.length() == 0)) { 152 path = "pack"; 153 } 154 if (path.startsWith(SLASH)) { 155 path = path.substring(1, path.length()); 156 } 157 if (path.endsWith(SLASH)) { 158 path = path.substring(0, path.length() - 1); 159 } 160 cacheFilePath = path; 161 } 162 } 163 } 164 return cacheFilePath; 165 } 166 167 } 168 | Popular Tags |