001
014
015 package com.liferay.taglib.core;
016
017 import com.liferay.portal.kernel.servlet.taglib.TagSupport;
018 import com.liferay.portal.kernel.util.StringUtil;
019
020 import javax.servlet.jsp.JspTagException;
021 import javax.servlet.jsp.PageContext;
022
023
026 public abstract class ConditionalTagSupport extends TagSupport {
027
028 @Override
029 @SuppressWarnings("unused")
030 public int doStartTag() throws JspTagException {
031 _result = condition();
032
033 if (_var != null) {
034 pageContext.setAttribute(_var, _result, _scope);
035 }
036
037 if (_result) {
038 return EVAL_BODY_INCLUDE;
039 }
040 else {
041 return SKIP_BODY;
042 }
043 }
044
045 @Override
046 public void release() {
047 super.release();
048
049 _result = false;
050 _scope = PageContext.PAGE_SCOPE;
051 _var = null;
052 }
053
054 public void setScope(String scope) {
055 String scopeLowerCase = StringUtil.toLowerCase(scope);
056
057 if (scopeLowerCase.equals("application")) {
058 _scope = PageContext.APPLICATION_SCOPE;
059 }
060 else if (scopeLowerCase.equals("page")) {
061 _scope = PageContext.PAGE_SCOPE;
062 }
063 else if (scopeLowerCase.equals("request")) {
064 _scope = PageContext.REQUEST_SCOPE;
065 }
066 else if (scopeLowerCase.equals("session")) {
067 _scope = PageContext.SESSION_SCOPE;
068 }
069 }
070
071 public void setVar(String var) {
072 _var = var;
073 }
074
075 protected abstract boolean condition();
076
077 private boolean _result;
078 private int _scope = PageContext.PAGE_SCOPE;
079 private String _var;
080
081 }