KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > admin > struts > actions > CommonPingTargetsAction


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.admin.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.model.PingTargetManager;
25 import org.apache.roller.model.RollerFactory;
26 import org.apache.roller.pojos.PingTargetData;
27 import org.apache.roller.pojos.WebsiteData;
28 import org.apache.roller.ui.authoring.struts.actions.BasePingTargetsAction;
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.ServletException JavaDoc;
37 import javax.servlet.http.HttpServletRequest JavaDoc;
38 import javax.servlet.http.HttpServletResponse JavaDoc;
39 import java.util.List JavaDoc;
40
41 /**
42  * Administer common ping targets.
43  *
44  * @author <a HREF="mailto:anil@busybuddha.org">Anil Gangolli</a>
45  * @struts.action name="pingTargetForm" path="/roller-ui/admin/commonPingTargets" scope="request" parameter="method"
46  * @struts.action-forward name="pingTargets.page" path=".CommonPingTargets"
47  * @struts.action-forward name="pingTargetEdit.page" path=".CommonPingTargetEdit"
48  * @struts.action-forward name="pingTargetDeleteOK.page" path=".CommonPingTargetDeleteOK"
49  */

50 public class CommonPingTargetsAction extends BasePingTargetsAction {
51     private static Log mLogger = LogFactory.getFactory().getInstance(CommonPingTargetsAction.class);
52
53     protected Log getLogger() {
54         return mLogger;
55     }
56
57     public String JavaDoc getPingTargetsTitle() {
58         return "commonPingTargets.commonPingTargets";
59     }
60
61     public String JavaDoc getPingTargetEditTitle() {
62         return "pingTarget.pingTarget";
63     }
64
65     public String JavaDoc getPingTargetDeleteOKTitle() {
66         return "pingTarget.confirmRemoveTitle";
67     }
68
69     /*
70     * Set a ping target auto enabled to true.
71     */

72     public ActionForward enableSelected(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws Exception JavaDoc {
73         RollerRequest rreq = RollerRequest.getRollerRequest(req);
74         PingTargetData pingTarget = select(rreq);
75         try {
76             if (!hasRequiredRights(rreq, rreq.getWebsite())) {
77                 return mapping.findForward("access-denied");
78             }
79             pingTarget.setAutoEnabled(true);
80             RollerFactory.getRoller().flush();
81
82             return view(mapping, form, req, res);
83         } catch (Exception JavaDoc e) {
84             mLogger.error("ERROR in action", e);
85             throw new ServletException JavaDoc(e);
86         }
87     }
88
89     /*
90      * Set a pint target auto enabled to false.
91      */

92     public ActionForward disableSelected(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws Exception JavaDoc {
93         RollerRequest rreq = RollerRequest.getRollerRequest(req);
94         PingTargetData pingTarget = select(rreq);
95         try {
96             if (!hasRequiredRights(rreq, rreq.getWebsite())) {
97                 return mapping.findForward("access-denied");
98             }
99             pingTarget.setAutoEnabled(false);
100             RollerFactory.getRoller().flush();
101
102             return view(mapping, form, req, res);
103         } catch (Exception JavaDoc e) {
104             mLogger.error("ERROR in action", e);
105             throw new ServletException JavaDoc(e);
106         }
107     }
108
109     /*
110     * Get the ping targets for the view. Here we return the common ping targets for the
111     * entire site.
112     */

113     protected List JavaDoc getPingTargets(RollerRequest rreq) throws RollerException {
114         PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
115         return pingTargetMgr.getCommonPingTargets();
116     }
117
118     /*
119      * Create a new ping target (blank). Here we create a common ping target.
120      */

121     protected PingTargetData createPingTarget(RollerRequest rreq, PingTargetForm pingTargetForm) throws RollerException {
122         return new PingTargetData(null, pingTargetForm.getName(), pingTargetForm.getPingUrl(), null, pingTargetForm.isAutoEnabled());
123     }
124
125
126     /*
127      * Check if request carries admin rights.
128      */

129     protected boolean hasRequiredRights(RollerRequest rreq, WebsiteData website) throws RollerException {
130         RollerSession rollerSession = RollerSession.getRollerSession(rreq.getRequest());
131         return rollerSession.isGlobalAdminUser();
132     }
133 }
134
Popular Tags