1 25 29 package org.jresearch.gossip.tags; 30 31 import java.io.IOException ; 32 33 import javax.servlet.jsp.JspException ; 34 import javax.servlet.jsp.JspWriter ; 35 import javax.servlet.jsp.tagext.BodyTagSupport ; 36 37 import org.apache.log.Logger; 38 import org.apache.struts.Globals; 39 import org.apache.struts.util.MessageResources; 40 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 41 import org.jresearch.gossip.IConst; 42 import org.jresearch.gossip.configuration.Configurator; 43 import org.jresearch.gossip.exception.ConfiguratorException; 44 import org.jresearch.gossip.exception.SystemException; 45 import org.jresearch.gossip.log.avalon.JGossipLog; 46 import org.jresearch.gossip.util.HtmlCodec; 47 import org.jresearch.gossip.util.MessageProcessor; 48 49 54 public class ProcessMessageTag extends BodyTagSupport { 55 56 59 private Logger log; 60 61 62 private int cutToLength; 63 64 private String value; 65 66 private boolean skipSmiles; 67 68 71 public ProcessMessageTag() { 72 super(); 73 try { 74 log = JGossipLog.getInstance().getAppLogger(); 75 } catch (SystemException e) { 76 } 77 } 78 79 private void eval() throws JspException { 80 if (value != null) { 81 value = (String ) ExpressionEvaluatorManager.evaluate("value", 82 value, String .class, this, pageContext); 83 } 84 } 85 86 94 public int doStartTag() throws JspException { 95 try { 96 if (value != null) { 97 eval(); 98 value = HtmlCodec.encode(value); 99 100 JspWriter out = pageContext.getOut(); 101 out.print(process(value, skipSmiles)); 102 } 103 } catch (IOException ex) { 104 if (log.isErrorEnabled()) { 105 log.error("ProcessMessageTag::", ex); 106 } 107 throw new JspException ("error in ProcessMessageTag tag:" 108 + ex.getMessage()); 109 } catch (ConfiguratorException e) { 110 if (log.isErrorEnabled()) { 111 log.error("ProcessMessageTag::", e); 112 } 113 throw new JspException ("error in ProcessMessageTag tag:" 114 + e.getMessage()); 115 } 116 117 return (EVAL_BODY_BUFFERED); 118 } 119 120 128 public int doAfterBody() throws JspException { 129 try { 130 String result = HtmlCodec.encode(bodyContent.getString()); 131 result = process(result, skipSmiles); 132 bodyContent.clearBody(); 133 bodyContent.print(result); 134 bodyContent.writeOut(getPreviousOut()); 135 } catch (IOException ex) { 136 if (log.isErrorEnabled()) { 137 log.error("ProcessMessageTag::", ex); 138 } 139 throw new JspException ("error in ProcessMessageTag tag:" 140 + ex.getMessage()); 141 } catch (ConfiguratorException e) { 142 if (log.isErrorEnabled()) { 143 log.error("ProcessMessageTag::", e); 144 } 145 throw new JspException ("error in ProcessMessageTag tag:" 146 + e.getMessage()); 147 } 148 149 return SKIP_BODY; 150 } 151 152 private String process(String result, boolean skipSmiles) 153 throws ConfiguratorException { 154 MessageProcessor mp = MessageProcessor.getInstance(); 155 Configurator conf = Configurator.getInstance(); 156 result = mp 157 .prepareMessage( 158 result, 159 this.cutToLength, 160 (MessageResources) pageContext 161 .getServletContext() 162 .getAttribute( 163 Globals.MESSAGES_KEY 164 + conf 165 .get(IConst.CONFIG.MODULE_PREFIX))); 166 167 if ((cutToLength == 0) && !skipSmiles) { 168 result = mp.processEmoticons(result, (MessageResources) pageContext 169 .getServletContext().getAttribute( 170 Globals.MESSAGES_KEY 171 + conf.get(IConst.CONFIG.MODULE_PREFIX))); 172 } else if (skipSmiles) { 173 result = mp.cleanup(result); 174 } 175 176 return result; 177 } 178 179 184 public int getCutToLength() { 185 return cutToLength; 186 } 187 188 193 public void setCutToLength(int i) { 194 cutToLength = i; 195 } 196 197 202 public String getValue() { 203 return value; 204 } 205 206 211 public void setValue(String string) { 212 value = string; 213 } 214 215 220 public boolean isSkipSmiles() { 221 return skipSmiles; 222 } 223 224 229 public void setSkipSmiles(boolean b) { 230 skipSmiles = b; 231 } 232 } 233 | Popular Tags |