1 16 package com.blandware.atleap.webapp.action.core.actionPage; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.ActionPage; 20 import com.blandware.atleap.model.core.ContentField; 21 import com.blandware.atleap.model.core.ContentFieldValue; 22 import com.blandware.atleap.search.SearchManager; 23 import com.blandware.atleap.service.core.PageManager; 24 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 25 import com.blandware.atleap.webapp.action.core.BaseAction; 26 import com.blandware.atleap.webapp.form.ActionPageForm; 27 import com.blandware.atleap.webapp.util.core.CacheUtil; 28 import com.blandware.atleap.webapp.util.core.WebappConstants; 29 import com.blandware.atleap.webapp.util.core.WebappUtil; 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 import org.apache.struts.action.ActionMessage; 34 import org.apache.struts.action.ActionMessages; 35 import org.apache.struts.config.ModuleConfig; 36 import org.apache.struts.util.ModuleUtils; 37 38 import javax.servlet.http.HttpServletRequest ; 39 import javax.servlet.http.HttpServletResponse ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 43 69 public final class CreateActionPageAction extends BaseAction { 70 79 public ActionForward execute(ActionMapping mapping, ActionForm form, 80 HttpServletRequest request, HttpServletResponse response) throws Exception { 81 82 if ( !isCancelled(request) ) { 83 ActionPageForm actionPageForm = (ActionPageForm) form; 84 85 if ( !WebappUtil.hasCorrectValues(actionPageForm.getTitleMap()) ) { 86 ActionMessages errors = new ActionMessages(); 88 errors.add("title", new ActionMessage("core.commons.errors.required", getMessage(request, "core.page.form.title"))); 89 saveErrors(request, errors, false); 90 saveToken(request); 91 return mapping.getInputForward(); 92 } 93 94 String uri = actionPageForm.getUri(); 96 ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request, getServlet().getServletContext()); 97 String prefix = moduleConfig.getPrefix(); 98 if ( log.isDebugEnabled() ) { 99 log.debug("Prefix: " + prefix); 100 } 101 102 String actionPath = new String (); 103 actionPath = prefix + uri; 104 105 if ( log.isDebugEnabled() ) { 106 log.debug("Searching for action with path=" + actionPath); 107 } 108 109 if ( moduleConfig.findActionConfig(actionPath) == null ) { 110 if ( log.isDebugEnabled() ) { 112 log.debug("Action with uri '" + actionPath + "' does not exist"); 113 } 114 ActionMessages errors = new ActionMessages(); 115 errors.add("actionPageIncorrectUri", new ActionMessage("core.actionPage.errors.incorrectUri")); 116 saveErrors(request, errors); 117 saveToken(request); 118 return mapping.getInputForward(); 119 } 120 121 ActionPage actionPage = new ActionPage(); 122 WebappUtil.copyProperties(actionPage, actionPageForm, request); 123 actionPage.setTitle(actionPageForm.getTitleMap()); 124 actionPage.setDescription(actionPageForm.getDescriptionMap()); 125 actionPage.setKeywords(actionPageForm.getKeywordsMap()); 126 127 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 128 Long actionPageId = null; 129 try { 130 actionPageId = pageManager.createActionPage(actionPage); 131 132 if ( actionPage.getActive().booleanValue() ) { 133 SearchManager searchManager = SearchManager.getInstance(request.getSession().getServletContext()); 135 searchManager.reIndexPage(actionPage, request); 136 } 137 138 CacheUtil cacheUtil = CacheUtil.getInstance(request); 140 141 ContentField titleField = (ContentField) actionPage.getContentFieldsMap().get("title"); 143 List titleValues = titleField.getContentFieldValues(); 144 for ( Iterator i = titleValues.iterator(); i.hasNext(); ) { 145 ContentFieldValue fieldValue = (ContentFieldValue) i.next(); 146 String content = fieldValue.getSimpleValue(); 148 CacheUtil.CFVData cfvData = new CacheUtil.CFVData(content, titleField.getId(), titleField.getType(), fieldValue.getId()); 149 cacheUtil.putPageFieldValueInCache(cfvData, actionPage.getUri(), titleField.getIdentifier(), fieldValue.getContentLocale().getIdentifier()); 150 } 151 152 ContentField descriptionField = (ContentField) actionPage.getContentFieldsMap().get("description"); 154 List descriptionValues = descriptionField.getContentFieldValues(); 155 for ( Iterator i = descriptionValues.iterator(); i.hasNext(); ) { 156 ContentFieldValue fieldValue = (ContentFieldValue) i.next(); 157 String content = fieldValue.getSimpleValue(); 159 CacheUtil.CFVData cfvData = new CacheUtil.CFVData(content, descriptionField.getId(), descriptionField.getType(), fieldValue.getId()); 160 cacheUtil.putPageFieldValueInCache(cfvData, actionPage.getUri(), descriptionField.getIdentifier(), fieldValue.getContentLocale().getIdentifier()); 161 } 162 163 ContentField keywordsField = (ContentField) actionPage.getContentFieldsMap().get("keywords"); 165 List keywordsValues = keywordsField.getContentFieldValues(); 166 for ( Iterator i = keywordsValues.iterator(); i.hasNext(); ) { 167 ContentFieldValue fieldValue = (ContentFieldValue) i.next(); 168 String content = fieldValue.getSimpleValue(); 170 CacheUtil.CFVData cfvData = new CacheUtil.CFVData(content, keywordsField.getId(), keywordsField.getType(), fieldValue.getId()); 171 cacheUtil.putPageFieldValueInCache(cfvData, actionPage.getUri(), keywordsField.getIdentifier(), fieldValue.getContentLocale().getIdentifier()); 172 } 173 174 } catch ( BeanAlreadyExistsException e ) { 175 ActionMessages errors = new ActionMessages(); 177 errors.add("actionPageAlreadyExists", new ActionMessage("core.actionPage.errors.alreadyExists")); 178 saveErrors(request, errors); 179 saveToken(request); 180 return mapping.getInputForward(); 181 } 182 request.getSession().setAttribute(WebappConstants.ACTION_PAGE_ID_KEY, actionPageId); 183 return mapping.findForward("viewActionPage"); 184 } else { 185 return mapping.findForward("listActionPages"); 186 } 187 } 188 } | Popular Tags |