//# 0 errors, 59 messages
//#
/*
    //#BootstrapFilter.java:1:1: class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
 * 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.core.filters;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.config.WebloggerConfig;


/**
 * Redirects clients to install page when app is not bootstrapped and install
 * type is "auto", otherwise does nothing.
 */
public class BootstrapFilter implements Filter {
    //#BootstrapFilter.java:42: method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()
    //#input(void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()): this
    //#output(void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()): this.context
    //#post(void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()): this.context == null
    private ServletContext context = null;
    //#BootstrapFilter.java:43: end of method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()
    private static Log log = LogFactory.getLog(BootstrapFilter.class);
    //#BootstrapFilter.java:44: method: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init
    //#BootstrapFilter.java:44: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
    //#    method: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/BootstrapFilter]
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.destroy()V
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.isInstallUrl(Ljava/lang/String;)Z
    //#output(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): log
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/BootstrapFilter] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.destroy()V == &destroy
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V == &doFilter
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V == &init
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): __Dispatch_Table.isInstallUrl(Ljava/lang/String;)Z == &isInstallUrl
    //#post(org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init): init'ed(log)
    //#BootstrapFilter.java:44: end of method: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init
    
    
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {
        
        HttpServletRequest request = (HttpServletRequest) req;
    //#BootstrapFilter.java:50: method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): "Entered "._tainted
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): "Exiting "._tainted
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): chain
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): log
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): req
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): res
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): this
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): this.context
    //#pre[2] (void doFilter(ServletRequest, ServletResponse, FilterChain)): log != null
    //#pre[3] (void doFilter(ServletRequest, ServletResponse, FilterChain)): req != null
    //#pre[1] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) chain != null
    //#pre[6] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) this.context != null
    //#presumption(void doFilter(ServletRequest, ServletResponse, FilterChain)): javax.servlet.ServletContext:getRequestDispatcher(...)@60 != null
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.String:startsWith
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.String:endsWith
    //#test_vector(void doFilter(ServletRequest, ServletResponse, FilterChain)): java.lang.String:equals(...)@55: {0}, {1}
    //#test_vector(void doFilter(ServletRequest, ServletResponse, FilterChain)): org.apache.roller.weblogger.business.WebloggerFactory:isBootstrapped(...)@55: {1}, {0}
        HttpServletResponse response = (HttpServletResponse) res;
        
        log.debug("Entered "+request.getRequestURI());
    //#BootstrapFilter.java:53: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
        
        if (!WebloggerFactory.isBootstrapped() &&
    //#BootstrapFilter.java:55: Warning: method not available
    //#    -- call on bool org.apache.roller.weblogger.business.WebloggerFactory:isBootstrapped()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: bool org.apache.roller.weblogger.business.WebloggerFactory:isBootstrapped()
    //#BootstrapFilter.java:55: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
                "auto".equals(WebloggerConfig.getProperty("installation.type")) &&
                !isInstallUrl(request.getServletPath())) {
            
            // we doing an install, so forward to installer
            RequestDispatcher rd = context.getRequestDispatcher(
                "/roller-ui/install/install.rol");
            rd.forward(req, res);
            
        } else {
            chain.doFilter(request, response);
        }
        
        log.debug("Exiting "+request.getRequestURI());
    //#BootstrapFilter.java:68: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    }
    //#BootstrapFilter.java:69: end of method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    
    
    private boolean isInstallUrl(String uri) {
        return (uri != null && (uri.startsWith("/roller-ui/install") ||
    //#BootstrapFilter.java:73: method: bool org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.isInstallUrl(String)
    //#input(bool isInstallUrl(String)): uri
    //#output(bool isInstallUrl(String)): return_value
    //#post(bool isInstallUrl(String)): init'ed(return_value)
    //#BootstrapFilter.java:73: end of method: bool org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.isInstallUrl(String)
                uri.endsWith(".js") || uri.endsWith(".css")));
    }
    
    
    public void init(FilterConfig filterConfig) throws ServletException {
        context = filterConfig.getServletContext();
    //#BootstrapFilter.java:79: method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.init(FilterConfig)
    //#input(void init(FilterConfig)): filterConfig
    //#input(void init(FilterConfig)): this
    //#output(void init(FilterConfig)): this.context
    //#pre[1] (void init(FilterConfig)): filterConfig != null
    //#post(void init(FilterConfig)): init'ed(this.context)
    }
    //#BootstrapFilter.java:80: end of method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.init(FilterConfig)
    
    public void destroy() {}    
    //#BootstrapFilter.java:82: method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.destroy()
    //#BootstrapFilter.java:82: end of method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter.destroy()
}
    //#BootstrapFilter.java:: end of class: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter
