View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
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  
17  package olr.presentation;
18  
19  import org.w3c.dom.html.HTMLAnchorElement;
20  
21  import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
22  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
23  
24  /***
25   * @version $Id: UnsavedChanges.java,v 1.1 2004/08/03 08:33:53 roku Exp $
26   */
27  public class UnsavedChanges extends ExtendedHttpPresentation {
28  
29      public UnsavedChanges() {
30      }
31  
32      public boolean loggedInUserRequired() {
33          return true;
34      }
35  
36      public String handleDefault() throws HttpPresentationException {
37          return showPage(true);
38      }
39  
40      public String handleSaveMenu() throws HttpPresentationException {
41          try {
42              getSessionData().getCourseViewers().save();
43          } catch (Exception e) {
44              showPage(true);
45          }
46  
47          throw new ClientPageRedirectException("Welcome1.po?event=Restart");
48      }
49  
50      public String handleSaveLogout() throws HttpPresentationException {
51          try {
52              getSessionData().getCourseViewers().save();
53          } catch (Exception e) {
54              showPage(true);
55          }
56          throw new ClientPageRedirectException("Login.po?event=Logout");
57      }
58  
59      public String handleMenu() {
60          return showPage(false);
61      }
62  
63      public String handleLogout() {
64          return showPage(true);
65      }
66  
67      public String showPage(boolean logout) {
68          UnsavedChangesHTML page = new UnsavedChangesHTML();
69          if (logout) {
70              HTMLAnchorElement yes = page.getElementYes();
71              HTMLAnchorElement no = page.getElementNo();
72              yes.setAttribute("href", "UnsavedChanges.po?event=SaveLogout");
73              no.setAttribute("href", "Login.po?event=Logout");
74          }
75          if (getSessionData().isChanged()) {
76              getSessionData().setChanged(false);
77              return page.toDocument();
78          } else
79              throw new ClientPageRedirectException(logout ? "Login.po?event=Logout"
80                      : "Welcome1.po?event=Restart");
81      }
82  }