//# 0 errors, 69 messages
//#
/*
    //#WebappResourceLoader.java:1:1: class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
 * 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.velocity;

import java.io.InputStream;
import javax.servlet.ServletContext;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.ui.core.RollerContext;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.loader.ResourceLoader;


/**
 * Loads Velocity resources from the webapp.
 *
 * All resource urls begin from the root of the webapp.  If a resource path
 * is relative (does not begin with a /) then it is prefixed with the path
 * /WEB-INF/velocity/, which is where Roller keeps its velocity files.
 */
public class WebappResourceLoader extends ResourceLoader {
    //#WebappResourceLoader.java:39: method: void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()
    //#WebappResourceLoader.java:39: Warning: method not available
    //#    -- call on void org.apache.velocity.runtime.resource.loader.ResourceLoader()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()
    //#    unanalyzed callee: void org.apache.velocity.runtime.resource.loader.ResourceLoader()
    //#input(void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()): this
    //#output(void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()): this.mContext
    //#post(void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()): this.mContext == null
    
    private static Log log = LogFactory.getLog(WebappResourceLoader.class);
    //#WebappResourceLoader.java:41: method: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init
    //#WebappResourceLoader.java:41: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader]
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.getLastModified(Lorg/apache/velocity/runtime/resource/Resource;)J
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.getResourceStream(Ljava/lang/String;)Ljava/io/InputStream;
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.init(Lorg/apache/commons/collections/ExtendedProperties;)V
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.isSourceModified(Lorg/apache/velocity/runtime/resource/Resource;)Z
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): log
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.getLastModified(Lorg/apache/velocity/runtime/resource/Resource;)J == &getLastModified
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.getResourceStream(Ljava/lang/String;)Ljava/io/InputStream; == &getResourceStream
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.init(Lorg/apache/commons/collections/ExtendedProperties;)V == &init
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): __Dispatch_Table.isSourceModified(Lorg/apache/velocity/runtime/resource/Resource;)Z == &isSourceModified
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init): init'ed(log)
    //#WebappResourceLoader.java:41: end of method: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader__static_init
    
    private ServletContext mContext = null;
    //#WebappResourceLoader.java:43: end of method: void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader()
    
    
    /**
     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
     */
    public void init(ExtendedProperties config) {
        
        log.debug("WebappResourceLoader : initialization starting.");
    //#WebappResourceLoader.java:51: method: void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.init(ExtendedProperties)
    //#WebappResourceLoader.java:51: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void init(ExtendedProperties)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    //#input(void init(ExtendedProperties)): "Servlet Context = "._tainted
    //#input(void init(ExtendedProperties)): config
    //#input(void init(ExtendedProperties)): log
    //#input(void init(ExtendedProperties)): this
    //#input(void init(ExtendedProperties)): this.mContext
    //#output(void init(ExtendedProperties)): this.mContext
    //#pre[2] (void init(ExtendedProperties)): log != null
    //#pre[3] (void init(ExtendedProperties)): init'ed(this.mContext)
    //#presumption(void init(ExtendedProperties)): org.apache.roller.weblogger.ui.core.RollerContext:getServletContext(...)@54 != null
    //#post(void init(ExtendedProperties)): (soft) this.mContext != null
    //#test_vector(void init(ExtendedProperties)): this.mContext: Inverse{null}, Addr_Set{null}
        
        if (mContext == null) {
            mContext = RollerContext.getServletContext();
    //#WebappResourceLoader.java:54: Warning: method not available
    //#    -- call on ServletContext org.apache.roller.weblogger.ui.core.RollerContext:getServletContext()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void init(ExtendedProperties)
    //#    unanalyzed callee: ServletContext org.apache.roller.weblogger.ui.core.RollerContext:getServletContext()
            log.debug("Servlet Context = "+mContext.getRealPath("/WEB-INF/velocity/"));
    //#WebappResourceLoader.java:55: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void init(ExtendedProperties)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
        }
        
        log.debug(config);
    //#WebappResourceLoader.java:58: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void init(ExtendedProperties)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
        
        log.debug("WebappResourceLoader : initialization complete.");
    //#WebappResourceLoader.java:60: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: void init(ExtendedProperties)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    }
    //#WebappResourceLoader.java:61: end of method: void org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.init(ExtendedProperties)
    
    
    /**
     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getResourceStream(java.lang.String)
     */
    public InputStream getResourceStream(String name) 
            throws ResourceNotFoundException {
        
        log.debug("Looking up resource named ... "+name);
    //#WebappResourceLoader.java:70: method: InputStream org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.getResourceStream(String)
    //#WebappResourceLoader.java:70: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: InputStream getResourceStream(String)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
    //#input(InputStream getResourceStream(String)): ".WEB-INF.velocity."._tainted
    //#input(InputStream getResourceStream(String)): "Couldn't find "._tainted
    //#input(InputStream getResourceStream(String)): "Looking up resource named ... "._tainted
    //#input(InputStream getResourceStream(String)): log
    //#input(InputStream getResourceStream(String)): name
    //#input(InputStream getResourceStream(String)): name._tainted
    //#input(InputStream getResourceStream(String)): this
    //#input(InputStream getResourceStream(String)): this.mContext
    //#output(InputStream getResourceStream(String)): return_value
    //#pre[1] (InputStream getResourceStream(String)): log != null
    //#pre[2] (InputStream getResourceStream(String)): name != null
    //#pre[5] (InputStream getResourceStream(String)): this.mContext != null
    //#presumption(InputStream getResourceStream(String)): java.lang.String:length(...)@72 >= 1
    //#presumption(InputStream getResourceStream(String)): javax.servlet.ServletContext:getResourceAsStream(...)@82 != null
    //#post(InputStream getResourceStream(String)): (soft) return_value != null
    //#test_vector(InputStream getResourceStream(String)): java.lang.String:startsWith(...)@79: {1}, {0}
        
        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException("No template name provided");
        }
        
        InputStream result = null;
    //#WebappResourceLoader.java:76: Warning: unused assignment
    //#    unused assignment into result
    //#    severity: SUPPRESSED
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
    //#    method: InputStream getResourceStream(String)
    //#    Attribs:  Uncertain
        
        try {
            if(!name.startsWith("/"))
                name = "/WEB-INF/velocity/" + name;
            
            result = this.mContext.getResourceAsStream(name);
            
        } catch(Exception e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
        
        if(result == null) {
            throw new ResourceNotFoundException("Couldn't find "+name);
        }
        
        return result;
    //#WebappResourceLoader.java:92: end of method: InputStream org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.getResourceStream(String)
    }
    
    
    /**
     * Files loaded by this resource loader are considered static, so they are
     * never reloaded by velocity.
     *
     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#isSourceModified(org.apache.velocity.runtime.resource.Resource)
     */
    public boolean isSourceModified(Resource arg0) {
        return false;
    //#WebappResourceLoader.java:103: method: bool org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.isSourceModified(Resource)
    //#output(bool isSourceModified(Resource)): return_value
    //#post(bool isSourceModified(Resource)): return_value == 0
    //#WebappResourceLoader.java:103: end of method: bool org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.isSourceModified(Resource)
    }
    
    
    /**
     * Defaults to return 0.
     *
     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(org.apache.velocity.runtime.resource.Resource)
     */
    public long getLastModified(Resource arg0) {
        return 0;
    //#WebappResourceLoader.java:113: method: long org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.getLastModified(Resource)
    //#output(long getLastModified(Resource)): return_value
    //#post(long getLastModified(Resource)): return_value == 0
    //#WebappResourceLoader.java:113: end of method: long org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.getLastModified(Resource)
    }
    
}
    //#WebappResourceLoader.java:: end of class: org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader
