1 package org.apache.turbine.services.upload; 2 3 18 19 import javax.servlet.ServletConfig ; 20 import javax.servlet.http.HttpServletRequest ; 21 22 import org.apache.turbine.Turbine; 23 import org.apache.turbine.services.TurbineBaseService; 24 import org.apache.turbine.services.servlet.TurbineServlet; 25 import org.apache.turbine.util.ServletUtils; 26 import org.apache.turbine.util.TurbineException; 27 import org.apache.turbine.util.parser.ParameterParser; 28 29 39 public abstract class BaseUploadService 40 extends TurbineBaseService 41 implements UploadService 42 { 43 47 public static final int MAX_HEADER_SIZE = 1024; 48 49 55 public void init() 56 { 57 String path = getProperties() 58 .getProperty(UploadService.REPOSITORY_KEY, 59 UploadService.REPOSITORY_DEFAULT.toString()); 60 if (!path.startsWith("/")) 61 { 62 String realPath = TurbineServlet.getRealPath(path); 63 if (realPath != null) 64 { 65 path = realPath; 66 } 67 } 68 getProperties().setProperty(UploadService.REPOSITORY_KEY, path); 69 setInit(true); 70 } 71 72 83 public abstract void parseRequest(HttpServletRequest req, 84 ParameterParser params, 85 String path) 86 throws TurbineException; 87 88 94 public long getSizeMax() 95 { 96 return getConfiguration().getLong( 97 UploadService.SIZE_MAX_KEY, 98 UploadService.SIZE_MAX_DEFAULT); 99 } 100 101 107 public int getSizeThreshold() 108 { 109 return getConfiguration().getInt( 110 UploadService.SIZE_THRESHOLD_KEY, 111 UploadService.SIZE_THRESHOLD_DEFAULT); 112 } 113 114 120 public String getRepository() 121 { 122 String tmpPath = getConfiguration().getString( 124 UploadService.REPOSITORY_KEY, 125 UploadService.REPOSITORY_DEFAULT); 126 127 ServletConfig config = Turbine.getTurbineServletConfig(); 129 return ServletUtils.expandRelative(config, tmpPath); 130 131 } 132 133 142 public boolean getAutomatic() 143 { 144 return getConfiguration().getBoolean( 145 UploadService.AUTOMATIC_KEY, 146 UploadService.AUTOMATIC_DEFAULT); 147 } 148 } 149 | Popular Tags |