KickJava   Java API By Example, From Geeks To Geeks.

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


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-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.servlets.MVCServlet;
17 import info.magnolia.cms.servlets.MVCServletHandler;
18 import info.magnolia.cms.util.RequestFormUtil;
19 import info.magnolia.module.admininterface.dialogs.ConfiguredDialog;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.log4j.Logger;
26
27
28 /**
29  * @author Philipp Bracher
30  * @version $Id$
31  */

32 public class DialogMVCServlet extends MVCServlet {
33
34     /**
35      * Stable serialVersionUID.
36      */

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

42     private static Logger log = Logger.getLogger(DialogMVCServlet.class);
43
44     /**
45      *
46      */

47     protected MVCServletHandler getHandler(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
48         String JavaDoc dialogName = RequestFormUtil.getParameter(request, "mgnlDialog"); //$NON-NLS-1$
49

50         if (StringUtils.isEmpty(dialogName)) {
51             if (StringUtils.isEmpty(dialogName)) {
52                 dialogName = (String JavaDoc) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
53
if (StringUtils.isEmpty(dialogName)) {
54                     dialogName = (String JavaDoc) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
55
}
56                 if (StringUtils.isEmpty(dialogName)) {
57                     dialogName = request.getRequestURI();
58                 }
59                 dialogName = StringUtils.replaceOnce(StringUtils.substringAfterLast(dialogName, "/dialogs/"), ".html", //$NON-NLS-1$ //$NON-NLS-2$
60
StringUtils.EMPTY);
61             }
62         }
63
64         DialogMVCHandler handler = null;
65
66         if (StringUtils.isNotBlank(dialogName)) {
67             // try to get a registered handler
68
try {
69                 handler = Store.getInstance().getDialogHandler(dialogName, request, response);
70             }
71             catch (InvalidDialogHandlerException e) {
72                 log.info("can't find handler will try to load directly from the config", e); //$NON-NLS-1$
73
Content configNode = ConfiguredDialog.getConfigNode(request, dialogName);
74                 // try to find a class property or return a ConfiguredDialog
75
if (configNode != null) {
76                     handler = ConfiguredDialog.getConfiguredDialog(dialogName, configNode, request, response);
77                 }
78                 else {
79                     log.error("no config node found for dialog : " + dialogName); //$NON-NLS-1$
80
}
81             }
82         }
83
84         if (handler == null) {
85             log.error("no dialog found: " + dialogName); //$NON-NLS-1$
86
}
87
88         return handler;
89     }
90
91 }
Popular Tags