KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2005
3  * Anil R. Gangolli. All rights reserved.
4  *
5  * Distributed with the Roller Weblogger Project under the terms of the Roller Software
6  * License
7  */

8
9 package org.roller.presentation.weblog.actions;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.roller.RollerException;
14 import org.roller.model.PingTargetManager;
15 import org.roller.pojos.PingTargetData;
16 import org.roller.presentation.RollerRequest;
17 import org.roller.config.PingConfig;
18 import org.roller.presentation.forms.PingTargetForm;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Collections JavaDoc;
23
24 /**
25  * Administer custom ping targets.
26  *
27  * @struts.action name="pingTargetForm" path="/editor/customPingTargets" scope="request" parameter="method"
28  * @struts.action-forward name="pingTargets.page" path="/weblog/CustomPingTargets.jsp"
29  * @struts.action-forward name="pingTargetEdit.page" path="/weblog/CustomPingTargetEdit.jsp"
30  * @struts.action-forward name="pingTargetDeleteOK.page" path="/weblog/CustomPingTargetDeleteOK.jsp"
31  */

32 public class CustomPingTargetsAction
33     extends BasePingTargetsAction
34 {
35     private static Log mLogger =
36         LogFactory.getFactory().getInstance(CustomPingTargetsAction.class);
37
38
39     public CustomPingTargetsAction() {
40         super();
41     }
42
43     protected Log getLogger() {
44         return mLogger;
45     }
46
47     /*
48      * Get the ping targets for the view. Here we return the custom ping targets for the
49      * website and set the value of attribute <code>allowCustomTargets</code> in the request.
50      * If custom ping targets have been disallowed, we just return the empty list.
51      */

52     protected List JavaDoc getPingTargets(RollerRequest rreq) throws RollerException
53     {
54         HttpServletRequest JavaDoc req = rreq.getRequest();
55         PingTargetManager pingTargetMgr = rreq.getRoller().getPingTargetManager();
56
57         Boolean JavaDoc allowCustomTargets = new Boolean JavaDoc(!PingConfig.getDisallowCustomTargets());
58         req.setAttribute("allowCustomTargets", allowCustomTargets);
59
60         List JavaDoc customPingTargets = allowCustomTargets.booleanValue() ?
61             pingTargetMgr.getCustomPingTargets(rreq.getWebsite()) : Collections.EMPTY_LIST;
62
63         return customPingTargets;
64     }
65
66     /*
67      * Create a new ping target (blank). Here we create a custom ping target for the website.
68      */

69     protected PingTargetData createPingTarget(RollerRequest rreq, PingTargetForm pingTargetForm)
70         throws RollerException
71     {
72         PingTargetManager pingTargetMgr = rreq.getRoller().getPingTargetManager();
73         return pingTargetMgr.createCustomPingTarget(
74             pingTargetForm.getName(), pingTargetForm.getPingUrl(), rreq.getWebsite());
75     }
76
77
78     /*
79      * Check if the user has editing rights.
80      */

81     protected boolean hasRequiredRights(RollerRequest rreq) throws RollerException
82     {
83         return (rreq.isUserAuthorizedToEdit() && !PingConfig.getDisallowCustomTargets());
84     }
85 }
86
Popular Tags