KickJava   Java API By Example, From Geeks To Geeks.

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


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.Handler;
25 import org.directwebremoting.extend.Remoter;
26 import org.directwebremoting.util.LocalUtil;
27 import org.directwebremoting.util.MimeConstants;
28
29 /**
30  * A handler for interface generation requests
31  * @author Joe Walker [joe at getahead dot ltd dot uk]
32  */

33 public class InterfaceHandler 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, interfaceHandlerUrl, "");
42         scriptName = LocalUtil.replace(scriptName, PathConstants.EXTENSION_JS, "");
43         String JavaDoc path = request.getContextPath() + request.getServletPath();
44
45         String JavaDoc script = remoter.generateInterfaceScript(scriptName, path);
46
47         // Officially we should use MimeConstants.MIME_JS, but if we cheat and
48
// use MimeConstants.MIME_PLAIN then it will be easier to read in a
49
// browser window, and will still work just fine.
50
response.setContentType(MimeConstants.MIME_PLAIN);
51         PrintWriter JavaDoc out = response.getWriter();
52         out.print(script);
53     }
54
55     /**
56      * Setter for the remoter
57      * @param remoter
58      */

59     public void setRemoter(Remoter remoter)
60     {
61         this.remoter = remoter;
62     }
63
64     /**
65      * The bean to execute remote requests and generate interfaces
66      */

67     protected Remoter remoter = null;
68
69     /**
70      * Setter for the URL that this handler available on
71      * @param interfaceHandlerUrl the interfaceHandlerUrl to set
72      */

73     public void setInterfaceHandlerUrl(String JavaDoc interfaceHandlerUrl)
74     {
75         this.interfaceHandlerUrl = interfaceHandlerUrl;
76     }
77
78     /**
79      * What URL is this handler available on?
80      */

81     protected String JavaDoc interfaceHandlerUrl;
82 }
83
Popular Tags