Subversion Repositories bacoAlunos

Rev

Rev 851 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.web;

import org.apache.log4j.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import jomm.web.utils.NavPlace;

import java.io.IOException;
import java.io.FileNotFoundException;

/**
 * @author Jorge Machado
 * @date 26/Fev/2008
 * @time 12:46:16
 * @see pt.estgp.estgweb.web
 */

public class DirProxy extends HttpServlet
{

    /** sss requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */




   
    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);

    protected void setQueryString(1.5.0/docs/api/java/lang/String.html">String queryString, HttpServletRequest request)
    {
        NavPlace.setAuxiliaryQueryString(queryString,request);
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException
    {

        1.5.0/docs/api/java/lang/String.html">String path = request.getPathInfo();
        int dirEnd = path.indexOf("/",1);
        if(dirEnd < 0)
            dirEnd = path.length();
        1.5.0/docs/api/java/lang/String.html">String directory = path.substring(1,dirEnd);
        logger.info("diectory:" + directory);
//        path = path.substring(dirEnd);
        logger.info("path:" + path);

        /**
         * 1 - Obtain Directory XML
         * 2 - Build a Xpath query based on path
         * 3 - Set Actual Node
         * 4 - Check Actual Node Rights
         * 5 - If is a leaf check absolute just to confirm the request is valid, if absolute redirect just in case
         * 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
         * 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
         * 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
         *  8.1 in this case check if is to be layout, usuallly will not be laouted but just in case check it.
         */


        if(path != null)
        {
            try
            {
                getServletContext().getRequestDispatcher("/dirLayout.do?directory=" + directory + "&path=" + path + "&" + request.getQueryString()).forward(request,response);
            }
            catch(1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException e)
            {
                throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException(path);
            }
            catch(1.5.0/docs/api/java/lang/Exception.html">Exception e)
            {
                throw new 1.5.0/docs/api/java/io/IOException.html">IOException(e.toString());
            }
        }
        else
        {
            throw new 1.5.0/docs/api/java/io/FileNotFoundException.html">FileNotFoundException("url not found for directory:" + directory + " and path:" + path);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        processRequest(request, response);
    }

    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException {
        processRequest(request, response);
    }

    /** Returns a short description of the servlet.
     */

    public 1.5.0/docs/api/java/lang/String.html">String getServletInfo() {
        return "Proxy Servlet to get pages form static web page servers";
    }
    // </editor-fold>
}