Rev 1306 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
368 | jmachado | 1 | package pt.estgp.estgweb.web; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | |||
5 | import javax.servlet.http.HttpServlet; |
||
6 | import javax.servlet.http.HttpServletRequest; |
||
7 | import javax.servlet.http.HttpServletResponse; |
||
8 | import javax.servlet.ServletException; |
||
9 | |||
10 | import jomm.web.utils.NavPlace; |
||
11 | |||
12 | import java.io.IOException; |
||
13 | import java.io.FileNotFoundException; |
||
14 | |||
15 | /** |
||
16 | * @author Jorge Machado |
||
17 | * @date 26/Fev/2008 |
||
18 | * @time 12:46:16 |
||
19 | * @see pt.estgp.estgweb.web |
||
20 | */ |
||
21 | public class DirProxy extends HttpServlet |
||
22 | { |
||
23 | |||
851 | jmachado | 24 | /** sss requests for both HTTP <code>GET</code> and <code>POST</code> methods. |
368 | jmachado | 25 | * @param request servlet request |
26 | * @param response servlet response |
||
27 | */ |
||
28 | |||
29 | |||
30 | |||
31 | |||
32 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(DirProxy.class); |
||
33 | |||
34 | protected void setQueryString(1.5.0/docs/api/java/lang/String.html">String queryString, HttpServletRequest request) |
||
35 | { |
||
36 | NavPlace.setAuxiliaryQueryString(queryString,request); |
||
37 | } |
||
38 | |||
39 | protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
||
40 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
41 | { |
||
42 | |||
43 | 1.5.0/docs/api/java/lang/String.html">String path = request.getPathInfo(); |
||
44 | int dirEnd = path.indexOf("/",1); |
||
45 | if(dirEnd < 0) |
||
46 | dirEnd = path.length(); |
||
47 | 1.5.0/docs/api/java/lang/String.html">String directory = path.substring(1,dirEnd); |
||
48 | logger.info("diectory:" + directory); |
||
49 | // path = path.substring(dirEnd); |
||
50 | logger.info("path:" + path); |
||
51 | |||
52 | /** |
||
53 | * 1 - Obtain Directory XML |
||
54 | * 2 - Build a Xpath query based on path |
||
55 | * 3 - Set Actual Node |
||
56 | * 4 - Check Actual Node Rights |
||
57 | * 5 - If is a leaf check absolute just to confirm the request is valid, if absolute redirect just in case |
||
58 | * 6 - If is a leaf check layout to define the use of a layout and get directory@layout to choose layout to forward in struts |
||
59 | * 7 - If is a leaf check style to define the use of a style and allays put the object in "body" parameter or directly put content in layout |
||
60 | * 8 - If is a leaf check proxy to know if it is an proxied source if it is get content by URL concat or just forward to an internal localhost/context/path |
||
61 | * 8.1 in this case check if is to be layout, usuallly will not be laouted but just in case check it. |
||
62 | */ |
||
63 | |||
64 | if(path != null) |
||
65 | { |
||
66 | try |
||
67 | { |
||
68 | getServletContext().getRequestDispatcher("/dirLayout.do?directory=" + directory + "&path=" + path + "&" + request.getQueryString()).forward(request,response); |
||
69 | } |
||
70 | catch(1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e) |
||
71 | { |
||
72 | throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException(path); |
||
73 | } |
||
74 | catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
75 | { |
||
76 | throw new 1.5.0/docs/api/java/io/IOException.html">IOException(e.toString()); |
||
77 | } |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException("url not found for directory:" + directory + " and path:" + path); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
||
86 | /** Handles the HTTP <code>GET</code> method. |
||
87 | * @param request servlet request |
||
88 | * @param response servlet response |
||
89 | */ |
||
90 | protected void doGet(HttpServletRequest request, HttpServletResponse response) |
||
91 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
92 | { |
||
93 | processRequest(request, response); |
||
94 | } |
||
95 | |||
96 | /** Handles the HTTP <code>POST</code> method. |
||
97 | * @param request servlet request |
||
98 | * @param response servlet response |
||
99 | */ |
||
100 | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
||
101 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
102 | processRequest(request, response); |
||
103 | } |
||
104 | |||
105 | /** Returns a short description of the servlet. |
||
106 | */ |
||
107 | public 1.5.0/docs/api/java/lang/String.html">String getServletInfo() { |
||
108 | return "Proxy Servlet to get pages form static web page servers"; |
||
109 | } |
||
110 | // </editor-fold> |
||
111 | } |