//# 0 errors, 93 messages
//#
/*
    //#ParsedRequest.java:1:1: class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  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.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.ui.rendering.util;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.User;


/**
 * An abstract class representing any request made to Roller that has been
 * parsed in order to extract relevant pieces of information from the url.
 *
 * NOTE: It is extremely important to mention that this class and all of its
 * subclasses are meant to be extremely light weight.  Meaning they should
 * avoid any time consuming operations at all costs, especially operations
 * which require a trip to the db.  Those operations should be used very, very
 * sparingly and should only be triggered when it's guaranteed that they are
 * needed.
 */
public abstract class ParsedRequest {
    
    private static Log log = LogFactory.getLog(ParsedRequest.class);
    //#ParsedRequest.java:43: method: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init
    //#ParsedRequest.java:43: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
    //#    method: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/util/ParsedRequest]
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.getAuthenticUser()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.getUser()Lorg/apache/roller/weblogger/pojos/User;
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.isLoggedIn()Z
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.setAuthenticUser(Ljava/lang/String;)V
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.setUser(Lorg/apache/roller/weblogger/pojos/User;)V
    //#output(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): log
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/util/ParsedRequest] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.getAuthenticUser()Ljava/lang/String; == &getAuthenticUser
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.getUser()Lorg/apache/roller/weblogger/pojos/User; == &getUser
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.isLoggedIn()Z == &isLoggedIn
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.setAuthenticUser(Ljava/lang/String;)V == &setAuthenticUser
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): __Dispatch_Table.setUser(Lorg/apache/roller/weblogger/pojos/User;)V == &setUser
    //#post(org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init): init'ed(log)
    //#ParsedRequest.java:43: end of method: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest__static_init
    
    HttpServletRequest request = null;
    
    // lightweight attributes
    private String authenticUser = null;
    
    // heavyweight attributes
    private User user = null;
    
    
    ParsedRequest() {}
    //#ParsedRequest.java:54: method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()
    //#input(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.authenticUser
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.request
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.user
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.authenticUser == null
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.request == null
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()): this.user == null
    //#ParsedRequest.java:54: end of method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest()
    
    
    /**
     * Parse the given http request and extract any information we can.
     *
     * This abstract version of the constructor gathers info likely to be
     * relevant to all requests to Roller.
     */
    public ParsedRequest(HttpServletRequest request) throws InvalidRequestException {
    //#ParsedRequest.java:63: method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)
    //#input(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): request
    //#input(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.authenticUser
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.request
    //#output(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.user
    //#pre[1] (void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): request != null
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): init'ed(this.authenticUser)
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.request == request
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.request != null
    //#post(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): this.user == null
    //#test_vector(void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getUserPrincipal(...)@69: Addr_Set{null}, Inverse{null}
        
        // keep a reference to the original request
        this.request = request;
        
        // login status
        java.security.Principal prince = request.getUserPrincipal();
        if(prince != null) {
            this.authenticUser = prince.getName();
        }
        
    }
    //#ParsedRequest.java:74: end of method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.org.apache.roller.weblogger.ui.rendering.util.ParsedRequest(HttpServletRequest)
    
    
    public String getAuthenticUser() {
        return this.authenticUser;
    //#ParsedRequest.java:78: method: String org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.getAuthenticUser()
    //#input(String getAuthenticUser()): this
    //#input(String getAuthenticUser()): this.authenticUser
    //#output(String getAuthenticUser()): return_value
    //#pre[2] (String getAuthenticUser()): init'ed(this.authenticUser)
    //#post(String getAuthenticUser()): return_value == this.authenticUser
    //#post(String getAuthenticUser()): init'ed(return_value)
    //#ParsedRequest.java:78: end of method: String org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.getAuthenticUser()
    }
    
    
    public void setAuthenticUser(String authenticUser) {
        this.authenticUser = authenticUser;
    //#ParsedRequest.java:83: method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.setAuthenticUser(String)
    //#input(void setAuthenticUser(String)): authenticUser
    //#input(void setAuthenticUser(String)): this
    //#output(void setAuthenticUser(String)): this.authenticUser
    //#post(void setAuthenticUser(String)): this.authenticUser == authenticUser
    //#post(void setAuthenticUser(String)): init'ed(this.authenticUser)
    }
    //#ParsedRequest.java:84: end of method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.setAuthenticUser(String)
    
    
    public User getUser() {
        
        if(user == null && authenticUser != null) {
    //#ParsedRequest.java:89: method: User org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.getUser()
    //#input(User getUser()): "Error looking up user "._tainted
    //#input(User getUser()): log
    //#input(User getUser()): this
    //#input(User getUser()): this.authenticUser
    //#input(User getUser()): this.authenticUser._tainted
    //#input(User getUser()): this.user
    //#output(User getUser()): return_value
    //#output(User getUser()): this.user
    //#pre[5] (User getUser()): init'ed(this.user)
    //#pre[4] (User getUser()): (soft) log != null
    //#pre[8] (User getUser()): (soft) init'ed(this.authenticUser)
    //#presumption(User getUser()): org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@91 != null
    //#presumption(User getUser()): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@91 != null
    //#post(User getUser()): init'ed(return_value)
    //#post(User getUser()): this.user == return_value
    //#test_vector(User getUser()): this.user: Inverse{null}, Addr_Set{null}
    //#test_vector(User getUser()): this.authenticUser: Addr_Set{null}, Inverse{null}
            try {
                UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
    //#ParsedRequest.java:91: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
    //#    method: User getUser()
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#ParsedRequest.java:91: Warning: method not available
    //#    -- call on UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
    //#    method: User getUser()
    //#    unanalyzed callee: UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
                user = umgr.getUserByUserName(authenticUser);
    //#ParsedRequest.java:92: Warning: method not available
    //#    -- call on User org.apache.roller.weblogger.business.UserManager:getUserByUserName(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
    //#    method: User getUser()
    //#    unanalyzed callee: User org.apache.roller.weblogger.business.UserManager:getUserByUserName(String)
            } catch (WebloggerException ex) {
                log.error("Error looking up user "+authenticUser, ex);
    //#ParsedRequest.java:94: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
    //#    method: User getUser()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
            }
        }
        
        return user;
    //#ParsedRequest.java:98: end of method: User org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.getUser()
    }
    
    
    public void setUser(User u) {
        this.user = u;
    //#ParsedRequest.java:103: method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.setUser(User)
    //#input(void setUser(User)): this
    //#input(void setUser(User)): u
    //#output(void setUser(User)): this.user
    //#post(void setUser(User)): this.user == u
    //#post(void setUser(User)): init'ed(this.user)
    }
    //#ParsedRequest.java:104: end of method: void org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.setUser(User)
    
    
    public boolean isLoggedIn() {
        return (this.authenticUser != null);
    //#ParsedRequest.java:108: method: bool org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.isLoggedIn()
    //#input(bool isLoggedIn()): this
    //#input(bool isLoggedIn()): this.authenticUser
    //#output(bool isLoggedIn()): return_value
    //#pre[2] (bool isLoggedIn()): init'ed(this.authenticUser)
    //#post(bool isLoggedIn()): init'ed(return_value)
    //#ParsedRequest.java:108: end of method: bool org.apache.roller.weblogger.ui.rendering.util.ParsedRequest.isLoggedIn()
    }
    
}
    //#ParsedRequest.java:: end of class: org.apache.roller.weblogger.ui.rendering.util.ParsedRequest
