1 18 19 package org.apache.roller.ui.authoring.struts.actions; 20 21 import java.util.List ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.struts.action.ActionError; 30 import org.apache.struts.action.ActionErrors; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import org.apache.struts.action.ActionMessage; 35 import org.apache.struts.action.ActionMessages; 36 import org.apache.struts.actions.DispatchAction; 37 import org.apache.roller.model.RefererManager; 38 import org.apache.roller.model.RollerFactory; 39 import org.apache.roller.pojos.RefererData; 40 import org.apache.roller.pojos.WebsiteData; 41 import org.apache.roller.ui.core.BasePageModel; 42 import org.apache.roller.ui.core.RollerRequest; 43 import org.apache.roller.ui.core.RollerSession; 44 import org.apache.roller.util.cache.CacheManager; 45 46 53 public class ReferersAction extends DispatchAction 54 { 55 private static Log mLogger = 56 LogFactory.getFactory().getInstance(ReferersAction.class); 57 58 public ActionForward unspecified( 59 ActionMapping mapping, 60 ActionForm actionForm, 61 HttpServletRequest request, 62 HttpServletResponse response) 63 throws Exception 64 { 65 return view(mapping, actionForm, request, response); 66 } 67 68 71 public ActionForward view( 72 ActionMapping mapping, ActionForm form, 73 HttpServletRequest req, HttpServletResponse res) 74 throws Exception 75 { 76 ActionForward forward = mapping.findForward("referers.page"); 77 RollerRequest rreq = RollerRequest.getRollerRequest(req); 78 RollerSession rollerSession = RollerSession.getRollerSession(req); 79 RefererManager refmgr = RollerFactory.getRoller().getRefererManager(); 80 try 81 { 82 if (rreq.getWebsite() != null 83 && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) ) 84 { 85 BasePageModel pageModel = new BasePageModel( 86 "referers.todaysReferers", req, res, mapping); 87 req.setAttribute("model", pageModel); 88 req.setAttribute("pageHits", 89 new Integer (refmgr.getDayHits(rreq.getWebsite()))); 90 91 req.setAttribute("totalHits", 92 new Integer (refmgr.getTotalHits(rreq.getWebsite()))); 93 94 List refs = refmgr.getTodaysReferers(rreq.getWebsite()); 95 req.setAttribute("referers",refs); 96 } 97 } 98 catch (Exception e) 99 { 100 mLogger.error("ERROR in action",e); 101 throw new ServletException (e); 102 } 103 104 return forward; 105 } 106 107 public ActionForward reset( 108 ActionMapping mapping, ActionForm form, 109 HttpServletRequest req, HttpServletResponse res) 110 throws Exception 111 { 112 this.servlet.log("ReferersAction.reset()"); 113 RollerRequest rreq = RollerRequest.getRollerRequest(req); 114 RollerSession rollerSession = RollerSession.getRollerSession(req); 115 try 116 { 117 if (rreq.getWebsite() != null 118 && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) ) 119 { 120 RefererManager refmgr = RollerFactory.getRoller().getRefererManager(); 121 WebsiteData website = rreq.getWebsite(); 122 refmgr.clearReferrers(website); 123 RollerFactory.getRoller().flush(); 124 125 CacheManager.invalidate(website); 126 } 127 this.servlet.log("ReferersAction.reset(): don't have permission"); 128 } 129 catch (Exception e) 130 { 131 mLogger.error("ERROR in action",e); 132 throw new ServletException (e); 133 } 134 return view(mapping, form, req, res); 135 } 136 137 public ActionForward delete( 138 ActionMapping mapping, ActionForm form, 139 HttpServletRequest req, HttpServletResponse res) 140 throws Exception 141 { 142 RollerRequest rreq = RollerRequest.getRollerRequest(req); 144 RollerSession rollerSession = RollerSession.getRollerSession(req); 145 try 146 { 147 if (rreq.getWebsite() != null 148 && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) ) 149 { 150 RefererManager refmgr = RollerFactory.getRoller().getRefererManager(); 151 WebsiteData website = rreq.getWebsite(); 152 153 RefererData referer = null; 154 String [] deleteIds = req.getParameterValues("id"); 155 if (deleteIds != null) 156 { 157 for (int i=0; i<deleteIds.length; i++) 158 { 159 referer = refmgr.getReferer(deleteIds[i]); 160 refmgr.removeReferer(referer); 161 } 162 RollerFactory.getRoller().flush(); 163 164 CacheManager.invalidate(website); 165 166 ActionMessages messages = new ActionMessages(); 167 messages.add(null, new ActionMessage("referers.deletedReferers")); 168 saveMessages(req, messages); 169 } 170 else 171 { 172 ActionErrors errors = new ActionErrors(); 173 errors.add(null, new ActionError("referers.noReferersSpecified")); 174 saveErrors(req, errors); 175 } 176 } 177 } 179 catch (Exception e) 180 { 181 mLogger.error("ERROR in action",e); 182 throw new ServletException (e); 183 } 184 return view(mapping, form, req, res); 185 } 186 } 187 | Popular Tags |