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 ; 20 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 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 request, 41 HttpServletResponse response) 42 throws Exception 43 { 44 return view(mapping, actionForm, request, response); 45 } 46 47 50 public ActionForward view( 51 ActionMapping mapping, ActionForm form, 52 HttpServletRequest req, HttpServletResponse res) 53 throws Exception 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 (refmgr.getDayHits(rreq.getWebsite()))); 66 67 req.setAttribute("totalHits", 68 new Integer (refmgr.getTotalHits(rreq.getWebsite()))); 69 70 List refs = refmgr.getTodaysReferers(rreq.getWebsite()); 71 req.setAttribute("referers",refs); 72 } 73 } 74 catch (Exception e) 75 { 76 mLogger.error("ERROR in action",e); 77 throw new ServletException (e); 78 } 79 80 return forward; 81 } 82 83 public ActionForward reset( 84 ActionMapping mapping, ActionForm form, 85 HttpServletRequest req, HttpServletResponse res) 86 throws Exception 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 e) 102 { 103 mLogger.error("ERROR in action",e); 104 throw new ServletException (e); 105 } 106 return view(mapping, form, req, res); 107 } 108 109 public ActionForward delete( 110 ActionMapping mapping, ActionForm form, 111 HttpServletRequest req, HttpServletResponse res) 112 throws Exception 113 { 114 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 [] 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 } 144 catch (Exception e) 145 { 146 mLogger.error("ERROR in action",e); 147 throw new ServletException (e); 148 } 149 return view(mapping, form, req, res); 150 } 151 } 152 153 | Popular Tags |