KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > dialogs > ConfiguredDialog


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.dialogs;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.util.ClassUtil;
17 import info.magnolia.module.admininterface.DialogMVCHandler;
18
19 import java.lang.reflect.Constructor JavaDoc;
20 import java.text.MessageFormat JavaDoc;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30 /**
31  * @author philipp
32  */

33 public class ConfiguredDialog extends DialogMVCHandler {
34
35     private static Logger log = LoggerFactory.getLogger(ConfiguredDialog.class);
36
37     private Content configNode;
38
39     public ConfiguredDialog(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Content configNode) {
40         super(name, request, response);
41         this.configNode = configNode;
42     }
43
44     /**
45      * Returns the node with the dialog definition.
46      * @return
47      */

48     public Content getConfigNode() {
49         return configNode;
50     }
51
52     public static ConfiguredDialog getConfiguredDialog(String JavaDoc name, Content configNode, HttpServletRequest JavaDoc request,
53         HttpServletResponse JavaDoc response) {
54         return getConfiguredDialog(name, configNode, request, response, ConfiguredDialog.class);
55     }
56
57     /**
58      * @param paragraph
59      * @param configNode2
60      * @param request
61      * @param response
62      * @param class1
63      * @return
64      */

65     public static ConfiguredDialog getConfiguredDialog(String JavaDoc name, Content configNode, HttpServletRequest JavaDoc request,
66         HttpServletResponse JavaDoc response, Class JavaDoc defaultClass) {
67         // get class name
68
String JavaDoc className = null;
69         try {
70             Class JavaDoc handlerClass = defaultClass;
71             try {
72                 className = configNode.getNodeData("class").getString(); //$NON-NLS-1$
73
if (StringUtils.isNotEmpty(className)) {
74                     handlerClass = ClassUtil.classForName(className);
75                 }
76             }
77             catch (Exception JavaDoc e) {
78                 log.error(MessageFormat.format("Unable to load class {0}", new Object JavaDoc[]{className})); //$NON-NLS-1$
79
}
80             Constructor JavaDoc constructor = handlerClass.getConstructor(new Class JavaDoc[]{
81                 String JavaDoc.class,
82                 HttpServletRequest JavaDoc.class,
83                 HttpServletResponse JavaDoc.class,
84                 Content.class});
85             return (ConfiguredDialog) constructor.newInstance(new Object JavaDoc[]{name, request, response, configNode});
86         }
87         catch (Exception JavaDoc e) {
88             log.error("can't instantiate dialog: ", e); //$NON-NLS-1$
89
return null;
90         }
91     }
92
93 }
Popular Tags