| 1 | |
package org.webslinger; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.StringWriter; |
| 5 | |
import java.util.Collection; |
| 6 | |
import java.util.HashMap; |
| 7 | |
import java.util.Map; |
| 8 | |
import java.util.logging.Logger; |
| 9 | |
|
| 10 | |
import javax.servlet.ServletException; |
| 11 | |
import javax.servlet.ServletRequest; |
| 12 | |
import javax.servlet.ServletResponse; |
| 13 | |
import javax.servlet.http.HttpServletRequest; |
| 14 | |
import javax.servlet.http.HttpServletResponse; |
| 15 | |
|
| 16 | |
import org.apache.commons.vfs.FileObject; |
| 17 | |
|
| 18 | |
import org.webslinger.container.GivenPathInfo; |
| 19 | |
import org.webslinger.servlet.FakeHttpServletRequest; |
| 20 | |
import org.webslinger.servlet.FakeHttpServletResponse; |
| 21 | |
import org.webslinger.servlet.FakeServletRequest; |
| 22 | |
import org.webslinger.servlet.FakeServletResponse; |
| 23 | |
|
| 24 | 96 | public abstract class TypeHandler { |
| 25 | 1 | public static final String[] runSignature = new String[] { |
| 26 | |
Webslinger.class.getName(), |
| 27 | |
HttpServletRequest.class.getName(), |
| 28 | |
HttpServletResponse.class.getName(), |
| 29 | |
Object.class.getName() |
| 30 | |
}; |
| 31 | |
|
| 32 | |
private WebslingerServletContext context; |
| 33 | |
private String type; |
| 34 | 96 | protected final Logger logger = Logger.getLogger(getClass().getName()); |
| 35 | |
|
| 36 | |
public WebslingerServletContext getContext() { |
| 37 | 914 | return context; |
| 38 | |
} |
| 39 | |
|
| 40 | |
public String getType() { |
| 41 | 0 | return type; |
| 42 | |
} |
| 43 | |
|
| 44 | |
public void init(WebslingerServletContext context, String type) throws IOException { |
| 45 | 70 | this.context = context; |
| 46 | 70 | this.type = type; |
| 47 | 70 | } |
| 48 | |
|
| 49 | |
protected boolean hasInit(final PathContext pc) throws IOException, ServletException { |
| 50 | 1595 | return "true".equals(pc.getAttribute("has-init")); |
| 51 | |
} |
| 52 | |
|
| 53 | |
public String getContentType(PathContext pathContext, String defaultType) throws IOException { |
| 54 | 0 | String contentType = (String) pathContext.getAttribute("content-type"); |
| 55 | 0 | if (contentType == null) contentType = pathContext.getFile().getContent().getContentInfo().getContentType(); |
| 56 | 0 | if (contentType == null) contentType = defaultType; |
| 57 | 0 | return contentType; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public Object run(Webslinger webslinger) throws IOException, ServletException { |
| 61 | 0 | throw new AbstractMethodError(getClass().toString()); |
| 62 | |
} |
| 63 | |
} |