001    /**
002     * Copyright (c) 2000-2012 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.portal.atom;
016    
017    import com.liferay.portal.kernel.atom.AtomRequestContext;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    
020    import org.apache.abdera.protocol.server.RequestContext;
021    
022    /**
023     * @author Igor Spasic
024     */
025    public class AtomRequestContextImpl implements AtomRequestContext {
026    
027            public AtomRequestContextImpl(RequestContext requestContext) {
028                    _requestContext = requestContext;
029            }
030    
031            public Object getContainerAttribute(String name) {
032                    return _requestContext.getAttribute(
033                            RequestContext.Scope.CONTAINER, name);
034            }
035    
036            public String getHeader(String name) {
037                    return _requestContext.getHeader(name);
038            }
039    
040            public int getIntParameter(String name) {
041                    String value = _requestContext.getParameter(name);
042    
043                    return GetterUtil.getInteger(value);
044            }
045    
046            public int getIntParameter(String name, int defaultValue) {
047                    String value = _requestContext.getParameter(name);
048    
049                    return GetterUtil.getInteger(value, defaultValue);
050            }
051    
052            public long getLongParameter(String name) {
053                    String value = _requestContext.getParameter(name);
054    
055                    return GetterUtil.getLong(value);
056            }
057    
058            public long getLongParameter(String name, long defaultValue) {
059                    String value = _requestContext.getParameter(name);
060    
061                    return GetterUtil.getLong(value, defaultValue);
062            }
063    
064            public String getParameter(String name) {
065                    return _requestContext.getParameter(name);
066            }
067    
068            public String getParameter(String name, String defaultValue) {
069                    String value = _requestContext.getParameter(name);
070    
071                    return GetterUtil.getString(value, defaultValue);
072            }
073    
074            public Object getRequestAttribute(String name) {
075                    return _requestContext.getAttribute(RequestContext.Scope.REQUEST, name);
076            }
077    
078            public String getResolvedUri() {
079                    return _requestContext.getResolvedUri().toString();
080            }
081    
082            public Object getSessionAttribute(String name) {
083                    return _requestContext.getAttribute(RequestContext.Scope.SESSION, name);
084            }
085    
086            public String getTargetBasePath() {
087                    return _requestContext.getTargetBasePath();
088            }
089    
090            public void setContainerAttribute(String name, Object value) {
091                    _requestContext.setAttribute(
092                            RequestContext.Scope.CONTAINER, name, value);
093            }
094    
095            public void setRequestAttribute(String name, Object value) {
096                    _requestContext.setAttribute(RequestContext.Scope.REQUEST, name, value);
097            }
098    
099            public void setSessionAttribute(String name, Object value) {
100                    _requestContext.setAttribute(RequestContext.Scope.SESSION, name, value);
101            }
102    
103            private RequestContext _requestContext;
104    
105    }