//# 0 errors, 54 messages
//#
/*
    //#RollerVelocity.java:1:1: class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
 * 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 java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.ui.core.RollerContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;


/**
 * Represents the VelocityEngine used by Roller.
 *
 * We construct our own instance of VelocityEngine, initialize it, and provide
 * access to the instance via the Singleton getInstance() method.
 */
public class RollerVelocity {
    //#RollerVelocity.java:39: method: void org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity()
    //#RollerVelocity.java:39: end of method: void org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity()
    
    public static final String VELOCITY_CONFIG = "/WEB-INF/velocity.properties";
    
    private static Log log = LogFactory.getLog(RollerVelocity.class);
    //#RollerVelocity.java:43: method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#RollerVelocity.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.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): ","._tainted
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): "Velocity engine props = "._tainted
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity]
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): log
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): new VelocityEngine(RollerVelocity__static_init#4) num objects
    //#output(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): velocityEngine
    //#new obj(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): new VelocityEngine(RollerVelocity__static_init#4)
    //#presumption(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): org.apache.commons.logging.LogFactory:getLog(...)@43 != null
    //#presumption(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): org.apache.roller.weblogger.ui.core.RollerContext:getServletContext(...)@55 != null
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): ","._tainted == 0
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): "Velocity engine props = "._tainted == 0
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): (soft) log != null
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): velocityEngine == &new VelocityEngine(RollerVelocity__static_init#4)
    //#post(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): new VelocityEngine(RollerVelocity__static_init#4) num objects == 1
    //#test_vector(org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init): org.apache.roller.weblogger.config.WebloggerConfig:getBooleanProperty(...)@61: {0}, {1}
    
    private static VelocityEngine velocityEngine = null;
    
    
    static {
        log.info("Initializing Velocity Rendering Engine");
    //#RollerVelocity.java:49: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)
        
        // initialize the Velocity engine
        Properties velocityProps = new Properties();
        
        try {
            InputStream instream =
    //#RollerVelocity.java:55: 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.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: ServletContext org.apache.roller.weblogger.ui.core.RollerContext:getServletContext()
                    RollerContext.getServletContext().getResourceAsStream(VELOCITY_CONFIG);
            
            velocityProps.load(instream);
            
            // need to dynamically add old macro libraries if they are enabled
            if(WebloggerConfig.getBooleanProperty("rendering.legacyModels.enabled")) {
    //#RollerVelocity.java:61: Warning: method not available
    //#    -- call on bool org.apache.roller.weblogger.config.WebloggerConfig:getBooleanProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: bool org.apache.roller.weblogger.config.WebloggerConfig:getBooleanProperty(String)
                String macroLibraries = (String) velocityProps.get("velocimacro.library");
                String oldLibraries = WebloggerConfig.getProperty("velocity.oldMacroLibraries");
    //#RollerVelocity.java:63: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
                
                // set the new value
                velocityProps.setProperty("velocimacro.library", oldLibraries+","+macroLibraries);
            }
            
            log.debug("Velocity engine props = "+velocityProps);
    //#RollerVelocity.java:69: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
            
            // construct the VelocityEngine
            velocityEngine = new VelocityEngine();
    //#RollerVelocity.java:72: Warning: method not available
    //#    -- call on void org.apache.velocity.app.VelocityEngine()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: void org.apache.velocity.app.VelocityEngine()
            
            // init velocity with our properties
            velocityEngine.init(velocityProps);
    //#RollerVelocity.java:75: Warning: method not available
    //#    -- call on void org.apache.velocity.app.VelocityEngine:init(Properties)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    //#    unanalyzed callee: void org.apache.velocity.app.VelocityEngine:init(Properties)
            
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    //#RollerVelocity.java:80: end of method: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity__static_init
    
    
    /**
     * Access to the VelocityEngine.
     *
     * This shouldn't ever be needed, but it's here just in case someone
     * really needs to do something special.
     */
    public static VelocityEngine getEngine() {
        return velocityEngine;
    //#RollerVelocity.java:90: method: VelocityEngine org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getEngine()
    //#input(VelocityEngine getEngine()): velocityEngine
    //#output(VelocityEngine getEngine()): return_value
    //#pre[1] (VelocityEngine getEngine()): init'ed(velocityEngine)
    //#post(VelocityEngine getEngine()): return_value == velocityEngine
    //#post(VelocityEngine getEngine()): init'ed(return_value)
    //#RollerVelocity.java:90: end of method: VelocityEngine org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getEngine()
    }
    
    
    /**
     * Convenience static method for looking up a template.
     */
    public static Template getTemplate(String name)
            throws ResourceNotFoundException, ParseErrorException, Exception {
        return velocityEngine.getTemplate(name);
    //#RollerVelocity.java:99: method: Template org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getTemplate(String)
    //#RollerVelocity.java:99: Warning: method not available
    //#    -- call on Template org.apache.velocity.app.VelocityEngine:getTemplate(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: Template getTemplate(String)
    //#    unanalyzed callee: Template org.apache.velocity.app.VelocityEngine:getTemplate(String)
    //#input(Template getTemplate(String)): name
    //#input(Template getTemplate(String)): velocityEngine
    //#output(Template getTemplate(String)): return_value
    //#pre[2] (Template getTemplate(String)): velocityEngine != null
    //#post(Template getTemplate(String)): init'ed(return_value)
    //#RollerVelocity.java:99: end of method: Template org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getTemplate(String)
    }
    
    
    /**
     * Convenience static method for looking up a template.
     */
    public static Template getTemplate(String name, String encoding)
            throws ResourceNotFoundException, ParseErrorException, Exception {
        return velocityEngine.getTemplate(name, encoding);
    //#RollerVelocity.java:108: method: Template org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getTemplate(String, String)
    //#RollerVelocity.java:108: Warning: method not available
    //#    -- call on Template org.apache.velocity.app.VelocityEngine:getTemplate(String, String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
    //#    method: Template getTemplate(String, String)
    //#    unanalyzed callee: Template org.apache.velocity.app.VelocityEngine:getTemplate(String, String)
    //#input(Template getTemplate(String, String)): encoding
    //#input(Template getTemplate(String, String)): name
    //#input(Template getTemplate(String, String)): velocityEngine
    //#output(Template getTemplate(String, String)): return_value
    //#pre[3] (Template getTemplate(String, String)): velocityEngine != null
    //#post(Template getTemplate(String, String)): init'ed(return_value)
    //#RollerVelocity.java:108: end of method: Template org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity.getTemplate(String, String)
    }
    
}
    //#RollerVelocity.java:: end of class: org.apache.roller.weblogger.ui.rendering.velocity.RollerVelocity
