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.tagext.TagSupport;
025
026
029 public class GetUrlTag extends TagSupport {
030
031 public int doEndTag() throws JspException {
032 try {
033 WebCacheItem wci = new GetUrlWebCacheItem(_url, _expires);
034
035 String content = (String)WebCachePoolUtil.get(
036 GetUrlTag.class.getName() + StringPool.PERIOD + _url, wci);
037
038 if (Validator.isNotNull(_var)) {
039 pageContext.setAttribute(_var, content);
040 }
041 else {
042 pageContext.getOut().print(content);
043 }
044
045 return EVAL_PAGE;
046 }
047 catch (Exception e) {
048 throw new JspException(e);
049 }
050 }
051
052 public void setUrl(String url) {
053 _url = url;
054 }
055
056 public void setExpires(long expires) {
057 _expires = expires;
058 }
059
060 public void setVar(String var) {
061 _var = var;
062 }
063
064 private String _url;
065 private long _expires = Time.WEEK;
066 private String _var;
067
068 }