KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > actions > my > EditBlogThemeFormAction


1 /*
2  * $Id: EditBlogThemeFormAction.java,v 1.11 2005/01/17 21:35:45 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.web.actions.my;
27
28 import java.io.File JavaDoc;
29 import java.io.FileFilter JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 import org.apache.commons.lang.StringUtils;
35
36 import com.j2biz.blogunity.BlogunityManager;
37 import com.j2biz.blogunity.dao.BlogDAO;
38 import com.j2biz.blogunity.exception.BlogunityException;
39 import com.j2biz.blogunity.i18n.I18N;
40 import com.j2biz.blogunity.i18n.I18NStatusFactory;
41 import com.j2biz.blogunity.pojo.Blog;
42 import com.j2biz.blogunity.util.BlogUtils;
43 import com.j2biz.blogunity.web.ActionResultFactory;
44 import com.j2biz.blogunity.web.IActionResult;
45
46 /**
47  * @author michelson
48  * @version $$
49  * @since 0.1
50  *
51  *
52  */

53 public class EditBlogThemeFormAction extends MyAbstractAction {
54
55     private static final IActionResult THEME_FORM_FORWARD = ActionResultFactory
56             .buildForward("/jsp/my/editBlogThemeForm.jsp");
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see com.j2biz.blogunity.web.actions.AbstractAction#execute(javax.servlet.http.HttpServletRequest,
62      * javax.servlet.http.HttpServletResponse)
63      */

64     public IActionResult execute(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
65             throws BlogunityException {
66
67         String JavaDoc blogId = request.getParameter("id");
68
69         if (StringUtils.isEmpty(blogId))
70                 throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ID_NOT_SETTED,
71                         "Blog"));
72
73         if (!(BlogunityManager.getSystemConfiguration().isThemeEditingAllowed() || user
74                 .isAdministrator())) { throw new BlogunityException(I18NStatusFactory
75                 .create(I18N.ERRORS.THEME_EDITING_NOT_ALLOWED)); }
76
77         BlogDAO dao = new BlogDAO();
78         Blog blog = dao.getBlogByID(new Long JavaDoc(blogId));
79
80         // BUGFIX [BGU-18]
81
if (user.getId().longValue() != blog.getFounder().getId().longValue()
82                 && !user.isAdministrator()) { throw new BlogunityException(I18NStatusFactory
83                 .create(I18N.ERRORS.USER_NOT_AUTHORIZED_FOR_EXECUTION)); }
84
85         File JavaDoc blogsDir = BlogunityManager.getSystemConfiguration().getBlogsDirectory();
86         File JavaDoc blogThemeDir = new File JavaDoc(blogsDir, blog.getUrlName() + "/theme");
87
88         if (!blogThemeDir.exists() || !blogThemeDir.isDirectory() || !blogThemeDir.canRead()
89                 || !blogThemeDir.canWrite()) { throw new BlogunityException(I18NStatusFactory
90                 .create(I18N.ERRORS.THEME_READ_ERROR, blog.getUrlName())); }
91
92         File JavaDoc[] themeFiles = blogThemeDir.listFiles(new FileFilter JavaDoc() {
93             public boolean accept(File JavaDoc f) {
94                 //FIXME this filter should be rewritten!
95
String JavaDoc name = f.getName();
96                 if (f.isFile()
97                         && (name.endsWith(".vm") || name.endsWith(".css") || name.endsWith(".jpg")
98                                 || name.endsWith(".jpeg") || name.endsWith(".gif") || name
99                                 .endsWith(".png"))) return true;
100                 return false;
101
102             }
103         });
104
105         File JavaDoc[] themeDirs = BlogUtils.getInstance().getThemeDirectories();
106
107         request.setAttribute("blog", blog);
108         request.setAttribute("themeFiles", themeFiles);
109         request.setAttribute("themeDirs", themeDirs);
110
111         navigationStack.push(ActionResultFactory.buildRedirect(I18N.MESSAGES.NAVI_EDIT_BLOG_THEME,
112                 currentActionPath));
113
114         return THEME_FORM_FORWARD;
115     }
116
117 }
Popular Tags