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.event.*; 35 import org.enhydra.barracuda.core.forms.*; 36 import org.enhydra.barracuda.plankton.data.*; 37 import org.enhydra.barracuda.plankton.http.*; 38 39 43 public class DataConfig extends DefaultEventGateway { 44 45 protected static final Logger logger = Logger.getLogger(DataConfig.class.getName()); 46 47 public static final String FORM = DataConfig.class.getName()+".Form"; 49 50 public static final String MODEL_NAME = "Data"; 52 53 public static final String DEFAULT_STATE_MAP_DL = "DefaultStateMap_DebugLevel"; 55 public static final String ERROR_MESSAGE = "ErrorMessage"; 56 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 57 public static final String UPDATE_BUTTON = "UpdateButton"; 58 59 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 61 62 public DataConfig() { 63 specifyLocalEventInterests(updateConfigFactory); 65 } 66 67 73 class DataModel extends AbstractTemplateModel { 74 75 public String getName() {return MODEL_NAME;} 77 78 public Object getItem(String key) { 80 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 81 ViewContext vc = getViewContext(); 82 83 if (key.equals(DEFAULT_STATE_MAP_DL)) { 85 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultStateMap.class); 86 } else if (key.equals(ERROR_MESSAGE)) { 87 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 88 } else if (key.equals(SUCCESS_MESSAGE)) { 89 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 90 } else if (key.equals(UPDATE_BUTTON)) { 91 return ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 92 } else return super.getItem(key); 93 } 94 } 95 96 102 class DataForm extends DefaultFormMap { 103 public DataForm() { 104 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 109 this.defineElement(new DefaultFormElement(DEFAULT_STATE_MAP_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultStateMap.class)), null, false)); 110 } 111 } 112 113 120 class UpdateConfigHandler extends DefaultBaseEventListener { 121 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 122 Locale locale = context.getViewCapabilities().getClientLocale(); 124 MasterScreen screen = new MasterScreenFactory().getInstance(DataConfig.this, context, locale); 125 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 126 127 ValidationException ve = null; 129 DataForm formMap = new DataForm(); 130 try { 131 formMap.map(context.getRequest()).validate(true); 133 134 ScreenUtil.setLevel(DefaultStateMap.class, formMap.getIntegerVal(DEFAULT_STATE_MAP_DL).intValue()); 142 143 formMap.putState(SUCCESS_MESSAGE, new Boolean (true)); 145 146 } catch (ValidationException e) { 147 ve = e; 148 } 149 150 formMap.putState(ERROR_MESSAGE, ve); 153 context.putState(FORM, formMap); 154 155 ((DataModel) screen.dataModel).fireModelChanged(); 157 158 throw new ClientSideRedirectException(new GetBConfig()); 160 } 161 } 162 163 public TemplateModel getModel() { 167 return new DataModel(); 168 } 169 } 170 171 | Popular Tags |