KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > PageMVCServlet


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface;
14
15 import info.magnolia.cms.servlets.MVCServlet;
16 import info.magnolia.cms.servlets.MVCServletHandler;
17 import info.magnolia.cms.util.RequestFormUtil;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27 /**
28  * @author Philipp Bracher
29  * @version $Id: PageMVCServlet.java 6341 2006-09-12 09:18:27Z philipp $
30  */

31 public class PageMVCServlet extends MVCServlet {
32
33     /**
34      * Stable serialVersionUID.
35      */

36     private static final long serialVersionUID = 222L;
37
38     /**
39      * Logger.
40      */

41     private static Logger log = LoggerFactory.getLogger(PageMVCServlet.class);
42
43     /**
44      *
45      */

46     protected MVCServletHandler getHandler(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
47
48         String JavaDoc pageName = RequestFormUtil.getParameter(request, "mgnlPage"); //$NON-NLS-1$
49
if (StringUtils.isEmpty(pageName)) {
50             pageName = (String JavaDoc) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
51
if (StringUtils.isEmpty(pageName)) {
52                 pageName = (String JavaDoc) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
53
}
54             if (StringUtils.isEmpty(pageName)) {
55                 pageName = request.getRequestURI();
56             }
57             pageName = StringUtils.substringAfterLast(pageName, "/pages/"); //$NON-NLS-1$
58

59             // strip any extension
60
pageName = StringUtils.substringBeforeLast(pageName, ".");
61         }
62
63         PageMVCHandler handler = null;
64
65         if (pageName != null) {
66             // try to get a registered handler
67
try {
68                 handler = PageHandlerManager.getInstance().getPageHandler(pageName, request, response);
69             }
70             catch (InvalidDialogPageHandlerException e) {
71                 log.error("no page found: [" + pageName + "]"); //$NON-NLS-1$
72
}
73         }
74         else {
75             log.error("no dialogpage name passed"); //$NON-NLS-1$
76
}
77
78         return handler;
79     }
80
81 }
Popular Tags