KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > pages > LogoutPage


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface.pages;
14
15 import info.magnolia.module.admininterface.PageMVCHandler;
16 import info.magnolia.context.MgnlContext;
17 import info.magnolia.context.SystemContext;
18 import info.magnolia.cms.beans.config.ContentRepository;
19
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25 import javax.servlet.http.HttpSession JavaDoc;
26 import javax.jcr.Session;
27
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32 /**
33  * @author Fabrizio Giustina
34  * @version $Revision: 6888 $ ($Author: scharles $)
35  */

36 public class LogoutPage extends PageMVCHandler {
37
38     /**
39      * Logger.
40      */

41     private static Logger log = LoggerFactory.getLogger(LogoutPage.class);
42
43     /**
44      * @param name
45      * @param request
46      * @param response
47      */

48     public LogoutPage(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
49         super(name, request, response);
50     }
51
52     /**
53      * @see info.magnolia.cms.servlets.MVCServletHandler#renderHtml(java.lang.String)
54      */

55     public void renderHtml(String JavaDoc view) throws IOException JavaDoc {
56         HttpSession JavaDoc session = getRequest().getSession(false);
57         if (session != null) {
58             if (!(MgnlContext.getInstance() instanceof SystemContext)) {
59                 Iterator JavaDoc configuredStores = ContentRepository.getAllRepositoryNames();
60                 while (configuredStores.hasNext()) {
61                     String JavaDoc store = (String JavaDoc) configuredStores.next();
62                     try {
63                         Session JavaDoc jcrSession = MgnlContext.getHierarchyManager(store).getWorkspace().getSession();
64                         if (jcrSession.isLive()) jcrSession.logout();
65                     } catch (Throwable JavaDoc t) {
66                         log.debug("Failed to close JCR session",t);
67                     }
68                 }
69             }
70             session.invalidate();
71             log.info("Logging out user");
72         }
73         getResponse().sendRedirect(request.getContextPath() + "/");
74     }
75
76 }
77
Popular Tags