X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2FPage.java;h=540969f3f2ede26eec5edf32aa8afa5860178391;hb=480cb29387c76ccc19f8fa8fb0abe8ae1b069730;hp=04f1dc67292176643ad43848cee92635be030775;hpb=0f68090e02ab53fc067ad9b00a49530ed84b93f5;p=gigi.git diff --git a/src/org/cacert/gigi/pages/Page.java b/src/org/cacert/gigi/pages/Page.java index 04f1dc67..540969f3 100644 --- a/src/org/cacert/gigi/pages/Page.java +++ b/src/org/cacert/gigi/pages/Page.java @@ -1,121 +1,118 @@ package org.cacert.gigi.pages; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; +import java.net.URL; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.cacert.gigi.Language; -import org.cacert.gigi.output.Template; +import org.cacert.gigi.User; +import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.template.Template; /** * This class encapsulates a sub page of Gigi. A template residing nearby this * class with name <className>.templ will be loaded automatically. */ public abstract class Page { - private String title; - private Template defaultTemplate; - - public Page(String title) { - this.title = title; - try { - InputStream resource = getClass().getResourceAsStream( - getClass().getSimpleName() + ".templ"); - if (resource != null) { - defaultTemplate = new Template(new InputStreamReader(resource, - "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - /** - * Retrives the default template (<className>.templ) which has already - * been loaded. - * - * @return the default template. - */ - public Template getDefaultTemplate() { - return defaultTemplate; - } - - /** - * This method can be overridden to execute code and do stuff before the - * default template is applied. - * - * @param req - * the request to handle. - * @param resp - * the response to write to - * @return true, iff the request is consumed and the default template should - * not be applied. - * @throws IOException - * if output goes wrong. - */ - public boolean beforeTemplate(HttpServletRequest req, - HttpServletResponse resp) throws IOException { - return false; - } - - /** - * This method is called to generate the content inside the default - * template. - * - * @param req - * the request to handle. - * @param resp - * the response to write to - * @throws IOException - * if output goes wrong. - */ - public abstract void doGet(HttpServletRequest req, HttpServletResponse resp) - throws IOException; - - /** - * Same as {@link #doGet(HttpServletRequest, HttpServletResponse)} but for - * POST requests. By default they are redirected to - * {@link #doGet(HttpServletRequest, HttpServletResponse)}; - * - * @param req - * the request to handle. - * @param resp - * the response to write to - * @throws IOException - * if output goes wrong. - */ - public void doPost(HttpServletRequest req, HttpServletResponse resp) - throws IOException { - doGet(req, resp); - } - - /** - * Returns true, iff this page requires login. Default is true - * - * @return iff the page needs login. - */ - public boolean needsLogin() { - return true; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - public static Language getLanguage(ServletRequest req) { - return Language.getInstance("de"); - } - - public static String translate(ServletRequest req, String string) { - Language l = getLanguage(req); - return l.getTranslation(string); - } + + private String title; + + private Template defaultTemplate; + + public Page(String title) { + this.title = title; + URL resource = getClass().getResource(getClass().getSimpleName() + ".templ"); + if (resource != null) { + defaultTemplate = new Template(resource); + } + } + + /** + * Retrieves the default template (<className>.templ) which has + * already been loaded. + * + * @return the default template. + */ + public Template getDefaultTemplate() { + return defaultTemplate; + } + + /** + * This method can be overridden to execute code and do stuff before the + * default template is applied. + * + * @param req + * the request to handle. + * @param resp + * the response to write to + * @return true, if the request is consumed and the default template should + * not be applied. + * @throws IOException + * if output goes wrong. + */ + public boolean beforeTemplate(HttpServletRequest req, HttpServletResponse resp) throws IOException { + return false; + } + + /** + * This method is called to generate the content inside the default + * template. + * + * @param req + * the request to handle. + * @param resp + * the response to write to + * @throws IOException + * if output goes wrong. + */ + public abstract void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException; + + /** + * Same as {@link #doGet(HttpServletRequest, HttpServletResponse)} but for + * POST requests. By default they are redirected to + * {@link #doGet(HttpServletRequest, HttpServletResponse)}; + * + * @param req + * the request to handle. + * @param resp + * the response to write to + * @throws IOException + * if output goes wrong. + */ + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + doGet(req, resp); + } + + /** + * Returns true, if this page requires login. Default is true + * + * @return if the page needs login. + */ + public boolean needsLogin() { + return true; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public static Language getLanguage(ServletRequest req) { + return Language.getInstance("de"); + } + + public static String translate(ServletRequest req, String string) { + Language l = getLanguage(req); + return l.getTranslation(string); + } + + public static User getUser(HttpServletRequest req) { + return LoginPage.getUser(req); + } }