1 package org.cacert.gigi.pages;
3 import java.io.IOException;
6 import javax.servlet.ServletRequest;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import org.cacert.gigi.Language;
11 import org.cacert.gigi.output.template.Template;
14 * This class encapsulates a sub page of Gigi. A template residing nearby this
15 * class with name <className>.templ will be loaded automatically.
17 public abstract class Page {
19 private Template defaultTemplate;
21 public Page(String title) {
23 URL resource = getClass().getResource(getClass().getSimpleName() + ".templ");
24 if (resource != null) {
25 defaultTemplate = new Template(resource);
30 * Retrieves the default template (<className>.templ) which has
31 * already been loaded.
33 * @return the default template.
35 public Template getDefaultTemplate() {
36 return defaultTemplate;
40 * This method can be overridden to execute code and do stuff before the
41 * default template is applied.
44 * the request to handle.
46 * the response to write to
47 * @return true, if the request is consumed and the default template should
50 * if output goes wrong.
52 public boolean beforeTemplate(HttpServletRequest req, HttpServletResponse resp) throws IOException {
57 * This method is called to generate the content inside the default
61 * the request to handle.
63 * the response to write to
65 * if output goes wrong.
67 public abstract void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException;
70 * Same as {@link #doGet(HttpServletRequest, HttpServletResponse)} but for
71 * POST requests. By default they are redirected to
72 * {@link #doGet(HttpServletRequest, HttpServletResponse)};
75 * the request to handle.
77 * the response to write to
79 * if output goes wrong.
81 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
86 * Returns true, if this page requires login. Default is <code>true</code>
88 * @return if the page needs login.
90 public boolean needsLogin() {
94 public String getTitle() {
98 public void setTitle(String title) {
102 public static Language getLanguage(ServletRequest req) {
103 return Language.getInstance("de");
106 public static String translate(ServletRequest req, String string) {
107 Language l = getLanguage(req);
108 return l.getTranslation(string);