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.authoring.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.config.PingConfig;
025: import org.apache.roller.business.pings.PingTargetManager;
026: import org.apache.roller.business.RollerFactory;
027: import org.apache.roller.pojos.PingTargetData;
028: import org.apache.roller.pojos.WebsiteData;
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.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038: import java.util.Collections;
039: import java.util.List;
040:
041: /**
042: * Administer custom ping targets.
043: *
044: * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
045: * @struts.action name="pingTargetForm" path="/roller-ui/authoring/customPingTargets" scope="request" parameter="method"
046: * @struts.action-forward name="pingTargets.page" path=".CustomPingTargets"
047: * @struts.action-forward name="pingTargetEdit.page" path=".CustomPingTargetEdit"
048: * @struts.action-forward name="pingTargetDeleteOK.page" path=".CustomPingTargetDeleteOK"
049: */
050: public class CustomPingTargetsAction extends BasePingTargetsAction {
051: private static Log mLogger = LogFactory.getFactory().getInstance(
052: CustomPingTargetsAction.class);
053:
054: public String getPingTargetsTitle() {
055: return "customPingTargets.customPingTargets";
056: }
057:
058: public String getPingTargetEditTitle() {
059: return "pingTarget.pingTarget";
060: }
061:
062: public String getPingTargetDeleteOKTitle() {
063: return "pingTarget.confirmRemoveTitle";
064: }
065:
066: public CustomPingTargetsAction() {
067: super ();
068: }
069:
070: protected Log getLogger() {
071: return mLogger;
072: }
073:
074: /*
075: * Get the ping targets for the view. Here we return the custom ping targets for the
076: * website and set the value of attribute <code>allowCustomTargets</code> in the request.
077: * If custom ping targets have been disallowed, we just return the empty list.
078: */
079: protected List getPingTargets(RollerRequest rreq)
080: throws RollerException {
081: HttpServletRequest req = rreq.getRequest();
082: PingTargetManager pingTargetMgr = RollerFactory.getRoller()
083: .getPingTargetManager();
084:
085: Boolean allowCustomTargets = new Boolean(!PingConfig
086: .getDisallowCustomTargets());
087: req.setAttribute("allowCustomTargets", allowCustomTargets);
088:
089: List customPingTargets = allowCustomTargets.booleanValue() ? pingTargetMgr
090: .getCustomPingTargets(rreq.getWebsite())
091: : Collections.EMPTY_LIST;
092:
093: return customPingTargets;
094: }
095:
096: /*
097: * Create a new ping target (blank). Here we create a custom ping target for the website.
098: */
099: protected PingTargetData createPingTarget(RollerRequest rreq,
100: PingTargetForm pingTargetForm) throws RollerException {
101: return new PingTargetData(null, pingTargetForm.getName(),
102: pingTargetForm.getPingUrl(), rreq.getWebsite(), false);
103: }
104:
105: /*
106: * Check if the user has editing rights.
107: */
108: protected boolean hasRequiredRights(RollerRequest rreq,
109: WebsiteData website) throws RollerException {
110: RollerSession rses = RollerSession.getRollerSession(rreq
111: .getRequest());
112: return (rses.isUserAuthorizedToAdmin(website) && !PingConfig
113: .getDisallowCustomTargets());
114: }
115:
116: public ActionForward cancel(ActionMapping mapping,
117: ActionForm actionForm, HttpServletRequest request,
118: HttpServletResponse response) throws Exception {
119: return view(mapping, actionForm, request, response);
120: }
121: }
|