KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > browser > BrowseLinkableItemsAction


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.browser;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.model.core.Page;
21 import com.blandware.atleap.service.core.PageManager;
22 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction;
23 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid;
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.Globals;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.ListIterator JavaDoc;
37 import java.util.Locale JavaDoc;
38 import java.util.Map JavaDoc;
39
40 /**
41  * <p>Returns browser page with allows to select a linkable item
42  * </p>
43  * <p><a HREF="BrowseLinkableItemsAction.java.htm"><i>View Source</i></a></p>
44  * <p/>
45  *
46  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
47  * @version $Revision: 1.13 $ $Date: 2006/03/10 17:10:17 $
48  * @struts.action path="/core/browser/browseLinkableItems"
49  * validate="false"
50  * roles="core-browser-linkableItems"
51  * @struts.action-forward name="showBrowser"
52  * path=".core.browser.linkableItemsBrowser"
53  */

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

65     public ActionForward execute(ActionMapping mapping, ActionForm form,
66                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
67
68         // check for locale suffix
69
String JavaDoc localeSuffix = null;
70         if ( !GenericValidator.isBlankOrNull(request.getParameter("editorAreaLanguage")) ) {
71             localeSuffix = request.getParameter("editorAreaLanguage");
72             request.getSession().setAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY, localeSuffix);
73         } else {
74             localeSuffix = (String JavaDoc) request.getSession().getAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY);
75         }
76
77         Grid liGrid = getGridByName(WebappConstants.BROWSER_LINKABLE_ITEMS_GRID, request.getSession());
78         if ( liGrid == null ) {
79             liGrid = new Grid(WebappConstants.BROWSER_LINKABLE_ITEMS_GRID);
80         }
81
82         saveGrid(liGrid, request.getSession());
83
84         QueryInfo queryInfo = new QueryInfo();
85         queryInfo.setWhereClause(liGrid.getWhereClause());
86
87         Map JavaDoc queryParameters = new HashMap JavaDoc();
88         Locale JavaDoc locale = (Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY);
89         queryParameters.put("localeIdentifier", locale.getLanguage());
90         queryInfo.setQueryParameters(queryParameters);
91
92         PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
93         List JavaDoc linkableItems = pageManager.listLinkableItems(queryInfo).asList();
94
95         for ( ListIterator JavaDoc i = linkableItems.listIterator(); i.hasNext(); ) {
96             Page linkableItem = (Page) i.next();
97             Page newItem = new Page() {
98             };
99             WebappUtil.copyProperties(newItem, linkableItem, request);
100             String JavaDoc uri = WebappUtil.getActionMappingURL(linkableItem.getUri(), null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE, localeSuffix);
101             if ( uri.startsWith("/") ) {
102                 uri = uri.substring(1);
103             }
104             newItem.setUri(uri);
105             i.set(newItem);
106         }
107
108         request.setAttribute(WebappConstants.BROWSER_LINKABLE_ITEMS_COLLECTION_KEY, linkableItems);
109
110         return mapping.findForward("showBrowser");
111     }
112 }
Popular Tags