01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.servlet;
17:
18: import java.io.IOException;
19: import java.io.PrintWriter;
20:
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: import org.directwebremoting.extend.DebugPageGenerator;
25: import org.directwebremoting.extend.Handler;
26: import org.directwebremoting.util.LocalUtil;
27: import org.directwebremoting.util.MimeConstants;
28:
29: /**
30: * A handler for requests to create a class debug page
31: * @author Joe Walker [joe at getahead dot ltd dot uk]
32: */
33: public class TestHandler implements Handler {
34: /* (non-Javadoc)
35: * @see org.directwebremoting.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
36: */
37: public void handle(HttpServletRequest request,
38: HttpServletResponse response) throws IOException {
39: String scriptName = request.getPathInfo();
40: scriptName = scriptName.replace(testHandlerUrl, "");
41: scriptName = scriptName.replace("/", "");
42: if (!LocalUtil.isJavaIdentifier(scriptName)) {
43: throw new SecurityException(
44: "Script names may only contain Java Identifiers");
45: }
46:
47: String page = debugPageGenerator.generateTestPage(request
48: .getContextPath()
49: + request.getServletPath(), scriptName);
50:
51: response.setContentType(MimeConstants.MIME_HTML);
52: PrintWriter out = response.getWriter();
53: out.print(page);
54: }
55:
56: /**
57: * Setter for the debug page generator
58: * @param debugPageGenerator The new debug page generator
59: */
60: public void setDebugPageGenerator(
61: DebugPageGenerator debugPageGenerator) {
62: this .debugPageGenerator = debugPageGenerator;
63: }
64:
65: /**
66: * The bean to handle debug page requests
67: */
68: protected DebugPageGenerator debugPageGenerator = null;
69:
70: /**
71: * Setter for the URL that this handler available on
72: * @param testHandlerUrl the testHandlerUrl to set
73: */
74: public void setTestHandlerUrl(String testHandlerUrl) {
75: this .testHandlerUrl = testHandlerUrl;
76: }
77:
78: /**
79: * What URL is this handler available on?
80: */
81: protected String testHandlerUrl;
82: }
|