KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > js > JsProviderServlet


1 package net.sf.uitags.js;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletConfig JavaDoc;
6 import javax.servlet.ServletException JavaDoc;
7 import javax.servlet.http.HttpServlet JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10
11 /**
12  * Reads JS source files from either uitags JAR or file system, and serves
13  * them to the browser.
14  *
15  * @author jonni
16  */

17 public final class JsProviderServlet extends HttpServlet JavaDoc {
18
19   private static final long serialVersionUID = 100L;
20
21   ///////////////////////////////
22
////////// Constants //////////
23
///////////////////////////////
24

25   /// Init param names ///
26

27   static final String JavaDoc DIR = "directory";
28   static final String JavaDoc SUITES = "suites";
29   static final String JavaDoc CUSTOM_FILES = "customFiles";
30   static final String JavaDoc DEBUG = "debug";
31
32
33
34   ////////////////////////////
35
////////// Fields //////////
36
////////////////////////////
37

38   private JsFiles jsFiles;
39
40
41
42   ////////////////////////////////////
43
////////// Initialization //////////
44
////////////////////////////////////
45

46   public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
47     Suites suites = Suites.getInstance(config.getInitParameter(SUITES));
48     FileFinder fileFinder = FileFinder.getInstance(
49         config.getServletContext(), config.getInitParameter(DIR));
50
51     this.jsFiles = new JsFiles(suites, fileFinder);
52     this.jsFiles.setCustomFileNames(config.getInitParameter(CUSTOM_FILES));
53     this.jsFiles.setInDebugMode(
54         Boolean.valueOf(config.getInitParameter(DEBUG)).booleanValue());
55   }
56
57
58
59   /////////////////////////////////////
60
////////// Service methods //////////
61
/////////////////////////////////////
62

63   /**
64    * Probably noone would request a JS using POST but implement this anyway.
65    */

66   protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
67       throws ServletException JavaDoc, IOException JavaDoc {
68     super.doPost(request, response);
69   }
70
71   protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
72       throws ServletException JavaDoc, IOException JavaDoc {
73     response.getOutputStream().println(this.jsFiles.getContents());
74   }
75
76   protected long getLastModified(HttpServletRequest JavaDoc arg0) {
77     long lastModified = this.jsFiles.getLastModified();
78     return (lastModified == 0)? -1 : lastModified;
79   }
80 }
81
Popular Tags