1 25 package org.snipsnap.net; 26 27 import org.snipsnap.app.Application; 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.container.Components; 30 import org.snipsnap.snip.Snip; 31 import org.snipsnap.snip.SnipSpace; 32 import org.snipsnap.versioning.VersionManager; 33 34 import javax.servlet.RequestDispatcher ; 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServlet ; 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpServletResponse ; 39 import java.io.IOException ; 40 import java.util.List ; 41 42 48 49 public class SnipVersionServlet extends HttpServlet { 50 51 public void doGet(HttpServletRequest request, HttpServletResponse response) 52 throws IOException , ServletException { 53 54 final String name = request.getParameter("name"); 55 if (null == name) { 56 Configuration config = Application.get().getConfiguration(); 57 response.sendRedirect(config.getUrl("/space/"+config.getStartSnip())); 58 return; 59 } 60 61 String versionString = request.getParameter("version"); 62 int version = Integer.parseInt(versionString); 63 64 SnipSpace space = (SnipSpace)Components.getComponent(SnipSpace.class); 65 Snip snip = space.load(name); 66 67 VersionManager versionManager = (VersionManager) Components.getComponent(VersionManager.class); 68 Snip versionSnip = versionManager.loadVersion(snip, version); 69 70 request.setAttribute("snip", snip); 71 request.setAttribute("versionSnip", versionSnip); 72 request.setAttribute("version", new Integer (version)); 73 request.setAttribute("maxVersion", new Integer (snip.getVersion())); 74 request.setAttribute("URI", request.getRequestURL().toString()); 75 76 RequestDispatcher dispatcher = request.getRequestDispatcher("/exec/versionsnip.jsp"); 77 dispatcher.forward(request, response); 78 } 79 } | Popular Tags |