//# 3 errors, 65 messages
//#
/*
    //#RendererManager.java:1:1: class: org.apache.roller.weblogger.ui.rendering.RendererManager
 * 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;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.Template;


/**
 * Returns Renderer for Template via configured RendererFactories. 
 * 
 * The purpose of the RendererManager is to provide a level of abstraction 
 * between classes that are rendering content and the implementations of the
 * rendering technology.  This allows us to provide easily pluggable rendering
 * implementations.
 */
public class RendererManager {
    
    private static Log log = LogFactory.getLog(RendererManager.class);
    //#RendererManager.java:40: method: org.apache.roller.weblogger.ui.rendering.RendererManager.org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#RendererManager.java:40: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#input(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): org/apache/roller/weblogger/ui/rendering/RendererFactory.__Descendant_Table[org/apache/roller/weblogger/ui/rendering/RendererFactory]
    //#input(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): org/apache/roller/weblogger/ui/rendering/RendererFactory.__Descendant_Table[others]
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): "Unable to instantiate renderer factory ["._tainted
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): "]"._tainted
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/RendererManager]
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): log
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): new HashSet(RendererManager__static_init#1) num objects
    //#output(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): rendererFactories
    //#new obj(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): new HashSet(RendererManager__static_init#1)
    //#presumption(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): org.apache.commons.logging.LogFactory:getLog(...)@40 != null
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): "Unable to instantiate renderer factory ["._tainted == 0
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): "]"._tainted == 0
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/RendererManager] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): (soft) log != null
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): rendererFactories == &new HashSet(RendererManager__static_init#1)
    //#post(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): new HashSet(RendererManager__static_init#1) num objects == 1
    //#test_vector(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): java.lang.String:length(...)@52: {0}, {1..4_294_967_295}
    //#test_vector(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): java.lang.String:length(...)@71: {0}, {1..4_294_967_295}
    //#test_vector(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): java.util.Set:size(...)@89: {1..4_294_967_295}, {-2_147_483_648..0}
    //#test_vector(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): org.apache.roller.weblogger.config.WebloggerConfig:getProperty(...)@48: Addr_Set{null}, Inverse{null}
    //#test_vector(org.apache.roller.weblogger.ui.rendering.RendererManager__static_init): org.apache.roller.weblogger.config.WebloggerConfig:getProperty(...)@49: Addr_Set{null}, Inverse{null}
    
    // a set of all renderer factories we are consulting
    private static Set rendererFactories = new HashSet();
    
    
    static {
        // lookup set of renderer factories we are going to use
        String rollerFactories = WebloggerConfig.getProperty("rendering.rollerRendererFactories");
    //#RendererManager.java:48: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    unanalyzed callee: String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
        String userFactories = WebloggerConfig.getProperty("rendering.userRendererFactories");
    //#RendererManager.java:49: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    unanalyzed callee: String org.apache.roller.weblogger.config.WebloggerConfig:getProperty(String)
        
        // instantiate user defined renderer factory classes
        if(userFactories != null && userFactories.trim().length() > 0) {
            
            RendererFactory rendererFactory = null;
            String[] uFactories = userFactories.split(",");
            for(int i=0; i < uFactories.length; i++) {
    //#RendererManager.java:56: ?use of default init
    //#    init'ed(uFactories.length)
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    basic block: bb_4
    //#    assertion: init'ed(uFactories.length)
    //#    VN: undefined
    //#    Expected: {-Inf..+Inf}
    //#    Bad: {Invalid}
    //#    Attribs:  Int  Bad only invalid
    //#RendererManager.java:56: Warning: test always goes same way
    //#    test predetermined because i == uFactories.length
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    from bb: bb_4
    //#    live edge: bb_4-->bb_10
    //#    tested vn: i - undefined
    //#    tested vn values: {0}
    //#RendererManager.java:56: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_9
                try {
                    Class factoryClass = Class.forName(uFactories[i]);
    //#RendererManager.java:58: Warning: dead code
    //#    dead code here because i == uFactories.length
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_5
    //#RendererManager.java:58: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_6
                    rendererFactory = (RendererFactory) factoryClass.newInstance();
    //#RendererManager.java:59: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_24
                    rendererFactories.add(rendererFactory);
                } catch(ClassCastException cce) {
                    log.error("It appears that your factory does not implement "+
                            "the RendererFactory interface", cce);
                } catch(Exception e) {
                    log.error("Unable to instantiate renderer factory ["+uFactories[i]+"]", e);
                }
            }
        }
        
        // instantiate roller standard renderer factory classes
        if(rollerFactories != null && rollerFactories.trim().length() > 0) {
            
            RendererFactory rendererFactory = null;
            String[] rFactories = rollerFactories.split(",");
            for(int i=0; i < rFactories.length; i++) {
    //#RendererManager.java:75: ?use of default init
    //#    init'ed(rFactories.length)
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    basic block: bb_13
    //#    assertion: init'ed(rFactories.length)
    //#    VN: undefined
    //#    Expected: {-Inf..+Inf}
    //#    Bad: {Invalid}
    //#    Attribs:  Int  Bad only invalid
    //#RendererManager.java:75: Warning: test always goes same way
    //#    test predetermined because i == rFactories.length
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    from bb: bb_13
    //#    live edge: bb_13-->bb_19
    //#    tested vn: i - undefined
    //#    tested vn values: {0}
    //#RendererManager.java:75: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_18
                try {
                    Class factoryClass = Class.forName(rFactories[i]);
    //#RendererManager.java:77: Warning: dead code
    //#    dead code here because i == rFactories.length
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_14
    //#RendererManager.java:77: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_15
                    rendererFactory = (RendererFactory) factoryClass.newInstance();
    //#RendererManager.java:78: Warning: dead code continues
    //#    dead code continues
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    dead bb: bb_22
                    rendererFactories.add(rendererFactory);
                } catch(ClassCastException cce) {
                    log.error("It appears that your factory does not implement "+
                            "the RendererFactory interface", cce);
                } catch(Exception e) {
                    log.error("Unable to instantiate renderer factory ["+rFactories[i]+"]", e);
                }
            }
        }
        
        if(rendererFactories.size() < 1) {
            // hmm ... failed to load any renderer factories?
            log.warn("Failed to load any renderer factories.  "+
    //#RendererManager.java:91: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:warn(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    unanalyzed callee: void org.apache.commons.logging.Log:warn(Object)
                    "Rendering probably won't function as you expect.");
        }
        
        log.info("Renderer Manager Initialized.");
    //#RendererManager.java:95: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)
    }
    //#RendererManager.java:96: end of method: org.apache.roller.weblogger.ui.rendering.RendererManager.org.apache.roller.weblogger.ui.rendering.RendererManager__static_init
    
    
    // this class is non-instantiable
    private RendererManager() {}
    //#RendererManager.java:100: method: void org.apache.roller.weblogger.ui.rendering.RendererManager.org.apache.roller.weblogger.ui.rendering.RendererManager()
    //#RendererManager.java:100: end of method: void org.apache.roller.weblogger.ui.rendering.RendererManager.org.apache.roller.weblogger.ui.rendering.RendererManager()
    
    
    /**
     * Find the appropriate Renderer for the given content.
     *
     * This method checks all renderer factories configured for the Roller
     * instance and tries to find a Renderer for the content.  If no Renderer
     * can be found then we throw an exception.
     */
    public static Renderer getRenderer(Template template) 
            throws RenderingException {
        
        Renderer renderer = null;
    //#RendererManager.java:113: method: Renderer org.apache.roller.weblogger.ui.rendering.RendererManager.getRenderer(Template)
    //#RendererManager.java:113: Warning: unused assignment
    //#    unused assignment into renderer
    //#    severity: SUPPRESSED
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: Renderer getRenderer(Template)
    //#    Attribs:  Uncertain
    //#input(Renderer getRenderer(Template)): "!"._tainted
    //#input(Renderer getRenderer(Template)): "No renderer found for template "._tainted
    //#input(Renderer getRenderer(Template)): org/apache/roller/weblogger/ui/rendering/RendererFactory.__Descendant_Table[org/apache/roller/weblogger/ui/rendering/RendererFactory]
    //#input(Renderer getRenderer(Template)): org/apache/roller/weblogger/ui/rendering/RendererFactory.__Descendant_Table[others]
    //#input(Renderer getRenderer(Template)): org/apache/roller/weblogger/ui/rendering/RendererFactory.__Dispatch_Table.getRenderer(Lorg/apache/roller/weblogger/pojos/Template;)Lorg/apache/roller/weblogger/ui/rendering/Renderer;
    //#input(Renderer getRenderer(Template)): rendererFactories
    //#input(Renderer getRenderer(Template)): template
    //#output(Renderer getRenderer(Template)): return_value
    //#pre[1] (Renderer getRenderer(Template)): rendererFactories != null
    //#presumption(Renderer getRenderer(Template)): java.util.Iterator:hasNext(...)@118 == 1
    //#presumption(Renderer getRenderer(Template)): java.util.Iterator:next(...).__Tag@119 == org/apache/roller/weblogger/ui/rendering/RendererFactory
    //#presumption(Renderer getRenderer(Template)): java.util.Iterator:next(...)@119 != null
    //#post(Renderer getRenderer(Template)): return_value != null
    //#unanalyzed(Renderer getRenderer(Template)): Effects-of-calling:org.apache.roller.weblogger.WebloggerException
    //#test_vector(Renderer getRenderer(Template)): getRenderer(...)@119: Addr_Set{null}, Inverse{null}
        
        // iterate over our renderer factories and see if one of them
        // wants to handle this content
        Iterator factories = rendererFactories.iterator();
        while(factories.hasNext()) {
            renderer = ((RendererFactory)factories.next()).getRenderer(template);
    //#RendererManager.java:119: Warning: method not available
    //#    -- call on Renderer getRenderer(Template)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: Renderer getRenderer(Template)
    //#    unanalyzed callee: Renderer getRenderer(Template)
            
            if(renderer != null) {
                return renderer;
            }
        }
        
        throw new RenderingException("No renderer found for template "+
    //#RendererManager.java:126: ?null dereference
    //#    template != null
    //#    severity: MEDIUM
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: Renderer getRenderer(Template)
    //#    basic block: bb_5
    //#    assertion: template != null
    //#    VN: template
    //#    Expected: Inverse{null} or Invalid
    //#    Bad: Addr_Set{null}
    //#    Attribs:  Ptr  null in Bad
    //#RendererManager.java:126: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.Template:getId()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.RendererManager
    //#    method: Renderer getRenderer(Template)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.Template:getId()
    //#RendererManager.java:126: end of method: Renderer org.apache.roller.weblogger.ui.rendering.RendererManager.getRenderer(Template)
                template.getId()+"!");
    }
    
}
    //#RendererManager.java:: end of class: org.apache.roller.weblogger.ui.rendering.RendererManager
