1 13 package info.magnolia.cms.taglibs.util; 14 15 import java.io.IOException ; 16 import java.util.StringTokenizer ; 17 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.JspTagException ; 20 import javax.servlet.jsp.JspWriter ; 21 import javax.servlet.jsp.tagext.BodyTagSupport ; 22 23 import org.apache.commons.lang.StringUtils; 24 25 26 31 public class ConvertNewLineTag extends BodyTagSupport { 32 33 36 private static final long serialVersionUID = 222L; 37 38 41 private boolean para; 42 43 47 public void setPara(boolean paragraphs) { 48 this.para = paragraphs; 49 } 50 51 54 public int doEndTag() throws JspException { 55 String bodyText = bodyContent.getString(); 56 57 if (StringUtils.isNotEmpty(bodyText)) { 58 StringTokenizer bodyTk = new StringTokenizer (bodyText, "\n", false); JspWriter out = pageContext.getOut(); 60 61 try { 62 if (this.para) { 63 while (bodyTk.hasMoreTokens()) { 65 out.write("<p>"); out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\'')); 67 out.write("</p>"); } 69 } 70 else { 71 while (bodyTk.hasMoreTokens()) { 73 out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\'')); 74 if (bodyTk.hasMoreTokens()) { 75 out.write("<br/>"); } 77 } 78 } 79 } 80 catch (IOException e) { 81 throw new JspTagException (e.getMessage()); 82 } 83 } 84 return EVAL_PAGE; 85 } 86 87 90 public void release() { 91 para = false; 92 super.release(); 93 } 94 95 } | Popular Tags |