1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.util;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.kernel.util.Time;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.kernel.webcache.WebCacheItem;
21  import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
22  
23  import javax.servlet.jsp.JspException;
24  import javax.servlet.jsp.tagext.BodyTagSupport;
25  
26  /**
27   * <a href="GetUrlTag.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class GetUrlTag extends BodyTagSupport {
32  
33      public int doEndTag() throws JspException {
34          try {
35              WebCacheItem wci = new GetUrlWebCacheItem(_url, _expires);
36  
37              String content = (String)WebCachePoolUtil.get(
38                  GetUrlTag.class.getName() + StringPool.PERIOD + _url, wci);
39  
40              if (Validator.isNotNull(_var)) {
41                  pageContext.setAttribute(_var, content);
42              }
43              else {
44                  pageContext.getOut().print(content);
45              }
46  
47              return EVAL_PAGE;
48          }
49          catch (Exception e) {
50              throw new JspException(e);
51          }
52      }
53  
54      public void setUrl(String url) {
55          _url = url;
56      }
57  
58      public void setExpires(long expires) {
59          _expires = expires;
60      }
61  
62      public void setVar(String var) {
63          _var = var;
64      }
65  
66      private String _url;
67      private long _expires = Time.WEEK;
68      private String _var;
69  
70  }