001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.admin.struts.actions;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.apache.roller.RollerException;
024: import org.apache.roller.business.pings.PingTargetManager;
025: import org.apache.roller.business.RollerFactory;
026: import org.apache.roller.pojos.PingTargetData;
027: import org.apache.roller.pojos.WebsiteData;
028: import org.apache.roller.ui.authoring.struts.actions.BasePingTargetsAction;
029: import org.apache.roller.ui.authoring.struts.forms.PingTargetForm;
030: import org.apache.roller.ui.core.RollerRequest;
031: import org.apache.roller.ui.core.RollerSession;
032: import org.apache.struts.action.ActionForm;
033: import org.apache.struts.action.ActionForward;
034: import org.apache.struts.action.ActionMapping;
035:
036: import javax.servlet.ServletException;
037: import javax.servlet.http.HttpServletRequest;
038: import javax.servlet.http.HttpServletResponse;
039: import java.util.List;
040:
041: /**
042: * Administer common ping targets.
043: *
044: * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
045: * @struts.action name="pingTargetForm" path="/roller-ui/admin/commonPingTargets" scope="request" parameter="method"
046: * @struts.action-forward name="pingTargets.page" path=".CommonPingTargets"
047: * @struts.action-forward name="pingTargetEdit.page" path=".CommonPingTargetEdit"
048: * @struts.action-forward name="pingTargetDeleteOK.page" path=".CommonPingTargetDeleteOK"
049: */
050: public class CommonPingTargetsAction extends BasePingTargetsAction {
051: private static Log mLogger = LogFactory.getFactory().getInstance(
052: CommonPingTargetsAction.class);
053:
054: protected Log getLogger() {
055: return mLogger;
056: }
057:
058: public String getPingTargetsTitle() {
059: return "commonPingTargets.commonPingTargets";
060: }
061:
062: public String getPingTargetEditTitle() {
063: return "pingTarget.pingTarget";
064: }
065:
066: public String getPingTargetDeleteOKTitle() {
067: return "pingTarget.confirmRemoveTitle";
068: }
069:
070: /*
071: * Set a ping target auto enabled to true.
072: */
073: public ActionForward enableSelected(ActionMapping mapping,
074: ActionForm form, HttpServletRequest req,
075: HttpServletResponse res) throws Exception {
076: RollerRequest rreq = RollerRequest.getRollerRequest(req);
077: PingTargetData pingTarget = select(rreq);
078: try {
079: if (!hasRequiredRights(rreq, rreq.getWebsite())) {
080: return mapping.findForward("access-denied");
081: }
082: pingTarget.setAutoEnabled(true);
083: RollerFactory.getRoller().flush();
084:
085: return view(mapping, form, req, res);
086: } catch (Exception e) {
087: mLogger.error("ERROR in action", e);
088: throw new ServletException(e);
089: }
090: }
091:
092: /*
093: * Set a pint target auto enabled to false.
094: */
095: public ActionForward disableSelected(ActionMapping mapping,
096: ActionForm form, HttpServletRequest req,
097: HttpServletResponse res) throws Exception {
098: RollerRequest rreq = RollerRequest.getRollerRequest(req);
099: PingTargetData pingTarget = select(rreq);
100: try {
101: if (!hasRequiredRights(rreq, rreq.getWebsite())) {
102: return mapping.findForward("access-denied");
103: }
104: pingTarget.setAutoEnabled(false);
105: RollerFactory.getRoller().flush();
106:
107: return view(mapping, form, req, res);
108: } catch (Exception e) {
109: mLogger.error("ERROR in action", e);
110: throw new ServletException(e);
111: }
112: }
113:
114: /*
115: * Get the ping targets for the view. Here we return the common ping targets for the
116: * entire site.
117: */
118: protected List getPingTargets(RollerRequest rreq)
119: throws RollerException {
120: PingTargetManager pingTargetMgr = RollerFactory.getRoller()
121: .getPingTargetManager();
122: return pingTargetMgr.getCommonPingTargets();
123: }
124:
125: /*
126: * Create a new ping target (blank). Here we create a common ping target.
127: */
128: protected PingTargetData createPingTarget(RollerRequest rreq,
129: PingTargetForm pingTargetForm) throws RollerException {
130: return new PingTargetData(null, pingTargetForm.getName(),
131: pingTargetForm.getPingUrl(), null, pingTargetForm
132: .isAutoEnabled());
133: }
134:
135: /*
136: * Check if request carries admin rights.
137: */
138: protected boolean hasRequiredRights(RollerRequest rreq,
139: WebsiteData website) throws RollerException {
140: RollerSession rollerSession = RollerSession
141: .getRollerSession(rreq.getRequest());
142: return rollerSession.isGlobalAdminUser();
143: }
144: }
|