source: trunk/www/admin/news/index.jsp @ 5426

Last change on this file since 5426 was 5426, checked in by Nicklas Nordborg, 12 years ago

References #1514: Fix character encoding of jsp files

  • Add pageEncoding="UTF-8" to all JSP files.
  • Add @charset="UTF-8"; to all CSS files.
  • Add charset="UTF-8" to all <script> tags

This should at least make Eclipse happy and hopefully allow other editors to automatically select the correct encoding.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.1 KB
Line 
1<%-- $Id: index.jsp 5426 2010-09-24 09:18:50Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Include"
31  import="net.sf.basedb.core.News"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.MultiPermissions"
36  import="net.sf.basedb.core.PermissionDeniedException"
37  import="net.sf.basedb.core.ItemAlreadyExistsException"
38  import="net.sf.basedb.util.RemovableUtil"
39  import="net.sf.basedb.clients.web.Base"
40  import="net.sf.basedb.clients.web.WebException"
41  import="net.sf.basedb.util.Values"
42  import="net.sf.basedb.clients.web.util.HTML"
43  import="net.sf.basedb.util.formatter.Formatter"
44  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
45  import="java.util.Date"
46  import="java.util.Set"
47  import="java.util.HashSet"
48  import="java.util.List"
49  import="java.util.ArrayList"
50  import="java.util.Collections"
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%!
54  private static final ItemContext defaultContext = Base.createDefaultContext("newsDate,id", "all");
55  static
56  {
57    defaultContext.setSortDirection(ItemContext.SortDirection.DESC);
58  }
59  private static final Item itemType = Item.NEWS;
60%>
61<%
62final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
63final String ID = sc.getId();
64final String cmd = request.getParameter("cmd");
65final String root = request.getContextPath()+"/";
66final String mode = request.getParameter("mode");
67final String callback = request.getParameter("callback");
68final String itemId = request.getParameter("item_id");
69final String listPage = "list_news.jsp?ID="+ID
70  +(mode == null ? "" : "&mode="+mode)
71  +(callback == null ? "" : "&callback="+callback)
72  +(itemId == null ? "" : "&item_id="+itemId);
73final String viewPage = "view_news.jsp?ID="+ID;
74final String editPage = "edit_news.jsp?ID="+ID;
75
76String forward = null;
77String redirect = null;
78String message = null;
79DbControl dc = null;
80
81try
82{
83  if (cmd == null || "List".equals(cmd))
84  {
85    // Display the list page without updatinging the current context
86    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
87    redirect = listPage;
88  }
89  else if ("UpdateContext".equals(cmd))
90  {
91    // Display the list page after updating the current context from the request parameters
92    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
93    redirect = listPage;
94  }
95  else if ("LoadContext".equals(cmd))
96  {
97    // Display the list page after loading a saved context
98    int contextId = Values.getInt(request.getParameter("context"));
99    Base.loadContext(sc, contextId, defaultContext);
100    redirect = listPage;
101  }
102
103  else if ("ViewItem".equals(cmd))
104  {
105    // Display the view page for a single item
106    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
107    forward = viewPage;
108  }
109  else if ("EditItem".equals(cmd))
110  {
111    // Display the edit page for a single item (should be opened in a popup)
112    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
113    redirect = editPage;
114  }
115  else if ("NewItem".equals(cmd))
116  {
117    // Display the edit page for a new item (should be opened in a popup)
118    if (!sc.hasPermission(Permission.CREATE, itemType))
119    {
120      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
121    }
122    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
123    cc.setId(0);
124    redirect = editPage;
125  }
126  else if ("UpdateItem".equals(cmd))
127  {
128    // Update the properties on an item (will close the popup)
129    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
130    dc = sc.newDbControl();
131    News news = (News)cc.getObject("item");
132    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
133    Date startDate = dateFormatter.parseString(Values.getStringOrNull(request.getParameter("start_date")));
134    Date newsDate = dateFormatter.parseString(Values.getStringOrNull(request.getParameter("news_date")));
135    if (news == null)
136    {
137      news = News.getNew(dc, startDate, newsDate);
138      message = "News created";
139      dc.saveItem(news);
140    }
141    else
142    {
143      news.setStartDate(startDate);
144      news.setNewsDate(newsDate);
145      dc.reattachItem(news, false);
146      message = "News updated";
147    }
148    news.setName(Values.getStringOrNull(request.getParameter("title")));
149    news.setEndDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("end_date"))));
150    news.setDescription(Values.getStringOrNull(request.getParameter("description")));
151    dc.commit();
152    cc.removeObject("item");
153  }
154  else if ("DeleteItem".equals(cmd))
155  {
156    // Delete a single item and then return to the view page
157    dc = sc.newDbControl();
158    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
159    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
160    dc.commit();
161    redirect = viewPage;
162  }
163  else if ("DeleteItems".equals(cmd))
164  {
165    // Delete all selected items on the list page
166    dc = sc.newDbControl();
167    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
168    int numTotal = cc.getSelected().size();
169    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
170    dc.commit();
171    if (numTotal != numRemoved)
172    {
173      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
174    }
175    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
176  }
177  else if ("RestoreItem".equals(cmd))
178  {
179    // Restore a single item and then return to the view page
180    dc = sc.newDbControl();
181    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
182    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
183    dc.commit();
184    redirect = viewPage;
185  }
186  else if ("RestoreItems".equals(cmd))
187  {
188    // Restore all selected items on the list page
189    dc = sc.newDbControl();
190    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
191    int numTotal = cc.getSelected().size();
192    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
193    dc.commit();
194    if (numTotal != numRemoved)
195    {
196      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
197    }
198    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
199  }
200  else if ("ExportItems".equals(cmd))
201  {
202    // Run an export plugin in a list context
203    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
204    final ItemQuery<News> query = News.getQuery();
205    cc.configureQuery(query, true);
206    cc.setQuery(query);
207    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+news";
208  }
209  else if ("ExportItem".equals(cmd))
210  {
211    // Run an export plugin in single-item context
212    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
213    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+news";
214  }
215  else if ("ImportItems".equals(cmd))
216  {
217    // Run an import plugin in a list context
218    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
219    final ItemQuery<News> query = News.getQuery();
220    cc.configureQuery(query, true);
221    cc.setQuery(query);
222    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+news";
223  }
224  else if ("ImportItem".equals(cmd))
225  {
226    // Run an import plugin in single-item context
227    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
228    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+news";
229  }
230  else if ("RunListPlugin".equals(cmd))
231  {
232    // Run another plugin in a list context
233    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
234    final ItemQuery<News> query = News.getQuery();
235    cc.configureQuery(query, true);
236    cc.setQuery(query);
237    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
238  }
239  else if ("RunPlugin".equals(cmd))
240  {
241    // Run another plugin in single-item context
242    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
243    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
244  }
245  else
246  {
247    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
248  }
249}
250finally
251{
252  if (dc != null) dc.close();
253}
254
255if (forward != null)
256{
257  pageContext.forward(forward);
258}
259else if (redirect != null)
260{
261  response.sendRedirect(redirect);
262}
263else if (message == null)
264{
265  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
266}
267else
268{
269  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
270}
271%>
272
Note: See TracBrowser for help on using the repository browser.