]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/Page.java
Implement a Template-Foreach (and use in "new email certificate")
[gigi.git] / src / org / cacert / gigi / pages / Page.java
index 04f1dc67292176643ad43848cee92635be030775..9a5c178a8d0a576422305094b7fe4383b5361e09 100644 (file)
@@ -1,16 +1,14 @@
 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.output.template.Template;
 
 /**
  * This class encapsulates a sub page of Gigi. A template residing nearby this
@@ -22,21 +20,15 @@ public abstract class Page {
 
        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();
+               URL resource = getClass().getResource(getClass().getSimpleName() + ".templ");
+               if (resource != null) {
+                       defaultTemplate = new Template(resource);
                }
        }
 
        /**
-        * Retrives the default template (<className>.templ) which has already
-        * been loaded.
+        * Retrieves the default template (<className>.templ) which has
+        * already been loaded.
         * 
         * @return the default template.
         */
@@ -52,13 +44,12 @@ public abstract class Page {
         *            the request to handle.
         * @param resp
         *            the response to write to
-        * @return true, iff the request is consumed and the default template should
+        * @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 {
+       public boolean beforeTemplate(HttpServletRequest req, HttpServletResponse resp) throws IOException {
                return false;
        }
 
@@ -73,8 +64,7 @@ public abstract class Page {
         * @throws IOException
         *             if output goes wrong.
         */
-       public abstract void doGet(HttpServletRequest req, HttpServletResponse resp)
-                       throws IOException;
+       public abstract void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException;
 
        /**
         * Same as {@link #doGet(HttpServletRequest, HttpServletResponse)} but for
@@ -88,15 +78,14 @@ public abstract class Page {
         * @throws IOException
         *             if output goes wrong.
         */
-       public void doPost(HttpServletRequest req, HttpServletResponse resp)
-                       throws IOException {
+       public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
                doGet(req, resp);
        }
 
        /**
-        * Returns true, iff this page requires login. Default is <code>true</code>
+        * Returns true, if this page requires login. Default is <code>true</code>
         * 
-        * @return iff the page needs login.
+        * @return if the page needs login.
         */
        public boolean needsLogin() {
                return true;
@@ -109,6 +98,7 @@ public abstract class Page {
        public void setTitle(String title) {
                this.title = title;
        }
+
        public static Language getLanguage(ServletRequest req) {
                return Language.getInstance("de");
        }