KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > servlet > HandleHelpFiles


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.admingui.servlet;
25
26 import com.sun.enterprise.tools.admingui.util.Util;
27 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
28
29 import java.io.*;
30 import java.util.*;
31 import java.net.URL JavaDoc;
32
33 import javax.servlet.*;
34 import javax.servlet.http.*;
35
36 import java.io.InputStreamReader JavaDoc;
37
38
39 /**
40  * This class allows us to load help files from classpath.
41  */

42 public class HandleHelpFiles extends HttpServlet {
43
44     public void init(ServletConfig config) throws ServletException {
45     super.init(config);
46     }
47
48     public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
49     doPost(req, res);
50     }
51
52
53     /**
54      */

55     public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException {
56     String JavaDoc pathInfo = req.getPathInfo();
57     String JavaDoc servletPath = req.getServletPath();
58     
59     URL JavaDoc htmlFile = null;
60     
61     if(pathInfo == null || pathInfo.length() == 0) {
62         //may never come here.
63
pathInfo = "/index.html";
64     }
65     htmlFile = getClass().getClassLoader().getResource(servletPath.substring(1)+pathInfo);
66     
67     if(htmlFile == null) {
68         //falling back to the default html file.
69
htmlFile = getClass().getClassLoader().getResource(servletPath.substring(1)+"/notfound.html");
70     }
71     
72     try {
73         ServletOutputStream sout = res.getOutputStream();
74         res.setCharacterEncoding("UTF-8");
75         res.setContentType("text/html");
76         BufferedReader bin = new BufferedReader
77                 (new InputStreamReader JavaDoc(htmlFile.openStream(), "UTF-8"));
78             String JavaDoc line;
79         while ((line=bin.readLine())!=null) {
80                 sout.println(line);
81         }
82             sout.close();
83     } catch (IOException ex) {
84         Util.logWARNING("******HandleHelpFiles*******"+ex.getMessage());
85     }
86     }
87 }
88
Popular Tags