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.HTMLTableCellElement;
20  
21  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
22  
23  /***
24   * @version $Id: Header.java,v 1.6 2004/08/02 18:52:31 roku Exp $
25   */
26  public class Header extends ExtendedHttpPresentation {
27      /***
28       * Initializes an instance of this class.
29       */
30      public Header() {
31      }
32  
33      public boolean loggedInUserRequired() {
34          return false;
35      }
36  
37      public String handleDefault() throws HttpPresentationException {
38          return showPage();
39      }
40  
41      public String handleSave() throws HttpPresentationException {
42          try {
43              getSessionData().setChanged(false);
44              getSessionData().getCourseViewers().save();
45          } catch (Exception e) {
46              showPage(e.getMessage());
47          }
48          return showPage();
49      }
50  
51      public String showPage() {
52          return showPage(null);
53      }
54  
55      public String showPage(String errorMsg) {
56          HeaderHTML page = new HeaderHTML();
57          if (errorMsg != null)
58              page.getElementErrorText().getFirstChild().setNodeValue(errorMsg);
59          HTMLTableCellElement importButton = page.getElementImport();
60          HTMLTableCellElement deleteButton = page.getElementDelete();
61          HTMLTableCellElement saveButton = page.getElementSave();
62          HTMLTableCellElement menuButton = page.getElementMenu();
63          HTMLTableCellElement logoutButton = page.getElementLogout();
64          if (getUser() == null)
65              logoutButton.getParentNode().removeChild(logoutButton);
66          if (!getSessionData().isStarted()) {
67              saveButton.getParentNode().removeChild(saveButton);
68              menuButton.getParentNode().removeChild(menuButton);
69              deleteButton.getParentNode().removeChild(deleteButton);
70              importButton.getParentNode().removeChild(importButton);
71          } else if (!getSessionData().isAuthor()) {
72              saveButton.getParentNode().removeChild(saveButton);
73              deleteButton.getParentNode().removeChild(deleteButton);
74              importButton.getParentNode().removeChild(importButton);
75          }
76          return page.toDocument();
77      }
78  }