1 16 package com.blandware.atleap.webapp.action.core.contentField; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.*; 20 import com.blandware.atleap.service.core.ContentFieldManager; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.ContentFieldForm; 23 import com.blandware.atleap.webapp.util.core.LocaleUtil; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import com.blandware.atleap.webapp.util.core.WebappUtil; 26 import org.apache.commons.validator.GenericValidator; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessage; 31 import org.apache.struts.action.ActionMessages; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import java.util.Collection ; 36 import java.util.List ; 37 import java.util.Set ; 38 39 59 public final class ViewContentFieldAction extends BaseAction { 60 69 public ActionForward execute(ActionMapping mapping, ActionForm form, 70 HttpServletRequest request, HttpServletResponse response) throws Exception { 71 72 ContentFieldForm contentFieldForm = (ContentFieldForm) form; 73 74 String redirectUrl = request.getParameter("redirectUrl"); 76 if ( !GenericValidator.isBlankOrNull(redirectUrl) ) { 77 request.getSession().setAttribute(WebappConstants.REDIRECT_URL_KEY, redirectUrl); 79 } else if ( !GenericValidator.isBlankOrNull(contentFieldForm.getOwnerId()) ) { 80 request.getSession().removeAttribute(WebappConstants.REDIRECT_URL_KEY); 82 } else { 83 } 85 86 Long contentFieldId = null; 87 if ( !GenericValidator.isBlankOrNull(contentFieldForm.getId()) ) { 88 contentFieldId = Long.valueOf(contentFieldForm.getId()); 89 } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_FIELD_ID_KEY) != null ) { 90 contentFieldId = (Long ) request.getSession().getAttribute(WebappConstants.CONTENT_FIELD_ID_KEY); 91 } else { 92 93 Long ownerId = null; 94 if ( contentFieldForm.getOwnerId() != null && contentFieldForm.getOwnerId().length() > 0 ) { 95 ownerId = Long.valueOf(contentFieldForm.getOwnerId()); 96 } else { 97 if ( log.isWarnEnabled() ) { 98 log.warn("Missing owner ID. Returning to index..."); 99 } 100 return mapping.findForward("admin"); 101 } 102 103 request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, ownerId); 104 105 if ( log.isWarnEnabled() ) { 106 log.warn("Missing content field ID. Returning to list..."); 107 } 108 109 return mapping.findForward("listContentFields"); 110 } 111 112 ContentFieldManager contentFieldManager = (ContentFieldManager) getBean(Constants.CONTENT_FIELD_MANAGER_BEAN); 113 ContentField contentField = contentFieldManager.retrieveContentField(contentFieldId); 114 if ( contentField == null ) { 115 ActionMessages errors = new ActionMessages(); 117 errors.add("contentFieldNotFound", new ActionMessage("core.contentField.errors.notFound")); 118 saveErrors(request, errors); 119 return mapping.findForward("listContentFields"); 120 } 121 122 String fieldIdentifier = contentField.getIdentifier(); 123 int k = fieldIdentifier.indexOf('['); 124 String index = null; 125 if ( k != -1 ) { 126 index = fieldIdentifier.substring(k + 1, fieldIdentifier.indexOf(']', k)); 127 fieldIdentifier = fieldIdentifier.substring(0, k); 128 contentFieldForm.setIdentifier(fieldIdentifier); 129 contentFieldForm.setIndex(index); 130 } 131 132 List contentFieldValues = contentField.getContentFieldValues(); 134 int cfvSize = contentFieldValues == null ? 0 : contentFieldValues.size(); 135 136 Collection contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales(); 137 int clSize = contentLocales == null ? 0 : contentLocales.size(); 138 139 if ( cfvSize == clSize ) { 140 request.setAttribute("isCFVCreate", Boolean.FALSE); 141 } else { 142 request.setAttribute("isCFVCreate", Boolean.TRUE); 143 } 144 145 request.setAttribute("contentField", contentField); 146 147 Localizable owner = contentField.getOwner(); 149 String ownerInfo = WebappUtil.getLocalizableInfo(owner, request); 150 request.getSession().setAttribute(WebappConstants.OWNER_INFO_KEY, ownerInfo); 151 152 boolean canUpdateCF = request.isUserInRole("core-contentField-update"); 153 boolean canUpdateOverridenCF = request.isUserInRole("core-contentField-updateOverriden"); 154 boolean canUpdateIndexedCF = request.isUserInRole("core-contentField-updateIndexed"); 155 boolean allowedIndexedField = index != null && !index.equalsIgnoreCase("0"); 156 157 Set identifiers = WebappUtil.getOverridableFieldIdentifiers(owner, request); 158 boolean overridenField = identifiers.contains(fieldIdentifier); 159 160 if ( canUpdateCF || (owner instanceof ContentPage && canUpdateOverridenCF) || (owner instanceof ActionPage && canUpdateOverridenCF && overridenField) || (owner instanceof Layout && ((canUpdateIndexedCF && allowedIndexedField) || (canUpdateOverridenCF && overridenField))) ) { 161 request.setAttribute("updateAllowed", "true"); 162 } 163 164 saveToken(request); 165 return mapping.findForward("viewContentField"); 166 } 167 } | Popular Tags |