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: package org.apache.roller.ui.authoring.struts.actions;
019:
020: import javax.servlet.ServletException;
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.apache.struts.action.Action;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionForward;
029: import org.apache.struts.action.ActionMapping;
030: import org.apache.roller.business.referrers.RefererManager;
031: import org.apache.roller.business.RollerFactory;
032: import org.apache.roller.pojos.RefererData;
033: import org.apache.roller.pojos.WeblogEntryData;
034: import org.apache.roller.ui.core.RequestConstants;
035: import org.apache.roller.ui.core.RollerContext;
036: import org.apache.roller.ui.core.RollerRequest;
037: import org.apache.roller.ui.core.RollerSession;
038: import org.apache.roller.util.cache.CacheManager;
039:
040: /**
041: * Toggle display of a linkback.
042: * @struts.action path="/roller-ui/authoring/toggleLinkback" name="toggleLinkback"
043: */
044: public class ToggleLinkbackDisplayAction extends Action {
045: private static Log mLogger = LogFactory.getFactory().getInstance(
046: ToggleLinkbackDisplayAction.class);
047:
048: /**
049: * execute
050: */
051: public ActionForward execute(ActionMapping mapping,
052: ActionForm form, HttpServletRequest req,
053: HttpServletResponse res) throws Exception {
054: WeblogEntryData entry = null;
055: RollerRequest rreq = RollerRequest.getRollerRequest(req);
056: RollerSession rollerSession = RollerSession
057: .getRollerSession(req);
058: try {
059: if (rreq.getWebsite() != null
060: && rollerSession.isUserAuthorizedToAuthor(rreq
061: .getWebsite())) {
062: String refid = req
063: .getParameter(RequestConstants.REFERRER_ID);
064: if (refid != null) {
065: RefererManager refmgr = RollerFactory.getRoller()
066: .getRefererManager();
067: RefererData ref = refmgr.getReferer(refid);
068: entry = ref.getWeblogEntry();
069: boolean was = ref.getVisible() == null ? false
070: : ref.getVisible().booleanValue();
071: ref.setVisible(Boolean.valueOf(!was)); // what up, dog?
072: refmgr.saveReferer(ref);
073:
074: RollerFactory.getRoller().flush();
075:
076: //PageCacheFilter.removeFromCache( req, rreq.getWebsite() );
077: CacheManager.invalidate(rreq.getWebsite());
078: }
079: }
080: } catch (Exception e) {
081: mLogger.error("Toggling linkback display", e);
082: throw new ServletException(e);
083: }
084:
085: // forward back to entry or to blog if we have no entry
086: String url = null;
087: try {
088: RollerContext rctx = RollerContext.getRollerContext();
089: if (entry != null) {
090: url = entry.getPermalink();
091: } else {
092: url = rreq.getWebsite().getURL();
093: }
094: res.sendRedirect(url);
095: } catch (Exception e) {
096: mLogger.error("Unexpected exception", e);
097: }
098:
099: return null;
100: }
101: }
|