| 1 25 26 package com.j2biz.blogunity.web.actions.my; 27 28 import java.io.File ; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import org.apache.commons.lang.StringUtils; 34 35 import com.j2biz.blogunity.BlogunityManager; 36 import com.j2biz.blogunity.IConstants; 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.pojo.SystemConfiguration; 43 import com.j2biz.blogunity.util.ResourceUtils; 44 import com.j2biz.blogunity.web.IActionResult; 45 46 54 public class OverwriteBlogThemeExecAction extends MyAbstractAction { 55 56 62 public IActionResult execute(HttpServletRequest request, HttpServletResponse response) 63 throws BlogunityException { 64 65 String blogId = request.getParameter("id"); 66 if (StringUtils.isEmpty(blogId)) { throw new BlogunityException(I18NStatusFactory.create( 67 I18N.ERRORS.ID_NOT_SETTED, "blog")); } 68 String theme = request.getParameter("theme"); 69 70 if (StringUtils.isEmpty(theme)) { throw new BlogunityException(I18NStatusFactory.create( 71 I18N.ERRORS.NOT_FOUND, "theme")); } 72 73 Blog b = (new BlogDAO()).getBlogByID(Long.parseLong(blogId)); 74 75 if (user.getId().longValue() != b.getFounder().getId().longValue() 76 && !user.isAdministrator()) 77 throw new BlogunityException(I18NStatusFactory 78 .create(I18N.ERRORS.USER_NOT_AUTHORIZED_FOR_EXECUTION)); 79 80 File requestedThemeDir = new File (BlogunityManager 81 .getRealPath(IConstants.BLOG_THEMES_DIRECTORY), theme); 82 83 if (!requestedThemeDir.exists() || !requestedThemeDir.canRead() 84 || requestedThemeDir.list().length <= 0) { throw new BlogunityException( 85 I18NStatusFactory.create(I18N.ERRORS.READ_DIRECTORY, requestedThemeDir 86 .getAbsolutePath())); } 87 88 SystemConfiguration config = BlogunityManager.getSystemConfiguration(); 89 File blogsDir = config.getBlogsDirectory(); 90 91 File oldThemeDir = new File (blogsDir, b.getUrlName() + "/theme"); 93 ResourceUtils.removeDirectory(oldThemeDir); 94 95 boolean result = oldThemeDir.mkdir(); 97 if (!result) { throw new BlogunityException(I18NStatusFactory.create( 98 I18N.ERRORS.READ_DIRECTORY, oldThemeDir.getAbsolutePath())); } 99 100 ResourceUtils.copyDirectory(requestedThemeDir, oldThemeDir); 102 103 navigationStack.pop(); 104 return navigationStack.peek(); 105 106 } 107 } | Popular Tags |