1 18 19 package org.apache.roller.ui.rendering; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.roller.config.RollerConfig; 27 import org.apache.roller.pojos.Template; 28 29 30 38 public class RendererManager { 39 40 private static Log log = LogFactory.getLog(RendererManager.class); 41 42 private static Set rendererFactories = new HashSet (); 44 45 46 static { 47 String rollerFactories = RollerConfig.getProperty("rendering.rollerRendererFactories"); 49 String userFactories = RollerConfig.getProperty("rendering.userRendererFactories"); 50 51 if(userFactories != null && userFactories.trim().length() > 0) { 53 54 RendererFactory rendererFactory = null; 55 String [] uFactories = userFactories.split(","); 56 for(int i=0; i < uFactories.length; i++) { 57 try { 58 Class factoryClass = Class.forName(uFactories[i]); 59 rendererFactory = (RendererFactory) factoryClass.newInstance(); 60 rendererFactories.add(rendererFactory); 61 } catch(ClassCastException cce) { 62 log.error("It appears that your factory does not implement "+ 63 "the RendererFactory interface", cce); 64 } catch(Exception e) { 65 log.error("Unable to instantiate renderer factory ["+uFactories[i]+"]", e); 66 } 67 } 68 } 69 70 if(rollerFactories != null && rollerFactories.trim().length() > 0) { 72 73 RendererFactory rendererFactory = null; 74 String [] rFactories = rollerFactories.split(","); 75 for(int i=0; i < rFactories.length; i++) { 76 try { 77 Class factoryClass = Class.forName(rFactories[i]); 78 rendererFactory = (RendererFactory) factoryClass.newInstance(); 79 rendererFactories.add(rendererFactory); 80 } catch(ClassCastException cce) { 81 log.error("It appears that your factory does not implement "+ 82 "the RendererFactory interface", cce); 83 } catch(Exception e) { 84 log.error("Unable to instantiate renderer factory ["+rFactories[i]+"]", e); 85 } 86 } 87 } 88 89 if(rendererFactories.size() < 1) { 90 log.warn("Failed to load any renderer factories. "+ 92 "Rendering probably won't function as you expect."); 93 } 94 95 log.info("Renderer Manager Initialized."); 96 } 97 98 99 private RendererManager() {} 101 102 103 110 public static Renderer getRenderer(Template template) 111 throws RenderingException { 112 113 Renderer renderer = null; 114 115 Iterator factories = rendererFactories.iterator(); 118 while(factories.hasNext()) { 119 renderer = ((RendererFactory)factories.next()).getRenderer(template); 120 121 if(renderer != null) { 122 return renderer; 123 } 124 } 125 126 throw new RenderingException("No renderer found for template "+ 127 template.getId()+"!"); 128 } 129 130 } 131 | Popular Tags |