source: trunk/www/main.jsp @ 5478

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

References #1545: Publish news as a rss feed

Added servlet RssNewsFeed to serve rss document. It will cache the current news so it should not be too heavy even if clients update often.

The feed includes all public news and the broadcast message that the admin can set in the Administrate -> Broadcast message dialog.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.1 KB
Line 
1<%-- $Id: main.jsp 5478 2010-11-05 10:38:08Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24  This is the front page of BASE. It displays a login form
25  and some of the relevant news items.
26
27  @param login The value to display in the login input field.
28  @param error An error message that should be displayed
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page pageEncoding="UTF-8" session="false"
34  import="net.sf.basedb.core.Application"
35  import="net.sf.basedb.core.SessionControl"
36  import="net.sf.basedb.core.DbControl"
37  import="net.sf.basedb.core.News"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.util.formatter.Formatter"
45  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
46  import="net.sf.basedb.util.Values"
47  import="java.util.Date"
48%>
49<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
50<%
51final String login = Values.getString(request.getParameter("login"), "");
52final String error = Values.getString(request.getParameter("error"), null);
53final String root = request.getContextPath()+"/";
54
55final SessionControl sc = Base.getSessionControl(pageContext, true);
56final String ID = sc.getId();
57final Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
58final DbControl dc = sc.newDbControl();
59String broadcastTitle = (String)application.getAttribute("broadcast.title");
60String broadcastMessage = (String)application.getAttribute("broadcast.message");
61boolean denyLogin = Boolean.TRUE.equals(application.getAttribute("broadcast.deny-login"));
62ItemResultList<News> news = null;
63try
64{
65  %>
66  <base:page type="default" title="">
67  <base:head scripts="md5.js" styles="login.css">
68    <script language="JavaScript" type="text/javascript">
69    // Set foucs on the login form
70    function init()
71    {
72      setFocus();
73      top.frames['footnote'].location.reload();
74    }
75   
76    // Set the focus on either the login or password field.
77    function setFocus()
78    {
79      frm = document.forms['login'];
80      if (frm.login.value == '' && window.parent.lastLogin) frm.login.value = window.parent.lastLogin;
81      if (frm.encrypt && window.parent.encrypt != undefined) frm.encrypt.checked = window.parent.encrypt;
82      if (frm.login.value == '')
83      {
84        frm.login.focus();
85      }
86      else
87      {
88        frm.password.focus();
89        frm.password.select();
90      }
91    }
92    function saveLogin()
93    {
94      var frm = document.forms['login'];
95      window.parent.lastLogin = frm.login.value;
96     
97      if (frm.encrypt)
98      {
99        window.parent.encrypt = frm.encrypt.checked;
100        if (frm.encrypt.checked)
101        {
102          var password = frm.password.value;
103          var md5password = hex_md5(password);
104          md5password = hex_md5(md5password + ':<%=sc.getChallenge()%>');
105          frm.encrypted_password.value = md5password;
106          frm.password.value = '';
107        }
108      }
109      return true;
110    }
111    function doLogin()
112    {
113      var denyLogin = <%=denyLogin ? "true" : "false"%>;
114      if (denyLogin && !confirm('Login has been disabled by an administrator. Do you want to continue anyway?'))
115      {
116        return false;
117      }
118      saveLogin();
119      var frm = document.forms['login'];
120      frm.submit();
121    }
122    function showLoginForm()
123    {
124      Main.show('loginForm');
125      Main.hide('denyLogin');
126    }
127    </script>
128  </base:head>
129 
130  <base:body onload="init();">
131 
132    <table border=0 cellspacing=5 cellpadding=0 width="80%" align="center">
133    <tr>
134    <td>
135      <br><br>
136      <table class="loginform" width="100%" border="0" align="center">
137      <%
138      if (error != null) 
139      {
140        %>
141        <tr><td colspan="2" align="center"><div class="error"><%=error%></div></td></tr>
142        <%
143      }
144      %>
145      <tr>
146        <td style="vertical-align: middle; width; 25%;">
147          <div align="center">
148            <img src="images/baselogo.png" alt="BASE logo" width=122 height=58>
149          </div>
150        </td>
151        <td style="width: 75%;">
152          <form name="login" action="login.jsp" method="post" onsubmit="doLogin();">
153          <input type="hidden" name="ID" value="<%=ID%>">
154          <input type="hidden" name="nextpage" value="<%=root%>my_base/user/index.jsp">
155          <input type="hidden" name="encrypted_password" value="">
156         
157          <div id="loginForm" <%=denyLogin ? "style=\"display:none;\"" : ""%>>
158          <table border="0" cellspacing="0" cellpadding="2">
159          <tr>
160            <td class="prompt">Login</td>
161            <td><input class="text" type="text" name="login" value="<%=HTML.encodeTags(login)%>" 
162              size="15" maxlength="100"
163              style="width: 120px"></td>
164          </tr>
165          <tr>
166            <td class="prompt">Password</td>
167            <td>
168              <input class="text" type="password" name="password" size="15" maxlength="80"
169                onkeypress="return Forms.submitOnEnter(event, doLogin)"
170                style="width: 120px">
171            </td>
172            <td><base:button image="login.png" 
173              onclick="doLogin();" title="Login" tooltip="<%=HTML.encodeTags(broadcastTitle)%>" /></td>
174          </tr>
175          <%
176          if (Application.isUsingInternalAuthentication())
177          {
178            %>
179            <tr>
180              <td class="prompt">Encrypt password</td>
181              <td>
182                <input type="checkbox" name="encrypt" <%=false ? "" : "checked"%> value="1"><br>
183              </td>
184            </tr>
185            <%
186          }
187          %>
188          <tr>
189            <td colspan="3">
190            <%
191            String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
192            String getAccount = sc.getClientDefaultSetting("server.get.account");
193            if (forgotPassword != null)
194            {
195              %>
196              <base:icon image="bullet.gif" />
197              <a href="javascript:Main.openPopup('info/forgot_password.jsp?ID=<%=ID%>', 'ForgotPassword', 500, 300)" title="Click here if you have forgotten your password">Forgot your password?</a>
198              <%
199            }
200            if (getAccount != null)
201            {
202              %>
203              <base:icon image="bullet.gif" />
204              <a href="javascript:Main.openPopup('info/get_account.jsp?ID=<%=ID%>', 'GetAccount', 500, 300)" title="Click here if you want to get an account on this server">Get an account!</a>
205              <%
206            }
207            %>
208            </td>
209          </tr>
210          </table>
211          </div>
212          <div id="denyLogin" <%=denyLogin ? "style=\"width: 90%; margin-left: 5%;\"" : "style=\"display:none;\""%> class="news">
213            <div class="item">
214            <span class="headline"><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</span><br>
215            <span class="text"><%=HTML.niceFormat(broadcastMessage)%></span>
216            </div>
217            <table>
218              <tr><td><base:button title="Login anyway" onclick="showLoginForm()" 
219                image="login.png" tooltip="At your own risk!"/></td></tr>
220            </table>
221          </div>
222          </form>
223        </td>
224      </tr>
225      </table>
226      <br>
227      <br>
228     
229      <%
230      String aboutServer = sc.getClientDefaultSetting("server.about");
231      if (aboutServer != null)
232      {
233        %>
234        <h3>About this server</h3>
235        <p>
236          <%=aboutServer%>
237        </p>
238        <base:icon image="bullet.gif" />
239        <a href="javascript:Main.openPopup('info/about.jsp?ID=<%=ID%>&page=about', 'About', 500, 350)">More about this server</a>
240        <%
241      }
242      %>
243     
244      <h3>News and announcements <a href="info/news.rss" 
245        title="Subscribe to news from this BASE server"
246        ><base:icon image="rss.png" /></a>
247      </h3>
248      <div id="news" class="news">
249      <%
250      if (broadcastTitle != null)
251      {
252        %>
253        <div class="item"><base:icon image="warning.gif" />
254          <span class="date"><%=dateFormatter.format(new Date())%></span>
255          <span class="headline"><%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %></span><br>
256          <span class="text"><%=HTML.niceFormat(broadcastMessage)%></span>
257        </div>
258        <% 
259      }
260     
261      ItemQuery<News> query = News.getQuery();
262      query.order(Orders.desc(Hql.property("newsDate")));
263      query.order(Orders.desc(Hql.property("id")));
264      query.setCacheResult(true);
265      query.setReturnTotalCount(true);
266      query.setMaxResults(10);
267      news = query.list(dc);
268      for (News n : news)
269      {
270        %>
271        <div class="item">
272          <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
273          <span class="headline"><%=HTML.encodeTags(n.getName())%></span><br>
274          <span class="text"><%=HTML.niceFormat(n.getDescription())%></span>
275        </div>
276        <%
277      }
278      if (news.getTotalCount() > 10)
279      {
280        %>
281        <base:icon image="bullet.gif" /><a href="info/news.jsp" 
282          title="Show older news..."><%=news.getTotalCount()-10%> more</a>
283        <%
284      }
285      %>
286      </div>
287    </td>
288    </tr>
289    </table>
290  </base:body>
291  </base:page>
292  <%
293}
294finally
295{
296  if (dc != null) dc.close();
297}
298%>
299
Note: See TracBrowser for help on using the repository browser.