001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import javax.portlet.CacheControl;
018    import javax.portlet.MimeResponse;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     * @author Deepak Gothe
023     */
024    public class CacheControlImpl implements CacheControl {
025    
026            public CacheControlImpl(
027                    String eTag, int expirationTime, boolean publicScope,
028                    boolean useCachedContent, MimeResponseImpl mimeResponseImpl) {
029    
030                    _eTag = eTag;
031                    _expirationTime = expirationTime;
032                    _publicScope = publicScope;
033                    _useCachedContent = useCachedContent;
034                    _mimeResponseImpl = mimeResponseImpl;
035            }
036    
037            @Override
038            public String getETag() {
039                    return _eTag;
040            }
041    
042            @Override
043            public int getExpirationTime() {
044                    return _expirationTime;
045            }
046    
047            @Override
048            public boolean isPublicScope() {
049                    return _publicScope;
050            }
051    
052            @Override
053            public void setETag(String eTag) {
054                    _eTag = eTag;
055    
056                    _mimeResponseImpl.setProperty(MimeResponse.ETAG, eTag);
057            }
058    
059            @Override
060            public void setExpirationTime(int expirationTime) {
061                    _expirationTime = expirationTime;
062    
063                    _mimeResponseImpl.setProperty(
064                            MimeResponse.EXPIRATION_CACHE, String.valueOf(expirationTime));
065            }
066    
067            @Override
068            public void setPublicScope(boolean publicScope) {
069                    _publicScope = publicScope;
070    
071                    _mimeResponseImpl.setProperty(
072                            MimeResponse.PUBLIC_SCOPE, String.valueOf(publicScope));
073            }
074    
075            @Override
076            public void setUseCachedContent(boolean useCachedContent) {
077                    _useCachedContent = useCachedContent;
078    
079                    _mimeResponseImpl.setProperty(
080                            MimeResponse.USE_CACHED_CONTENT, String.valueOf(useCachedContent));
081            }
082    
083            @Override
084            public boolean useCachedContent() {
085                    return _useCachedContent;
086            }
087    
088            private String _eTag;
089            private int _expirationTime;
090            private MimeResponseImpl _mimeResponseImpl;
091            private boolean _publicScope;
092            private boolean _useCachedContent;
093    
094    }