You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2010/03/20 19:37:54 UTC

svn commit: r925653 [3/5] - in /roller/trunk: planet-business/src/test/resources/ planet-web/ planet-web/src/ planet-web/src/main/ planet-web/src/main/java/ planet-web/src/main/java/org/ planet-web/src/main/java/org/apache/ planet-web/src/main/java/org...

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/pagers/PlanetEntriesPager.java Sat Mar 20 18:37:51 2010
@@ -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.pagers;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+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.PlanetFactory;
+import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.pojos.SubscriptionEntry;
+import org.apache.roller.planet.pojos.PlanetGroup;
+import org.apache.roller.planet.pojos.Subscription;
+
+
+/**
+ * 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 PlanetGroup group = 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,
+            PlanetGroup group,
+            String         baseUrl,
+            int            sinceDays,
+            int            page,
+            int            length) {
+        
+        super(baseUrl, page);
+        
+        this.feedURL = feedURL;
+        this.group = group;
+        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) {
+                    Subscription sub = planetManager.getSubscription(feedURL);
+                    if(sub != null) {
+                        rawEntries = planetManager.getEntries(sub, offset, length+1);
+                    }
+                } else if (group != null) {
+                    rawEntries = planetManager.getEntries(group, startDate, null, offset, length+1);
+                } else {
+                    //rawEntries = planetManager.getEntries(startDate, null, offset, length+1);
+                    rawEntries = Collections.EMPTY_LIST;
+                }
+                
+                // 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();) {
+                    SubscriptionEntry entry = (SubscriptionEntry) 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: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/FeedServlet.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,179 @@
+/*
+ * 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.planet.PlanetException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.Planet;
+import org.apache.roller.planet.pojos.PlanetGroup;
+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");
+
+        Planet planet = null;
+        PlanetGroup 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 PlanetException("unable to lookup planet: "+
+                        feedRequest.getPlanetHandle());
+            }
+            
+            group = feedRequest.getGroup();
+            if(group == null) {
+                throw new PlanetException("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("planetRequest", feedRequest);
+            
+            // Load models for feeds
+            String feedModels = PlanetConfig.getProperty("rendering.feedModels");
+            ModelLoader.loadModels(feedModels, model, initData, true);
+
+        } catch (PlanetException 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: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/HomepageServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/HomepageServlet.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/HomepageServlet.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/HomepageServlet.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,137 @@
+/*
+ * 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.planet.PlanetException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.Planet;
+import org.apache.roller.planet.pojos.PlanetGroup;
+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.PlanetGroupPageRequest;
+
+
+/**
+ * Responsible for rendering application homepage.
+ */
+public class HomepageServlet extends HttpServlet {
+
+    private static Log log = LogFactory.getLog(HomepageServlet.class);
+
+
+    /**
+     * Init method for this servlet
+     */
+    public void init(ServletConfig servletConfig) throws ServletException {
+
+        super.init(servletConfig);
+
+        log.info("Initializing HomepageServlet");
+    }
+
+
+    /**
+     * Handle GET requests for weblog feeds.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+
+        log.debug("Entering");
+
+        // set content type
+        response.setContentType("text/html; charset=utf-8");
+        
+        
+        // initialize model
+        HashMap model = new HashMap();
+        try {
+            // populate the rendering model
+            Map initData = new HashMap();
+            
+            // Load models for pages
+            String models = PlanetConfig.getProperty("rendering.homepageModels");
+            ModelLoader.loadModels(models, model, initData, true);
+
+        } catch (PlanetException ex) {
+            log.error("ERROR loading model", 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");
+            
+            // what template are we going to render?
+            Template template = new StaticTemplate("home.vm", null, "velocity");
+            
+            // get the Renderer
+            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
+        try {
+            log.debug("Doing rendering");
+            renderer.render(model, response.getWriter());
+        } catch(Exception e) {
+            // bummer, error during rendering
+            log.error("Error during rendering", 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: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/OpmlServlet.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,159 @@
+/*
+ * 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.planet.PlanetException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.Planet;
+import org.apache.roller.planet.pojos.PlanetGroup;
+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");
+        
+        Planet planet = null;
+        PlanetGroup 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 PlanetException("unable to lookup planet: "+
+                        opmlRequest.getPlanetHandle());
+            }
+            
+            group = opmlRequest.getGroup();
+            if(group == null) {
+                throw new PlanetException("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("planetRequest", opmlRequest);
+            
+            // Load models for feeds
+            String opmlModels = PlanetConfig.getProperty("rendering.opmlModels");
+            ModelLoader.loadModels(opmlModels, model, initData, true);
+
+        } catch (PlanetException 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");
+    }
+
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/PageServlet.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/PageServlet.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/servlets/PageServlet.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,168 @@
+/*
+ * 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.planet.PlanetException;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.roller.planet.pojos.Planet;
+import org.apache.roller.planet.pojos.PlanetGroup;
+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.PlanetGroupPageRequest;
+
+
+/**
+ * Responsible for rendering planet pages.
+ */
+public class PageServlet extends HttpServlet {
+
+    private static Log log = LogFactory.getLog(PageServlet.class);
+
+
+    /**
+     * Init method for this servlet
+     */
+    public void init(ServletConfig servletConfig) throws ServletException {
+
+        super.init(servletConfig);
+
+        log.info("Initializing PageServlet");
+    }
+
+
+    /**
+     * Handle GET requests for weblog feeds.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+
+        log.debug("Entering");
+        
+        Planet planet = null;
+        PlanetGroup group = null;
+
+        PlanetGroupPageRequest pageRequest = null;
+        try {
+            // parse the incoming request and extract the relevant data
+            pageRequest = new PlanetGroupPageRequest(request);
+
+            planet = pageRequest.getPlanet();
+            if(planet == null) {
+                throw new PlanetException("unable to lookup planet: "+
+                        pageRequest.getPlanetHandle());
+            }
+            
+            group = pageRequest.getGroup();
+
+        } 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("text/html; 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("planetRequest", pageRequest);
+            
+            // Load models for pages
+            String pageModels = PlanetConfig.getProperty("rendering.pageModels");
+            ModelLoader.loadModels(pageModels, model, initData, true);
+
+        } catch (PlanetException 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");
+            
+            // what template are we going to render?
+            Template template = null;
+            if(group == null) {
+                // planet homepage
+                template = new StaticTemplate("planet.vm", null, "velocity");
+            } else {
+                // group homepage
+                template = new StaticTemplate("group.vm", null, "velocity");
+            }
+            
+            // get the Renderer
+            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
+        try {
+            log.debug("Doing rendering");
+            renderer.render(model, response.getWriter());
+        } catch(Exception e) {
+            // bummer, error during rendering
+            log.error("Error during rendering", 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: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/InvalidRequestException.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/InvalidRequestException.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/InvalidRequestException.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/InvalidRequestException.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.util;
+
+import org.apache.roller.planet.PlanetException;
+
+
+/**
+ * An InvalidRequestException is thrown by the ParsedRequest class or any of
+ * its subclasses when the request being parsed is invalid in any way.
+ */
+public class InvalidRequestException extends PlanetException {
+    
+    public InvalidRequestException(String msg) {
+        super(msg);
+    }
+    
+    public InvalidRequestException(String msg, Exception e) {
+        super(msg, e);
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/ParsedRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/ParsedRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/ParsedRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/ParsedRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.util;
+
+import java.util.Locale;
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * An abstract class representing any request made to Roller that has been
+ * parsed in order to extract relevant pieces of information from the url.
+ *
+ * NOTE: It is extremely important to mention that this class and all of its
+ * subclasses are meant to be extremely light weight.  Meaning they should
+ * avoid any time consuming operations at all costs, especially operations
+ * which require a trip to the db.  Those operations should be used very, very
+ * sparingly and should only be triggered when it's guaranteed that they are
+ * needed.
+ */
+public abstract class ParsedRequest {
+    
+    HttpServletRequest request = null;
+    
+    private String authenticUser = null;
+    
+    
+    ParsedRequest() {}
+    
+    
+    /**
+     * Parse the given http request and extract any information we can.
+     *
+     * This abstract version of the constructor gathers info likely to be
+     * relevant to all requests to Roller.
+     */
+    public ParsedRequest(HttpServletRequest request) throws InvalidRequestException {
+        
+        // keep a reference to the original request
+        this.request = request;
+        
+        // login status
+        java.security.Principal prince = request.getUserPrincipal();
+        if(prince != null) {
+            this.authenticUser = prince.getName();
+        }
+        
+    }
+    
+    
+    public String getAuthenticUser() {
+        return this.authenticUser;
+    }
+    
+    
+    public void setAuthenticUser(String authenticUser) {
+        this.authenticUser = authenticUser;
+    }
+    
+    
+    public boolean isLoggedIn() {
+        return (this.authenticUser != null);
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupFeedRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupFeedRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupFeedRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupFeedRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,91 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.ui.rendering.util.InvalidRequestException;
+import org.apache.roller.planet.ui.rendering.util.PlanetRequest;
+
+
+/**
+ * Represents a request for a Roller planet group feed.
+ * 
+ * /planet-ui/rendering/feeds/*
+ *
+ * We use this class as a helper to parse an incoming url and sort out the
+ * information embedded in the url for later use.
+ */
+public class PlanetGroupFeedRequest extends PlanetGroupRequest {
+    
+    private static Log log = LogFactory.getLog(PlanetGroupFeedRequest.class);
+    
+    // lightweight attributes
+    private String format = null;
+    
+    
+    public PlanetGroupFeedRequest() {}
+    
+    
+    /**
+     * Construct the WeblogFeedRequest by parsing the incoming url
+     */
+    public PlanetGroupFeedRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
+        
+        // let our parent take care of their business first
+        // parent determines weblog handle and locale if specified
+        super(request);
+        
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // parse the request object and figure out what we've got
+        log.debug("parsing path "+pathInfo);
+        
+        
+        /* 
+         * parse the path info.  must look like this ...
+         *
+         * <format>
+         */
+        if(pathInfo != null && pathInfo.trim().length() > 1) {
+            
+            this.format = pathInfo;
+            
+        } else {
+            throw new InvalidRequestException("not a valid planet group feed, "+
+                    request.getRequestURL());
+        }
+        
+        if(log.isDebugEnabled()) {
+            log.debug("format = "+this.format);
+        }
+    }
+
+    public String getFormat() {
+        return format;
+    }
+
+    public void setFormat(String format) {
+        this.format = format;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupOpmlRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupOpmlRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupOpmlRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupOpmlRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.ui.rendering.util.InvalidRequestException;
+import org.apache.roller.planet.ui.rendering.util.PlanetRequest;
+
+
+/**
+ * Represents a request for a Roller planet group page.
+ * 
+ * /planet-ui/rendering/opml/*
+ *
+ * We use this class as a helper to parse an incoming url and sort out the
+ * information embedded in the url for later use.
+ */
+public class PlanetGroupOpmlRequest extends PlanetGroupRequest {
+    
+    private static Log log = LogFactory.getLog(PlanetGroupOpmlRequest.class);
+    
+    // lightweight attributes
+    
+    
+    public PlanetGroupOpmlRequest() {}
+    
+    
+    /**
+     * Construct the WeblogFeedRequest by parsing the incoming url
+     */
+    public PlanetGroupOpmlRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
+        
+        // let our parent take care of their business first
+        // parent determines weblog handle and locale if specified
+        super(request);
+        
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // parse the request object and figure out what we've got
+        log.debug("parsing path "+pathInfo);
+        
+        if(pathInfo != null) {
+            throw new InvalidRequestException("not a valid planet opml page, "+
+                    request.getRequestURL());
+        }
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupPageRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupPageRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupPageRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupPageRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Represents a request for a Roller planet group page.
+ * 
+ * /planet-ui/rendering/pages/*
+ *
+ * We use this class as a helper to parse an incoming url and sort out the
+ * information embedded in the url for later use.
+ */
+public class PlanetGroupPageRequest extends PlanetGroupRequest {
+    
+    private static Log log = LogFactory.getLog(PlanetGroupPageRequest.class);
+    
+    // lightweight attributes
+    private int pageNum = 0;
+    
+    
+    public PlanetGroupPageRequest() {}
+    
+    
+    /**
+     * Construct the WeblogFeedRequest by parsing the incoming url
+     */
+    public PlanetGroupPageRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
+        
+        // let our parent take care of their business first
+        // parent determines planet handle
+        super(request);
+        
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // parse the request object and figure out what we've got
+        log.debug("parsing path "+pathInfo);
+        
+        if(pathInfo != null) {
+            throw new InvalidRequestException("not a valid planet group page, "+
+                    request.getRequestURL());
+        }
+        
+        // parse request parameters, right now we only allow for a "page" param
+        if(request.getParameter("page") != null) {
+            String pageInt = request.getParameter("page");
+            try {
+                this.pageNum = Integer.parseInt(pageInt);
+            } catch(NumberFormatException e) {
+                // ignored, bad input
+            }
+        }
+    }
+
+    public int getPageNum() {
+        return pageNum;
+    }
+
+    public void setPageNum(int pageNum) {
+        this.pageNum = pageNum;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetGroupRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.PlanetException;
+import org.apache.roller.planet.business.PlanetFactory;
+import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.pojos.PlanetGroup;
+
+
+/**
+ * Represents a request to a planet group.
+ * 
+ * /<planetHandle>/group/<groupHandle>[/extra/path/info]
+ *
+ */
+public class PlanetGroupRequest extends PlanetRequest {
+    
+    private static Log log = LogFactory.getLog(PlanetGroupRequest.class);
+    
+    // lightweight attributes
+    private String groupHandle = null;
+    
+    // heavyweight attributes
+    private PlanetGroup group = null;
+    
+    
+    public PlanetGroupRequest() {}
+    
+    
+    public PlanetGroupRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
+        
+        // let our parent take care of their business first
+        super(request);
+        
+        String myPathInfo = this.getPathInfo();
+        
+        log.debug("parsing path "+myPathInfo);
+        
+        /* 
+         * parse the path info.  must look like this ...
+         *
+         * <groupHandle>[/extra/info]
+         */
+        if(myPathInfo != null && myPathInfo.trim().length() > 1) {
+            
+            String[] urlPath = myPathInfo.split("/", 2);
+            this.groupHandle = urlPath[0];
+            this.pathInfo = null;
+            
+            if(urlPath.length == 2) {
+                this.pathInfo = urlPath[1];
+            }
+            
+        }
+        
+        if(log.isDebugEnabled()) {
+            log.debug("groupHandle = "+this.groupHandle);
+            log.debug("pathInfo = "+this.pathInfo);
+        }
+    }
+    
+    
+    public String getGroupHandle() {
+        return groupHandle;
+    }
+
+    public void setGroupHandle(String groupHandle) {
+        this.groupHandle = groupHandle;
+    }
+
+    public PlanetGroup getGroup() {
+        
+        if(group == null && groupHandle != null) {
+            try {
+                PlanetManager mgr = PlanetFactory.getPlanet().getPlanetManager();
+                group = mgr.getGroup(getPlanet(), groupHandle);
+            } catch (PlanetException ex) {
+                log.error("Error looking up group "+groupHandle, ex);
+            }
+        }
+        
+        return group;
+    }
+
+    public void setGroup(PlanetGroup group) {
+        this.group = group;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetRequest.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetRequest.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/util/PlanetRequest.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,143 @@
+/*
+ * 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.util;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.PlanetException;
+import org.apache.roller.planet.business.PlanetFactory;
+import org.apache.roller.planet.business.PlanetManager;
+import org.apache.roller.planet.pojos.Planet;
+
+
+/**
+ * Represents a request to a weblog.
+ * 
+ * This is a fairly generic parsed request which is only trying to figure out
+ * the elements of a weblog request which apply to all weblogs.  We try to 
+ * determine the weblogHandle, if a locale was specified, and then what extra 
+ * path info remains.  The basic format is like this ...
+ * 
+ * /<planetHandle>[/extra/path/info]
+ * 
+ * All weblog urls require a weblogHandle, so we ensure that part of the url is
+ * properly specified.  locale is always optional, so we do our best to see
+ * if a locale is specified.  and path info is always optional.
+ *
+ * NOTE: this class purposely exposes a getPathInfo() method which provides the
+ * path info specified by the request that has not been parsed by this
+ * particular class.  this makes it relatively easy for subclasses to extend
+ * this class and simply pick up where it left off in the parsing process.
+ */
+public class PlanetRequest extends ParsedRequest {
+    
+    private static Log log = LogFactory.getLog(PlanetRequest.class);
+    
+    // lightweight attributes
+    private String planetHandle = null;
+    protected String pathInfo = null;
+    
+    // heavyweight attributes
+    private Planet planet = null;
+    
+    
+    public PlanetRequest() {}
+    
+    
+    public PlanetRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
+        
+        // let our parent take care of their business first
+        super(request);
+        
+        String path = request.getPathInfo();
+        
+        log.debug("parsing path "+path);
+        
+        // first, cleanup extra slashes and extract the planet handle
+        if(path != null && path.trim().length() > 1) {
+            
+            // strip off the leading slash
+            path = path.substring(1);
+            
+            // strip off trailing slash if needed
+            if(path.endsWith("/")) {
+                path = path.substring(0, path.length() - 1);
+            }
+            
+            String[] pathElements = path.split("/", 2);
+            if(pathElements[0].trim().length() > 0) {
+                this.planetHandle = pathElements[0];
+            } else {
+                // no planetHandle in path info
+                throw new InvalidRequestException("not a planet request, "+
+                        request.getRequestURL());
+            }
+            
+            // if there is more left of the path info then hold onto it
+            if(pathElements.length == 2) {
+                pathInfo = pathElements[1];
+            } else {
+                pathInfo = null;
+            }
+        }
+        
+        if(log.isDebugEnabled()) {
+            log.debug("planetHandle = "+this.planetHandle);
+            log.debug("pathInfo = "+this.pathInfo);
+        }
+    }
+    
+    
+    public String getPlanetHandle() {
+        return planetHandle;
+    }
+
+    public void setPlanetHandle(String planetHandle) {
+        this.planetHandle = planetHandle;
+    }
+
+    public Planet getPlanet() {
+        
+        if(planet == null && planetHandle != null) {
+            try {
+                PlanetManager mgr = PlanetFactory.getPlanet().getPlanetManager();
+                planet = mgr.getPlanet(planetHandle);
+            } catch (PlanetException ex) {
+                log.error("Error looking up planet "+planetHandle, ex);
+            }
+        }
+        
+        return planet;
+    }
+
+    public void setPlanet(Planet planet) {
+        this.planet = planet;
+    }
+    
+    public String getPathInfo() {
+        return pathInfo;
+    }
+
+    public void setPathInfo(String pathInfo) {
+        this.pathInfo = pathInfo;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/PlanetVelocity.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/PlanetVelocity.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/PlanetVelocity.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/PlanetVelocity.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,101 @@
+/*
+ * 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.velocity;
+
+import java.io.InputStream;
+import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.ui.core.PlanetContext;
+import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+
+/**
+ * Represents the VelocityEngine used by Planet.
+ *
+ * We construct our own instance of VelocityEngine, initialize it, and provide
+ * access to the instance via the Singleton getInstance() method.
+ */
+public class PlanetVelocity {
+    
+    public static final String VELOCITY_CONFIG = "/WEB-INF/velocity.properties";
+    
+    private static Log log = LogFactory.getLog(PlanetVelocity.class);
+    
+    private static VelocityEngine velocityEngine = null;
+    
+    
+    static {
+        log.info("Initializing Velocity Rendering Engine");
+        
+        // initialize the Velocity engine
+        Properties velocityProps = new Properties();
+        
+        try {
+            InputStream instream =
+                    PlanetContext.getServletContext().getResourceAsStream(VELOCITY_CONFIG);
+            
+            velocityProps.load(instream);
+            
+            log.debug("Velocity engine props = "+velocityProps);
+            
+            // construct the VelocityEngine
+            velocityEngine = new VelocityEngine();
+            
+            // init velocity with our properties
+            velocityEngine.init(velocityProps);
+            
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    
+    /**
+     * Access to the VelocityEngine.
+     *
+     * This shouldn't ever be needed, but it's here just in case someone
+     * really needs to do something special.
+     */
+    public static VelocityEngine getEngine() {
+        return velocityEngine;
+    }
+    
+    
+    /**
+     * Convenience static method for looking up a template.
+     */
+    public static Template getTemplate(String name)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name);
+    }
+    
+    
+    /**
+     * Convenience static method for looking up a template.
+     */
+    public static Template getTemplate(String name, String encoding)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name, encoding);
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/TemplateResourceLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/TemplateResourceLoader.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/TemplateResourceLoader.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/TemplateResourceLoader.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,115 @@
+/*
+ * 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.velocity;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.config.PlanetConfig;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+
+
+/**
+ * Loads Velocity resources from the planet "templates.dir" folder.
+ */
+public class TemplateResourceLoader extends ResourceLoader {
+    
+    private static Log log = LogFactory.getLog(TemplateResourceLoader.class);
+    
+    private String templateDir = null;
+    
+    
+    /**
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
+     */
+    public void init(ExtendedProperties config) {
+        
+        log.debug("TemplateResourceLoader : initialization starting.");
+        
+        if (templateDir == null) {
+            templateDir = PlanetConfig.getProperty("template.dir");
+            log.debug("Templates dir = "+templateDir);
+        }
+        
+        log.debug(config);
+        
+        log.debug("TemplateResourceLoader : initialization complete.");
+    }
+    
+    
+    /**
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getResourceStream(java.lang.String)
+     */
+    public InputStream getResourceStream(String name) 
+            throws ResourceNotFoundException {
+        
+        log.debug("Looking up resource named ... "+name);
+        
+        if (name == null || name.length() == 0) {
+            throw new ResourceNotFoundException("No template name provided");
+        }
+        
+        InputStream result = null;
+        
+        try {
+            if(!name.startsWith("/"))
+                name = templateDir + "/" + name;
+            else {
+                name = templateDir + name;
+            }
+            
+            result = new FileInputStream(name);
+            
+        } catch(Exception e) {
+            throw new ResourceNotFoundException(e.getMessage());
+        }
+        
+        if(result == null) {
+            throw new ResourceNotFoundException("Couldn't find "+name);
+        }
+        
+        return result;
+    }
+    
+    
+    /**
+     * Files loaded by this resource loader are considered static, so they are
+     * never reloaded by velocity.
+     *
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#isSourceModified(org.apache.velocity.runtime.resource.Resource)
+     */
+    public boolean isSourceModified(Resource arg0) {
+        return false;
+    }
+    
+    
+    /**
+     * Defaults to return 0.
+     *
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(org.apache.velocity.runtime.resource.Resource)
+     */
+    public long getLastModified(Resource arg0) {
+        return 0;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRenderer.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRenderer.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRenderer.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRenderer.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,124 @@
+/*
+ * 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.velocity;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.pojos.Template;
+import org.apache.roller.planet.ui.rendering.Renderer;
+import org.apache.roller.planet.ui.rendering.RenderingException;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+
+/**
+ * Renderer for Velocity templates.
+ */
+public class VelocityRenderer implements Renderer {
+    
+    private static Log log = LogFactory.getLog(VelocityRenderer.class);
+    
+    // the original template we are supposed to render
+    private Template renderTemplate = null;
+    
+    // the velocity templates
+    private org.apache.velocity.Template velocityTemplate = null;
+    
+    // a possible exception
+    private Exception parseException = null;
+    
+    
+    public VelocityRenderer(Template template) throws Exception {
+        
+        // the Template we are supposed to render
+        this.renderTemplate = template;
+        
+        try {
+            // make sure that we can locate the template
+            // if we can't then this will throw an exception
+            velocityTemplate = PlanetVelocity.getTemplate(template.getId(), "UTF-8");
+            
+        } catch(ResourceNotFoundException ex) {
+            // velocity couldn't find the resource so lets log a warning
+            log.warn("Error creating renderer for "+template.getId()+
+                    " due to ["+ex.getMessage()+"]");
+            
+            // then just rethrow so that the caller knows this instantiation failed
+            throw ex;
+            
+        } catch(ParseErrorException ex) {
+            // in the case of a parsing error we want to render an
+            // error page instead so the user knows what was wrong
+            parseException = ex;
+            
+            // need to lookup error page template
+            velocityTemplate = PlanetVelocity.getTemplate("error-page.vm");
+            
+        } catch(Exception ex) {
+            // some kind of generic/unknown exception, dump it to the logs
+            log.error("Unknown exception creatting renderer for "+template.getId(), ex);
+            
+            // throw if back to the caller
+            throw ex;
+        }
+    }
+    
+    
+    public void render(Map model, Writer out) throws RenderingException {
+        
+        try {
+            if(parseException != null) {
+                
+                Context ctx = new VelocityContext(model);
+                ctx.put("exception", parseException);
+                ctx.put("exceptionSource", renderTemplate.getId());
+                
+                // render output to Writer
+                velocityTemplate.merge(ctx, out);
+                
+                // and we're done
+                return;
+            }
+            
+            long startTime = System.currentTimeMillis();
+            
+            // convert model to Velocity Context
+            Context ctx = new VelocityContext(model);
+            
+            // no decorator, so just merge template to our output writer
+            velocityTemplate.merge(ctx, out);
+
+            long endTime = System.currentTimeMillis();
+            long renderTime = (endTime - startTime)/1000;
+            
+            log.debug("Rendered ["+renderTemplate.getId()+"] in "+renderTime+" secs");
+            
+        } catch (Exception ex) {
+            // wrap and rethrow so caller can deal with it
+            throw new RenderingException("Error during rendering", ex);
+        }
+    }
+
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRendererFactory.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRendererFactory.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRendererFactory.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/VelocityRendererFactory.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.velocity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.pojos.Template;
+import org.apache.roller.planet.ui.rendering.Renderer;
+import org.apache.roller.planet.ui.rendering.RendererFactory;
+
+
+/**
+ * Velocity RendererFactory for Roller.
+ */
+public class VelocityRendererFactory implements RendererFactory {
+    
+    private static Log log = LogFactory.getLog(VelocityRendererFactory.class);
+    
+    
+    public Renderer getRenderer(Template template) {
+        
+        Renderer renderer = null;
+        
+        // nothing we can do with null values
+        if(template.getTemplateLanguage() == null || template.getId() == null) {
+            return null;
+        }
+        
+        if("velocity".equals(template.getTemplateLanguage())) { 
+            
+            // standard velocity template
+            try {
+               renderer = new VelocityRenderer(template);
+            } catch(Exception ex) {
+                // some kind of exception so we don't have a renderer
+                // we do catching/logging in VelocityRenderer constructor
+                return null;
+            }            
+            
+        }
+        
+        return renderer;
+    }
+    
+}

Added: roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/WebappResourceLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/WebappResourceLoader.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/WebappResourceLoader.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/planet/ui/rendering/velocity/WebappResourceLoader.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,116 @@
+/*
+ * 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.velocity;
+
+import java.io.InputStream;
+import javax.servlet.ServletContext;
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.ui.core.PlanetContext;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+
+
+/**
+ * Loads Velocity resources from the webapp.
+ *
+ * All resource urls begin from the root of the webapp.  If a resource path
+ * is relative (does not begin with a /) then it is prefixed with the path
+ * /WEB-INF/velocity/, which is where we keep velocity files.
+ */
+public class WebappResourceLoader extends ResourceLoader {
+    
+    private static Log log = LogFactory.getLog(WebappResourceLoader.class);
+    
+    private ServletContext mContext = null;
+    
+    
+    /**
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
+     */
+    public void init(ExtendedProperties config) {
+        
+        log.debug("WebappResourceLoader : initialization starting.");
+        
+        if (mContext == null) {
+            mContext = PlanetContext.getServletContext();
+            log.debug("Servlet Context = "+mContext.getRealPath("/WEB-INF/velocity/"));
+        }
+        
+        log.debug(config);
+        
+        log.debug("WebappResourceLoader : initialization complete.");
+    }
+    
+    
+    /**
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getResourceStream(java.lang.String)
+     */
+    public InputStream getResourceStream(String name) 
+            throws ResourceNotFoundException {
+        
+        log.debug("Looking up resource named ... "+name);
+        
+        if (name == null || name.length() == 0) {
+            throw new ResourceNotFoundException("No template name provided");
+        }
+        
+        InputStream result = null;
+        
+        try {
+            if(!name.startsWith("/"))
+                name = "/WEB-INF/velocity/" + name;
+            
+            result = this.mContext.getResourceAsStream(name);
+            
+        } catch(Exception e) {
+            throw new ResourceNotFoundException(e.getMessage());
+        }
+        
+        if(result == null) {
+            throw new ResourceNotFoundException("Couldn't find "+name);
+        }
+        
+        return result;
+    }
+    
+    
+    /**
+     * Files loaded by this resource loader are considered static, so they are
+     * never reloaded by velocity.
+     *
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#isSourceModified(org.apache.velocity.runtime.resource.Resource)
+     */
+    public boolean isSourceModified(Resource arg0) {
+        return false;
+    }
+    
+    
+    /**
+     * Defaults to return 0.
+     *
+     * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(org.apache.velocity.runtime.resource.Resource)
+     */
+    public long getLastModified(Resource arg0) {
+        return 0;
+    }
+    
+}