1 23 package org.enhydra.barracuda.config; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import org.apache.log4j.*; 31 32 import org.enhydra.barracuda.config.events.*; 33 import org.enhydra.barracuda.core.comp.*; 34 import org.enhydra.barracuda.core.comp.helper.*; 35 import org.enhydra.barracuda.core.comp.renderer.*; 36 import org.enhydra.barracuda.core.comp.renderer.html.*; 37 import org.enhydra.barracuda.core.comp.renderer.xml.*; 38 import org.enhydra.barracuda.core.event.*; 39 import org.enhydra.barracuda.core.forms.*; 40 import org.enhydra.barracuda.plankton.http.*; 41 42 43 47 public class CompConfig extends DefaultEventGateway { 48 49 protected static final Logger logger = Logger.getLogger(CompConfig.class.getName()); 50 51 public static final String FORM = CompConfig.class.getName()+".Form"; 53 54 public static final String MODEL_NAME = "Comp"; 56 57 public static final String ABSTRACT_BCOMPONENT_DL = "AbstractBComponent_DebugLevel"; 60 public static final String BACTION_DL = "BAction_DebugLevel"; 61 public static final String BINPUT_DL = "BInput_DebugLevel"; 62 public static final String BLINK_DL = "BLink_DebugLevel"; 63 public static final String BLIST_DL = "BList_DebugLevel"; 64 public static final String BSELECT_DL = "BSelect_DebugLevel"; 65 public static final String BTABLE_DL = "BTable_DebugLevel"; 66 public static final String BTEMPLATE_DL = "BTemplate_DebugLevel"; 67 public static final String BTEXT_DL = "BText_DebugLevel"; 68 public static final String BTOGGLE_BUTTON_DL = "BToggleButton_DebugLevel"; 69 public static final String COMPONENT_GATEWAY_DL = "ComponentGateway_DebugLevel"; 70 public static final String DEFAULT_LIST_MODEL_DL = "DefaultListModel_DebugLevel"; 72 public static final String DEFAULT_PROPERTIES_MODEL_DL = "DefaultPropertiesModel_DebugLevel"; 73 public static final String DEFAULT_TABLE_VIEW_DL = "DefaultTableView_DebugLevel"; 76 public static final String DEFAULT_TEMPLATE_VIEW_DL = "DefaultTemplateView_DebugLevel"; 77 public static final String DEFAULT_VIEW_DL = "DefaultView_DebugLevel"; 78 public static final String HTML_COMPONENT_RENDERER_DL = "HTMLComponentRenderer_DebugLevel"; 80 public static final String HTML_ACTION_RENDERER_DL = "HTMLActionRenderer_DebugLevel"; 81 public static final String HTML_INPUT_RENDERER_DL = "HTMLInputRenderer_DebugLevel"; 82 public static final String HTML_LINK_RENDERER_DL = "HTMLLinkRenderer_DebugLevel"; 83 public static final String HTML_LIST_RENDERER_DL = "HTMLListRenderer_DebugLevel"; 84 public static final String HTML_SELECT_RENDERER_DL = "HTMLSelectRenderer_DebugLevel"; 85 public static final String HTML_TABLE_RENDERER_DL = "HTMLTableRenderer_DebugLevel"; 86 public static final String HTML_TOGGLE_RENDERER_DL = "HTMLToggleRenderer_DebugLevel"; 87 public static final String HTML_TEMPLATE_RENDERER_DL = "HTMLTemplateRenderer_DebugLevel"; 88 public static final String HTML_TEXT_RENDERER_DL = "HTMLTextRenderer_DebugLevel"; 89 public static final String TEMPLATE_HELPER_DL = "TemplateHelper_DebugLevel"; 90 public static final String XML_COMPONENT_RENDERER_DL = "XMLComponentRenderer_DebugLevel"; 91 public static final String XML_TEMPLATE_RENDERER_DL = "XMLTemplateRenderer_DebugLevel"; 92 public static final String XML_TEXT_RENDERER_DL = "XMLTextRenderer_DebugLevel"; 93 public static final String ERROR_MESSAGE = "ErrorMessage"; 95 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 96 public static final String UPDATE_BUTTON = "UpdateButton"; 97 98 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 100 101 public CompConfig() { 102 specifyLocalEventInterests(updateConfigFactory); 104 } 105 106 112 class CompModel extends AbstractTemplateModel { 113 114 public String getName() {return MODEL_NAME;} 116 117 public Object getItem(String key) { 120 ViewContext vc = getViewContext(); 121 122 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 123 124 if (key.equals(ABSTRACT_BCOMPONENT_DL)) { 127 return ScreenUtil.getDebugLevelComp2(vc, key, AbstractBComponent.class); 128 } else if (key.equals(BACTION_DL)) { 129 return ScreenUtil.getDebugLevelComp2(vc, key, BAction.class); 130 } else if (key.equals(BINPUT_DL)) { 131 return ScreenUtil.getDebugLevelComp2(vc, key, BInput.class); 132 } else if (key.equals(BLINK_DL)) { 133 return ScreenUtil.getDebugLevelComp2(vc, key, BLink.class); 134 } else if (key.equals(BLIST_DL)) { 135 return ScreenUtil.getDebugLevelComp2(vc, key, BList.class); 136 } else if (key.equals(BSELECT_DL)) { 137 return ScreenUtil.getDebugLevelComp2(vc, key, BSelect.class); 138 } else if (key.equals(BTABLE_DL)) { 139 return ScreenUtil.getDebugLevelComp2(vc, key, BTable.class); 140 } else if (key.equals(BTEMPLATE_DL)) { 141 return ScreenUtil.getDebugLevelComp2(vc, key, BTemplate.class); 142 } else if (key.equals(BTEXT_DL)) { 143 return ScreenUtil.getDebugLevelComp2(vc, key, BText.class); 144 } else if (key.equals(BTOGGLE_BUTTON_DL)) { 145 return ScreenUtil.getDebugLevelComp2(vc, key, BToggleButton.class); 146 } else if (key.equals(COMPONENT_GATEWAY_DL)) { 147 return ScreenUtil.getDebugLevelComp2(vc, key, ComponentGateway.class); 148 } else if (key.equals(DEFAULT_LIST_MODEL_DL)) { 150 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultListModel.class); 151 } else if (key.equals(DEFAULT_PROPERTIES_MODEL_DL)) { 152 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultPropertiesModel.class); 153 } else if (key.equals(DEFAULT_TABLE_VIEW_DL)) { 155 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultTableView.class); 156 } else if (key.equals(DEFAULT_TEMPLATE_VIEW_DL)) { 157 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultTemplateView.class); 158 } else if (key.equals(DEFAULT_VIEW_DL)) { 159 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultView.class); 160 } else if (key.equals(HTML_COMPONENT_RENDERER_DL)) { 162 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLComponentRenderer.class); 163 } else if (key.equals(HTML_COMPONENT_RENDERER_DL)) { 164 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLComponentRenderer.class); 165 } else if (key.equals(HTML_ACTION_RENDERER_DL)) { 166 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLActionRenderer.class); 167 } else if (key.equals(HTML_INPUT_RENDERER_DL)) { 168 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLInputRenderer.class); 169 } else if (key.equals(HTML_LINK_RENDERER_DL)) { 170 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLLinkRenderer.class); 171 } else if (key.equals(HTML_LIST_RENDERER_DL)) { 172 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLListRenderer.class); 173 } else if (key.equals(HTML_SELECT_RENDERER_DL)) { 174 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLSelectRenderer.class); 175 } else if (key.equals(HTML_TABLE_RENDERER_DL)) { 176 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLTableRenderer.class); 177 } else if (key.equals(HTML_TOGGLE_RENDERER_DL)) { 178 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLToggleRenderer.class); 179 } else if (key.equals(HTML_TEMPLATE_RENDERER_DL)) { 180 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLTemplateRenderer.class); 181 } else if (key.equals(HTML_TEXT_RENDERER_DL)) { 182 return ScreenUtil.getDebugLevelComp2(vc, key, HTMLTextRenderer.class); 183 } else if (key.equals(TEMPLATE_HELPER_DL)) { 184 return ScreenUtil.getDebugLevelComp2(vc, key, TemplateHelper.class); 185 } else if (key.equals(XML_COMPONENT_RENDERER_DL)) { 186 return ScreenUtil.getDebugLevelComp2(vc, key, XMLComponentRenderer.class); 187 } else if (key.equals(XML_TEMPLATE_RENDERER_DL)) { 188 return ScreenUtil.getDebugLevelComp2(vc, key, XMLTemplateRenderer.class); 189 } else if (key.equals(XML_TEXT_RENDERER_DL)) { 190 return ScreenUtil.getDebugLevelComp2(vc, key, XMLTextRenderer.class); 191 } else if (key.equals(ERROR_MESSAGE)) { 193 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 194 } else if (key.equals(SUCCESS_MESSAGE)) { 195 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 196 } else if (key.equals(UPDATE_BUTTON)) { 197 return ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 198 } else return super.getItem(key); 200 201 } 202 } 203 204 210 class CompForm extends DefaultFormMap { 211 public CompForm() { 212 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 217 this.defineElement(new DefaultFormElement(ABSTRACT_BCOMPONENT_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(AbstractBComponent.class)), null, false)); 219 this.defineElement(new DefaultFormElement(BACTION_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BAction.class)), null, false)); 220 this.defineElement(new DefaultFormElement(BINPUT_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BInput.class)), null, false)); 221 this.defineElement(new DefaultFormElement(BLINK_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BLink.class)), null, false)); 222 this.defineElement(new DefaultFormElement(BLIST_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BList.class)), null, false)); 223 this.defineElement(new DefaultFormElement(BSELECT_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BSelect.class)), null, false)); 224 this.defineElement(new DefaultFormElement(BTABLE_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BTable.class)), null, false)); 225 this.defineElement(new DefaultFormElement(BTEMPLATE_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BTemplate.class)), null, false)); 226 this.defineElement(new DefaultFormElement(BTEXT_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BText.class)), null, false)); 227 this.defineElement(new DefaultFormElement(BTOGGLE_BUTTON_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(BToggleButton.class)), null, false)); 228 this.defineElement(new DefaultFormElement(COMPONENT_GATEWAY_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(ComponentGateway.class)), null, false)); 229 this.defineElement(new DefaultFormElement(DEFAULT_LIST_MODEL_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultListModel.class)), null, false)); 231 this.defineElement(new DefaultFormElement(DEFAULT_PROPERTIES_MODEL_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultPropertiesModel.class)), null, false)); 232 this.defineElement(new DefaultFormElement(DEFAULT_TABLE_VIEW_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultTableView.class)), null, false)); 234 this.defineElement(new DefaultFormElement(DEFAULT_TEMPLATE_VIEW_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultTemplateView.class)), null, false)); 235 this.defineElement(new DefaultFormElement(DEFAULT_VIEW_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultView.class)), null, false)); 236 this.defineElement(new DefaultFormElement(HTML_COMPONENT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLComponentRenderer.class)), null, false)); 238 this.defineElement(new DefaultFormElement(HTML_COMPONENT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLComponentRenderer.class)), null, false)); 239 this.defineElement(new DefaultFormElement(HTML_ACTION_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLActionRenderer.class)), null, false)); 240 this.defineElement(new DefaultFormElement(HTML_INPUT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLInputRenderer.class)), null, false)); 241 this.defineElement(new DefaultFormElement(HTML_LINK_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLLinkRenderer.class)), null, false)); 242 this.defineElement(new DefaultFormElement(HTML_LIST_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLListRenderer.class)), null, false)); 243 this.defineElement(new DefaultFormElement(HTML_SELECT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLSelectRenderer.class)), null, false)); 244 this.defineElement(new DefaultFormElement(HTML_TABLE_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLTableRenderer.class)), null, false)); 245 this.defineElement(new DefaultFormElement(HTML_TOGGLE_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLToggleRenderer.class)), null, false)); 246 this.defineElement(new DefaultFormElement(HTML_TEMPLATE_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLTemplateRenderer.class)), null, false)); 247 this.defineElement(new DefaultFormElement(HTML_TEXT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(HTMLTextRenderer.class)), null, false)); 248 this.defineElement(new DefaultFormElement(TEMPLATE_HELPER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(TemplateHelper.class)), null, false)); 249 this.defineElement(new DefaultFormElement(XML_COMPONENT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(XMLComponentRenderer.class)), null, false)); 250 this.defineElement(new DefaultFormElement(XML_TEMPLATE_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(XMLTemplateRenderer.class)), null, false)); 251 this.defineElement(new DefaultFormElement(XML_TEXT_RENDERER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(XMLTextRenderer.class)), null, false)); 252 } 253 } 254 255 262 class UpdateConfigHandler extends DefaultBaseEventListener { 263 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 264 Locale locale = context.getViewCapabilities().getClientLocale(); 266 MasterScreen screen = new MasterScreenFactory().getInstance(CompConfig.this, context, locale); 267 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 268 269 ValidationException ve = null; 271 CompForm formMap = new CompForm(); 272 try { 273 formMap.map(context.getRequest()).validate(true); 275 276 ScreenUtil.setLevel(AbstractBComponent.class, formMap.getIntegerVal(ABSTRACT_BCOMPONENT_DL).intValue()); 285 ScreenUtil.setLevel(BAction.class, formMap.getIntegerVal(BACTION_DL).intValue()); 286 ScreenUtil.setLevel(BInput.class, formMap.getIntegerVal(BINPUT_DL).intValue()); 287 ScreenUtil.setLevel(BLink.class, formMap.getIntegerVal(BLINK_DL).intValue()); 288 ScreenUtil.setLevel(ScreenUtil.class, formMap.getIntegerVal(BLIST_DL).intValue()); 289 ScreenUtil.setLevel(ScreenUtil.class, formMap.getIntegerVal(BSELECT_DL).intValue()); 290 ScreenUtil.setLevel(ScreenUtil.class, formMap.getIntegerVal(BTABLE_DL).intValue()); 291 ScreenUtil.setLevel(ScreenUtil.class, formMap.getIntegerVal(BTEMPLATE_DL).intValue()); 292 ScreenUtil.setLevel(BText.class, formMap.getIntegerVal(BTEXT_DL).intValue()); 293 ScreenUtil.setLevel(BToggleButton.class, formMap.getIntegerVal(BTOGGLE_BUTTON_DL).intValue()); 294 ScreenUtil.setLevel(ComponentGateway.class, formMap.getIntegerVal(COMPONENT_GATEWAY_DL).intValue()); 295 ScreenUtil.setLevel(DefaultListModel.class, formMap.getIntegerVal(DEFAULT_LIST_MODEL_DL).intValue()); 297 ScreenUtil.setLevel(DefaultPropertiesModel.class, formMap.getIntegerVal(DEFAULT_PROPERTIES_MODEL_DL).intValue()); 298 ScreenUtil.setLevel(DefaultTableView.class, formMap.getIntegerVal(DEFAULT_TABLE_VIEW_DL).intValue()); 300 ScreenUtil.setLevel(DefaultTemplateView.class, formMap.getIntegerVal(DEFAULT_TEMPLATE_VIEW_DL).intValue()); 301 ScreenUtil.setLevel(DefaultView.class, formMap.getIntegerVal(DEFAULT_VIEW_DL).intValue()); 302 ScreenUtil.setLevel(HTMLComponentRenderer.class, formMap.getIntegerVal(HTML_COMPONENT_RENDERER_DL).intValue()); 304 ScreenUtil.setLevel(HTMLComponentRenderer.class, formMap.getIntegerVal(HTML_COMPONENT_RENDERER_DL).intValue()); 305 ScreenUtil.setLevel(HTMLActionRenderer.class, formMap.getIntegerVal(HTML_ACTION_RENDERER_DL).intValue()); 306 ScreenUtil.setLevel(HTMLInputRenderer.class, formMap.getIntegerVal(HTML_INPUT_RENDERER_DL).intValue()); 307 ScreenUtil.setLevel(HTMLLinkRenderer.class, formMap.getIntegerVal(HTML_LINK_RENDERER_DL).intValue()); 308 ScreenUtil.setLevel(HTMLListRenderer.class, formMap.getIntegerVal(HTML_LIST_RENDERER_DL).intValue()); 309 ScreenUtil.setLevel(HTMLSelectRenderer.class, formMap.getIntegerVal(HTML_SELECT_RENDERER_DL).intValue()); 310 ScreenUtil.setLevel(HTMLTableRenderer.class, formMap.getIntegerVal(HTML_TABLE_RENDERER_DL).intValue()); 311 ScreenUtil.setLevel(HTMLToggleRenderer.class, formMap.getIntegerVal(HTML_TOGGLE_RENDERER_DL).intValue()); 312 ScreenUtil.setLevel(HTMLTemplateRenderer.class, formMap.getIntegerVal(HTML_TEMPLATE_RENDERER_DL).intValue()); 313 ScreenUtil.setLevel(HTMLTextRenderer.class, formMap.getIntegerVal(HTML_TEXT_RENDERER_DL).intValue()); 314 ScreenUtil.setLevel(TemplateHelper.class, formMap.getIntegerVal(TEMPLATE_HELPER_DL).intValue()); 315 ScreenUtil.setLevel(XMLComponentRenderer.class, formMap.getIntegerVal(XML_COMPONENT_RENDERER_DL).intValue()); 316 ScreenUtil.setLevel(XMLTemplateRenderer.class, formMap.getIntegerVal(XML_TEMPLATE_RENDERER_DL).intValue()); 317 ScreenUtil.setLevel(XMLTextRenderer.class, formMap.getIntegerVal(XML_TEXT_RENDERER_DL).intValue()); 318 319 formMap.putState(SUCCESS_MESSAGE, new Boolean (true)); 321 322 } catch (ValidationException e) { 323 ve = e; 324 } 325 326 formMap.putState(ERROR_MESSAGE, ve); 329 context.putState(FORM, formMap); 330 331 ((CompModel) screen.compModel).fireModelChanged(); 333 334 throw new ClientSideRedirectException(new GetBConfig()); 336 } 337 } 338 339 public TemplateModel getModel() { 343 return new CompModel(); 344 } 345 } 346 347 | Popular Tags |