001
014
015 package com.liferay.taglib.util;
016
017 import com.liferay.portal.kernel.util.StringPool;
018 import com.liferay.portal.kernel.util.Time;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.kernel.webcache.WebCacheItem;
021 import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
022
023 import javax.servlet.jsp.JspException;
024 import javax.servlet.jsp.JspWriter;
025 import javax.servlet.jsp.tagext.TagSupport;
026
027
030 public class GetUrlTag extends TagSupport {
031
032 @Override
033 public int doEndTag() throws JspException {
034 try {
035 WebCacheItem wci = new GetUrlWebCacheItem(_url, _expires);
036
037 String content = (String)WebCachePoolUtil.get(
038 GetUrlTag.class.getName() + StringPool.PERIOD + _url, wci);
039
040 if (Validator.isNotNull(_var)) {
041 pageContext.setAttribute(_var, content);
042 }
043 else {
044 JspWriter jspWriter = pageContext.getOut();
045
046 jspWriter.print(content);
047 }
048
049 return EVAL_PAGE;
050 }
051 catch (Exception e) {
052 throw new JspException(e);
053 }
054 }
055
056 public void setExpires(long expires) {
057 _expires = expires;
058 }
059
060 public void setUrl(String url) {
061 _url = url;
062 }
063
064 public void setVar(String var) {
065 _var = var;
066 }
067
068 private long _expires = Time.WEEK;
069 private String _url;
070 private String _var;
071
072 }