KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package org.roller.presentation.weblog.actions;
3
4 import org.apache.commons.logging.Log;
5 import org.apache.commons.logging.LogFactory;
6 import org.apache.struts.action.ActionError;
7 import org.apache.struts.action.ActionErrors;
8 import org.apache.struts.action.ActionForm;
9 import org.apache.struts.action.ActionForward;
10 import org.apache.struts.action.ActionMapping;
11 import org.apache.struts.action.ActionMessage;
12 import org.apache.struts.action.ActionMessages;
13 import org.apache.struts.actions.DispatchAction;
14 import org.roller.model.RefererManager;
15 import org.roller.pojos.UserData;
16 import org.roller.pojos.WebsiteData;
17 import org.roller.presentation.RollerRequest;
18
19 import java.util.List JavaDoc;
20
21 import javax.servlet.ServletException JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 /**
26  * Display today's referers.
27  * @struts.action name="refererForm" path="/editor/referers"
28  * scope="session" parameter="method"
29  *
30  * @struts.action-forward name="referers.page" path="/weblog/referers.jsp"
31  */

32 public class ReferersAction extends DispatchAction
33 {
34     private static Log mLogger =
35         LogFactory.getFactory().getInstance(ReferersAction.class);
36         
37     public ActionForward unspecified(
38         ActionMapping mapping,
39         ActionForm actionForm,
40         HttpServletRequest JavaDoc request,
41         HttpServletResponse JavaDoc response)
42         throws Exception JavaDoc
43     {
44         return view(mapping, actionForm, request, response);
45     }
46     
47     /**
48      * execute
49      */

50     public ActionForward view(
51         ActionMapping mapping, ActionForm form,
52         HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
53         throws Exception JavaDoc
54     {
55         ActionForward forward = mapping.findForward("referers.page");
56         RollerRequest rreq = RollerRequest.getRollerRequest(req);
57         RefererManager refmgr = rreq.getRoller().getRefererManager();
58         try
59         {
60             if ( rreq.isUserAuthorizedToEdit() )
61             {
62                 UserData ud = rreq.getUser();
63                 
64                 req.setAttribute("pageHits",
65                     new Integer JavaDoc(refmgr.getDayHits(rreq.getWebsite())));
66                     
67                 req.setAttribute("totalHits",
68                     new Integer JavaDoc(refmgr.getTotalHits(rreq.getWebsite())));
69                     
70                 List JavaDoc refs = refmgr.getTodaysReferers(rreq.getWebsite());
71                 req.setAttribute("referers",refs);
72             }
73         }
74         catch (Exception JavaDoc e)
75         {
76             mLogger.error("ERROR in action",e);
77             throw new ServletException JavaDoc(e);
78         }
79         
80         return forward;
81     }
82     
83     public ActionForward reset(
84         ActionMapping mapping, ActionForm form,
85         HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
86         throws Exception JavaDoc
87     {
88         this.servlet.log("ReferersAction.reset()");
89         RollerRequest rreq = RollerRequest.getRollerRequest(req);
90         try
91         {
92             if ( rreq.isUserAuthorizedToEdit() )
93             {
94                 RefererManager refmgr = rreq.getRoller().getRefererManager();
95                 WebsiteData website = rreq.getWebsite();
96                 refmgr.forceTurnover(website.getId());
97                 rreq.getRoller().commit();
98             }
99             this.servlet.log("ReferersAction.reset(): don't have permission");
100         }
101         catch (Exception JavaDoc e)
102         {
103             mLogger.error("ERROR in action",e);
104             throw new ServletException JavaDoc(e);
105         }
106         return view(mapping, form, req, res);
107     }
108     
109     public ActionForward delete(
110             ActionMapping mapping, ActionForm form,
111             HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
112         throws Exception JavaDoc
113     {
114         //this.servlet.log("ReferersAction.delete()");
115
RollerRequest rreq = RollerRequest.getRollerRequest(req);
116         try
117         {
118             if ( rreq.isUserAuthorizedToEdit() )
119             {
120                 RefererManager refmgr = rreq.getRoller().getRefererManager();
121                 WebsiteData website = rreq.getWebsite();
122
123                 String JavaDoc[] deleteIds = req.getParameterValues("id");
124                 if (deleteIds != null)
125                 {
126                     for (int i=0; i<deleteIds.length; i++)
127                     {
128                         refmgr.removeReferer(deleteIds[i]);
129                     }
130                     rreq.getRoller().commit();
131                     ActionMessages messages = new ActionMessages();
132                     messages.add(null, new ActionMessage("referers.deletedReferers"));
133                     saveMessages(req, messages);
134                 }
135                 else
136                 {
137                     ActionErrors errors = new ActionErrors();
138                     errors.add(null, new ActionError("referers.noReferersSpecified"));
139                     saveErrors(req, errors);
140                 }
141             }
142             //this.servlet.log("ReferersAction.delete(): don't have permission");
143
}
144         catch (Exception JavaDoc e)
145         {
146             mLogger.error("ERROR in action",e);
147             throw new ServletException JavaDoc(e);
148         }
149         return view(mapping, form, req, res);
150     }
151 }
152
153
Popular Tags