KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > CompileServlet


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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 /*
17  * $Id: CompileServlet.java,v 1.7 2004/02/17 19:06:04 minchau Exp $
18  */

19
20 import java.io.IOException JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22
23 import java.net.URL JavaDoc;
24
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServlet JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.apache.xalan.xsltc.compiler.XSLTC;
31
32 /**
33  * @author Morten Jorgensen
34  * @author Jacek Ambroziak
35  */

36 public class CompileServlet extends HttpServlet JavaDoc {
37
38     /**
39      * Main servlet entry point. The servlet reads a stylesheet from the
40      * URI specified by the "sheet" parameter. The compiled Java class
41      * ends up in the CWD of the web server (a better solution would be
42      * to have an environment variable point to a translet directory).
43      */

44     public void doGet(HttpServletRequest JavaDoc request,
45               HttpServletResponse JavaDoc response)
46     throws IOException JavaDoc, ServletException JavaDoc {
47
48     response.setContentType("text/html");
49     PrintWriter JavaDoc out = response.getWriter();
50         
51     String JavaDoc stylesheetName = request.getParameter("sheet");
52     
53     out.println("<html><head>");
54     out.println("<title>Servlet Stylesheet Compilation</title>");
55     out.println("</head><body>");
56
57     if (stylesheetName == null) {
58         out.println("<h1>Compilation error</h1>");
59         out.println("The parameter <b><tt>sheet</tt></b> "+
60             "must be specified");
61     }
62     else {
63         XSLTC xsltc = new XSLTC();
64
65         xsltc.init();
66         xsltc.compile(new URL JavaDoc(stylesheetName));
67         out.println("<h1>Compilation successful</h1>");
68         out.println("The stylesheet was compiled into the translet "+
69             "class "+xsltc.getClassName() + " and is now "+
70             "available for transformations on this server.");
71     }
72     out.println("</body></html>");
73     }
74 }
75
Popular Tags