KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentFieldValue > ContentFieldValueListController


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 JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.SortedMap JavaDoc;
23 import java.util.TreeMap JavaDoc;
24
25
26 /**
27  * <p>Content field value list controller. This class is used to check can user create content field values or not.
28  * </p>
29  * <p><a HREF="ContentFieldValueListController.java.htm"><i>View Source</i></a></p>
30  *
31  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
32  * @version $Revision: 1.3 $ $Date: 2006/03/10 17:10:18 $
33  */

34 public final class ContentFieldValueListController extends ControllerSupport {
35     //~ Methods ================================================================
36
/**
37      * Retrieves locales and puts them into request to use on the page with list of CFV
38      *
39      * @param tilesContext Current tile context
40      * @param request Current request
41      * @param response Current response
42      * @param servletContext Current Servlet Context
43      */

44     public void execute(ComponentContext tilesContext, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, ServletContext JavaDoc servletContext) throws Exception JavaDoc {
45
46         // owner content field ID
47
Long JavaDoc contentFieldId = (Long JavaDoc) request.getAttribute("contentFieldId");
48
49         // acquire list of content field values which belong to this field
50
QueryInfo queryInfo = new QueryInfo();
51         Map JavaDoc queryParameters = new HashMap JavaDoc();
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 JavaDoc cfvList = fieldManager.listContentFieldValues(queryInfo).asList();
57
58         // get lit of available locales
59
List JavaDoc availableLocales = LocaleUtil.getInstance(request.getSession().getServletContext()).getAvailableLocales();
60
61         // construct map
62
SortedMap JavaDoc cfvMap = new TreeMap JavaDoc();
63         for ( Iterator JavaDoc iterator = cfvList.iterator(); iterator.hasNext(); ) {
64             ContentFieldValue cfv = (ContentFieldValue) iterator.next();
65             cfvMap.put(cfv.getContentLocale(), cfv);
66         }
67
68         // add 'null' values for remaining locales
69
for ( Iterator JavaDoc 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