1 16 package com.blandware.atleap.webapp.action.core.contentPage; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.common.util.PartialCollection; 20 import com.blandware.atleap.model.core.ContentPage; 21 import com.blandware.atleap.model.core.Layout; 22 import com.blandware.atleap.service.core.LayoutManager; 23 import com.blandware.atleap.service.core.PageManager; 24 import com.blandware.atleap.webapp.action.core.BaseAction; 25 import com.blandware.atleap.webapp.form.ContentPageForm; 26 import com.blandware.atleap.webapp.util.core.LocaleUtil; 27 import com.blandware.atleap.webapp.util.core.WebappConstants; 28 import com.blandware.atleap.webapp.util.core.WebappUtil; 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.struts.action.ActionMessage; 33 import org.apache.struts.action.ActionMessages; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 40 59 public final class CallUpdateContentPageAction extends BaseAction { 60 69 public ActionForward execute(ActionMapping mapping, ActionForm form, 70 HttpServletRequest request, HttpServletResponse response) throws Exception { 71 72 if ( isCancelled(request) ) { 73 return mapping.findForward("listContentPages"); 74 } 75 76 if (!request.isUserInRole("core-contentPage-update")) { 77 response.sendError(HttpServletResponse.SC_FORBIDDEN); 78 return null; 79 } 80 81 ContentPageForm contentPageForm = (ContentPageForm) form; 82 Long contentPageId = null; 83 if ( contentPageForm.getId() != null ) { 84 contentPageId = Long.valueOf(contentPageForm.getId()); 85 } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY) != null ) { 86 contentPageId = (Long ) request.getSession().getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY); 87 } else { 88 if ( log.isWarnEnabled() ) { 89 log.warn("Missing content page ID. Returning to list..."); 90 } 91 return mapping.findForward("listContentPages"); 92 } 93 94 PageManager contentPageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 95 ContentPage contentPage = contentPageManager.retrieveContentPage(contentPageId); 96 if ( contentPage == null ) { 97 ActionMessages errors = new ActionMessages(); 99 errors.add("contentPageNotFound", new ActionMessage("core.contentPage.errors.notFound")); 100 saveErrors(request, errors); 101 return mapping.findForward("listContentPages"); 102 } 103 WebappUtil.copyProperties(contentPageForm, contentPage, request); 104 contentPageForm.setLayoutId(String.valueOf(contentPage.getLayout().getId())); 105 contentPageForm.setTitleMap(contentPage.getTitle()); 106 contentPageForm.setDescriptionMap(contentPage.getDescription()); 107 contentPageForm.setKeywordsMap(contentPage.getKeywords()); 108 109 String uri = contentPage.getUri(); 110 if ( uri.startsWith(WebappConstants.CONTENT_PAGES_URI_PREFIX) ) { 111 uri = uri.substring(WebappConstants.CONTENT_PAGES_URI_PREFIX.length()); 112 } 113 contentPageForm.setUri(uri); 114 115 LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN); 117 PartialCollection layouts = null; 118 layouts = layoutManager.listLayouts(null); 119 120 if ( layouts != null ) { 121 for ( Iterator i = layouts.iterator(); i.hasNext(); ) { 122 Layout layout = (Layout) i.next(); 123 if ( layout.getCpDefinition() == null || layout.getCpDefinition().length() == 0 ) { 124 i.remove(); 125 } 126 } 127 } 128 129 if ( layouts == null || layouts.size() == 0 ) { 130 saveToken(request); 131 ActionMessages errors = new ActionMessages(); 132 errors.add("noLayoutFound", new ActionMessage("core.contentPage.errors.noLayoutFound")); 133 saveErrors(request, errors); 134 return mapping.findForward("listContentPages"); 135 } 136 137 request.getSession().setAttribute(WebappConstants.LAYOUT_COLLECTION_KEY, layouts); 138 139 List contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales(); 140 141 request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales); 142 143 saveToken(request); 145 return mapping.findForward("updateContentPage"); 146 } 147 148 } | Popular Tags |