KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > authoring > struts > actions > CustomPingTargetsAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.authoring.struts.actions;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.roller.RollerException;
24 import org.apache.roller.config.PingConfig;
25 import org.apache.roller.model.PingTargetManager;
26 import org.apache.roller.model.RollerFactory;
27 import org.apache.roller.pojos.PingTargetData;
28 import org.apache.roller.pojos.WebsiteData;
29 import org.apache.roller.ui.authoring.struts.forms.PingTargetForm;
30 import org.apache.roller.ui.core.RollerRequest;
31 import org.apache.roller.ui.core.RollerSession;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import javax.servlet.http.HttpServletResponse JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.List JavaDoc;
40
41
42 /**
43  * Administer custom ping targets.
44  *
45  * @author <a HREF="mailto:anil@busybuddha.org">Anil Gangolli</a>
46  * @struts.action name="pingTargetForm" path="/roller-ui/authoring/customPingTargets" scope="request" parameter="method"
47  * @struts.action-forward name="pingTargets.page" path=".CustomPingTargets"
48  * @struts.action-forward name="pingTargetEdit.page" path=".CustomPingTargetEdit"
49  * @struts.action-forward name="pingTargetDeleteOK.page" path=".CustomPingTargetDeleteOK"
50  */

51 public class CustomPingTargetsAction extends BasePingTargetsAction {
52     private static Log mLogger = LogFactory.getFactory().getInstance(CustomPingTargetsAction.class);
53
54     public String JavaDoc getPingTargetsTitle() {
55         return "customPingTargets.customPingTargets";
56     }
57
58     public String JavaDoc getPingTargetEditTitle() {
59         return "pingTarget.pingTarget";
60     }
61
62     public String JavaDoc getPingTargetDeleteOKTitle() {
63         return "pingTarget.confirmRemoveTitle";
64     }
65
66     public CustomPingTargetsAction() {
67         super();
68     }
69
70     protected Log getLogger() {
71         return mLogger;
72     }
73
74     /*
75      * Get the ping targets for the view. Here we return the custom ping targets for the
76      * website and set the value of attribute <code>allowCustomTargets</code> in the request.
77      * If custom ping targets have been disallowed, we just return the empty list.
78      */

79     protected List JavaDoc getPingTargets(RollerRequest rreq) throws RollerException {
80         HttpServletRequest JavaDoc req = rreq.getRequest();
81         PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
82
83         Boolean JavaDoc allowCustomTargets = new Boolean JavaDoc(!PingConfig.getDisallowCustomTargets());
84         req.setAttribute("allowCustomTargets", allowCustomTargets);
85
86         List JavaDoc customPingTargets = allowCustomTargets.booleanValue() ? pingTargetMgr.getCustomPingTargets(rreq.getWebsite()) : Collections.EMPTY_LIST;
87
88         return customPingTargets;
89     }
90
91     /*
92      * Create a new ping target (blank). Here we create a custom ping target for the website.
93      */

94     protected PingTargetData createPingTarget(RollerRequest rreq, PingTargetForm pingTargetForm) throws RollerException {
95         return new PingTargetData(null, pingTargetForm.getName(), pingTargetForm.getPingUrl(), rreq.getWebsite(), false);
96     }
97
98
99     /*
100      * Check if the user has editing rights.
101      */

102     protected boolean hasRequiredRights(RollerRequest rreq, WebsiteData website) throws RollerException {
103         RollerSession rses = RollerSession.getRollerSession(rreq.getRequest());
104         return (rses.isUserAuthorizedToAdmin(website) && !PingConfig.getDisallowCustomTargets());
105     }
106
107     public ActionForward cancel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
108         return view(mapping, actionForm, request, response);
109     }
110 }
111
Popular Tags