1 package info.magnolia.cms.cache; 2 3 import info.magnolia.cms.beans.config.ContentRepository; 4 import info.magnolia.cms.beans.config.Server; 5 import info.magnolia.cms.core.Content; 6 import info.magnolia.cms.core.HierarchyManager; 7 import info.magnolia.cms.i18n.MessagesManager; 8 import info.magnolia.context.MgnlContext; 9 10 import java.io.IOException ; 11 import java.io.PrintWriter ; 12 13 import javax.servlet.ServletException ; 14 import javax.servlet.http.HttpServlet ; 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 18 import org.slf4j.Logger; 19 import org.slf4j.LoggerFactory; 20 21 22 27 public class CacheGeneratorServlet extends HttpServlet { 28 29 32 private static final long serialVersionUID = 222L; 33 34 private static final String CACHE_GENERATE_ACTION = "create.cache"; 35 36 private CacheManager cacheManager = CacheManagerFactory.getCacheManager(); 37 38 41 private static Logger log = LoggerFactory.getLogger(CacheGeneratorServlet.class); 42 43 46 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 47 48 if (request.getParameter(CACHE_GENERATE_ACTION) == null) { 49 displayCacheForm(request, response.getWriter()); 50 } 51 else { 52 try { 53 HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); 54 cachePage(hm.getRoot(), request); 55 cachePage(hm.getRoot(), request); 56 response.getWriter().write(MessagesManager.get("cacheservlet.success")); 57 } 58 catch (Exception e) { 59 throw new ServletException (e); 60 } 61 } 62 } 63 64 69 private void displayCacheForm(HttpServletRequest request, PrintWriter out) { 70 71 out.println("<html><head><title>Magnolia</title>"); out.println("</head><body class=\"mgnlBgLight mgnlImportExport\">"); 75 out.println("<h2>"); out.println(MessagesManager.get("cacheservlet.title")); out.println("</h2>"); if (Server.isAdmin()) { 79 out.println("<h3 style=\"color:red;\">" + MessagesManager.get("cacheservlet.warning") + "</h3>"); 80 } 81 82 out.println("<form method=\"get\" action=\"\">"); out.println("<input type=\"submit\" name=\"" + CACHE_GENERATE_ACTION 85 + "\" value=\"" + MessagesManager.get("cacheservlet.generate") + "\" />"); 89 out.println("</form></body></html>"); } 91 92 private void cachePage(Content page, HttpServletRequest request) { 93 105 } 106 107 111 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , 112 IOException { 113 doGet(request, response); 114 } 115 } 116 | Popular Tags |