Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 package org.apache.sling.engine.impl;
 
 import java.util.List;
 import java.util.Map;
 
 
 import  org.osgi.service.http.HttpContext;
 import  org.osgi.service.useradmin.Authorization;
 
 public class SlingHttpServletRequestImpl extends HttpServletRequestWrapper implements
         SlingHttpServletRequest {
 
     private final RequestData requestData;
     private final String pathInfo;
     private String responseContentType;
 
     public SlingHttpServletRequestImpl(RequestData requestData,
             HttpServletRequest servletRequest) {
         super(servletRequest);
         this. = requestData;
 
         // prepare the pathInfo property
         String pathInfo = servletRequest.getServletPath();
         if (servletRequest.getPathInfo() != null) {
             pathInfo = pathInfo.concat(servletRequest.getPathInfo());
         }
         this. = pathInfo;
     }

    

Returns:
the requestData
 
     public final RequestData getRequestData() {
         return this.;
     }
 
     //---------- Adaptable interface
 
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
         return getRequestData().adaptTo(thistype);
     }
 
     //---------- SlingHttpServletRequest interface
 
         return this.getRequestData().getParameterSupport();
     }
 
     public Resource getResource() {
         final ContentData cd = getRequestData().getContentData();
         return (cd == null) ? null : cd.getResource();
     }
 
        return getRequestData().getResourceResolver();
    }
        return getRequestData().getRequestProgressTracker();
    }

    
Returns null if resource is null.
    public RequestDispatcher getRequestDispatcher(Resource resource) {
        return getRequestDispatcher(resourcenull);
    }

    
Returns null if resource is null.
            RequestDispatcherOptions options) {
        return (resource != null) ? new SlingRequestDispatcher(resourceoptions) : null;
    }

    
Returns null if path is null.
        return getRequestDispatcher(pathnull);
    }

    
Returns null if path is null.
            RequestDispatcherOptions options) {
        return (path != null) ? new SlingRequestDispatcher(pathoptions) : null;
    }

    

See also:
javax.servlet.ServletRequestWrapper.getParameter(java.lang.String)
    public String getParameter(String name) {
        return this.getParameterSupport().getParameter(name);
    }

    

See also:
javax.servlet.ServletRequestWrapper.getParameterMap()
    public Map<StringString[]> getParameterMap() {
        return this.getParameterSupport().getParameterMap();
    }

    

See also:
javax.servlet.ServletRequestWrapper.getParameterNames()
    public Enumeration<StringgetParameterNames() {
        return this.getParameterSupport().getParameterNames();
    }

    

See also:
javax.servlet.ServletRequestWrapper.getParameterValues(java.lang.String)
    public String[] getParameterValues(String name) {
        return this.getParameterSupport().getParameterValues(name);
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getRequestParameter(java.lang.String)
        return this.getParameterSupport().getRequestParameter(name);
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getRequestParameters(java.lang.String)
    public RequestParameter[] getRequestParameters(String name) {
        return this.getParameterSupport().getRequestParameters(name);
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getRequestParameterMap()
        return this.getParameterSupport().getRequestParameterMap();
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getRequestParameterList()
        return this.getParameterSupport().getRequestParameterList();
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getCookie(java.lang.String)
    public Cookie getCookie(String name) {
        Cookie[] cookies = getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.lengthi++) {
                if (cookies[i].getName().equals(name)) {
                    return cookies[i];
                }
            }
        }
        return null;
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getRequestPathInfo()
        final ContentData cd = getRequestData().getContentData();
        return (cd == null) ? null : cd.getRequestPathInfo();
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getResourceBundle(java.util.Locale)
    public ResourceBundle getResourceBundle(Locale locale) {
        return getResourceBundle(nulllocale);
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getResourceBundle(String, Locale)
    public ResourceBundle getResourceBundle(String baseNameLocale locale) {
        if (locale == null) {
            locale = getLocale();
        }
        return new NullResourceBundle(locale);
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getResponseContentType()
    public String getResponseContentType() {
        if( == null) {
            final String ext = getRequestPathInfo().getExtension();
             = .getMimeType("dummy." + ext);
        }
        return ;
    }

    

See also:
org.apache.sling.api.SlingHttpServletRequest.getResponseContentTypes()
        List<Stringresult = new ArrayList<String>();
        // TODO for now this returns a single value
        final String singleType = getResponseContentType();
        if(singleType!=null) {
            result.add(singleType);
        }
        return Collections.enumeration(result);
    }

    

See also:
javax.servlet.ServletRequestWrapper.getInputStream()
    public ServletInputStream getInputStream() throws IOException {
        return this.getRequestData().getInputStream();
    }

    

See also:
javax.servlet.ServletRequestWrapper.getReader()
            IOException {
        return this.getRequestData().getReader();
    }

    

See also:
javax.servlet.http.HttpServletRequestWrapper.getUserPrincipal()
    @Override
    public Principal getUserPrincipal() {
        Principal principal = getResourceResolver().adaptTo(Principal.class);
        if (principal != null) {
            return principal;
        }
        //fallback to the userid
        String remoteUser = getRemoteUser();
        return (remoteUser != null) ? new UserPrincipal(remoteUser) : null;
    }

    

See also:
javax.servlet.http.HttpServletRequestWrapper.isUserInRole(String)
    @Override
    public boolean isUserInRole(String role) {
        Object authorization = getAttribute(HttpContext.AUTHORIZATION);
        return (authorization instanceof Authorization)
                ? ((Authorization) authorization).hasRole(role)
                : false;
    }

    
Always returns the empty string since the actual servlet registered with the servlet container (the HttpService actually) is registered as if the servlet path is "/*".
    @Override
    public String getServletPath() {
        return "";
    }

    
Returns the part of the request URL without the leading servlet context path.
    @Override
    public String getPathInfo() {
        return ;
    }

    
A UserPrincipal ...
    private static class UserPrincipal implements PrincipalSerializable {
        private final String name;

        
Creates a UserPrincipal with the given name.

Parameters:
name the name of this principal
Throws:
IllegalArgumentException if name is null.
        public UserPrincipal(String namethrows IllegalArgumentException {
            if (name == null) {
                throw new IllegalArgumentException("name can not be null");
            }
            this. = name;
        }
        public String toString() {
            return ("UserPrincipal: " + );
        }
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj instanceof UserPrincipal) {
                UserPrincipal other = (UserPrincipalobj;
                return .equals(other.name);
            }
            return false;
        }
        public int hashCode() {
            return .hashCode();
        }
        //------------------------------------------------------------< Principal >
        
        public String getName() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X