KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Created on Oct 21, 2003
20  */

21 package org.apache.roller.ui.authoring.struts.actions;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25
26 import org.apache.struts.action.Action;
27 import org.apache.struts.action.ActionError;
28 import org.apache.struts.action.ActionErrors;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.roller.model.RollerFactory;
33 import org.apache.roller.model.WeblogManager;
34 import org.apache.roller.pojos.PermissionsData;
35 import org.apache.roller.pojos.WeblogCategoryData;
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 import org.apache.roller.ui.authoring.struts.formbeans.WeblogCategoryFormEx;
40 import org.apache.roller.ui.core.RequestConstants;
41 import org.apache.roller.RollerException;
42
43 /**
44  * @struts.action path="/roller-ui/authoring/categorySave" name="weblogCategoryFormEx"
45  * validate="true" input="/roller-ui/authoring/categoryEdit.do"
46  *
47  * @author Dave Johnson
48  */

49 public class CategorySaveAction extends Action
50 {
51     public ActionForward execute(
52         ActionMapping mapping,
53         ActionForm actionForm,
54         HttpServletRequest JavaDoc request,
55         HttpServletResponse JavaDoc response)
56         throws Exception JavaDoc
57     {
58         ActionForward forward = mapping.findForward("categories");
59         WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
60         RollerRequest rreq = RollerRequest.getRollerRequest(request);
61         WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
62
63         WeblogCategoryData cd = null;
64         if (null != form.getId() && !form.getId().trim().equals(""))
65         {
66             cd = wmgr.getWeblogCategory(form.getId());
67         }
68         else
69         {
70             cd = new WeblogCategoryData();
71             String JavaDoc pid = form.getParentId();
72             WeblogCategoryData parentCat = wmgr.getWeblogCategory(pid);
73             cd.setWebsite(parentCat.getWebsite());
74             cd.setParent(parentCat);
75         }
76
77         RollerSession rses = RollerSession.getRollerSession(request);
78         if (cd.getWebsite().hasUserPermissions(
79             rses.getAuthenticatedUser(), PermissionsData.AUTHOR))
80         {
81             form.copyTo(cd, request.getLocale());
82             try {
83                 wmgr.saveWeblogCategory(cd);
84                 RollerFactory.getRoller().flush();
85                 
86                 // notify caches of object invalidation
87
CacheManager.invalidate(cd);
88             } catch (RollerException re) {
89                 ActionErrors errors = new ActionErrors();
90                 errors.add(ActionErrors.GLOBAL_ERROR,
91                     new ActionError("error.untranslated", re.getMessage()));
92                 saveErrors(request, errors);
93             }
94         }
95         else
96         {
97             ActionErrors errors = new ActionErrors();
98             errors.add(null, new ActionError("error.permissions.deniedSave"));
99             saveErrors(request, errors);
100             forward = mapping.findForward("access-denied");
101         }
102         request.setAttribute(
103             RequestConstants.WEBLOGCATEGORY_ID, cd.getParent().getId());
104         return forward;
105     }
106 }
107
Popular Tags