1 package org.roller.presentation.velocity; 2 import org.apache.commons.lang.StringUtils; 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.apache.velocity.Template; 6 import org.apache.velocity.context.Context; 7 import org.apache.velocity.servlet.VelocityServlet; 8 import org.roller.RollerException; 9 import org.roller.presentation.RollerRequest; 10 import java.io.IOException ; 11 import javax.servlet.ServletException ; 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpServletResponse ; 14 import javax.servlet.jsp.JspFactory ; 15 import javax.servlet.jsp.PageContext ; 16 40 public class FlavorServlet extends VelocityServlet 41 { 42 static final long serialVersionUID = -2720532269434186051L; 43 44 private static Log mLogger = LogFactory.getFactory() 45 .getInstance(RollerRequest.class); 46 public Template handleRequest(HttpServletRequest request, 47 HttpServletResponse response, Context ctx) 48 { 49 RollerRequest rreq = null; 50 try 51 { 52 rreq = RollerRequest.getRollerRequest(request,getServletContext()); 53 54 String [] pathInfo = StringUtils.split(rreq.getPathInfo(),"/"); 57 if (pathInfo.length < 1) 58 { 59 rreq.setWebsite(null); 61 } 62 } 63 catch (RollerException e) 64 { 65 if (mLogger.isDebugEnabled()) 67 { 68 mLogger.debug("RollerRequest threw Exception", e); 69 } 70 try 71 { 72 response.sendError(HttpServletResponse.SC_NOT_FOUND); 73 } 74 catch (IOException e1) 75 { 76 if (mLogger.isDebugEnabled()) 77 { 78 mLogger.debug("IOException sending error", e); 79 } 80 } 81 return null; 82 } 83 try 84 { 85 PageContext pageContext = 87 JspFactory.getDefaultFactory().getPageContext( 88 this, request, response, "", true, 8192, true); 89 rreq.setPageContext(pageContext); 90 ContextLoader.setupContext(ctx, rreq, response); 91 92 final String useTemplate; 93 PageModel pageModel = (PageModel)ctx.get("pageModel"); 94 if ( request.getServletPath().endsWith("rss") 95 && pageModel.getPageByName("_rss") != null ) 96 { 97 useTemplate = pageModel.getPageByName("_rss").getId(); 100 } 101 else if (request.getParameter("flavor") != null) 102 { 103 String flavor = request.getParameter("flavor"); 105 useTemplate = "/flavors/" + flavor + ".vm"; 106 } 107 else 108 { 109 useTemplate = "/flavors/rss.vm"; 111 } 112 return getTemplate(useTemplate); 113 } 114 catch (Exception e) 115 { 116 mLogger.error("ERROR in RssServlet", e); 117 } 118 return null; 119 } 120 121 125 protected void error( HttpServletRequest req, HttpServletResponse res, 126 Exception e) throws ServletException , IOException 127 { 128 mLogger.warn("ERROR in FlavorServlet",e); 129 } 130 } 131 132 | Popular Tags |