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.SnipSpaceFactory; 32 import org.snipsnap.user.AuthenticationService; 33 import org.snipsnap.user.User; 34 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.io.PrintWriter ; 41 42 47 public class SnipRawServlet extends HttpServlet { 48 49 public void doGet(HttpServletRequest request, HttpServletResponse response) 50 throws IOException , ServletException { 51 52 User user = Application.get().getUser(); 53 AuthenticationService service = (AuthenticationService) Components.getComponent(AuthenticationService.class); 54 55 if (service.isAuthenticated(user)) { 56 user.lastAccess(); 57 } 58 59 String name = request.getPathInfo(); 60 if (null == name || "/".equals(name)) { 61 name = Application.get().getConfiguration().getStartSnip(); 62 } else { 63 name = name.substring(1); 64 } 65 66 Configuration config = Application.get().getConfiguration(); 67 String encodedSpace = config.getEncodedSpace(); 68 if (encodedSpace != null && encodedSpace.length() > 0) { 69 name = name.replace(encodedSpace.charAt(0), ' '); 70 } 71 Snip snip = SnipSpaceFactory.getInstance().load(name); 72 73 response.setContentType("text/plain; charset="+Application.get().getConfiguration().getEncoding()); 74 PrintWriter out = response.getWriter(); 75 if (null != snip) { 77 snip.handle(request); 78 out.println(snip.getContent()); 79 } else { 80 out.println("Snip not found."); 81 } 82 } 83 } | Popular Tags |