1 25 package org.snipsnap.net; 26 27 import org.snipsnap.app.Application; 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.snip.SnipLink; 30 31 import javax.servlet.RequestDispatcher ; 32 import javax.servlet.ServletConfig ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServlet ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.io.IOException ; 38 39 44 public class Layouter extends HttpServlet { 45 46 public final static String ATT_PAGE = "page"; 47 48 public void init(ServletConfig config) throws ServletException { 49 super.init(config); 50 } 51 52 public void doGet(HttpServletRequest request, HttpServletResponse response) 53 throws IOException , ServletException { 54 55 String layout = (String ) request.getAttribute(ATT_PAGE); 57 if (null == layout) { 58 layout = SnipLink.decode(request.getPathInfo()); 59 } 60 Configuration config = Application.get().getConfiguration(); 61 62 if (null == layout || "/".equals(layout)) { 63 response.sendRedirect(config.getUrl("/space/" + config.getStartSnip())); 64 return; 65 } 66 67 if(layout.endsWith(".jsp")) { 68 request.setAttribute(ATT_PAGE, layout); 69 } else { 70 request.setAttribute(ATT_PAGE, "/plugin"+layout); 71 } 72 73 RequestDispatcher dispatcher = request.getRequestDispatcher("/main.jsp"); 74 75 if (dispatcher != null) { 76 dispatcher.forward(request, response); 77 } else { 78 response.sendRedirect(config.getUrl()); 79 } 80 } 81 82 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 83 doGet(request, response); 84 } 85 } 86 | Popular Tags |