KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentLocale > ListContentLocalesAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.contentLocale;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.service.core.ContentLocaleManager;
21 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction;
22 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid;
23 import com.blandware.atleap.webapp.taglib.core.grid.util.SortField;
24 import com.blandware.atleap.webapp.util.core.LocaleUtil;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * <p>Forward to the page with list of content locales
36  * </p>
37  * <p><a HREF="ListContentLocalesAction.java.htm"><i>View Source</i></a></p>
38  * <p/>
39  *
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.11 $ $Date: 2006/03/10 17:10:19 $
42  * @struts.action path="/core/contentLocale/list"
43  * name="contentLocaleForm"
44  * validate="false"
45  * roles="core-contentLocale-list"
46  * @struts.action-forward name="listContentLocales"
47  * path=".core.contentLocale.list"
48  */

49 public final class ListContentLocalesAction extends BaseGridAction {
50     /**
51      * @param mapping The ActionMapping used to select this instance
52      * @param form The optional ActionForm bean for this request (if any)
53      * @param request The HTTP request we are proceeding
54      * @param response The HTTP response we are creating
55      * @return an ActionForward instance describing where and how
56      * control should be forwarded, or null if response
57      * has already been completed
58      */

59     public ActionForward execute(ActionMapping mapping, ActionForm form,
60                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
61
62         Grid clGrid = getGridByName(WebappConstants.CONTENT_LOCALES_GRID, request.getSession());
63
64         if ( clGrid == null ) {
65             clGrid = new Grid(WebappConstants.CONTENT_LOCALES_GRID);
66         }
67
68         // catch parameters related to sorting
69
String JavaDoc sortFieldName = request.getParameter("sortField");
70         String JavaDoc orderByClause = new String JavaDoc();
71         if ( WebappConstants.CONTENT_LOCALES_GRID.equals(request.getParameter("gridName")) && sortFieldName != null && sortFieldName.length() > 0 ) {
72             SortField sortField = clGrid.getSortFieldByFieldName(sortFieldName);
73             if ( sortField == null ) {
74                 sortField = new SortField(sortFieldName, SortField.ORDER_DESCENDING);
75                 clGrid.addSortField(sortField);
76             } else {
77                 sortField.reverseOrder();
78                 clGrid.addSortField(sortField);
79             }
80             orderByClause = clGrid.getOrderByClause();
81             clGrid.getSortFieldByFieldName(sortFieldName).reverseOrder();
82         }
83
84         saveGrid(clGrid, request.getSession());
85
86         QueryInfo queryInfo = new QueryInfo();
87         queryInfo.setWhereClause(clGrid.getWhereClause());
88         queryInfo.setOrderByClause(orderByClause);
89
90         ContentLocaleManager contentLocaleManager = (ContentLocaleManager) getBean(Constants.CONTENT_LOCALE_MANAGER_BEAN);
91         List JavaDoc contentLocales = contentLocaleManager.listContentLocales(queryInfo).asList();
92
93         request.setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
94
95         // save number of available locales
96
request.setAttribute(WebappConstants.AVAILABLE_LOCALES_LIST_SIZE_KEY, new Integer JavaDoc(LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales().size()));
97
98         // save transaction token in request
99
saveToken(request);
100         return mapping.findForward("listContentLocales");
101     }
102 }
Popular Tags