1 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 ; 20 import java.text.MessageFormat ; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.commons.lang.StringUtils; 26 import org.slf4j.Logger; 27 import org.slf4j.LoggerFactory; 28 29 30 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 name, HttpServletRequest request, HttpServletResponse response, Content configNode) { 40 super(name, request, response); 41 this.configNode = configNode; 42 } 43 44 48 public Content getConfigNode() { 49 return configNode; 50 } 51 52 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request, 53 HttpServletResponse response) { 54 return getConfiguredDialog(name, configNode, request, response, ConfiguredDialog.class); 55 } 56 57 65 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request, 66 HttpServletResponse response, Class defaultClass) { 67 String className = null; 69 try { 70 Class handlerClass = defaultClass; 71 try { 72 className = configNode.getNodeData("class").getString(); if (StringUtils.isNotEmpty(className)) { 74 handlerClass = ClassUtil.classForName(className); 75 } 76 } 77 catch (Exception e) { 78 log.error(MessageFormat.format("Unable to load class {0}", new Object []{className})); } 80 Constructor constructor = handlerClass.getConstructor(new Class []{ 81 String .class, 82 HttpServletRequest .class, 83 HttpServletResponse .class, 84 Content.class}); 85 return (ConfiguredDialog) constructor.newInstance(new Object []{name, request, response, configNode}); 86 } 87 catch (Exception e) { 88 log.error("can't instantiate dialog: ", e); return null; 90 } 91 } 92 93 } | Popular Tags |