1 2 package org.roller.presentation.website.actions; 3 4 import java.io.IOException ; 5 import java.util.Arrays ; 6 import java.util.List ; 7 8 import javax.servlet.ServletContext ; 9 import javax.servlet.ServletException ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.http.HttpServletResponse ; 12 import org.apache.commons.lang.StringUtils; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.apache.struts.action.ActionError; 17 import org.apache.struts.action.ActionErrors; 18 import org.apache.struts.action.ActionForm; 19 import org.apache.struts.action.ActionForward; 20 import org.apache.struts.action.ActionMapping; 21 import org.apache.struts.actions.DispatchAction; 22 import org.roller.RollerException; 23 import org.roller.RollerPermissionsException; 24 import org.roller.config.RollerRuntimeConfig; 25 import org.roller.model.UserManager; 26 import org.roller.model.WeblogManager; 27 import org.roller.pojos.UserData; 28 import org.roller.pojos.WeblogCategoryData; 29 import org.roller.pojos.WebsiteData; 30 import org.roller.presentation.RollerRequest; 31 import org.roller.presentation.RollerSession; 32 import org.roller.presentation.pagecache.PageCacheFilter; 33 import org.roller.presentation.forms.WebsiteForm; 34 import org.roller.presentation.website.formbeans.WebsiteFormEx; 35 36 37 46 public final class WebsiteFormAction extends DispatchAction 47 { 48 private static Log mLogger = 49 LogFactory.getFactory().getInstance(WebsiteFormAction.class); 50 51 public ActionForward add( 52 ActionMapping mapping, 53 ActionForm actionForm, 54 HttpServletRequest request, 55 HttpServletResponse response) 56 throws IOException , ServletException 57 { 58 return update( mapping, actionForm, request, response ); 59 } 60 61 public ActionForward edit( 63 ActionMapping mapping, 64 ActionForm actionForm, 65 HttpServletRequest request, 66 HttpServletResponse response) 67 throws IOException , ServletException 68 { 69 ActionForward forward = mapping.findForward("editWebsite.page"); 70 try 71 { 72 RollerRequest rreq = RollerRequest.getRollerRequest(request); 73 if ( rreq.isUserAuthorizedToEdit() ) 74 { 75 UserData ud = rreq.getUser(); 76 request.setAttribute("user",ud); 77 78 WebsiteData hd = rreq.getWebsite(); 79 WebsiteForm wf = (WebsiteFormEx)actionForm; 80 wf.copyFrom(hd, request.getLocale()); 81 82 List cd = rreq.getRoller().getWeblogManager() 83 .getWeblogCategories(rreq.getWebsite(), true); 84 request.setAttribute("categories",cd); 85 86 List bcd = rreq.getRoller().getWeblogManager() 87 .getWeblogCategories(rreq.getWebsite(), true); 88 request.setAttribute("bloggerCategories",bcd); 89 90 List pages = rreq.getRoller().getUserManager().getPages(rreq.getWebsite()); 91 request.setAttribute("pages",pages); 92 93 ServletContext ctx = request.getSession().getServletContext(); 94 String editorPages = 95 RollerRuntimeConfig.getProperty("users.editor.pages"); 96 97 List epages = Arrays.asList(StringUtils.split(StringUtils.deleteWhitespace(editorPages), ",")); 98 request.setAttribute("editorPagesList", epages); 99 } 100 else 101 { 102 forward = mapping.findForward("access-denied"); 103 } 104 } 105 catch (Exception e) 106 { 107 throw new ServletException (e); 108 } 109 return forward; 110 } 111 112 113 public ActionForward update( 115 ActionMapping mapping, 116 ActionForm actionForm, 117 HttpServletRequest request, 118 HttpServletResponse response) 119 throws IOException , ServletException 120 { 121 ActionForward forward = mapping.findForward("editWebsite"); 122 try 123 { 124 RollerRequest rreq = RollerRequest.getRollerRequest(request); 125 WeblogManager wmgr = rreq.getRoller().getWeblogManager(); 126 UserManager umgr = rreq.getRoller().getUserManager(); 127 if ( rreq.isUserAuthorizedToEdit() ) 128 { 129 WebsiteFormEx form = (WebsiteFormEx)actionForm; 130 131 if (form.getAllowComments() == null) 133 { 134 form.setAllowComments( Boolean.FALSE ); 135 } 136 if (form.getEmailComments() == null) 137 { 138 form.setEmailComments( Boolean.FALSE ); 139 } 140 if (form.getEnableBloggerApi() == null) 141 { 142 form.setEnableBloggerApi( Boolean.FALSE ); 143 } 144 145 if(!form.getDefaultPageId().equals(form.getWeblogDayPageId())) 146 { 147 WebsiteData wd = umgr.retrieveWebsite(form.getId()); 148 wd.save(); 150 form.setIsEnabled(wd.getIsEnabled()); 152 form.copyTo(wd, request.getLocale()); 153 154 if (form.getDefaultCategoryId() != null) 155 { 156 WeblogCategoryData defaultCat = 157 wmgr.retrieveWeblogCategory(form.getDefaultCategoryId()); 158 wd.setDefaultCategory(defaultCat); 159 } 160 161 if (form.getBloggerCategoryId() != null) 162 { 163 WeblogCategoryData bloggerCat = 164 wmgr.retrieveWeblogCategory(form.getBloggerCategoryId()); 165 wd.setBloggerCategory(bloggerCat); 166 } 167 168 wd.save(); 169 rreq.getRoller().getRefererManager().applyRefererFilters(wd); 170 rreq.getRoller().commit(); 171 172 request.getSession().setAttribute( 173 RollerSession.STATUS_MESSAGE, 174 "Successfully submitted new Weblog templates"); 175 176 request.getSession().setAttribute( 177 RollerRequest.WEBSITEID_KEY,form.getId()); 178 179 PageCacheFilter.removeFromCache( request, wd.getUser() ); 181 182 ServletContext ctx = request.getSession().getServletContext(); 184 String editorPages = 185 RollerRuntimeConfig.getProperty("users.editor.pages"); 186 187 List epages = Arrays.asList(StringUtils.split( 188 StringUtils.deleteWhitespace(editorPages), ",")); 189 request.setAttribute("editorPagesList", epages); 190 } 191 else 192 { 193 request.getSession().setAttribute( 194 RollerSession.ERROR_MESSAGE, 195 "CHANGES REJECTED: Cannot set default page template " 196 +"and day template to same template"); 197 } 198 } 199 else 200 { 201 forward = mapping.findForward("access-denied"); 202 } 203 204 actionForm.reset(mapping,request); 205 } 206 catch (RollerPermissionsException e) 207 { 208 ActionErrors errors = new ActionErrors(); 209 errors.add(null, new ActionError("error.permissions.deniedSave")); 210 saveErrors(request, errors); 211 forward = mapping.findForward("access-denied"); 212 } 213 catch (RollerException re) 214 { 215 mLogger.error("Unexpected exception",re.getRootCause()); 216 throw new ServletException (re); 217 } 218 catch (Exception e) 219 { 220 mLogger.error("Unexpected exception",e); 221 throw new ServletException (e); 222 } 223 return forward; 224 } 225 226 } 227 228 | Popular Tags |