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