KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > weblog > actions > ToggleLinkbackDisplayAction


1 package org.roller.presentation.weblog.actions;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.apache.struts.action.Action;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9 import org.roller.model.RefererManager;
10 import org.roller.pojos.RefererData;
11 import org.roller.presentation.RollerContext;
12 import org.roller.presentation.RollerRequest;
13 import org.roller.presentation.pagecache.PageCacheFilter;
14
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18
19
20 /**
21  * Toggle display of a linkback.
22  * @struts.action name="toggleLinkback" path="/editor/toggleLinkback" scope="session"
23  */

24 public class ToggleLinkbackDisplayAction extends Action
25 {
26     private static Log mLogger = LogFactory.getFactory().getInstance(
27         ToggleLinkbackDisplayAction.class);
28         
29     /**
30      * execute
31      */

32     public ActionForward execute(
33         ActionMapping mapping, ActionForm form,
34         HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
35         throws Exception JavaDoc
36     {
37          
38         RollerRequest rreq = RollerRequest.getRollerRequest(req);
39         String JavaDoc userName = rreq.getUser().getUserName();
40
41         try
42         {
43             if ( rreq.isUserAuthorizedToEdit() )
44             {
45                 String JavaDoc refid = req.getParameter(RollerRequest.REFERERID_KEY);
46                 if ( refid != null )
47                 {
48                     RefererManager refmgr =
49                         rreq.getRoller().getRefererManager();
50                     RefererData ref = refmgr.retrieveReferer(refid);
51                     boolean was = ref.getVisible()==null ?
52                                   false : ref.getVisible().booleanValue();
53                     ref.setVisible(Boolean.valueOf( !was )); // what up, dog?
54
ref.save();
55                     
56                     rreq.getRoller().commit();
57                     
58                     PageCacheFilter.removeFromCache( req, rreq.getUser() );
59                 }
60             }
61         }
62         catch (Exception JavaDoc e)
63         {
64             mLogger.error("Toggling linkback display",e);
65             throw new ServletException JavaDoc(e);
66         }
67         
68         // forward to user's website URL
69
String JavaDoc url = null;
70         try
71         {
72             RollerContext rctx = RollerContext.getRollerContext(
73                 rreq.getServletContext());
74             url = rctx.getContextUrl( req, userName);
75             res.sendRedirect(url);
76         }
77         catch (Exception JavaDoc e)
78         {
79             mLogger.error("Unexpected exception",e);
80         }
81
82         return null;
83     }
84 }
85
86
Popular Tags