1 package com.blandware.atleap.webapp.action.core.contentField; 2 3 import com.blandware.atleap.common.Constants; 4 import com.blandware.atleap.model.core.*; 5 import com.blandware.atleap.service.core.LookupManager; 6 import com.blandware.atleap.webapp.util.core.WebappUtil; 7 import org.apache.struts.tiles.ComponentContext; 8 import org.apache.struts.tiles.ControllerSupport; 9 import org.springframework.context.ApplicationContext; 10 import org.springframework.web.context.support.WebApplicationContextUtils; 11 12 import javax.servlet.ServletContext ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 import java.util.*; 16 17 18 26 public final class ContentFieldListController extends ControllerSupport { 27 36 public void execute(ComponentContext tilesContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) 37 throws Exception { 38 39 Long ownerId = (Long ) request.getAttribute("ownerId"); 40 if ( ownerId != null ) { 41 ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 42 LookupManager lookupManager = (LookupManager) applicationContext.getBean(Constants.LOOKUP_MANAGER_BEAN); 43 Localizable owner = lookupManager.retrieveLocalizable(ownerId); 44 45 if (owner instanceof ActionPage) { 46 Set identifiers = WebappUtil.getOverridableFieldIdentifiers(owner, request); 47 Map overridenAPFields = new HashMap(); 48 List fields = owner.getContentFields(); 49 for (int i = 0; i < fields.size(); i++) { 50 ContentField field = (ContentField) fields.get(i); 51 String identifier = field.getIdentifier(); 52 int k = identifier.indexOf('['); 53 String identifierWithoutIndex; 54 if (k != -1) { 55 identifierWithoutIndex = identifier.substring(0, k); 56 } else { 57 identifierWithoutIndex = identifier; 58 } 59 overridenAPFields.put(identifier, new Boolean (identifiers.contains(identifierWithoutIndex))); 60 } 61 request.setAttribute("overridenAPFields", overridenAPFields); 62 } 63 64 if (owner instanceof Layout) { 65 Set identifiers = WebappUtil.getOverridableFieldIdentifiers(owner, request); 66 Map overridenLayoutFields = new HashMap(); 67 List fields = owner.getContentFields(); 68 for (int i = 0; i < fields.size(); i++) { 69 ContentField field = (ContentField) fields.get(i); 70 String identifier = field.getIdentifier(); 71 int k = identifier.indexOf('['); 72 String identifierWithoutIndex; 73 if (k != -1) { 74 identifierWithoutIndex = identifier.substring(0, k); 75 } else { 76 identifierWithoutIndex = identifier; 77 } 78 overridenLayoutFields.put(identifier, new Boolean (identifiers.contains(identifierWithoutIndex))); 79 } 80 request.setAttribute("overridenLayoutFields", overridenLayoutFields); 81 } 82 83 if ( owner != null ) { 84 Set identifiers = null; 85 if ( owner instanceof ContentPage || (owner instanceof ActionPage && !request.isUserInRole("core-contentField-create") && !request.isUserInRole("core-contentField-update")) ) { 86 identifiers = WebappUtil.getOverridableFieldIdentifiers(owner, request); 87 if ( identifiers != null && !identifiers.isEmpty() ) { 88 request.setAttribute("canCreateOrUpdate", "true"); 89 } 90 } else if ( owner instanceof Layout && !request.isUserInRole("core-contentField-create") && !request.isUserInRole("core-contentField-update") ) { 91 Layout ownerLayout = (Layout) owner; 92 identifiers = WebappUtil.getIndexedFieldIdentifiers(ownerLayout.getDefinition(), request); 93 if (identifiers == null) { 94 identifiers = new TreeSet(); 95 } 96 identifiers.addAll(WebappUtil.getOverridableFieldIdentifiers(ownerLayout, request)); 97 if ( identifiers != null && !identifiers.isEmpty() ) { 98 request.setAttribute("canCreateOrUpdate", "true"); 99 } 100 } else { 101 if ( request.isUserInRole("core-contentField-create") || request.isUserInRole("core-contentField-update") ) { 104 request.setAttribute("canCreateOrUpdate", "true"); 105 } 106 } 107 } 108 } 109 } 110 } 111 | Popular Tags |