KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > servlet > TestHandler


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.io.PrintWriter JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
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 {
35     /* (non-Javadoc)
36      * @see org.directwebremoting.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
37      */

38     public void handle(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc
39     {
40         String JavaDoc scriptName = request.getPathInfo();
41         scriptName = LocalUtil.replace(scriptName, testHandlerUrl, "");
42         scriptName = LocalUtil.replace(scriptName, "/", "");
43
44         String JavaDoc page = debugPageGenerator.generateTestPage(request.getContextPath() + request.getServletPath(), scriptName);
45
46         response.setContentType(MimeConstants.MIME_HTML);
47         PrintWriter JavaDoc out = response.getWriter();
48         out.print(page);
49     }
50
51     /**
52      * Setter for the debug page generator
53      * @param debugPageGenerator
54      */

55     public void setDebugPageGenerator(DebugPageGenerator debugPageGenerator)
56     {
57         this.debugPageGenerator = debugPageGenerator;
58     }
59
60     /**
61      * The bean to handle debug page requests
62      */

63     protected DebugPageGenerator debugPageGenerator = null;
64
65     /**
66      * Setter for the URL that this handler available on
67      * @param testHandlerUrl the testHandlerUrl to set
68      */

69     public void setTestHandlerUrl(String JavaDoc testHandlerUrl)
70     {
71         this.testHandlerUrl = testHandlerUrl;
72     }
73
74     /**
75      * What URL is this handler available on?
76      */

77     protected String JavaDoc testHandlerUrl;
78 }
79
Popular Tags