01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.framework;
11:
12: import javax.servlet.http.*;
13: import javax.servlet.*;
14: import java.io.*;
15: import java.util.Arrays;
16: import org.mmbase.util.functions.*;
17: import org.mmbase.util.GenericResponseWrapper;
18: import org.mmbase.util.logging.Logger;
19: import org.mmbase.util.logging.Logging;
20:
21: /**
22: * A Processor implementation based on a jsp.
23: *
24: * @author Michiel Meeuwissen
25: * @version $Id: JspProcessor.java,v 1.14 2007/11/16 16:06:30 michiel Exp $
26: * @since MMBase-1.9
27: */
28: public class JspProcessor extends AbstractProcessor {
29: private static final Logger log = Logging
30: .getLoggerInstance(JspProcessor.class);
31:
32: protected final String path;
33:
34: public JspProcessor(String p, Block parent) {
35: super (parent);
36: path = p;
37: }
38:
39: public String getPath() {
40: return path.charAt(0) == '/' ? path : JspRenderer.JSP_ROOT
41: + getBlock().getComponent().getName() + '/' + path;
42: }
43:
44: public Parameter[] getParameters() {
45: return new Parameter[] { Parameter.RESPONSE, Parameter.REQUEST };
46: }
47:
48: public void process(Parameters blockParameters,
49: Parameters frameworkParameters) throws FrameworkException {
50: try {
51: HttpServletResponse response = blockParameters
52: .get(Parameter.RESPONSE);
53: GenericResponseWrapper respw = new GenericResponseWrapper(
54: response);
55: HttpServletRequest request = blockParameters
56: .get(Parameter.REQUEST);
57: Framework framework = Framework.getInstance();
58: // String url = framework.getInternalUrl(getPath(), this, parent.getComponent(), blockParameters.toEntryList(), frameworkParameters).toString();
59: String url = getPath();
60: if (log.isDebugEnabled()) {
61: log.debug("Block parameters : [" + blockParameters
62: + "]");
63: log.debug("Framework parameters : ["
64: + frameworkParameters + "]");
65: log.debug("Framework returned url: [" + url + "]");
66: }
67: RequestDispatcher requestDispatcher = request
68: .getRequestDispatcher(url);
69: requestDispatcher.include(request, respw);
70: } catch (ServletException se) {
71: throw new FrameworkException(se.getMessage(), se);
72: } catch (IOException ioe) {
73: throw new FrameworkException(ioe.getMessage(), ioe);
74: }
75: }
76:
77: public String toString() {
78: return getPath() + '?' + Arrays.asList(getParameters());
79: }
80:
81: public java.net.URI getUri() {
82: try {
83: return org.mmbase.util.ResourceLoader.getWebRoot()
84: .getResource(getPath()).toURI();
85: } catch (Exception e) {
86: log.error(e);
87: return null;
88: }
89: }
90:
91: }
|