1 13 package info.magnolia.cms.gui.dialog; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.util.ClassUtil; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import javax.jcr.RepositoryException; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.commons.lang.exception.NestableRuntimeException; 26 import org.slf4j.Logger; 27 import org.slf4j.LoggerFactory; 28 29 30 36 public final class DialogFactory { 37 38 41 private static Map controls = new HashMap (); 42 43 46 private static Logger log = LoggerFactory.getLogger(DialogFactory.class); 47 48 51 private DialogFactory() { 52 } 54 55 61 public static void registerDialog(String name, Class dialogClass) { 62 65 if (log.isDebugEnabled()) { 66 log.debug("Registering control [{}]", name); } 68 69 controls.put(name, dialogClass); 70 } 71 72 79 public static DialogControl loadDialog(HttpServletRequest request, HttpServletResponse response, 80 Content storageNode, Content configNode) throws RepositoryException { 81 String controlType = configNode.getNodeData("controlType").getString(); 83 return getDialogControlInstanceByName(request, response, storageNode, configNode, controlType); 84 } 85 86 public static Dialog getDialogInstance(HttpServletRequest request, HttpServletResponse response, 87 Content storageNode, Content configNode) throws RepositoryException { 88 Dialog dialog = new Dialog(); 89 dialog.init(request, response, storageNode, configNode); 90 return dialog; 91 } 92 93 public static DialogStatic getDialogStaticInstance(HttpServletRequest request, HttpServletResponse response, 94 Content storageNode, Content configNode) throws RepositoryException { 95 DialogStatic dialog = new DialogStatic(); 96 dialog.init(request, response, storageNode, configNode); 97 return dialog; 98 } 99 100 public static DialogHidden getDialogHiddenInstance(HttpServletRequest request, HttpServletResponse response, 101 Content storageNode, Content configNode) throws RepositoryException { 102 DialogHidden dialog = new DialogHidden(); 103 dialog.init(request, response, storageNode, configNode); 104 return dialog; 105 } 106 107 public static DialogEdit getDialogEditInstance(HttpServletRequest request, HttpServletResponse response, 108 Content storageNode, Content configNode) throws RepositoryException { 109 DialogEdit dialog = new DialogEdit(); 110 dialog.init(request, response, storageNode, configNode); 111 return dialog; 112 } 113 114 public static DialogButton getDialogButtonInstance(HttpServletRequest request, HttpServletResponse response, 115 Content storageNode, Content configNode) throws RepositoryException { 116 DialogButton dialog = new DialogButton(); 117 dialog.init(request, response, storageNode, configNode); 118 return dialog; 119 } 120 121 public static DialogPassword getDialogPasswordInstance(HttpServletRequest request, HttpServletResponse response, 122 Content storageNode, Content configNode) throws RepositoryException { 123 DialogPassword dialog = new DialogPassword(); 124 dialog.init(request, response, storageNode, configNode); 125 return dialog; 126 } 127 128 public static DialogButtonSet getDialogButtonSetInstance(HttpServletRequest request, HttpServletResponse response, 129 Content storageNode, Content configNode) throws RepositoryException { 130 DialogButtonSet dialog = new DialogButtonSet(); 131 dialog.init(request, response, storageNode, configNode); 132 return dialog; 133 } 134 135 public static DialogInclude getDialogIncludeInstance(HttpServletRequest request, HttpServletResponse response, 136 Content storageNode, Content configNode) throws RepositoryException { 137 DialogInclude dialog = new DialogInclude(); 138 dialog.init(request, response, storageNode, configNode); 139 return dialog; 140 } 141 142 public static DialogSelect getDialogSelectInstance(HttpServletRequest request, HttpServletResponse response, 143 Content storageNode, Content configNode) throws RepositoryException { 144 DialogSelect dialog = new DialogSelect(); 145 dialog.init(request, response, storageNode, configNode); 146 return dialog; 147 } 148 149 160 public static DialogControl getDialogControlInstanceByName(HttpServletRequest request, 161 HttpServletResponse response, Content storageNode, Content configNode, String controlType) 162 throws RepositoryException { 163 164 Class dialogClass = (Class ) controls.get(controlType); 165 166 if (dialogClass == null) { 167 try { 168 dialogClass = ClassUtil.classForName(controlType); 169 } 170 catch (ClassNotFoundException e) { 171 throw new IllegalArgumentException ("Unknown control type: \"" + controlType + "\""); } 173 } 174 175 DialogControl control = null; 176 try { 177 control = (DialogControl) dialogClass.newInstance(); 178 } 179 catch (Exception e) { 180 throw new NestableRuntimeException("Unable to instantiate " + dialogClass 183 + " due to: InstantiationException - " + e.getMessage()); 185 } 186 187 control.init(request, response, storageNode, configNode); 188 return control; 189 } 190 } 191 | Popular Tags |