1 package com.blandware.atleap.webapp.action.core.contentFieldValue; 2 3 import com.blandware.atleap.common.Constants; 4 import com.blandware.atleap.common.util.QueryInfo; 5 import com.blandware.atleap.model.core.ContentFieldValue; 6 import com.blandware.atleap.model.core.ContentLocale; 7 import com.blandware.atleap.service.core.ContentFieldManager; 8 import com.blandware.atleap.webapp.util.core.LocaleUtil; 9 import com.blandware.atleap.webapp.util.core.WebappConstants; 10 import org.apache.struts.tiles.ComponentContext; 11 import org.apache.struts.tiles.ControllerSupport; 12 import org.springframework.context.ApplicationContext; 13 import org.springframework.web.context.support.WebApplicationContextUtils; 14 15 import javax.servlet.ServletContext ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.SortedMap ; 23 import java.util.TreeMap ; 24 25 26 34 public final class ContentFieldValueListController extends ControllerSupport { 35 44 public void execute(ComponentContext tilesContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws Exception { 45 46 Long contentFieldId = (Long ) request.getAttribute("contentFieldId"); 48 49 QueryInfo queryInfo = new QueryInfo(); 51 Map queryParameters = new HashMap (); 52 queryParameters.put("contentFieldId", contentFieldId); 53 queryInfo.setQueryParameters(queryParameters); 54 ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 55 ContentFieldManager fieldManager = (ContentFieldManager) applicationContext.getBean(Constants.CONTENT_FIELD_MANAGER_BEAN); 56 List cfvList = fieldManager.listContentFieldValues(queryInfo).asList(); 57 58 List availableLocales = LocaleUtil.getInstance(request.getSession().getServletContext()).getAvailableLocales(); 60 61 SortedMap cfvMap = new TreeMap (); 63 for ( Iterator iterator = cfvList.iterator(); iterator.hasNext(); ) { 64 ContentFieldValue cfv = (ContentFieldValue) iterator.next(); 65 cfvMap.put(cfv.getContentLocale(), cfv); 66 } 67 68 for ( Iterator i = availableLocales.iterator(); i.hasNext(); ) { 70 ContentLocale locale = (ContentLocale) i.next(); 71 if ( !cfvMap.containsKey(locale) ) { 72 cfvMap.put(locale, null); 73 } 74 } 75 76 request.setAttribute(WebappConstants.CONTENT_FIELD_VALUES_COLLECTION_KEY, cfvMap); 77 } 78 } 79 | Popular Tags |