1 23 package org.enhydra.barracuda.config; 24 25 import java.io.*; 26 import java.util.*; 27 import java.lang.ref.*; 28 import java.net.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 import org.apache.log4j.*; 33 import org.w3c.dom.*; 34 import org.w3c.dom.html.*; 35 36 import org.enhydra.barracuda.core.comp.*; 37 import org.enhydra.barracuda.core.event.*; 38 import org.enhydra.barracuda.core.forms.*; 39 import org.enhydra.barracuda.plankton.l10n.*; 40 41 42 47 public class ScreenUtil { 48 49 protected static final Logger logger = Logger.getLogger(ScreenUtil.class.getName()); 51 52 60 public static BSelect getDebugLevelComp(ViewContext vc, String compName, int selectedIndex) { 61 DefaultListModel dlm = new DefaultListModel(); 62 63 71 72 Locale curloc = vc.getViewCapabilities().getClientLocale(); 73 ResourceBundle rb = ResourceBundle.getBundle("org.enhydra.barracuda.config.xmlc.Config", curloc); 74 String debugOffStr = Localize.getString(rb, "Config.General.Debug_Off"); 75 String debugStr = Localize.getString(rb, "Config.General.Debug"); 76 77 dlm.add(new DefaultItemMap(0, debugOffStr)); 78 dlm.add(new DefaultItemMap(1, debugStr+" = 1")); 79 dlm.add(new DefaultItemMap(2, debugStr+" = 2")); 80 dlm.add(new DefaultItemMap(3, debugStr+" = 3")); 81 dlm.add(new DefaultItemMap(4, debugStr+" = 4")); 82 dlm.add(new DefaultItemMap(5, debugStr+" = 5")); 83 84 return getSelectComp(vc, compName, dlm, selectedIndex); 85 } 86 87 96 public static BSelect getDebugLevelComp2(ViewContext vc, String compName, Class cl) { 97 DefaultListModel dlm = new DefaultListModel(); 98 99 Locale curloc = vc.getViewCapabilities().getClientLocale(); 101 ResourceBundle rb = ResourceBundle.getBundle("org.enhydra.barracuda.config.xmlc.Config", curloc); 102 String logShort = Localize.getString(rb, "Config.General.Logging.Short"); 103 dlm.add(new DefaultItemMap(0, logShort+" "+Localize.getString(rb, "Config.General.Logging.Default"))); 104 dlm.add(new DefaultItemMap(1, logShort+" "+Localize.getString(rb, "Config.General.Logging.Fatal"))); 105 dlm.add(new DefaultItemMap(2, logShort+" "+Localize.getString(rb, "Config.General.Logging.Error"))); 106 dlm.add(new DefaultItemMap(3, logShort+" "+Localize.getString(rb, "Config.General.Logging.Warn"))); 107 dlm.add(new DefaultItemMap(4, logShort+" "+Localize.getString(rb, "Config.General.Logging.Info"))); 108 dlm.add(new DefaultItemMap(5, logShort+" "+Localize.getString(rb, "Config.General.Logging.Debug"))); 109 110 return getSelectComp(vc, compName, dlm, cvtLevelToInt(cl)); 111 } 112 113 public static int cvtLevelToInt(Class cl) { 114 Level l = null; 115 if (cl==null) l = Logger.getRootLogger().getLevel(); 116 else l = Logger.getLogger(cl).getLevel(); 117 return cvtLevelToInt(l); 119 } 120 121 public static int cvtLevelToInt(Level l) { 122 if (l==null) return 0; 123 if (l.equals(Level.DEBUG)) return 5; 124 else if (l.equals(Level.INFO)) return 4; 125 else if (l.equals(Level.WARN)) return 3; 126 else if (l.equals(Level.ERROR)) return 2; 127 else if (l.equals(Level.FATAL)) return 1; 128 else return 0; 129 } 130 131 public static Level cvtIntToLevel(int i) { 132 if (i==5) return Level.DEBUG; 133 else if (i==4) return Level.INFO; 134 else if (i==3) return Level.WARN; 135 else if (i==2) return Level.ERROR; 136 else if (i==1) return Level.FATAL; 137 else return null; 138 } 139 140 public static void setLevel(Class cl, int i) { 141 Logger logr = Logger.getLogger(cl); 142 logr.setLevel(cvtIntToLevel(i)); 143 } 144 145 146 154 public static BSelect getSelectComp(ViewContext vc, String compName, ListModel lm, int selectedIndex) { 155 BSelect bsComp = new BSelect(lm); 158 bsComp.setName(compName); 159 bsComp.setSelectedIndex(selectedIndex); 160 if (logger.isDebugEnabled()) logger.debug("created BSelect component: "+bsComp); 161 return bsComp; 162 } 163 164 171 public static BToggleButton getToggleButton(ViewContext vc, String compName, String value, boolean selected) { 172 BToggleButton btbComp = new BToggleButton(null, compName, value, selected); 175 if (logger.isDebugEnabled()) logger.debug("created BToggleButton component: "+btbComp); 176 return btbComp; 177 } 178 179 180 188 public static BAction getActionLink(ViewContext vc, ListenerFactory lf) { 189 BAction baComp = new BAction(); 192 baComp.addEventListener(lf); 193 baComp.setDisableBackButton(true); 194 if (logger.isDebugEnabled()) logger.debug("created BAction component: "+baComp); 195 return baComp; 196 } 197 198 205 public static BAction getUpdateButtonComp(ViewContext vc, ListenerFactory lf) { 206 BAction baComp = new BAction(); 209 baComp.addEventListener(lf); 210 if (logger.isDebugEnabled()) logger.debug("created BAction component: "+baComp); 212 return baComp; 213 } 214 215 227 public static String getErrMsg(ViewContext vc, String formName, String keyName) { 228 String errmsg = " "; 229 EventContext ec = vc.getEventContext(); 230 if (ec!=null) { 231 FormMap formMap = (FormMap) ec.getState(formName); 232 if (formMap!=null) { 233 ValidationException ve = (ValidationException) formMap.getState(keyName); 234 if (ve!=null) { 235 List errlist = ve.getExceptionList(); 236 Iterator it = errlist.iterator(); 237 StringBuffer sb = new StringBuffer (100); 238 while (it.hasNext()) { 239 sb.append(" "+((ValidationException) it.next()).getMessage()); 240 } 241 errmsg = sb.toString(); 242 } 243 } 244 } 245 if (logger.isDebugEnabled()) logger.debug("errmsg: "+errmsg); 246 return errmsg; 247 } 248 249 257 public static String getSuccessMsg(ViewContext vc, String formName, String keyName) { 258 String msg = " "; 259 EventContext ec = vc.getEventContext(); 260 if (ec!=null) { 261 FormMap formMap = (FormMap) ec.getState(formName); 262 if (formMap!=null) { 263 if (formMap.getState(keyName)!=null) msg = "Update successful."; 264 } 265 } 266 return msg; 267 } 268 } 269 270 271 272 | Popular Tags |