You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2007/02/08 23:58:25 UTC

svn commit: r505078 [3/6] - in /incubator/roller/trunk: apps/planet/ apps/planet/nbproject/ apps/planet/src/java/org/apache/roller/planet/business/ apps/planet/src/java/org/apache/roller/planet/business/hibernate/ apps/planet/src/java/org/apache/roller...

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/Renderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/Renderer.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/Renderer.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/Renderer.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.planet.ui.rendering;
+
+import java.io.Writer;
+import java.util.Map;
+
+
+/**
+ * Interface representing a content renderer in Roller.
+ */
+public interface Renderer {
+    
+    
+    /**
+     * Render the content for this Renderer to the given Writer using
+     * the given set of model objects.
+     *
+     * Throws an exception if there is a problem during rendering.
+     */
+    public void render(Map model, Writer writer) throws RenderingException;
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererFactory.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererFactory.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererFactory.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererFactory.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.planet.ui.rendering;
+
+import org.apache.roller.planet.pojos.Template;
+
+
+/**
+ * A factory for Renderer objects.
+ *
+ * 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 {
+    
+    
+    /**
+     * Get a Renderer that will handle the given Template.
+     * If a RendererFactory does not have a Renderer which can handle the
+     * content then it may return null.
+     *
+     * This method purposely does not throw exceptions because the rendering
+     * system as a whole does not care if a given factory generates an exception
+     * while trying to find a renderer.  It is up to the factory itself to
+     * report any relevant exceptions itself.
+     */
+    public Renderer getRenderer(Template template);
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererManager.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererManager.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RendererManager.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,133 @@
+/*
+ * 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.planet.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.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.Template;
+import org.apache.roller.planet.ui.rendering.Renderer;
+import org.apache.roller.planet.ui.rendering.RendererFactory;
+import org.apache.roller.planet.ui.rendering.RenderingException;
+
+
+/**
+ * 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 = PlanetConfig.getProperty("rendering.rollerRendererFactories");
+        String userFactories = PlanetConfig.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(Template template) 
+            throws RenderingException {
+        
+        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(template);
+            
+            if(renderer != null) {
+                return renderer;
+            }
+        }
+        
+        throw new RenderingException("No renderer found for template "+
+                template.getId()+"!");
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RenderingException.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RenderingException.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RenderingException.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RenderingException.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.planet.ui.rendering;
+
+import org.apache.roller.RollerException;
+
+
+/**
+ * A generic Roller rendering exception.
+ */
+public class RenderingException extends RollerException {
+    
+    public RenderingException(String s) {
+        super(s);
+    }
+    
+    public RenderingException(String s, Throwable t) {
+        super(s, t);
+    }
+    
+    public RenderingException(Throwable t) {
+        super(t);
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RequestMapper.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RequestMapper.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RequestMapper.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/RequestMapper.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,26 @@
+
+package org.apache.roller.planet.ui.rendering;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * Interface representing an object that maps requests.
+ */
+public interface RequestMapper {
+    
+    /**
+     * Handle an incoming request.
+     *
+     * RequestMappers are not required to handle all requests and are instead
+     * encouraged to inspect the request and only take action when it
+     * wants to.  If action is taken then the RequestMapper should return a 
+     * boolean "true" value indicating that no further action is required.
+     */
+    public boolean handleRequest(HttpServletRequest req, HttpServletResponse res)
+        throws ServletException, IOException;
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/filters/RequestMappingFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/filters/RequestMappingFilter.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/filters/RequestMappingFilter.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/filters/RequestMappingFilter.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,147 @@
+/*
+ * 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.planet.ui.rendering.filters;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.ui.rendering.RequestMapper;
+
+
+/**
+ * Provides generalized request mapping capablilites.
+ *
+ * Incoming requests can be inspected by a series of RequestMappers and can
+ * potentially be re-routed to different places within the application.
+ */
+public class RequestMappingFilter implements Filter {
+    
+    private static Log log = LogFactory.getLog(RequestMappingFilter.class);
+    
+    // list of RequestMappers that want to inspect the request
+    private final List requestMappers = new ArrayList();
+    
+    
+    public void init(FilterConfig filterConfig) {
+        
+        // lookup set of request mappers we are going to use
+        String rollerMappers = PlanetConfig.getProperty("rendering.rollerRequestMappers");
+        String userMappers = PlanetConfig.getProperty("rendering.userRequestMappers");
+        
+        // instantiate user defined request mapper classes
+        if(userMappers != null && userMappers.trim().length() > 0) {
+            
+            RequestMapper requestMapper = null;
+            String[] uMappers = userMappers.split(",");
+            for(int i=0; i < uMappers.length; i++) {
+                try {
+                    Class mapperClass = Class.forName(uMappers[i]);
+                    requestMapper = (RequestMapper) mapperClass.newInstance();
+                    requestMappers.add(requestMapper);
+                } catch(ClassCastException cce) {
+                    log.error("It appears that your mapper does not implement "+
+                            "the RequestMapper interface", cce);
+                } catch(Exception e) {
+                    log.error("Unable to instantiate request mapper ["+uMappers[i]+"]", e);
+                }
+            }
+        }
+        
+        // instantiate roller standard request mapper classes
+        if(rollerMappers != null && rollerMappers.trim().length() > 0) {
+            
+            RequestMapper requestMapper = null;
+            String[] rMappers = rollerMappers.split(",");
+            for(int i=0; i < rMappers.length; i++) {
+                try {
+                    Class mapperClass = Class.forName(rMappers[i]);
+                    requestMapper = (RequestMapper) mapperClass.newInstance();
+                    requestMappers.add(requestMapper);
+                } catch(ClassCastException cce) {
+                    log.error("It appears that your mapper does not implement "+
+                            "the RequestMapper interface", cce);
+                } catch(Exception e) {
+                    log.error("Unable to instantiate request mapper ["+rMappers[i]+"]", e);
+                }
+            }
+        }
+        
+        if(requestMappers.size() < 1) {
+            // hmm ... failed to load any request mappers?
+            log.warn("Failed to load any request mappers.  "+
+                    "Weblog urls probably won't function as you expect.");
+        }
+        
+        log.info("Request mapping filter initialized, "+requestMappers.size()+
+                " mappers configured.");
+    }
+    
+    
+    /**
+     * Inspect incoming urls and see if they should be routed.
+     */
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+            throws IOException, ServletException {
+        
+        HttpServletRequest request = (HttpServletRequest) req;
+        HttpServletResponse response = (HttpServletResponse) res;
+        
+        log.debug("entering");
+        
+        // give each mapper a chance to handle the request
+        RequestMapper mapper = null;
+        Iterator mappersIT = this.requestMappers.iterator();
+        while(mappersIT.hasNext()) {
+            mapper = (RequestMapper) mappersIT.next();
+            
+            log.debug("trying mapper "+mapper.getClass().getName());
+            
+            boolean wasHandled = mapper.handleRequest(request, response);
+            if(wasHandled) {
+                // if mapper has handled the request then we are done
+                log.debug("request handled by "+mapper.getClass().getName());
+                log.debug("exiting");
+                return;
+            }
+        }
+        
+        log.debug("request not mapped");
+        
+        // nobody handled the request, so let it continue as usual
+        chain.doFilter(request, response);
+        
+        log.debug("exiting");
+    }
+    
+    
+    public void destroy() {}
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/FeedModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/FeedModel.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/FeedModel.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/FeedModel.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,134 @@
+/*
+ * 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.planet.ui.rendering.model; 
+
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.pojos.PlanetData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.ui.rendering.pagers.Pager;
+import org.apache.roller.planet.ui.rendering.pagers.PlanetEntriesPager;
+import org.apache.roller.planet.ui.rendering.util.PlanetGroupFeedRequest;
+import org.apache.roller.planet.ui.rendering.util.PlanetRequest;
+import org.apache.roller.planet.util.URLUtilities;
+
+
+/**
+ * Model which provides information needed to render a planet feed.
+ */
+public class FeedModel implements Model {
+    
+    private static Log log = LogFactory.getLog(FeedModel.class);
+    
+    private PlanetGroupFeedRequest feedRequest = null;
+    private Map requestParameters = null;
+    private PlanetData planet = null;
+    private PlanetGroupData group = null;
+    
+    
+    /** 
+     * Creates an un-initialized new instance, Roller calls init() to complete
+     * construction. 
+     */
+    public FeedModel() {}
+    
+    
+    /** 
+     * Template context name to be used for model.
+     */
+    public String getModelName() {
+        return "model";
+    }
+    
+    
+    /** 
+     * Init page model based on request. 
+     */
+    public void init(Map initData) throws RollerException {
+        
+        // we expect the init data to contain a weblogRequest object
+        PlanetRequest planetRequest = (PlanetRequest) initData.get("planetRequest");
+        if(planetRequest == null) {
+            throw new RollerException("expected planetRequest from init data");
+        }
+        
+        // PageModel only works on page requests, so cast planetRequest
+        // into a PlanetRequest and if it fails then throw exception
+        if(planetRequest instanceof PlanetGroupFeedRequest) {
+            this.feedRequest = (PlanetGroupFeedRequest) planetRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogPageRequest."+
+                    "  PageModel only supports page requests.");
+        }
+        
+        // custom request parameters
+        this.requestParameters = (Map)initData.get("requestParameters");
+        
+        // extract planet object
+        planet = feedRequest.getPlanet();
+        
+        // extract weblog object
+        group = feedRequest.getGroup();
+    }
+    
+    
+    /**
+     * Get planet being displayed.
+     */
+    public PlanetData getPlanet() {
+        return planet;
+    }
+    
+    
+    /**
+     * Get group being displayed.
+     */
+    public PlanetGroupData getGroup() {
+        return group;
+    }
+    
+    
+    public Pager getPager() {
+        
+        String pagerUrl = URLUtilities.getPlanetGroupURL(planet.getHandle(), feedRequest.getGroupHandle());
+        
+        return new PlanetEntriesPager(
+                null,
+                feedRequest.getGroup(),
+                pagerUrl,
+                0,
+                0,
+                30);
+    }
+    
+    
+    /**
+     * Get request parameter by name.
+     */
+    public String getRequestParameter(String paramName) {
+        String[] values = (String[])requestParameters.get(paramName);
+        if (values != null && values.length > 0) {
+            return values[0];
+        }
+        return null;
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/Model.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/Model.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/Model.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/Model.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.planet.ui.rendering.model;
+
+import java.util.Map;
+import org.apache.roller.RollerException;
+
+
+/**
+ * Represents a set of functionality to be used at rendering.
+ */
+public interface Model {
+    
+    /**
+     * Name to be used when referring to this model.
+     */
+    public String getModelName();
+    
+    
+    /**
+     * Initialize.
+     */
+    public void init(Map params) throws RollerException;
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/ModelLoader.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/ModelLoader.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/ModelLoader.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/ModelLoader.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.planet.ui.rendering.model;
+
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.util.Utilities;
+
+
+/**
+ * Helps with model loading process.
+ */
+public class ModelLoader {
+    
+    private static Log log = LogFactory.getLog(ModelLoader.class);
+    
+    
+    /**
+     * Convenience method to load a comma-separated list of page models.
+     *
+     * Optionally fails if any exceptions are thrown when initializing
+     * the Model instances.
+     */
+    public static void loadModels(String modelsString, Map model, 
+                                   Map initData, boolean fail) 
+            throws RollerException {
+        
+        String[] models = Utilities.stringToStringArray(modelsString, ",");
+        for(int i=0; i < models.length; i++) {
+            try {
+                Class modelClass = Class.forName(models[i]);
+                Model pageModel = (Model) modelClass.newInstance();
+                pageModel.init(initData);
+                model.put(pageModel.getModelName(), pageModel);
+            } catch (RollerException re) {
+                if(fail) {
+                    throw re;
+                } else {
+                    log.warn("Error initializing model: " + models[i]);
+                }
+            } catch (ClassNotFoundException cnfe) {
+                if(fail) {
+                    throw new RollerException("Error finding model: " + models[i], cnfe);
+                } else {
+                    log.warn("Error finding model: " + models[i]);
+                }
+            } catch (InstantiationException ie) {
+                if(fail) {
+                    throw new RollerException("Error insantiating model: " + models[i], ie);
+                } else {
+                    log.warn("Error insantiating model: " + models[i]);
+                }
+            } catch (IllegalAccessException iae) {
+                if(fail) {
+                    throw new RollerException("Error accessing model: " + models[i], iae);
+                } else {
+                    log.warn("Error accessing model: " + models[i]);
+                }
+            }
+        }
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PageModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PageModel.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PageModel.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PageModel.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,134 @@
+/*
+ * 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.planet.ui.rendering.model; 
+
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.pojos.PlanetData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.ui.rendering.pagers.Pager;
+import org.apache.roller.planet.ui.rendering.pagers.PlanetEntriesPager;
+import org.apache.roller.planet.ui.rendering.util.PlanetGroupPageRequest;
+import org.apache.roller.planet.ui.rendering.util.PlanetRequest;
+import org.apache.roller.planet.util.URLUtilities;
+
+
+/**
+ * Model which provides information needed to render a weblog page.
+ */
+public class PageModel implements Model {
+    
+    private static Log log = LogFactory.getLog(PageModel.class);
+    
+    private PlanetGroupPageRequest pageRequest = null;
+    private Map requestParameters = null;
+    private PlanetData planet = null;
+    private PlanetGroupData group = null;
+    
+    
+    /** 
+     * Creates an un-initialized new instance, Roller calls init() to complete
+     * construction. 
+     */
+    public PageModel() {}
+    
+    
+    /** 
+     * Template context name to be used for model.
+     */
+    public String getModelName() {
+        return "model";
+    }
+    
+    
+    /** 
+     * Init page model based on request. 
+     */
+    public void init(Map initData) throws RollerException {
+        
+        // we expect the init data to contain a weblogRequest object
+        PlanetRequest planetRequest = (PlanetRequest) initData.get("planetRequest");
+        if(planetRequest == null) {
+            throw new RollerException("expected planetRequest from init data");
+        }
+        
+        // PageModel only works on page requests, so cast planetRequest
+        // into a PlanetRequest and if it fails then throw exception
+        if(planetRequest instanceof PlanetGroupPageRequest) {
+            this.pageRequest = (PlanetGroupPageRequest) planetRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogPageRequest."+
+                    "  PageModel only supports page requests.");
+        }
+        
+        // custom request parameters
+        this.requestParameters = (Map)initData.get("requestParameters");
+        
+        // extract planet object
+        planet = pageRequest.getPlanet();
+        
+        // extract group object
+        group = pageRequest.getGroup();
+    }
+    
+    
+    /**
+     * Get planet being displayed.
+     */
+    public PlanetData getPlanet() {
+        return planet;
+    }
+    
+    
+    /**
+     * Get group being displayed.
+     */
+    public PlanetGroupData getGroup() {
+        return group;
+    }
+    
+    
+    public Pager getPager() {
+        
+        String pagerUrl = URLUtilities.getPlanetGroupURL(planet.getHandle(), pageRequest.getGroupHandle());
+        
+        return new PlanetEntriesPager(
+                null,
+                pageRequest.getGroup(),
+                pagerUrl,
+                0,
+                0,
+                30);
+    }
+    
+    
+    /**
+     * Get request parameter by name.
+     */
+    public String getRequestParameter(String paramName) {
+        String[] values = (String[])requestParameters.get(paramName);
+        if (values != null && values.length > 0) {
+            return values[0];
+        }
+        return null;
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PlanetGroupModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PlanetGroupModel.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PlanetGroupModel.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/PlanetGroupModel.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,117 @@
+/*
+ * 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.planet.ui.rendering.model; 
+
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.pojos.PlanetData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.ui.rendering.util.PlanetGroupRequest;
+import org.apache.roller.planet.ui.rendering.util.PlanetRequest;
+
+
+/**
+ * Model which provides information needed to render a weblog page.
+ */
+public class PlanetGroupModel implements Model {
+    
+    private static Log log = LogFactory.getLog(PlanetGroupModel.class);
+    
+    private PlanetGroupRequest planetGroupRequest = null;
+    private Map requestParameters = null;
+    private PlanetData planet = null;
+    private PlanetGroupData group = null;
+    
+    
+    /** 
+     * Creates an un-initialized new instance, Roller calls init() to complete
+     * construction. 
+     */
+    public PlanetGroupModel() {}
+    
+    
+    /** 
+     * Template context name to be used for model.
+     */
+    public String getModelName() {
+        return "model";
+    }
+    
+    
+    /** 
+     * Init page model based on request. 
+     */
+    public void init(Map initData) throws RollerException {
+        
+        // we expect the init data to contain a weblogRequest object
+        PlanetRequest planetRequest = (PlanetRequest) initData.get("planetRequest");
+        if(planetRequest == null) {
+            throw new RollerException("expected planetRequest from init data");
+        }
+        
+        // PageModel only works on page requests, so cast planetRequest
+        // into a PlanetRequest and if it fails then throw exception
+        if(planetRequest instanceof PlanetGroupRequest) {
+            this.planetGroupRequest = (PlanetGroupRequest) planetRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogPageRequest."+
+                    "  PageModel only supports page requests.");
+        }
+        
+        // custom request parameters
+        this.requestParameters = (Map)initData.get("requestParameters");
+        
+        // extract planet object
+        planet = planetGroupRequest.getPlanet();
+        
+        // extract group object
+        group = planetGroupRequest.getGroup();
+    }
+    
+    
+    /**
+     * Get planet being displayed.
+     */
+    public PlanetData getPlanet() {
+        return planet;
+    }
+    
+    
+    /**
+     * Get group being displayed.
+     */
+    public PlanetGroupData getGroup() {
+        return group;
+    }
+    
+    
+    /**
+     * Get request parameter by name.
+     */
+    public String getRequestParameter(String paramName) {
+        String[] values = (String[])requestParameters.get(paramName);
+        if (values != null && values.length > 0) {
+            return values[0];
+        }
+        return null;
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/UtilitiesModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/UtilitiesModel.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/UtilitiesModel.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/model/UtilitiesModel.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,487 @@
+/*
+ * 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.planet.ui.rendering.model;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.util.DateUtil;
+import org.apache.roller.planet.util.RegexUtil;
+import org.apache.roller.planet.util.Utilities;
+
+/**
+ * Model which provides access to a set of general utilities.
+ */
+public class UtilitiesModel implements Model {
+    
+    private static Log log = LogFactory.getLog(UtilitiesModel.class); 
+    
+    private static Pattern mLinkPattern =
+            Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);    
+    private static final Pattern OPENING_B_TAG_PATTERN = 
+            Pattern.compile("&lt;b&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_B_TAG_PATTERN = 
+            Pattern.compile("&lt;/b&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_I_TAG_PATTERN = 
+            Pattern.compile("&lt;i&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_I_TAG_PATTERN = 
+            Pattern.compile("&lt;/i&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_BLOCKQUOTE_TAG_PATTERN = 
+            Pattern.compile("&lt;blockquote&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_BLOCKQUOTE_TAG_PATTERN = 
+            Pattern.compile("&lt;/blockquote&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern BR_TAG_PATTERN = 
+            Pattern.compile("&lt;br */*&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_P_TAG_PATTERN = 
+            Pattern.compile("&lt;p&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_P_TAG_PATTERN = 
+            Pattern.compile("&lt;/p&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_PRE_TAG_PATTERN = 
+            Pattern.compile("&lt;pre&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_PRE_TAG_PATTERN = 
+            Pattern.compile("&lt;/pre&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_UL_TAG_PATTERN = 
+            Pattern.compile("&lt;ul&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_UL_TAG_PATTERN = 
+            Pattern.compile("&lt;/ul&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_OL_TAG_PATTERN = 
+            Pattern.compile("&lt;ol&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_OL_TAG_PATTERN = 
+            Pattern.compile("&lt;/ol&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_LI_TAG_PATTERN = 
+            Pattern.compile("&lt;li&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_LI_TAG_PATTERN = 
+            Pattern.compile("&lt;/li&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern CLOSING_A_TAG_PATTERN = 
+            Pattern.compile("&lt;/a&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern OPENING_A_TAG_PATTERN = 
+            Pattern.compile("&lt;a href=.*?&gt;", Pattern.CASE_INSENSITIVE);
+    private static final Pattern QUOTE_PATTERN = 
+            Pattern.compile("&quot;", Pattern.CASE_INSENSITIVE);
+    
+    private HttpServletRequest request = null;
+    private TimeZone tz = null;
+    
+    
+    /** Template context name to be used for model */
+    public String getModelName() {
+        return "utils";
+    }
+    
+    
+    /** Init page model based on request */
+    public void init(Map initData) throws RollerException {
+        
+        // extract request object
+        this.request = (HttpServletRequest) initData.get("request");
+    }
+    
+        
+    //-------------------------------------------------------------- Date utils
+    /**
+     * Return date for current time.
+     */
+    public static Date getNow() {
+        return new Date();
+    }
+    
+    /**
+     * Format date using SimpleDateFormat format string.
+     */
+    public String formatDate(Date d, String fmt) {
+        if(d == null || fmt == null)
+            return fmt;
+        
+        SimpleDateFormat format = new SimpleDateFormat(fmt);
+        if (tz != null) {
+            format.setTimeZone(tz);
+        }
+        return format.format(d);
+    }
+    
+    /**
+     * Format date using SimpleDateFormat format string.
+     */
+    public static String formatDate(Date d, String fmt, TimeZone tzOverride) {
+        if(d == null || fmt == null)
+            return fmt;
+        
+        SimpleDateFormat format = new SimpleDateFormat(fmt);
+        format.setTimeZone(tzOverride);
+        return format.format(d);
+    }
+    
+    /**
+     * Format date in ISO-8601 format.
+     */
+    public static String formatIso8601Date(Date d) {
+        return DateUtil.formatIso8601(d);
+    }
+    
+    /**
+     * Format date in ISO-8601 format.
+     */
+    public static String formatIso8601Day(Date d) {
+        return DateUtil.formatIso8601Day(d);
+    }
+    
+    /**
+     * Return a date in RFC-822 format.
+     */
+    public static String formatRfc822Date(Date date) {
+        return DateUtil.formatRfc822(date);
+    }
+    
+    /**
+     * Return a date in RFC-822 format.
+     */
+    public static String format8charsDate(Date date) {
+        return DateUtil.format8chars(date);
+    }
+
+    //------------------------------------------------------------ String utils
+    
+    public static boolean isEmpty(String str) {
+        if (str == null) return true;
+        return "".equals(str.trim());
+    }
+    
+    public static boolean isNotEmpty(String str) {
+        return !isEmpty(str);
+    }
+    
+    public static String[] split(String str1, String str2) {
+        return StringUtils.split(str1, str2);
+    }
+    
+    
+    public static boolean equals(String str1, String str2) {
+        return StringUtils.equals(str1, str2);
+    }
+    
+    public static boolean isAlphanumeric(String str) {
+        return StringUtils.isAlphanumeric(str);
+    }
+    
+    public static String[] stripAll(String[] strs) {
+        return StringUtils.stripAll(strs);
+    }
+    
+    public static String left(String str, int length) {
+        return StringUtils.left(str, length);
+    }
+    
+    public static String escapeHTML(String str) {
+        return StringEscapeUtils.escapeHtml(str);
+    }
+    
+    public static String unescapeHTML(String str) {
+        return StringEscapeUtils.unescapeHtml(str);
+    }
+    
+    public static String escapeXML(String str) {
+        return StringEscapeUtils.escapeXml(str);
+    }
+    
+    public static String unescapeXML(String str) {
+        return StringEscapeUtils.unescapeXml(str);
+    }
+    
+    public static String replace(String src, String target, String rWith) {
+        return StringUtils.replace(src, target, rWith);
+    }
+    
+    public static String replace(String src, String target, String rWith, int maxCount) {
+        return StringUtils.replace(src, target, rWith, maxCount);
+    }
+    
+    private static String replace(String string, Pattern pattern, String replacement) {
+        Matcher m = pattern.matcher(string);
+        return m.replaceAll(replacement);
+    }
+    
+    /**
+     * Remove occurences of html, defined as any text
+     * between the characters "&lt;" and "&gt;".  Replace
+     * any HTML tags with a space.
+     */
+    public static String removeHTML(String str) {
+        return removeHTML(str, true);
+    }
+    
+    /**
+     * Remove occurences of html, defined as any text
+     * between the characters "&lt;" and "&gt;".
+     * Optionally replace HTML tags with a space.
+     */
+    public static String removeHTML(String str, boolean addSpace) {
+        return Utilities.removeHTML(str, addSpace);
+    }
+        
+    /**
+     * Autoformat.
+     */
+    public static String autoformat(String s) {
+        String ret = StringUtils.replace(s, "\n", "<br />");
+        return ret;
+    }
+    /**
+     * Strips HTML and truncates.
+     */
+    public static String truncate(
+            String str, int lower, int upper, String appendToEnd) {
+        // strip markup from the string
+        String str2 = removeHTML(str, false);
+        
+        // quickly adjust the upper if it is set lower than 'lower'
+        if (upper < lower) {
+            upper = lower;
+        }
+        
+        // now determine if the string fits within the upper limit
+        // if it does, go straight to return, do not pass 'go' and collect $200
+        if(str2.length() > upper) {
+            // the magic location int
+            int loc;
+            
+            // first we determine where the next space appears after lower
+            loc = str2.lastIndexOf(' ', upper);
+            
+            // now we'll see if the location is greater than the lower limit
+            if(loc >= lower) {
+                // yes it was, so we'll cut it off here
+                str2 = str2.substring(0, loc);
+            } else {
+                // no it wasnt, so we'll cut it off at the upper limit
+                str2 = str2.substring(0, upper);
+                loc = upper;
+            }
+            
+            // the string was truncated, so we append the appendToEnd String
+            str2 = str2 + appendToEnd;
+        }
+        
+        return str2;
+    }
+    
+    public static String truncateNicely(String str, int lower, int upper, String appendToEnd) {
+        return Utilities.truncateNicely(str, lower, upper, appendToEnd);
+    }
+    
+    public static String truncateText(String str, int lower, int upper, String appendToEnd) {
+        // strip markup from the string
+        String str2 = removeHTML(str, false);
+        boolean diff = (str2.length() < str.length());
+        
+        // quickly adjust the upper if it is set lower than 'lower'
+        if(upper < lower) {
+            upper = lower;
+        }
+        
+        // now determine if the string fits within the upper limit
+        // if it does, go straight to return, do not pass 'go' and collect $200
+        if(str2.length() > upper) {
+            // the magic location int
+            int loc;
+            
+            // first we determine where the next space appears after lower
+            loc = str2.lastIndexOf(' ', upper);
+            
+            // now we'll see if the location is greater than the lower limit
+            if(loc >= lower) {
+                // yes it was, so we'll cut it off here
+                str2 = str2.substring(0, loc);
+            } else {
+                // no it wasnt, so we'll cut it off at the upper limit
+                str2 = str2.substring(0, upper);
+                loc = upper;
+            }
+            // the string was truncated, so we append the appendToEnd String
+            str = str2 + appendToEnd;
+        }
+        return str;
+    }    
+    
+    public static String hexEncode(String str) {
+        if (StringUtils.isEmpty(str)) return str;
+        
+        return RegexUtil.encode(str);
+    }
+    
+    public static String encodeEmail(String str) {
+        return str!=null ? RegexUtil.encodeEmail(str) : null;
+    }
+    
+    /**
+     * URL encoding.
+     * @param s a string to be URL-encoded
+     * @return URL encoding of s using character encoding UTF-8; null if s is null.
+     */
+    public static final String encode(String s) {
+        try {
+            if (s != null)
+                return URLEncoder.encode(s, "UTF-8");
+            else
+                return s;
+        } catch (UnsupportedEncodingException e) {
+            // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+            return s;
+        }
+    }
+    
+    /**
+     * URL decoding.
+     * @param s a URL-encoded string to be URL-decoded
+     * @return URL decoded value of s using character encoding UTF-8; null if s is null.
+     */
+    public static final String decode(String s) {
+        try {
+            if (s != null)
+                return URLDecoder.decode(s, "UTF-8");
+            else
+                return s;
+        } catch (UnsupportedEncodingException e) {
+            // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+            return s;
+        }
+    }
+        
+    /**
+     * Code (stolen from Pebble) to add rel="nofollow" string to all links in HTML.
+     */
+    public static String addNofollow(String html) {
+        if (html == null || html.length() == 0) {
+            return html;
+        }
+        Matcher m = mLinkPattern.matcher(html);
+        StringBuffer buf = new StringBuffer();
+        while (m.find()) {
+            int start = m.start();
+            int end = m.end();
+            String link = html.substring(start, end);
+            buf.append(html.substring(0, start));
+            if (link.indexOf("rel=\"nofollow\"") == -1) {
+                buf.append(
+                        link.substring(0, link.length() - 1) + " rel=\"nofollow\">");
+            } else {
+                buf.append(link);
+            }
+            html = html.substring(end, html.length());
+            m = mLinkPattern.matcher(html);
+        }
+        buf.append(html);
+        return buf.toString();
+    }
+    
+    /**
+     * Transforms the given String into a subset of HTML displayable on a web
+     * page. The subset includes &lt;b&gt;, &lt;i&gt;, &lt;p&gt;, &lt;br&gt;,
+     * &lt;pre&gt; and &lt;a href&gt; (and their corresponding end tags).
+     *
+     * @param s   the String to transform
+     * @return    the transformed String
+     */
+    public static String transformToHTMLSubset(String s) {
+        
+        if (s == null) {
+            return null;
+        }
+        
+        s = replace(s, OPENING_B_TAG_PATTERN, "<b>");
+        s = replace(s, CLOSING_B_TAG_PATTERN, "</b>");
+        s = replace(s, OPENING_I_TAG_PATTERN, "<i>");
+        s = replace(s, CLOSING_I_TAG_PATTERN, "</i>");
+        s = replace(s, OPENING_BLOCKQUOTE_TAG_PATTERN, "<blockquote>");
+        s = replace(s, CLOSING_BLOCKQUOTE_TAG_PATTERN, "</blockquote>");
+        s = replace(s, BR_TAG_PATTERN, "<br />");
+        s = replace(s, OPENING_P_TAG_PATTERN, "<p>");
+        s = replace(s, CLOSING_P_TAG_PATTERN, "</p>");
+        s = replace(s, OPENING_PRE_TAG_PATTERN, "<pre>");
+        s = replace(s, CLOSING_PRE_TAG_PATTERN, "</pre>");
+        s = replace(s, OPENING_UL_TAG_PATTERN, "<ul>");
+        s = replace(s, CLOSING_UL_TAG_PATTERN, "</ul>");
+        s = replace(s, OPENING_OL_TAG_PATTERN, "<ol>");
+        s = replace(s, CLOSING_OL_TAG_PATTERN, "</ol>");
+        s = replace(s, OPENING_LI_TAG_PATTERN, "<li>");
+        s = replace(s, CLOSING_LI_TAG_PATTERN, "</li>");
+        s = replace(s, QUOTE_PATTERN, "\"");
+        
+        // HTTP links
+        s = replace(s, CLOSING_A_TAG_PATTERN, "</a>");
+        Matcher m = OPENING_A_TAG_PATTERN.matcher(s);
+        while (m.find()) {
+            int start = m.start();
+            int end = m.end();
+            String link = s.substring(start, end);
+            link = "<" + link.substring(4, link.length() - 4) + ">";
+            s = s.substring(0, start) + link + s.substring(end, s.length());
+            m = OPENING_A_TAG_PATTERN.matcher(s);
+        }
+        
+        // escaped angle brackets
+        s = s.replaceAll("&amp;lt;", "&lt;");
+        s = s.replaceAll("&amp;gt;", "&gt;");
+        s = s.replaceAll("&amp;#", "&#");
+        
+        return s;
+    }
+    
+    /**
+     * Convert a byte array into a Base64 string (as used in mime formats)
+     */
+    public static String toBase64(byte[] aValue) {
+        
+        final String m_strBase64Chars =
+                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+        
+        int byte1;
+        int byte2;
+        int byte3;
+        int iByteLen = aValue.length;
+        StringBuffer tt = new StringBuffer();
+        
+        for (int i = 0; i < iByteLen; i += 3) {
+            boolean bByte2 = (i + 1) < iByteLen;
+            boolean bByte3 = (i + 2) < iByteLen;
+            byte1 = aValue[i] & 0xFF;
+            byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
+            byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
+            
+            tt.append(m_strBase64Chars.charAt(byte1 / 4));
+            tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
+            tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + ((byte2 & 0xF) * 4)) : '='));
+            tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : '='));
+        }
+        
+        return tt.toString();
+    }
+       
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/AbstractPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/AbstractPager.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/AbstractPager.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/AbstractPager.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,119 @@
+/*
+ * 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.planet.ui.rendering.pagers;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.roller.planet.util.URLUtilities;
+
+
+/**
+ * Abstract base for simple pagers.
+ */
+public abstract class AbstractPager implements Pager {
+    
+    private String url = null;
+    private int page = 0;
+    
+    
+    public AbstractPager(String baseUrl, int pageNum) {
+        
+        this.url = baseUrl;
+        if(pageNum > 0) {
+            this.page = pageNum;
+        }
+    }
+    
+    
+    public String getHomeLink() {
+        return url;
+    }
+    
+    
+    public String getHomeName() {
+        return "Home";
+    }
+    
+    
+    public String getNextLink() {
+        if(hasMoreItems()) {
+            int nextPage = page + 1;
+            Map params = new HashMap();
+            params.put("page", ""+nextPage);
+            return createURL(url, params);
+        }
+        return null;
+    }
+    
+    
+    public String getNextName() {
+        if(hasMoreItems()) {
+            return "Next";
+        }
+        return null;
+    }
+    
+    
+    public String getPrevLink() {
+        if (page > 0) {
+            int prevPage = page - 1;
+            Map params = new HashMap();
+            params.put("page", ""+prevPage);
+            return createURL(url, params);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevName() {
+        if (page > 0) {
+            return "Previous";
+        }
+        return null;
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return false;
+    }
+    
+    
+    protected String createURL(String url, Map params) {
+        
+        return url + URLUtilities.getQueryString(params);
+    }
+
+    
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public int getPage() {
+        return page;
+    }
+
+    public void setPage(int page) {
+        this.page = page;
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/Pager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/Pager.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/Pager.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/Pager.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.planet.ui.rendering.pagers;
+
+import java.util.List;
+
+/**
+ * Common pager interface.
+ */
+public interface Pager {
+    /**
+     * Link value for returning to pager home
+     */
+    public String getHomeLink();
+
+    /**
+     * Name of pager home.
+     */
+    public String getHomeName();
+
+    /**
+     * Link value for next page in current collection view
+     */
+    public String getNextLink();
+
+    /**
+     * Name for next page in current collection view
+     */
+    public String getNextName();
+
+    /**
+     * Link value for prev page in current collection view
+     */
+    public String getPrevLink();
+
+    /**
+     * Link value for prev page in current collection view
+     */
+    public String getPrevName();
+    
+    /**
+     * Get current list of items available from the pager.
+     */
+    public List getItems();
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,131 @@
+/*
+ * 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.planet.ui.rendering.pagers;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.business.Planet;
+import org.apache.roller.planet.business.PlanetFactory;
+import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.pojos.PlanetEntryData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+
+
+/**
+ * Paging through a collection of planet entries.
+ */
+public class PlanetEntriesPager extends AbstractPager {
+    
+    private static Log log = LogFactory.getLog(PlanetEntriesPager.class);
+    
+    private String feedURL = null;
+    private PlanetGroupData group = null;
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    // the collection for the pager
+    private List entries = null;
+    
+    // are there more items?
+    private boolean more = false;
+    
+    
+    public PlanetEntriesPager(
+            String         feedURL,
+            PlanetGroupData group,
+            String         baseUrl,
+            int            sinceDays,
+            int            page,
+            int            length) {
+        
+        super(baseUrl, page);
+        
+        this.feedURL = feedURL;
+        this.group = group;
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
+        getItems();
+    }
+    
+    
+    public List getItems() {
+        
+        if (entries == null) {
+            // calculate offset
+            int offset = getPage() * length;
+            
+            Date startDate = null;
+            if(sinceDays > 0) {
+                Calendar cal = Calendar.getInstance();
+                cal.setTime(new Date());
+                cal.add(Calendar.DATE, -1 * sinceDays);
+                startDate = cal.getTime();
+            }
+            
+            List results = new ArrayList();
+            try {
+                PlanetManager planetManager = PlanetFactory.getPlanet().getPlanetManager();
+                
+                List rawEntries = null;
+                if (feedURL != null) {
+                    rawEntries = planetManager.getFeedEntries(feedURL, offset, length+1);
+                } else if (group != null) {
+                    rawEntries = planetManager.getAggregation(group, startDate, null, offset, length+1);
+                } else {
+                    rawEntries = planetManager.getAggregation(startDate, null, offset, length+1);
+                }
+                
+                // check if there are more results for paging
+                if(rawEntries.size() > length) {
+                    more = true;
+                    rawEntries.remove(rawEntries.size() - 1);
+                }
+                
+                // wrap 'em
+                for (Iterator it = rawEntries.iterator(); it.hasNext();) {
+                    PlanetEntryData entry = (PlanetEntryData) it.next();
+                    // TODO needs pojo wrapping from planet
+                    results.add(entry);
+                }
+                
+            } catch (Exception e) {
+                log.error("ERROR: get aggregation", e);
+            }
+            
+            entries = results;
+        }
+        
+        return entries;
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+    
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,180 @@
+/*
+ * 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.planet.ui.rendering.servlets;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.PlanetData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.pojos.StaticTemplate;
+import org.apache.roller.planet.pojos.Template;
+import org.apache.roller.planet.ui.rendering.Renderer;
+import org.apache.roller.planet.ui.rendering.RendererManager;
+import org.apache.roller.planet.ui.rendering.model.ModelLoader;
+import org.apache.roller.planet.ui.rendering.util.PlanetGroupFeedRequest;
+
+
+/**
+ * Responsible for rendering weblog feeds.
+ */
+public class FeedServlet extends HttpServlet {
+
+    private static Log log = LogFactory.getLog(FeedServlet.class);
+
+
+    /**
+     * Init method for this servlet
+     */
+    public void init(ServletConfig servletConfig) throws ServletException {
+
+        super.init(servletConfig);
+
+        log.info("Initializing FeedServlet");
+    }
+
+
+    /**
+     * Handle GET requests for weblog feeds.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+
+        log.debug("Entering");
+
+        PlanetData planet = null;
+        PlanetGroupData group = null;
+
+        PlanetGroupFeedRequest feedRequest = null;
+        try {
+            // parse the incoming request and extract the relevant data
+            feedRequest = new PlanetGroupFeedRequest(request);
+            
+            planet = feedRequest.getPlanet();
+            if(planet == null) {
+                throw new RollerException("unable to lookup planet: "+
+                        feedRequest.getPlanetHandle());
+            }
+            
+            group = feedRequest.getGroup();
+            if(group == null) {
+                throw new RollerException("unable to lookup group: "+
+                        feedRequest.getGroupHandle());
+            }
+
+        } catch(Exception e) {
+            // invalid feed request format or weblog doesn't exist
+            log.debug("error creating weblog feed request", e);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+        // set content type
+        String accepts = request.getHeader("Accept");
+        String userAgent = request.getHeader("User-Agent");
+        if (accepts != null && accepts.indexOf("*/*") != -1 &&
+            userAgent != null && userAgent.startsWith("Mozilla")) {
+            // client is a browser and feed style is enabled so we want 
+            // browsers to load the page rather than popping up the download 
+            // dialog, so we provide a content-type that browsers will display
+            response.setContentType("text/xml");
+        } else if("rss".equals(feedRequest.getFormat())) {
+            response.setContentType("application/rss+xml; charset=utf-8");
+        } else if("atom".equals(feedRequest.getFormat())) {
+            response.setContentType("application/atom+xml; charset=utf-8");
+        }
+        
+        
+        // looks like we need to render content
+        HashMap model = new HashMap();
+        try {
+            // populate the rendering model
+            Map initData = new HashMap();
+            initData.put("request", request);
+            initData.put("planetRequest", feedRequest);
+            
+            // Load models for feeds
+            String feedModels = PlanetConfig.getProperty("rendering.feedModels");
+            ModelLoader.loadModels(feedModels, model, initData, true);
+
+        } catch (RollerException ex) {
+            log.error("ERROR loading model for page", ex);
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+
+
+        // lookup Renderer we are going to use
+        Renderer renderer = null;
+        try {
+            log.debug("Looking up renderer");
+            
+            String templateFile = null;
+            if("rss".equals(feedRequest.getFormat())) {
+                templateFile = "group-rss.vm";
+            } else if("atom".equals(feedRequest.getFormat())) {
+                templateFile = "group-atom.vm";
+            }
+            
+            Template template = new StaticTemplate(templateFile, null, "velocity");
+            renderer = RendererManager.getRenderer(template);
+        } catch(Exception e) {
+            // nobody wants to render my content :(
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+        // render content.  use default size of about 24K for a standard page
+        try {
+            log.debug("Doing rendering");
+            renderer.render(model, response.getWriter());
+        } catch(Exception e) {
+            // bummer, error during rendering
+            log.error("Error during rendering for group-atom.vm", e);
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+
+        // post rendering process
+
+        // flush rendered content to response
+        log.debug("Flushing response output");
+        //response.setContentLength(rendererOutput.getContent().length);
+        //response.getOutputStream().write(rendererOutput.getContent());
+
+        log.debug("Exiting");
+    }
+
+}

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java?view=auto&rev=505078
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java (added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java Thu Feb  8 14:58:16 2007
@@ -0,0 +1,160 @@
+/*
+ * 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.planet.ui.rendering.servlets;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.PlanetData;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+import org.apache.roller.planet.pojos.StaticTemplate;
+import org.apache.roller.planet.pojos.Template;
+import org.apache.roller.planet.ui.rendering.Renderer;
+import org.apache.roller.planet.ui.rendering.RendererManager;
+import org.apache.roller.planet.ui.rendering.model.ModelLoader;
+import org.apache.roller.planet.ui.rendering.util.PlanetGroupOpmlRequest;
+
+
+/**
+ * Responsible for rendering planet opml files.
+ */
+public class OpmlServlet extends HttpServlet {
+
+    private static Log log = LogFactory.getLog(OpmlServlet.class);
+
+
+    /**
+     * Init method for this servlet
+     */
+    public void init(ServletConfig servletConfig) throws ServletException {
+
+        super.init(servletConfig);
+
+        log.info("Initializing OpmlServlet");
+    }
+
+
+    /**
+     * Handle GET requests for weblog feeds.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+
+        log.debug("Entering");
+        
+        PlanetData planet = null;
+        PlanetGroupData group = null;
+
+        PlanetGroupOpmlRequest opmlRequest = null;
+        try {
+            // parse the incoming request and extract the relevant data
+            opmlRequest = new PlanetGroupOpmlRequest(request);
+
+            planet = opmlRequest.getPlanet();
+            if(planet == null) {
+                throw new RollerException("unable to lookup planet: "+
+                        opmlRequest.getPlanetHandle());
+            }
+            
+            group = opmlRequest.getGroup();
+            if(group == null) {
+                throw new RollerException("unable to lookup group: "+
+                        opmlRequest.getGroupHandle());
+            }
+
+        } catch(Exception e) {
+            // invalid feed request format or weblog doesn't exist
+            log.debug("error creating planet page request", e);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+        // set content type
+        response.setContentType("application/xml; charset=utf-8");
+        
+        
+        // looks like we need to render content
+        HashMap model = new HashMap();
+        try {
+            // populate the rendering model
+            Map initData = new HashMap();
+            initData.put("request", request);
+            initData.put("planetRequest", opmlRequest);
+            
+            // Load models for feeds
+            String opmlModels = PlanetConfig.getProperty("rendering.opmlModels");
+            ModelLoader.loadModels(opmlModels, model, initData, true);
+
+        } catch (RollerException ex) {
+            log.error("ERROR loading model for page", ex);
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+
+
+        // lookup Renderer we are going to use
+        Renderer renderer = null;
+        try {
+            log.debug("Looking up renderer");
+            Template template = new StaticTemplate("opml.vm", null, "velocity");
+            renderer = RendererManager.getRenderer(template);
+        } catch(Exception e) {
+            // nobody wants to render my content :(
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+        // render content.  use default size of about 24K for a standard page
+        try {
+            log.debug("Doing rendering");
+            renderer.render(model, response.getWriter());
+        } catch(Exception e) {
+            // bummer, error during rendering
+            log.error("Error during rendering for opml.vm", e);
+
+            if(!response.isCommitted()) response.reset();
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+
+        // post rendering process
+
+        // flush rendered content to response
+        log.debug("Flushing response output");
+        //response.setContentLength(rendererOutput.getContent().length);
+        //response.getOutputStream().write(rendererOutput.getContent());
+
+        log.debug("Exiting");
+    }
+
+}