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.plankton.http.*; 38 39 43 public class DomConfig extends DefaultEventGateway { 44 45 protected static final Logger logger = Logger.getLogger(DomConfig.class.getName()); 46 47 public static final String FORM = DomConfig.class.getName()+".Form"; 49 50 public static final String MODEL_NAME = "Dom"; 52 53 public static final String DEFAULT_DOM_LOADER_DL = "DefaultDOMLoader_DebugLevel"; 55 public static final String DEFAULT_DOM_WRITER_DL = "DefaultDOMWriter_DebugLevel"; 56 public static final String DEFAULT_DOM_WRITER_DPP = "DefaultDOMWriter_DefaultPrintPretty"; 57 public static final String ERROR_MESSAGE = "ErrorMessage"; 58 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 59 public static final String UPDATE_BUTTON = "UpdateButton"; 60 61 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 63 64 public DomConfig() { 65 specifyLocalEventInterests(updateConfigFactory); 67 } 68 69 75 class DomModel extends AbstractTemplateModel { 76 77 public String getName() {return MODEL_NAME;} 79 80 public Object getItem(String key) { 82 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 83 ViewContext vc = getViewContext(); 84 85 if (key.equals(DEFAULT_DOM_LOADER_DL)) { 87 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultDOMLoader.class); 88 } else if (key.equals(DEFAULT_DOM_WRITER_DL)) { 89 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultDOMWriter.class); 90 } else if (key.equals(DEFAULT_DOM_WRITER_DPP)) { 91 return ScreenUtil.getToggleButton(vc, DEFAULT_DOM_WRITER_DPP, "true", DefaultDOMWriter.DEFAULT_PRINT_PRETTY); 92 } else if (key.equals(ERROR_MESSAGE)) { 93 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 94 } else if (key.equals(SUCCESS_MESSAGE)) { 95 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 96 } else if (key.equals(UPDATE_BUTTON)) { 97 return ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 98 } else return super.getItem(key); 99 100 } 101 } 102 103 109 class DomForm extends DefaultFormMap { 110 public DomForm() { 111 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 116 this.defineElement(new DefaultFormElement(DEFAULT_DOM_LOADER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultDOMLoader.class)), null, false)); 117 this.defineElement(new DefaultFormElement(DEFAULT_DOM_WRITER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultDOMWriter.class)), null, false)); 118 this.defineElement(new DefaultFormElement(DEFAULT_DOM_WRITER_DPP, FormType.BOOLEAN, new Boolean (false), null, false)); } 120 } 121 122 129 class UpdateConfigHandler extends DefaultBaseEventListener { 130 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 131 Locale locale = context.getViewCapabilities().getClientLocale(); 133 MasterScreen screen = new MasterScreenFactory().getInstance(DomConfig.this, context, locale); 134 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 135 136 ValidationException ve = null; 138 DomForm fm = new DomForm(); 139 try { 140 fm.map(context.getRequest()).validate(true); 142 143 ScreenUtil.setLevel(DefaultDOMLoader.class, fm.getIntegerVal(DEFAULT_DOM_LOADER_DL).intValue()); 151 ScreenUtil.setLevel(DefaultDOMWriter.class, fm.getIntegerVal(DEFAULT_DOM_WRITER_DL).intValue()); 152 DefaultDOMWriter.DEFAULT_PRINT_PRETTY = fm.getBooleanVal(DEFAULT_DOM_WRITER_DPP).booleanValue(); 153 154 fm.putState(SUCCESS_MESSAGE, new Boolean (true)); 156 157 } catch (ValidationException e) { 158 ve = e; 159 } 160 161 fm.putState(ERROR_MESSAGE, ve); 164 context.putState(FORM, fm); 165 166 ((DomModel) screen.domModel).fireModelChanged(); 168 169 throw new ClientSideRedirectException(new GetBConfig()); 171 } 172 } 173 174 public TemplateModel getModel() { 178 return new DomModel(); 179 } 180 } 181 182
| Popular Tags
|