1 23 24 package org.apache.slide.webdav; 25 26 import java.util.Enumeration ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.servlet.ServletConfig ; 32 import javax.servlet.ServletContext ; 33 34 import org.apache.slide.util.XMLValue; 35 import org.jdom.Element; 36 import org.jdom.JDOMException; 37 38 46 public class WebdavServletConfig 47 implements ServletConfig { 48 49 50 52 53 static final String DEFAULT_SERVLET_PARAMETER = 54 "default-servlet"; 55 56 57 static final String DEPTH_LIMIT_PARAMETER = 58 "depth-limit"; 59 60 61 static final String DEFAULT_MIME_TYPE_PARAMETER = 62 "default-mime-type"; 63 64 65 static final String METHOD_FACTORY_PARAMETER = 66 "method-factory"; 67 68 69 static final String SCOPE_PARAMETER = 70 "scope"; 71 72 73 75 76 79 protected ServletConfig config; 80 81 82 94 protected boolean isDefaultServlet = true; 95 96 97 100 protected String defaultMimeType = "text/plain"; 101 102 103 106 protected int depthLimit = 3; 107 108 109 113 protected String scope = ""; 114 115 116 119 protected String methodFactory; 120 121 124 protected Map externalReports = new HashMap (); 125 126 127 129 130 135 public WebdavServletConfig(ServletConfig config) { 136 137 this.config = config; 138 139 ServletContext context = getServletContext(); 140 String value = null; 141 142 value = getInitParameter(SCOPE_PARAMETER); 144 if (value == null) { 145 value = context.getInitParameter(SCOPE_PARAMETER); 146 } 147 if (value != null) { 148 scope = value; 149 } 150 151 value = getInitParameter(DEPTH_LIMIT_PARAMETER); 153 if (value == null) { 154 value = context.getInitParameter(DEPTH_LIMIT_PARAMETER); 155 } 156 if (value != null) { 157 depthLimit = Integer.parseInt(value); 158 } 159 160 value = getInitParameter(DEFAULT_MIME_TYPE_PARAMETER); 162 if (value == null) { 163 value = context.getInitParameter(DEFAULT_MIME_TYPE_PARAMETER); 164 } 165 if (value != null) { 166 defaultMimeType = value; 167 } 168 169 value = getInitParameter(DEFAULT_SERVLET_PARAMETER); 171 if (value != null) { 172 isDefaultServlet = Boolean.valueOf(value).booleanValue(); 173 } 174 175 value = getInitParameter(METHOD_FACTORY_PARAMETER); 177 if (value == null) { 178 value = context.getInitParameter(METHOD_FACTORY_PARAMETER); 179 } 180 if (value != null) { 181 methodFactory = value; 182 } 183 184 try { 186 XMLValue xv = new XMLValue(getInitParameter("external-reports")); 187 Iterator i = xv.iterator(); 188 while (i.hasNext()) { 189 Object r = i.next(); 190 if (r instanceof Element && "report".equals(((Element)r).getName())) { 191 192 String name = ((Element)r).getAttributeValue("name"); 193 String clsName = ((Element)r).getTextTrim(); 194 externalReports.put(name, clsName); 195 } 196 } 197 } 198 catch (JDOMException e) { 199 e.printStackTrace(); 200 } 201 } 202 203 204 206 207 214 public String getInitParameter(String name) { 215 216 return config.getInitParameter(name); 217 } 218 219 220 228 public Enumeration getInitParameterNames() { 229 230 return config.getInitParameterNames(); 231 } 232 233 234 241 public ServletContext getServletContext() { 242 243 return config.getServletContext(); 244 } 245 246 247 255 public String getServletName() { 256 257 return config.getServletName(); 258 } 259 260 262 263 270 public String getDefaultMimeType() { 271 272 return defaultMimeType; 273 } 274 275 276 283 public int getDepthLimit() { 284 285 return depthLimit; 286 } 287 288 289 296 public String getMethodFactory() { 297 298 return methodFactory; 299 } 300 301 302 309 public String getScope() { 310 311 return scope; 312 } 313 314 315 322 public boolean isDefaultServlet() { 323 324 return isDefaultServlet; 325 } 326 327 335 public String getExternalReport(String name) { 336 return (String )externalReports.get(name); 337 } 338 } 339 340 | Popular Tags |