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.util.dom.*; 35 import org.enhydra.barracuda.core.event.*; 36 import org.enhydra.barracuda.core.forms.*; 37 import org.enhydra.barracuda.core.forms.validators.*; 38 import org.enhydra.barracuda.core.util.l10n.*; 39 import org.enhydra.barracuda.core.util.srv.*; 40 import org.enhydra.barracuda.plankton.data.*; 41 import org.enhydra.barracuda.plankton.http.*; 42 43 47 public class UtilConfig extends DefaultEventGateway { 48 49 protected static final Logger logger = Logger.getLogger(UtilConfig.class.getName()); 50 51 public static final String FORM = UtilConfig.class.getName()+".Form"; 53 54 public static final String MODEL_NAME = "Util"; 56 57 public static final String LOCALES_DL = "Locales_DebugLevel"; 60 public static final String SESSION_SERVICES_DL = "SessionServices_DebugLevel"; 62 public static final String SIMPLE_SERVICE_FINDER_DL = "SimpleServiceFinder_DebugLevel"; 64 public static final String ERROR_MESSAGE = "ErrorMessage"; 65 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 66 public static final String UPDATE_BUTTON = "UpdateButton"; 67 68 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 70 71 public UtilConfig() { 72 specifyLocalEventInterests(updateConfigFactory); 74 } 75 76 82 class UtilModel extends AbstractTemplateModel { 83 84 public String getName() {return MODEL_NAME;} 86 87 public Object getItem(String key) { 89 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 90 ViewContext vc = getViewContext(); 91 92 if (key.equals(LOCALES_DL)) { 94 return ScreenUtil.getDebugLevelComp2(vc, key, Locales.class); 95 } else if (key.equals(SESSION_SERVICES_DL)) { 96 return ScreenUtil.getDebugLevelComp2(vc, key, SessionServices.class); 97 } else if (key.equals(SIMPLE_SERVICE_FINDER_DL)) { 101 return ScreenUtil.getDebugLevelComp2(vc, key, SimpleServiceFinder.class); 102 } else if (key.equals(ERROR_MESSAGE)) { 103 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 104 } else if (key.equals(SUCCESS_MESSAGE)) { 105 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 106 } else if (key.equals(UPDATE_BUTTON)) { 107 return ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 108 } else return super.getItem(key); 109 } 110 } 111 112 118 class UtilForm extends DefaultFormMap { 119 public UtilForm() { 120 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 125 this.defineElement(new DefaultFormElement(LOCALES_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(Locales.class)), null, false)); 126 this.defineElement(new DefaultFormElement(SESSION_SERVICES_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(SessionServices.class)), null, false)); 127 this.defineElement(new DefaultFormElement(SIMPLE_SERVICE_FINDER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(SimpleServiceFinder.class)), null, false)); 131 } 132 } 133 134 141 class UpdateConfigHandler extends DefaultBaseEventListener { 142 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 143 Locale locale = context.getViewCapabilities().getClientLocale(); 145 MasterScreen screen = new MasterScreenFactory().getInstance(UtilConfig.this, context, locale); 146 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 147 148 ValidationException ve = null; 150 UtilForm formMap = new UtilForm(); 151 try { 152 formMap.map(context.getRequest()).validate(true); 154 155 ScreenUtil.setLevel(Locales.class, formMap.getIntegerVal(LOCALES_DL).intValue()); 163 ScreenUtil.setLevel(SessionServices.class, formMap.getIntegerVal(SESSION_SERVICES_DL).intValue()); 164 ScreenUtil.setLevel(SimpleServiceFinder.class, formMap.getIntegerVal(SIMPLE_SERVICE_FINDER_DL).intValue()); 166 167 formMap.putState(SUCCESS_MESSAGE, new Boolean (true)); 169 170 } catch (ValidationException e) { 171 ve = e; 172 } 173 174 formMap.putState(ERROR_MESSAGE, ve); 177 context.putState(FORM, formMap); 178 179 ((UtilModel) screen.utilModel).fireModelChanged(); 181 182 throw new ClientSideRedirectException(new GetBConfig()); 184 } 185 } 186 187 public TemplateModel getModel() { 191 return new UtilModel(); 192 } 193 } 194 195 | Popular Tags |