KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.roller.ui.authoring.struts.actions;
19
20 import javax.servlet.ServletException JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.struts.action.Action;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.roller.model.RefererManager;
31 import org.apache.roller.model.RollerFactory;
32 import org.apache.roller.pojos.RefererData;
33 import org.apache.roller.pojos.WeblogEntryData;
34 import org.apache.roller.ui.core.RequestConstants;
35 import org.apache.roller.ui.core.RollerContext;
36 import org.apache.roller.ui.core.RollerRequest;
37 import org.apache.roller.ui.core.RollerSession;
38 import org.apache.roller.util.cache.CacheManager;
39
40 /**
41  * Toggle display of a linkback.
42  * @struts.action path="/roller-ui/authoring/toggleLinkback" name="toggleLinkback"
43  */

44 public class ToggleLinkbackDisplayAction extends Action
45 {
46     private static Log mLogger = LogFactory.getFactory().getInstance(
47         ToggleLinkbackDisplayAction.class);
48         
49     /**
50      * execute
51      */

52     public ActionForward execute(
53         ActionMapping mapping, ActionForm form,
54         HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
55         throws Exception JavaDoc
56     {
57         WeblogEntryData entry = null;
58         RollerRequest rreq = RollerRequest.getRollerRequest(req);
59         RollerSession rollerSession = RollerSession.getRollerSession(req);
60         try
61         {
62             if (rreq.getWebsite() != null
63                  && rollerSession.isUserAuthorizedToAuthor(rreq.getWebsite()) )
64             {
65                 String JavaDoc refid = req.getParameter(RequestConstants.REFERRER_ID);
66                 if ( refid != null )
67                 {
68                     RefererManager refmgr =
69                         RollerFactory.getRoller().getRefererManager();
70                     RefererData ref = refmgr.getReferer(refid);
71                     entry = ref.getWeblogEntry();
72                     boolean was = ref.getVisible()==null ?
73                                   false : ref.getVisible().booleanValue();
74                     ref.setVisible(Boolean.valueOf( !was )); // what up, dog?
75
refmgr.saveReferer(ref);
76                     
77                     RollerFactory.getRoller().flush();
78                     
79                     //PageCacheFilter.removeFromCache( req, rreq.getWebsite() );
80
CacheManager.invalidate(rreq.getWebsite());
81                 }
82             }
83         }
84         catch (Exception JavaDoc e)
85         {
86             mLogger.error("Toggling linkback display",e);
87             throw new ServletException JavaDoc(e);
88         }
89         
90         // forward back to entry or to blog if we have no entry
91
String JavaDoc url = null;
92         try
93         {
94             RollerContext rctx = RollerContext.getRollerContext();
95             if (entry != null) {
96                 url = entry.getPermalink();
97             } else {
98                 url = rreq.getWebsite().getURL();
99             }
100             res.sendRedirect(url);
101         }
102         catch (Exception JavaDoc e)
103         {
104             mLogger.error("Unexpected exception",e);
105         }
106
107         return null;
108     }
109 }
110
111
Popular Tags