001
014
015 package com.liferay.taglib.util;
016
017 import com.liferay.portal.kernel.util.StringPool;
018 import com.liferay.portal.kernel.util.StringUtil;
019
020 import javax.servlet.jsp.JspException;
021 import javax.servlet.jsp.JspWriter;
022 import javax.servlet.jsp.tagext.BodyContent;
023 import javax.servlet.jsp.tagext.BodyTagSupport;
024
025
028 public class WhitespaceRemoverTag extends BodyTagSupport {
029
030 @Override
031 public int doEndTag() throws JspException {
032 try {
033 JspWriter jspWriter = pageContext.getOut();
034
035 jspWriter.write(getBodyContentString());
036 }
037 catch (Exception e) {
038 throw new JspException(e);
039 }
040
041 return EVAL_PAGE;
042 }
043
044 @Override
045 public int doStartTag() {
046 return EVAL_BODY_BUFFERED;
047 }
048
049 protected String getBodyContentString() {
050 BodyContent bodyContent = getBodyContent();
051
052 String bodyContentString = StringUtil.trim(bodyContent.getString());
053
054 bodyContentString = StringUtil.replace(
055 bodyContentString,
056 new String[] {StringPool.NEW_LINE, StringPool.TAB},
057 new String[] {StringPool.BLANK, StringPool.BLANK});
058
059 return bodyContentString;
060 }
061
062 }