1 5 package org.exoplatform.portlets.log.component; 6 7 import java.util.*; 8 import javax.faces.context.FacesContext; 9 import org.apache.commons.logging.Log; 10 import org.exoplatform.faces.FacesConstants; 11 import org.exoplatform.faces.core.component.UIRadioBox; 12 import org.exoplatform.faces.core.component.UISimpleForm; 13 import org.exoplatform.faces.core.component.model.*; 14 import org.exoplatform.services.log.LogService; 15 import org.exoplatform.services.log.impl.ExoLog; 16 17 21 public class UILogConfig extends UISimpleForm { 22 protected static Log log_ = getLog("org.exoplatform.portal.portal.portlets.log") ; 23 private static List LEVELS ; 24 25 static { 26 LEVELS = new ArrayList(6) ; 27 LEVELS.add(new SelectItem("fatal", "0")) ; 28 LEVELS.add(new SelectItem("error", "1")) ; 29 LEVELS.add(new SelectItem("warn", "2")) ; 30 LEVELS.add(new SelectItem("info", "3")) ; 31 LEVELS.add(new SelectItem("debug", "4")) ; 32 LEVELS.add(new SelectItem("trace", "5")) ; 33 } 34 35 private LogService service_ ; 36 private String name_ ; 37 private int availableLog_ ; 38 private boolean admin_ ; 39 40 public UILogConfig(LogService service) { 41 super("configForm", "post", null) ; 42 service_ = service ; 43 name_ = "Configuration" ; 44 setId("UILogConfig"); 45 admin_ = hasRole("admin"); 46 update() ; 47 } 48 49 private void update() { 50 clear() ; 51 Collection logs = service_.getLogs() ; 52 availableLog_ = logs.size() ; 53 add(new HeaderRow(). 54 add(new Cell("#{UIConfig.header.log-name}")). 55 add(new Cell("#{UIConfig.header.log-level}"))); 56 Iterator i = logs.iterator() ; 57 while(i.hasNext()) { 58 ExoLog log = (ExoLog) i.next() ; 59 String category = log.getLogCategory() ; 60 String level = Integer.toString(log.getLevel()) ; 61 UIRadioBox uiRadio = new UIRadioBox(category,level, LEVELS); 62 uiRadio.setClazz("radio") ; 63 add(new Row(). 64 add(new LabelCell(category)). 65 add(new ComponentCell(this, uiRadio). 66 addAlign("center"))); 67 } 68 add(new Row(). 69 add(new ListComponentCell(). 70 add(new FormButton("#{UIConfig.button.save}", SAVE_ACTION)). 71 addColspan("2").addAlign("center").addHeight("30"))) ; 72 } 73 74 public String getComponentType() { return COMPONENT_TYPE; } 75 76 public void decode(FacesContext context) { 77 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 78 String action = (String ) paramMap.get(FacesConstants.ACTION) ; 79 if (SAVE_ACTION.equals(action)) { 80 if (!admin_) return ; 81 List children = getChildren() ; 82 try { 83 for(int i = 0; i < children.size(); i++) { 84 Object o = children.get(i) ; 85 if (o instanceof UIRadioBox) { 86 UIRadioBox child = (UIRadioBox) o ; 87 int level = Integer.parseInt(child.getValue()) ; 88 service_.setLogLevel(child.getName(), level, false ) ; 89 } 90 } 91 update() ; 92 } catch (Exception ex) { 93 log_.error("Error: ", ex) ; 94 } 95 } else { 96 Collection logs = service_.getLogs() ; 97 if(availableLog_ < logs.size()) { 98 update() ; 99 } 100 } 101 } 102 } | Popular Tags |