001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
027     * @author Brian Wing Shun Chan
028     */
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    }