roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r414421 - in /incubator/roller/branches/roller_3.0: src/org/apache/roller/ui/rendering/ src/org/apache/roller/ui/rendering/servlets/ src/org/apache/roller/ui/rendering/velocity/ web/WEB-INF/classes/
Date Thu, 15 Jun 2006 01:12:48 GMT
Author: agilliland
Date: Wed Jun 14 18:12:47 2006
New Revision: 414421

URL: http://svn.apache.org/viewvc?rev=414421&view=rev
Log:
adding in RendererManager class for governing the rendering system.

- added RendererManager class.
- modified servlets (page, feed, rsd) to use RendererManager.
- tweaked RendererFactory interface to not throw exception from getRenderer().
- renamed RollerRendererFactory to VelocityRendererFactory.
- added new static config properties for specifying renderer factories.



Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/VelocityRendererFactory.java
      - copied, changed from r414313, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RollerRendererFactory.java
Removed:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RollerRendererFactory.java
Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererFactory.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityWeblogPageRenderer.java
    incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererFactory.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererFactory.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererFactory.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererFactory.java
Wed Jun 14 18:12:47 2006
@@ -1,3 +1,20 @@
+/*
+ * 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.ui.rendering;
 
@@ -5,11 +22,17 @@
 /**
  * A factory for Renderer objects.
  *
- * Implementations of this interface are used to handle that actual lookup of
+ * Implementations of this interface are used to handle the actual lookup of
  * what Renderer object should be used to render a given resource.
  */
 public interface RendererFactory {
     
-    public Renderer getRenderer(String rendererType, String resourceId) throws Exception;
+    
+    /**
+     * Get a Renderer that will handle the given rendererType and resource.
+     * If a RendererFactory does not have a Renderer which can handle the
+     * content then it may return null.
+     */
+    public Renderer getRenderer(String rendererType, String resourceId);
     
 }

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java?rev=414421&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
Wed Jun 14 18:12:47 2006
@@ -0,0 +1,128 @@
+/*
+ * 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.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.config.RollerConfig;
+
+
+/**
+ * A governing class for Rollers rendering system.
+ * 
+ * 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);
+    
+    // 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 = RollerConfig.getProperty("rendering.rollerRendererFactories");
+        String userFactories = RollerConfig.getProperty("rendering.userRendererFactories");
+        
+        // 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++) {
+                try {
+                    Class factoryClass = Class.forName(uFactories[i]);
+                    rendererFactory = (RendererFactory) factoryClass.newInstance();
+                    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++) {
+                try {
+                    Class factoryClass = Class.forName(rFactories[i]);
+                    rendererFactory = (RendererFactory) factoryClass.newInstance();
+                    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.  "+
+                    "Rendering probably won't function as you expect.");
+        }
+        
+        log.info("Renderer Manager Initialized.");
+    }
+    
+    
+    // this class is non-instantiable
+    private 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(String rendererType, String resourceId) 
+            throws Exception {
+        
+        Renderer renderer = 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(rendererType, resourceId);
+            
+            if(renderer != null) {
+                return renderer;
+            }
+        }
+        
+        throw new Exception("No renderer found!");
+    }
+    
+}

Copied: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/VelocityRendererFactory.java
(from r414313, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RollerRendererFactory.java)
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/VelocityRendererFactory.java?p2=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/VelocityRendererFactory.java&p1=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RollerRendererFactory.java&r1=414313&r2=414421&rev=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RollerRendererFactory.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/VelocityRendererFactory.java
Wed Jun 14 18:12:47 2006
@@ -8,11 +8,10 @@
 /**
  * The default RendererFactory for Roller.
  */
-public class RollerRendererFactory implements RendererFactory {
+public class VelocityRendererFactory implements RendererFactory {
     
     
-    public Renderer getRenderer(String rendererType, String resourceId) 
-            throws Exception {
+    public Renderer getRenderer(String rendererType, String resourceId) {
         
         if("velocity".equals(rendererType)) {
             
@@ -25,7 +24,8 @@
             return new VelocityWeblogPageRenderer(resourceId);
         }
         
-        throw new Exception("No renderer found!");
+        // we don't want to handle this content
+        return null;
     }
     
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
Wed Jun 14 18:12:47 2006
@@ -52,8 +52,7 @@
 import org.apache.roller.ui.rendering.velocity.ContextLoader;
 import org.apache.roller.util.cache.CachedContent;
 import org.apache.roller.ui.rendering.Renderer;
-import org.apache.roller.ui.rendering.RendererFactory;
-import org.apache.roller.ui.rendering.RollerRendererFactory;
+import org.apache.roller.ui.rendering.RendererManager;
 import org.apache.roller.util.cache.Cache;
 import org.apache.roller.util.cache.CacheHandler;
 import org.apache.roller.util.cache.CacheManager;
@@ -76,8 +75,6 @@
     // roller config properties that apply to this cache
     private static final String CACHE_ID = "cache.feed";
     
-    private RendererFactory rendererFactory = null;
-    
     private Cache contentCache = null;
     
     // for metrics
@@ -112,8 +109,6 @@
         log.info(cacheProps);
         
         contentCache = CacheManager.constructCache(this, cacheProps);
-        
-        this.rendererFactory = new RollerRendererFactory();
     }
     
     
@@ -285,7 +280,7 @@
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = rendererFactory.getRenderer("velocity", pageId);
+            renderer = RendererManager.getRenderer("velocity", pageId);
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for page "+pageId, e);

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
Wed Jun 14 18:12:47 2006
@@ -48,13 +48,10 @@
 import org.apache.roller.ui.core.RollerContext;
 import org.apache.roller.ui.core.RollerRequest;
 import org.apache.roller.ui.core.WeblogPageRequest;
-import org.apache.roller.ui.core.util.ResponseContent;
 import org.apache.roller.ui.rendering.velocity.ContextLoader;
-import org.apache.roller.ui.rendering.velocity.WebappResourceLoader;
 import org.apache.roller.util.cache.CachedContent;
 import org.apache.roller.ui.rendering.Renderer;
-import org.apache.roller.ui.rendering.RendererFactory;
-import org.apache.roller.ui.rendering.RollerRendererFactory;
+import org.apache.roller.ui.rendering.RendererManager;
 import org.apache.roller.util.Utilities;
 import org.apache.roller.util.cache.Cache;
 import org.apache.roller.util.cache.CacheHandler;
@@ -76,8 +73,6 @@
     // roller config properties that apply to this cache
     private static final String CACHE_ID = "cache.weblogpage";
     
-    private RendererFactory rendererFactory = null;
-    
     private boolean excludeOwnerPages = false;
     private Cache contentCache = null;
     
@@ -117,8 +112,6 @@
         log.info(cacheProps);
         
         contentCache = CacheManager.constructCache(this, cacheProps);
-        
-        this.rendererFactory = new RollerRendererFactory();
     }
     
     
@@ -284,7 +277,7 @@
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = rendererFactory.getRenderer("velocityWeblogPage", page.getId());
+            renderer = RendererManager.getRenderer("velocityWeblogPage", page.getId());
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for page "+page.getId(), e);

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
Wed Jun 14 18:12:47 2006
@@ -35,8 +35,7 @@
 import org.apache.roller.ui.core.RollerContext;
 import org.apache.roller.ui.core.WeblogRequest;
 import org.apache.roller.ui.rendering.Renderer;
-import org.apache.roller.ui.rendering.RendererFactory;
-import org.apache.roller.ui.rendering.RollerRendererFactory;
+import org.apache.roller.ui.rendering.RendererManager;
 import org.apache.roller.util.cache.CachedContent;
 
 
@@ -53,8 +52,6 @@
     
     private static Log log = LogFactory.getLog(RSDServlet.class);
     
-    private RendererFactory rendererFactory = null;
-    
     
     /**
      * Init method for this servlet
@@ -64,8 +61,6 @@
         super.init(servletConfig);
         
         log.info("Initializing RSDServlet");
-        
-        this.rendererFactory = new RollerRendererFactory();
     }
     
     
@@ -131,7 +126,7 @@
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = rendererFactory.getRenderer("velocity", "templates/weblog/rsd.vm");
+            renderer = RendererManager.getRenderer("velocity", "templates/weblog/rsd.vm");
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for rsd template", e);

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
Wed Jun 14 18:12:47 2006
@@ -21,7 +21,7 @@
     private String resourceId = null;
     
     
-    public VelocityRenderer(String resource) throws Exception {
+    public VelocityRenderer(String resource) {
         
         this.resourceId = resource;
     }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityWeblogPageRenderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityWeblogPageRenderer.java?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityWeblogPageRenderer.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityWeblogPageRenderer.java
Wed Jun 14 18:12:47 2006
@@ -27,7 +27,7 @@
     private String resourceId = null;
     
     
-    public VelocityWeblogPageRenderer(String resource) throws Exception {
+    public VelocityWeblogPageRenderer(String resource) {
         
         this.resourceId = resource;
     }

Modified: incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties?rev=414421&r1=414420&r2=414421&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties Wed Jun 14
18:12:47 2006
@@ -74,6 +74,17 @@
 # is false, comments are not included in the index.
 search.index.comments=true
 
+
+#----------------------------------
+# Rendering system settings.
+
+# The set of default Roller renderer factories.
+rendering.rollerRendererFactories=org.apache.roller.ui.rendering.VelocityRendererFactory
+
+# The set of user defined renderer factories.  This is added to the list above.
+rendering.userRendererFactories=
+
+
 #----------------------------------
 # Cache settings.
 # Remember ... times are in seconds



Mime
View raw message