1 16 17 package org.apache.taglibs.log; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.PageContext ; 21 import javax.servlet.jsp.tagext.BodyTagSupport ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 32 33 public abstract class LoggerTag extends BodyTagSupport { 34 35 private String category; 36 private String message; 37 38 39 public void setCategory(String category) { 40 this.category = category; 41 } 42 43 public void setMessage(String message) { 44 this.message = message; 45 } 46 47 public int doStartTag() throws JspException { 50 if ( message != null ) { 51 Log logCategory = getLoggingCategory(); 52 if ( isEnabled( logCategory ) ) { 53 log( logCategory, message ); 55 } 56 return SKIP_BODY; 57 } 58 return EVAL_BODY_TAG; 59 } 60 61 public int doAfterBody() throws JspException { 62 if (message == null) { 63 Log logCategory = getLoggingCategory(); 64 if ( isEnabled( logCategory ) ) { 65 log( logCategory, getBodyContent().getString().trim() ); 66 } 67 } 68 return SKIP_BODY; 69 } 70 71 protected abstract boolean isEnabled(Log logCategory); 74 protected abstract void log(Log logCategory, String message); 75 76 protected Log getLoggingCategory() { 77 if ( category == null ) { 78 return LogFactory.getLog(""); 80 } 81 else { 82 return LogFactory.getLog( category ); 83 } 84 } 85 } 86 87 | Popular Tags |