next steps in itegrating struts and hibernate.\rlogin and logout ist now possible...
authoridfx <idfx>
Sun, 7 Sep 2003 16:55:00 +0000 (16:55 +0000)
committeridfx <idfx>
Sun, 7 Sep 2003 16:55:00 +0000 (16:55 +0000)
17 files changed:
etc/struts-config-admin.xml [new file with mode: 0755]
etc/struts-config.xml [deleted file]
etc/web.xml
source/mir/core/model/IMedia.java
source/mir/core/service/storage/CommentService.java
source/mir/core/service/storage/StorageService.java
source/mir/core/service/storage/UserService.java
source/mir/core/test/Test.java
source/mir/core/ui/action/AuthenticationAction.java [deleted file]
source/mir/core/ui/action/admin/AuthenticationAction.java [new file with mode: 0755]
source/mir/core/ui/action/admin/MessageAction.java [new file with mode: 0755]
source/mir/core/ui/action/admin/StartpageAction.java [new file with mode: 0755]
source/mir/core/ui/filter/AuthenticationFilter.java
source/mir/core/ui/plugin/ConfigurationPlugin.java [new file with mode: 0755]
source/mir/core/ui/servlet/ServletConstants.java
source/mir/core/ui/servlet/TemplateServlet.java
source/mir/util/GeneratorHTMLFunctions.java

diff --git a/etc/struts-config-admin.xml b/etc/struts-config-admin.xml
new file mode 100755 (executable)
index 0000000..426513e
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
+<struts-config>
+    
+    <!-- ========== Data Source Configuration =============================== -->
+    <data-sources />
+    
+    <!-- ========== Form Bean Definitions ================================== -->
+    <form-beans>
+        <form-bean dynamic="true" name="logonForm" type="org.apache.struts.action.DynaActionForm">
+               <form-property name="login" type="java.lang.String"/>
+               <form-property name="password" type="java.lang.String"/>
+        </form-bean>
+    </form-beans>
+    
+    <!-- ========== Global Exception Definitions ============================== -->
+    <global-exceptions />
+    
+    <!-- ========== Global Forward Definitions =============================== -->
+    <global-forwards>
+        <forward
+            name="index"
+            path="index.do"
+            redirect="true"
+            contextRelative="false" />
+    </global-forwards>
+    
+    <!-- ========== Action Mapping Definitions =============================== -->
+    <action-mappings>
+        <action
+            attribute="logonForm"
+            input="/admin/logon.shtml"
+            name="logonForm"
+            parameter="logon"
+            path="/logon"
+            scope="session"
+            type="mir.core.ui.action.admin.AuthenticationAction"
+            unknown="false"
+            validate="true">
+            <forward
+                name="failed"
+                path="/logon.shtml"/>
+            <forward
+                name="success"
+                path="/index.do"/>
+        </action>
+        
+        <action
+            parameter="logoff"
+            path="/logoff"
+            type="mir.core.ui.action.admin.AuthenticationAction">
+        </action>
+        
+        <action
+            parameter="index"
+            path="/index"
+            type="mir.core.ui.action.admin.StartpageAction">
+            <forward
+                name="success"
+                path="/admin/index.shtml"/>
+        </action>
+        
+        <action
+            parameter="list"
+            path="/messageList"
+            type="mir.core.ui.action.admin.MessageAction">
+            <forward
+                name="success"
+                path="/admin/messagelist.shtml"/>
+        </action>
+    </action-mappings>
+    
+    <!-- ========== Controller Configuration ================================ -->
+    <controller
+        bufferSize="4096"
+        contentType="text/html"
+        debug="0"
+        locale="false"
+        maxFileSize="250M"
+        multipartClass="org.apache.struts.upload.CommonsMultipartRequestHandler"
+        nocache="false"
+        processorClass="org.apache.struts.action.RequestProcessor"
+        inputForward="false" />
+    
+    <!-- ========== Message Resources Definitions ============================ -->
+    
+    <!-- ========== Plug Ins Configuration ================================= -->
+</struts-config>
+
diff --git a/etc/struts-config.xml b/etc/struts-config.xml
deleted file mode 100755 (executable)
index 4b94619..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>\r
-\r
-<!DOCTYPE struts-config PUBLIC\r
-          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"\r
-          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">\r
-\r
-<!--\r
-     This is the Struts configuration file for the example application,\r
-     using the proposed new syntax.\r
--->\r
-\r
-\r
-<struts-config>\r
-\r
-\r
-  <!-- ========== Data Source Configuration =============================== -->\r
-<!--\r
- <data-sources>\r
-   <data-source>\r
-     <set-property property="autoCommit"\r
-                      value="false"/>\r
-     <set-property property="description"\r
-                      value="Example Data Source Configuration"/>\r
-     <set-property property="driverClass"\r
-                      value="org.postgresql.Driver"/>\r
-     <set-property property="maxCount"\r
-                      value="4"/>\r
-     <set-property property="minCount"\r
-                      value="2"/>\r
-     <set-property property="password"\r
-                      value="mypassword"/>\r
-     <set-property property="url"\r
-                      value="jdbc:postgresql://localhost/mydatabase"/>\r
-     <set-property property="user"\r
-                      value="myusername"/>\r
-   </data-source>\r
- </data-sources>\r
--->\r
-  <!-- ========== Form Bean Definitions =================================== -->\r
-  <form-beans>\r
-\r
-    <!-- Logon form bean -->\r
-    <form-bean       name="logonForm"\r
-                     type="org.apache.struts.validator.DynaValidatorForm">\r
-      <form-property name="username" type="java.lang.String"/>\r
-      <form-property name="password" type="java.lang.String"/>\r
-    </form-bean>\r
-\r
-  <!-- ========== Global Forward Definitions ============================== -->\r
-  <global-forwards>\r
-    <forward   name="logoff"               path="/admin/logout.do"/>\r
-    <forward   name="logon"                path="/admin/login.shtml"/>\r
-    <forward   name="success"              path="/admin/index.shtml"/>\r
-  </global-forwards>\r
-\r
-\r
-  <!-- ========== Action Mapping Definitions ============================== -->\r
-  <action-mappings>\r
-    <!-- Process a user logoff -->\r
-    <action    path="/logoff"\r
-               type="mir.core.ui.action.AuthenticationAction">\r
-      <forward name="success" path="/index.shtml"/>\r
-    </action>\r
-\r
-    <!-- Process a user logon -->\r
-    <action    path="/logon"\r
-               type="mir.core.ui.action.AuthenticationAction"\r
-               name="logonForm"\r
-              scope="session"\r
-              input="logon">\r
-      <exception\r
-                key="expired.password"\r
-               type="org.apache.struts.webapp.example.ExpiredPasswordException"\r
-               path="/changePassword.jsp"/>\r
-    </action>\r
-  </action-mappings>\r
-\r
-\r
-  <!-- ========== Controller Configuration ================================ -->\r
-\r
-  <controller>\r
-    <!-- The "input" parameter on "action" elements is the name of a\r
-         local or global "forward" rather than a module-relative path -->\r
-    <set-property property="inputForward" value="true"/>\r
-  </controller>\r
-\r
-\r
-  <!-- ========== Message Resources Definitions =========================== -->\r
-\r
-  <!-- ========== Plug Ins Configuration ================================== -->\r
-\r
-  <plug-in className="mir.core.ui.plugin.HibernatePlugin">\r
-    <!--\r
-    <set-property property="pathname" value="/WEB-INF/database.xml"/>\r
-    -->\r
-  </plug-in>\r
-</struts-config>\r
index db47a25..b028d4f 100755 (executable)
@@ -1,84 +1,75 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 
 <!DOCTYPE web-app
-    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3 //EN"
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd">
 
 <web-app>
+       <display-name>Mir CMS</display-name>
+    <servlet>
+        <servlet-name>Mir</servlet-name>
+        <servlet-class>Mir</servlet-class>
+        <init-param>
+            <param-name>Config</param-name>
+            <param-value>etc/config.properties</param-value>
+        </init-param>
+    </servlet>
 
+    <servlet>
+        <servlet-name>OpenMir</servlet-name>
+        <servlet-class>OpenMir</servlet-class>
+        <init-param>
+            <param-name>Config</param-name>
+            <param-value>etc/config.properties</param-value>
+        </init-param>
+    </servlet>
+       
        <servlet>
                <servlet-name>presentation</servlet-name>
+               <description>Presentation</description>
                <servlet-class>mir.core.ui.servlet.TemplateServlet</servlet-class>
        </servlet>
-       <servlet-mapping>
-               <servlet-name>presentation</servlet-name>
-               <url-pattern>*.shtml</url-pattern>
-       </servlet-mapping>
-       
+
        <servlet>
                <servlet-name>action</servlet-name>
+               <description>Action</description>
                <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
         <init-param>
-               <param-name>config</param-name>
-               <param-value>/WEB-INF/etc/struts-config.xml</param-value>
+            <param-name>config</param-name>
+            <param-value>/WEB-INF/etc/struts-config.xml</param-value>            
         </init-param>
-               <load-on-startup>1</load-on-startup>
-       </servlet>
-       
-    <servlet>
-        <servlet-name>
-            Mir
-        </servlet-name>
-        <servlet-class>
-            Mir
-        </servlet-class>
-
         <init-param>
-            <param-name>Config</param-name>
-            <param-value>etc/config.properties</param-value>
+            <param-name>config/admin</param-name>
+            <param-value>/WEB-INF/etc/struts-config-admin.xml</param-value>
         </init-param>
-
-    </servlet>
-
-    <servlet>
-        <servlet-name>
-            OpenMir
-        </servlet-name>
-        <servlet-class>
-            OpenMir
-        </servlet-class>
-
         <init-param>
-            <param-name>Config</param-name>
-            <param-value>etc/config.properties</param-value>
+            <param-name>debug</param-name>
+            <param-value>3</param-value>        
         </init-param>
-
-    </servlet>
-    
-    <servlet-mapping>
-        <servlet-name>
-            Mir
-        </servlet-name>
-        <url-pattern>
-            /Mir
-        </url-pattern>
-    </servlet-mapping>
+        <init-param>
+            <param-name>detail</param-name>
+            <param-value>3</param-value>     
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+       </servlet>
+       
+       <servlet-mapping>
+               <servlet-name>presentation</servlet-name>
+               <url-pattern>*.shtml</url-pattern>
+       </servlet-mapping>
+       
+       <servlet-mapping>
+               <servlet-name>action</servlet-name>
+               <url-pattern>*.do</url-pattern>
+       </servlet-mapping> 
 
     <servlet-mapping>
-        <servlet-name>
-            Mir
-        </servlet-name>
-        <url-pattern>
-            /servlet/Mir
-        </url-pattern>
+        <servlet-name>Mir</servlet-name>
+        <url-pattern>/servlet/Mir</url-pattern>
     </servlet-mapping>
 
     <servlet-mapping>
         <servlet-name>OpenMir</servlet-name>
-        <url-pattern>/OpenMir</url-pattern>
-    </servlet-mapping>
-    <servlet-mapping>
-        <servlet-name>OpenMir</servlet-name>
         <url-pattern>/servlet/OpenMir</url-pattern>
     </servlet-mapping>
 
                <filter-name>authentication</filter-name>
                <filter-class>mir.core.ui.filter.AuthenticationFilter</filter-class>    
        </filter>
-       
-       <filter-mapping>
+
+    <filter-mapping>
                <filter-name>authentication</filter-name>
                <servlet-name>presentation</servlet-name>
        </filter-mapping>
+       
+       <filter-mapping>
+               <filter-name>authentication</filter-name>
+               <servlet-name>action</servlet-name>
+       </filter-mapping>       
+       
+       <welcome-file-list>
+               <welcome-file>index.shtml</welcome-file>
+       </welcome-file-list>
+       
     <mime-mapping>
       <extension>
         mp3 
index eeb6ff1..6865d1e 100755 (executable)
  */
 package mir.core.model;
 
-import java.util.Date;
 import java.util.Set;
 
 /**
  * IMedia
  * @author idefix
- * @version $Id: IMedia.java,v 1.2 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: IMedia.java,v 1.3 2003/09/07 16:55:00 idfx Exp $
  */
 public interface IMedia {
        public abstract java.lang.Integer getId();
index 780bc06..2075efd 100755 (executable)
 package mir.core.service.storage;
 
 import mir.core.model.Comment;
-import net.sf.hibernate.Hibernate;
 import net.sf.hibernate.HibernateException;
 import net.sf.hibernate.SessionFactory;
 
 /**
  * CommentService
  * @author idefix
- * @version $Id: CommentService.java,v 1.2 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: CommentService.java,v 1.3 2003/09/07 16:55:00 idfx Exp $
  */
 public class CommentService extends StorageService {
 
index 6a21d94..e8ced3c 100755 (executable)
@@ -34,9 +34,9 @@ package mir.core.service.storage;
 
 import java.util.List;
 
-import mir.core.model.IImage;
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
 import net.sf.hibernate.Criteria;
-import net.sf.hibernate.Hibernate;
 import net.sf.hibernate.HibernateException;
 import net.sf.hibernate.Session;
 import net.sf.hibernate.SessionFactory;
@@ -47,21 +47,36 @@ import net.sf.hibernate.expression.Expression;
  * 
  * StorageService
  * @author idefix
- * @version $Id: StorageService.java,v 1.3 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: StorageService.java,v 1.4 2003/09/07 16:55:00 idfx Exp $
  */
 public abstract class StorageService {
        private Class objectClass;
        private SessionHolder sessionHolder;
+       protected MirPropertiesConfiguration _configuration;
 
        public StorageService(Class objectClass, SessionFactory factory){
                this.objectClass = objectClass;
                sessionHolder = new SessionHolder(factory);
+               try {
+                       _configuration = MirPropertiesConfiguration.instance();
+               } catch (PropertiesConfigExc e) {
+                       throw new multex.Failure("could not get the config", e);
+               }
        }
        
        public List list(int offset, int limit){
                return list(offset, limit, null);
        }
        
+       public List list(int offset){
+               int limit = _configuration.getInt("ServletModule.Default.ListSize");
+               return list(offset, limit, null);
+       }
+               
+       public List list(int offset, Expression expression){
+               int limit = _configuration.getInt("ServletModule.Default.ListSize");
+               return list(offset, limit, expression);
+       }       
        public List list(int offset, int limit, Expression expression){
                try {
                        Session session = sessionHolder.currentSession();
index 51f4386..f1c9223 100755 (executable)
@@ -42,7 +42,7 @@ import net.sf.hibernate.expression.Expression;
 /**
  * UserService
  * @author idefix
- * @version $Id: UserService.java,v 1.2 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: UserService.java,v 1.3 2003/09/07 16:55:00 idfx Exp $
  */
 public class UserService extends StorageService {
 
@@ -64,6 +64,9 @@ public class UserService extends StorageService {
                                Expression.eq("isAdmin", new Boolean(true))
                        )
                );
+               if(list.size() == 0){
+                       return null;
+               }
                return (MirUser)list.get(0);
        }
 
@@ -73,5 +76,4 @@ public class UserService extends StorageService {
        protected void initializeLazyCollections(Object returnObject) throws HibernateException {               
                //do nothing
        }
-
 }
index f94670d..33cccc1 100755 (executable)
@@ -34,13 +34,9 @@ package mir.core.test;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.log4j.BasicConfigurator;
-
 import mir.core.model.Audio;
 import mir.core.model.Content;
-import mir.core.model.IContent;
 import mir.core.model.IImage;
-import mir.core.model.Image;
 import mir.core.model.Media;
 import mir.core.model.Topic;
 import mir.core.model.UploadedMedia;
@@ -56,7 +52,7 @@ import net.sf.hibernate.cfg.Configuration;
 
 /**
  * Test
- * @version $Id: Test.java,v 1.6 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: Test.java,v 1.7 2003/09/07 16:55:00 idfx Exp $
  * @author idefix
  */
 public class Test {
diff --git a/source/mir/core/ui/action/AuthenticationAction.java b/source/mir/core/ui/action/AuthenticationAction.java
deleted file mode 100755 (executable)
index 7a1bb2f..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * AuthenticationAction.java created on 05.09.2003
- * 
- * Copyright (C) 2001, 2002, 2003 The Mir-coders group
- *
- * This file is part of Mir.
- *
- * Mir is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Mir is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mir; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two.  You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries.  If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
- * If you do not wish to do so, delete this exception statement from your version.
- */
-package mir.core.ui.action;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts.action.Action;
-import org.apache.struts.action.ActionForm;
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.action.ActionMapping;
-
-/**
- * AuthenticationAction
- * @author idefix
- * @version $Id: AuthenticationAction.java,v 1.1 2003/09/05 20:23:59 idfx Exp $
- */
-public class AuthenticationAction extends Action {
-
-       
-       /**
-        * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-        */
-       public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, 
-               HttpServletRequest request, HttpServletResponse response)
-               throws Exception {
-               // TODO Auto-generated method stub
-               return actionMapping.findForward("success");
-       }
-
-}
diff --git a/source/mir/core/ui/action/admin/AuthenticationAction.java b/source/mir/core/ui/action/admin/AuthenticationAction.java
new file mode 100755 (executable)
index 0000000..55f6022
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * AuthenticationAction.java created on 05.09.2003
+ * 
+ * Copyright (C) 2001, 2002, 2003 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.core.ui.action.admin;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.core.model.MirUser;
+import mir.core.service.storage.UserService;
+import mir.core.ui.servlet.ServletConstants;
+import mir.util.StringRoutines;
+import mircoders.global.MirGlobal;
+import multex.Failure;
+import net.sf.hibernate.SessionFactory;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.DynaActionForm;
+import org.apache.struts.action.RedirectingActionForward;
+import org.apache.struts.util.MessageResources;
+
+/**
+ * AuthenticationAction
+ * @author idefix
+ * @version $Id: AuthenticationAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ */
+public class AuthenticationAction extends Action {
+       private MirPropertiesConfiguration _configuration;
+       
+       public AuthenticationAction(){
+               try {
+                       _configuration = MirPropertiesConfiguration.instance();
+               } catch (PropertiesConfigExc e) {
+                       throw new Failure("could not load config", e);
+               }
+       }
+       
+       /**
+        * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+
+               String param = actionMapping.getParameter();
+               if(param.equals("logon")){
+                       return logon(actionMapping, actionForm, request, response);     
+               }
+               if(param.equals("logoff")){
+                       return logoff(actionMapping, actionForm, request, response);    
+               }
+               return null;
+       }
+       
+       private ActionForward logon(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               
+               //retrieve the form input data                          
+               DynaActionForm form = (DynaActionForm)actionForm;
+               String login = (String) form.get("login");
+               String password = (String) form.get("password");
+       
+               if((login == null || login.trim().length() == 0) 
+                       && (password == null || password.trim().length() == 0)){
+                       //no input --> error
+                       return actionMapping.findForward("failed");
+               }
+               
+               //access to persitence layer
+               ServletContext context = this.getServlet().getServletContext();
+               UserService userService = 
+                       new UserService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               setLoginLanguages(context);
+               
+               //try to retrieve user for the given values     
+               MirUser mirUser = userService.loadUser(login, password);
+               if(mirUser == null){
+                       //not existent user --> error
+                       return actionMapping.findForward("failed");
+               }
+               
+               //add user to the session context
+               HttpSession session = request.getSession();
+               session.setAttribute(ServletConstants.USER, mirUser);
+               
+               //check if we have to redirect the user
+               String requestUri = 
+                       (String) session.getAttribute(ServletConstants.REDIRECT_ACTION);
+               
+               if(requestUri != null && requestUri.indexOf("index") == -1 
+                       && requestUri.indexOf("logon") == -1){
+                       
+                       // we have to redirect the user
+                       requestUri = requestUri.substring(requestUri.lastIndexOf("/"));
+
+                       //retrieve the correct action name
+                       String queryString = 
+                               (String) session.getAttribute(ServletConstants.REDIRECT_QUERY_STRING);
+                       if(queryString != null){
+                               requestUri = requestUri + "?" +queryString;
+                       }
+                       
+                       //construct a redirect
+                       RedirectingActionForward actionForward = 
+                               new RedirectingActionForward(requestUri);
+                       
+                       //return the redirect
+                       return actionForward;
+               }
+               
+               //normal redirect to the startpage
+               return actionMapping.findForward("success");    
+       }
+       
+       private ActionForward logoff(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               
+               //kill session
+               HttpSession session = request.getSession();
+               session.setAttribute(ServletConstants.USER, null);
+               session.invalidate();
+               
+               //return to the logon form
+               return actionMapping.findForward("index");
+       }
+       
+       private void setLoginLanguages(ServletContext context) throws ServletException {
+               List loginLanguages = 
+                       (List) context.getAttribute(ServletConstants.LOGIN_LANGUAGES);  
+               try {
+                       if (loginLanguages == null) {
+                               MessageResources messageResources =
+                                       MessageResources.getMessageResources("bundles.adminlocal");
+                               MessageResources messageResources2 =
+                                       MessageResources.getMessageResources("bundles.admin");
+
+                               List languages =
+                                       StringRoutines.splitString(
+                                               MirGlobal.config().getString("Mir.Login.Languages", "en"), ";");
+
+                               loginLanguages = new ArrayList();
+                               Iterator i = languages.iterator();
+                               while (i.hasNext()) {
+                                       String code = (String) i.next();
+                                       Locale locale = new Locale(code, "");
+                                       String name = messageResources.getMessage(locale, "languagename");
+
+                                       if (name == null) {
+                                               name = messageResources2.getMessage(locale, "languagename");
+                                       }
+
+                                       if (name == null) {
+                                               name = code;
+                                       }
+
+                                       Map record = new HashMap();
+                                       record.put("name", name);
+                                       record.put("code", code);
+                                       loginLanguages.add(record);
+                               }
+                               context.setAttribute(ServletConstants.LOGIN_LANGUAGES, 
+                                       loginLanguages);
+                               context.setAttribute(ServletConstants.DEFAULT_LANGUAGE, 
+                                       _configuration.getString("Mir.Login.DefaultLanguage"));
+                       }
+               } catch (Throwable t) {
+                       throw new ServletException(t.getMessage());
+               }
+       }
+}
diff --git a/source/mir/core/ui/action/admin/MessageAction.java b/source/mir/core/ui/action/admin/MessageAction.java
new file mode 100755 (executable)
index 0000000..4c9f2ec
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * AuthenticationAction.java created on 05.09.2003
+ * 
+ * Copyright (C) 2001, 2002, 2003 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.core.ui.action.admin;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.core.service.storage.MessageService;
+import mir.core.ui.servlet.ServletConstants;
+
+import multex.Failure;
+
+import net.sf.hibernate.SessionFactory;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+
+/**
+ * AuthenticationAction
+ * @author idefix
+ * @version $Id: MessageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ */
+public class MessageAction extends Action {
+       private MirPropertiesConfiguration _configuration;
+
+       public MessageAction(){
+               try {
+                       _configuration = MirPropertiesConfiguration.instance();
+               } catch (PropertiesConfigExc e) {
+                       throw new Failure("could not load config", e);
+               }               
+       }
+       
+       /**
+        * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+
+               String param = actionMapping.getParameter();
+               if(param.equals("list")){
+                       return list(actionMapping, actionForm, request, response);      
+               }
+               return null;
+       }
+       
+       private ActionForward list(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //retrieve parameters
+               String offsetString = request.getParameter(ServletConstants.OFFSET);
+               int offset = 0;
+               if(offsetString != null){
+                       offset = new Integer(offsetString).intValue();
+               }
+               
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               MessageService messageService = 
+                       new MessageService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               //retrieve entities
+               List messages = messageService.list(offset);
+               
+               //configure the data to send to view
+               int listSize = _configuration.getInt("ServletModule.Default.ListSize");
+               Integer lastOffset;
+               if(offset-listSize < 0){
+                       lastOffset = new Integer(0);
+               } else {
+                       lastOffset = new Integer(offset-listSize);
+               }
+               request.setAttribute(ServletConstants.LAST_OFFSET, lastOffset);
+               request.setAttribute(ServletConstants.NEXT_OFFSET, 
+                       new Integer(offset + listSize));
+               request.setAttribute(ServletConstants.OFFSET, 
+                       new Integer(offset));
+               request.setAttribute("messages", messages);
+               
+               //show the view
+               return actionMapping.findForward("success");    
+       }
+}
diff --git a/source/mir/core/ui/action/admin/StartpageAction.java b/source/mir/core/ui/action/admin/StartpageAction.java
new file mode 100755 (executable)
index 0000000..d4f59ac
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * AuthenticationAction.java created on 05.09.2003
+ * 
+ * Copyright (C) 2001, 2002, 2003 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.core.ui.action.admin;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.core.service.storage.MessageService;
+import mir.core.ui.servlet.ServletConstants;
+import net.sf.hibernate.SessionFactory;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+
+/**
+ * AuthenticationAction
+ * @author idefix
+ * @version $Id: StartpageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ */
+public class StartpageAction extends Action {
+       
+       /**
+        * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+
+               String param = actionMapping.getParameter();
+               if(param.equals("index")){
+                       return index(actionMapping, actionForm, request, response);     
+               }
+               return null;
+       }
+       
+       private ActionForward index(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               
+               ServletContext context = this.getServlet().getServletContext();
+               MessageService messageService = 
+                       new MessageService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               List messages = messageService.list(0);
+               
+               request.setAttribute("messages", messages);
+               return actionMapping.findForward("success");    
+       }
+}
index f83eea5..7102f10 100755 (executable)
@@ -48,10 +48,11 @@ import mir.core.ui.servlet.*;
 /**
  * AuthenticationFilter
  * @author idefix
- * @version $Id: AuthenticationFilter.java,v 1.1 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: AuthenticationFilter.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
  */
 public class AuthenticationFilter implements Filter {
        private FilterConfig _filterConfig;
+       
        /**
         * 
         */
@@ -62,27 +63,42 @@ public class AuthenticationFilter implements Filter {
        /**
         * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
         */
-       public void init(final FilterConfig filterConfig) throws ServletException {
+       public void init(final FilterConfig filterConfig) 
+               throws ServletException {
                _filterConfig = filterConfig;
        }
 
        /**
         * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
         */
-       public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+       public void doFilter(ServletRequest servletRequest, 
+               ServletResponse servletResponse, FilterChain filterChain)
                throws IOException, ServletException {
+               
                HttpServletRequest request = (HttpServletRequest)servletRequest;        
                String requestUri = request.getRequestURI();
-               System.out.println(requestUri);
-               System.out.println(request.getContextPath());
-               if(requestUri != null && requestUri.startsWith(request.getContextPath() + "/admin")){
+               
+               if(requestUri != null 
+                       && requestUri.startsWith(request.getContextPath() + "/admin")
+                       && requestUri.indexOf("logon") == -1){
                        //check if authenticated, only if in admin-module
                        HttpSession httpSession = request.getSession();
-                       MirUser mirUser = (MirUser)httpSession.getAttribute(ServletConstants.USER);
+                       MirUser mirUser = 
+                               (MirUser)httpSession.getAttribute(ServletConstants.USER);
+                       
                        if(mirUser == null){
-                               servletRequest.getRequestDispatcher("/admin/login.shtml").forward(servletRequest, servletResponse);
-                       }
-               }
+                               //user is not authorized to access
+                               //set redirect attributes that the user comes to place he wants to be
+                               httpSession.setAttribute(ServletConstants.REDIRECT_ACTION, requestUri);
+                               httpSession.setAttribute(ServletConstants.REDIRECT_QUERY_STRING, 
+                                       request.getQueryString());
+                               
+                               //send user to logon-page
+                               servletRequest.getRequestDispatcher("/admin/logon.do")
+                                       .forward(servletRequest, servletResponse);
+                       } 
+               } 
+                
                filterChain.doFilter(servletRequest, servletResponse);
        }
 
@@ -90,6 +106,7 @@ public class AuthenticationFilter implements Filter {
         * @see javax.servlet.Filter#destroy()
         */
        public void destroy() {
+               _filterConfig = null;
        }
 
 }
diff --git a/source/mir/core/ui/plugin/ConfigurationPlugin.java b/source/mir/core/ui/plugin/ConfigurationPlugin.java
new file mode 100755 (executable)
index 0000000..4acf368
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * ConfigurationPlugin.java
+ * 
+ * Copyright (C) 2001, 2002, 2003 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.core.ui.plugin;
+
+import javax.servlet.ServletException;
+
+import mir.config.MirPropertiesConfiguration;
+import mircoders.global.MirGlobal;
+
+import org.apache.struts.action.ActionServlet;
+import org.apache.struts.action.PlugIn;
+import org.apache.struts.config.ModuleConfig;
+
+/**
+ * ConfigurationPlugin
+ * @version $Id: ConfigurationPlugin.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ * @author idefix
+ */
+public class ConfigurationPlugin implements PlugIn {
+
+       /**
+        * @see org.apache.struts.action.PlugIn#destroy()
+        */
+       public void destroy() {
+       }
+
+       /**
+        * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet, org.apache.struts.config.ModuleConfig)
+        */
+       public void init(ActionServlet actionServlet, ModuleConfig config)
+               throws ServletException {
+               MirPropertiesConfiguration.setContext(actionServlet.getServletContext());
+               try {
+                       MirPropertiesConfiguration.instance();
+               }
+               catch (Throwable t) {
+                       throw new ServletException("can't read configuration: " + t.toString());
+               }
+
+               try {
+                       MirGlobal.localizer();
+               }
+               catch (Throwable t) {
+                       throw new ServletException("can't get localizer: " + t.toString());
+               }
+       }
+
+}
index 215f5c3..726e46b 100755 (executable)
@@ -35,9 +35,23 @@ package mir.core.ui.servlet;
  * ServletConstants<br>
  * Some constant string values needed as keys to store values in the servlet context.
  * @author idefix
- * @version $Id: ServletConstants.java,v 1.1 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: ServletConstants.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
  */
 public interface ServletConstants {
+       public static final String REDIRECT_ACTION = "redirect action";
+
+       public static final String REDIRECT_QUERY_STRING = "redirect query string";
+
+       public static final String NEXT_OFFSET = "nextoffset";
+
+       public static final String LAST_OFFSET = "lastoffset";
+
+       public static final String OFFSET = "offset";
+
+       public static final String DEFAULT_LANGUAGE = "defaultlanguage";
+
+       public static final String LOGIN_LANGUAGES = "languages";
+
        public static final String SESSION_FACTORY = "session factory";
 
        public static final String USER = "user";
index 06711cc..2c70b2c 100755 (executable)
@@ -33,10 +33,13 @@ package mir.core.ui.servlet;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Vector;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -47,9 +50,16 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
 import mir.servlet.ServletModuleExc;
+import mir.util.GeneratorDateTimeFunctions;
+import mir.util.GeneratorExpressionFunctions;
+import mir.util.GeneratorHTMLFunctions;
+import mir.util.GeneratorIntegerFunctions;
+import mir.util.GeneratorListFunctions;
+import mir.util.GeneratorRegularExpressionFunctions;
+import mir.util.GeneratorStringFunctions;
 import mir.util.ResourceBundleGeneratorFunction;
+import mir.util.StringRoutines;
 import mircoders.servlet.ServletHelper;
 
 import org.apache.struts.util.MessageResources;
@@ -57,7 +67,7 @@ import org.apache.struts.util.MessageResources;
 /**
  * TemplateServlet
  * @author idefix
- * @version $Id: TemplateServlet.java,v 1.1 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: TemplateServlet.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
  */
 public class TemplateServlet extends HttpServlet {
 
@@ -68,6 +78,8 @@ public class TemplateServlet extends HttpServlet {
                super();
        }
        
+       
+       
        /**
         * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         */
@@ -91,47 +103,106 @@ public class TemplateServlet extends HttpServlet {
         */
        protected void process(HttpServletRequest request, HttpServletResponse response) 
                throws IOException, ServletException {
-               PrintWriter printWriter = response.getWriter();
-               Map requestData = new HashMap();
-               Enumeration keys = request.getAttributeNames();
-               while(keys.hasMoreElements()){
-                       final String key = (String)keys.nextElement();
-                       requestData.put(key, request.getAttribute(key));
-               }
-               Map sessionData = new HashMap();
-               HttpSession httpSession = request.getSession();
-               keys = httpSession.getAttributeNames();
-               while(keys.hasMoreElements()){
-                       final String key = (String)keys.nextElement();
-                       sessionData.put(key, httpSession.getAttribute(key));
-               }
-               Map applicationData = new HashMap();
-               ServletContext servletContext = getServletContext();
-               keys = servletContext.getAttributeNames();
-               while(keys.hasMoreElements()){
-                       final String key = (String)keys.nextElement();
-                       applicationData.put(key, servletContext.getAttribute(key));
-               }               
-               Map templateData = new HashMap();
-               templateData.put("request", requestData);
-               templateData.put("session", sessionData);
-               templateData.put("application", applicationData);
                try {
-                       templateData.put("config", MirPropertiesConfiguration.instance().allSettings());
-               } catch (PropertiesConfigExc e) {
-                       throw new ServletException(e);
-               }
-               
-               String templateName = generateTemplateString(request);
-               
-               Locale[] locales = new Locale[2];
-               locales[0] = request.getLocale();
-               locales[1] = request.getLocale();
+                       Map requestData = new HashMap();
+                       Enumeration keys = request.getAttributeNames();
+                       while(keys.hasMoreElements()){
+                               final String key = (String)keys.nextElement();
+                               requestData.put(key, request.getAttribute(key));
+                       }
+                       requestData.putAll(request.getParameterMap());
+                       
+                       Map sessionData = new HashMap();
+                       HttpSession httpSession = request.getSession();
+                       keys = httpSession.getAttributeNames();
+                       while(keys.hasMoreElements()){
+                               final String key = (String)keys.nextElement();
+                               sessionData.put(key, httpSession.getAttribute(key));
+                       }
+                       
+                       Map applicationData = new HashMap();
+                       ServletContext servletContext = getServletContext();
+                       keys = servletContext.getAttributeNames();
+                       while(keys.hasMoreElements()){
+                               final String key = (String)keys.nextElement();
+                               applicationData.put(key, servletContext.getAttribute(key));
+                       }               
+                       
+                       Map utilityMap = new HashMap();
+                       utilityMap.put("compressWhitespace", 
+                               new freemarker.template.utility.CompressWhitespace());
+                       utilityMap.put("encodeHTML", 
+                               new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());
+                       utilityMap.put("encodeXML", 
+                               new GeneratorHTMLFunctions.encodeXMLGeneratorFunction());
+                       utilityMap.put("encodeURI", 
+                               new GeneratorHTMLFunctions.encodeURIGeneratorFunction());
+                       utilityMap.put("subString", 
+                               new GeneratorStringFunctions.subStringFunction());
+                       utilityMap.put("subList", 
+                               new GeneratorListFunctions.subListFunction());
+                       utilityMap.put("isOdd", 
+                               new GeneratorIntegerFunctions.isOddFunction());
+                       utilityMap.put("increment", 
+                               new GeneratorIntegerFunctions.incrementFunction());
+                       utilityMap.put("evaluate", 
+                               new GeneratorExpressionFunctions.evaluateExpressionFunction());
+                       utilityMap.put("constructString", 
+                               new GeneratorStringFunctions.constructStructuredStringFunction());
+                       utilityMap.put("escapeJDBCString", 
+                               new GeneratorStringFunctions.jdbcStringEscapeFunction());
+                       utilityMap.put("regexpreplace", 
+                               new GeneratorRegularExpressionFunctions.regularExpressionReplaceFunction());
+                       utilityMap.put("datetime", 
+                               new GeneratorDateTimeFunctions.DateTimeFunctions(
+                                       MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone")));
+                       utilityMap.put("encodeLink", 
+                               new GeneratorHTMLFunctions.encodeLinksGeneratorFunction(response));
+
+                       Map configData = MirPropertiesConfiguration.instance().allSettings();
+                       configData.put("docRoot", request.getContextPath());
+                       configData.put("now", new Date());
+                       
+                       //administeroperations
+                       List administerOperations = new Vector();
+                       String settings[] = MirPropertiesConfiguration.instance().getStringArray("Mir.Localizer.Admin.AdministerOperations");
+                       if (settings!=null) {
+                               for (int i = 0; i < settings.length; i++) {
+                                       String setting = settings[i].trim();
+
+                                       if (setting.length() > 0) {
+                                               List parts = StringRoutines.splitString(setting, ":");
+                                               if (parts.size() != 2) {
+//                                                     logger.error("config error: " + settings[i] + ", 2 parts expected");
+                                               }
+                                               else {
+                                                       Map entry = new HashMap();
+                                                       entry.put("name", (String) parts.get(0));
+                                                       entry.put("url", (String) parts.get(1));
+                                                       administerOperations.add(entry);
+                                               }
+                                       }
+                               }
+                       }
+                                               
+                       Map templateData = new HashMap();
+                       templateData.put("request", requestData);
+                       templateData.put("session", sessionData);
+                       templateData.put("application", applicationData);
+                       templateData.put("utility", utilityMap);
+                       templateData.put("config", configData);
+                       templateData.put("administeroperations", administerOperations);
+                       
+                       String templateName = generateTemplateString(request);
+                       
+                       Locale[] locales = new Locale[2];
+                       locales[0] = request.getLocale();
+                       locales[1] = request.getLocale();
                
-               try {
                        //write the servlet
+                       PrintWriter printWriter = response.getWriter();
                        generateResponse(printWriter, templateData, templateName, locales);
-               } catch (ServletModuleExc e) {
+               } catch (Throwable e) {
                        throw new ServletException(e);
                }
        }
@@ -139,7 +210,7 @@ public class TemplateServlet extends HttpServlet {
        private String generateTemplateString(HttpServletRequest request){
                String returnString = request.getServletPath();
                returnString = returnString.substring(0, returnString.indexOf("."));
-               return returnString + ".template";
+               return returnString + ".tmpl";
        }
        
        private void generateResponse(PrintWriter printWriter, Map map, 
@@ -148,19 +219,23 @@ public class TemplateServlet extends HttpServlet {
                if(templateString.startsWith("/admin")){
                        map.put( "lang",
                                        new ResourceBundleGeneratorFunction( locales,
-                                                new MessageResources[] { MessageResources.getMessageResources("bundles.admin"),
-                                                               MessageResources.getMessageResources("bundles.adminlocal")}));
+                                                new MessageResources[] { 
+                                                               MessageResources.getMessageResources("bundles.admin"),
+                                                               MessageResources.getMessageResources("bundles.adminlocal")
+                                                               }));
                                                                
-                       templateString = templateString.substring(6);
+                       templateString = templateString.substring(templateString.lastIndexOf('/'));
                        ServletHelper.generateResponse(printWriter, map, templateString);       
                }
                if(templateString.startsWith("/open")){
                        map.put( "lang",
-                                       new ResourceBundleGeneratorFunction( locales,
-                                                new MessageResources[] { MessageResources.getMessageResources("bundles.open"),
-                                                               MessageResources.getMessageResources("bundles.open")}));
+                               new ResourceBundleGeneratorFunction( locales,
+                                       new MessageResources[] { 
+                                               MessageResources.getMessageResources("bundles.open"),
+                                               MessageResources.getMessageResources("bundles.open")
+                                       }));
                                                                
-                       templateString = templateString.substring(5);
+                       templateString = templateString.substring(templateString.lastIndexOf('/'));
                        ServletHelper.generateOpenPostingResponse(printWriter, map, templateString);    
                }               
        }
@@ -177,5 +252,12 @@ public class TemplateServlet extends HttpServlet {
         */
        public void init(ServletConfig servletConfig) throws ServletException {
                super.init(servletConfig);
+               MirPropertiesConfiguration.setContext(servletConfig.getServletContext());
+               try {
+                       MirPropertiesConfiguration.instance();
+               }
+               catch (Throwable t) {
+                       throw new ServletException("can't read configuration: " + t.toString());
+               }
        }
 }
index 661ff56..511f0b2 100755 (executable)
@@ -30,7 +30,7 @@
 package mir.util;
 
 import java.util.List;
-import java.io.*;
+import javax.servlet.http.HttpServletResponse;
 
 import mir.generator.Generator;
 import mir.generator.GeneratorExc;
@@ -94,4 +94,25 @@ public class GeneratorHTMLFunctions {
       }
     };
   }
+  
+       public static class encodeLinksGeneratorFunction implements Generator.GeneratorFunction {
+               private HttpServletResponse _response;
+               public encodeLinksGeneratorFunction(HttpServletResponse response){
+                       _response = response;
+               }
+               public Object perform(List aParameters) throws GeneratorExc {
+                       try {
+                               if (aParameters.size()!=1)
+                                       throw new GeneratorExc("encodeHTMLGeneratorFunction: only 1 parameter expected");
+
+                               return _response.encodeURL((String)aParameters.get(0));
+                       }
+                       catch (GeneratorExc e) {
+                               throw e;
+                       }
+                       catch (Throwable t) {
+                               throw new GeneratorFailure("encodeHTMLGeneratorFunction: " + t.getMessage(), t);
+                       }
+               };
+       }
 }