*/
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.core.service.storage.UserService;
import mir.core.ui.action.DispatchAction;
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.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.2 2003/09/10 20:58:27 idfx Exp $
+ * @version $Id: AuthenticationAction.java,v 1.3 2003/09/18 21:42:16 idfx Exp $
*/
public class AuthenticationAction extends DispatchAction {
private MirPropertiesConfiguration _configuration;
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);
//check if we have to redirect the user
String requestUri =
(String) session.getAttribute(ServletConstants.REDIRECT_ACTION);
-
+ System.out.println(requestUri);
if(requestUri != null && requestUri.indexOf("index") == -1
&& requestUri.indexOf("logon") == -1){
//construct a redirect
RedirectingActionForward actionForward =
new RedirectingActionForward(requestUri);
-
+ System.out.println("redirect");
//return the redirect
return actionForward;
}
//normal redirect to the startpage
+ System.out.println("success");
return actionMapping.findForward("success");
}
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());
- }
+ return actionMapping.findForward("logon");
}
}
--- /dev/null
+/*
+ * ConfirmAction.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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.core.ui.action.DispatchAction;
+import mir.core.ui.servlet.ServletConstants;
+import multex.Failure;
+
+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.ForwardingActionForward;
+
+/**
+ * ConfirmAction
+ * @author idefix
+ * @version $Id: ConfirmAction.java,v 1.1 2003/09/18 21:42:16 idfx Exp $
+ */
+public class ConfirmAction extends DispatchAction {
+ private MirPropertiesConfiguration _configuration;
+
+ public ConfirmAction(){
+ try {
+ _configuration = MirPropertiesConfiguration.instance();
+ } catch (PropertiesConfigExc e) {
+ throw new Failure("could not load config", e);
+ }
+ }
+
+ private ActionForward confirm(ActionMapping actionMapping, ActionForm actionForm,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+
+ //retrieve the form input data
+ DynaActionForm form = (DynaActionForm)actionForm;
+ String url = null;
+ if(form.get("cancel") != null && form.get("cancel").toString().length() > 0){
+ url = (String) form.get("cancelurl");
+ } else {
+ url = (String) form.get("okurl");
+ }
+
+ request.setAttribute(ServletConstants.ID, form.get("id"));
+ request.setAttribute("where", form.get("where"));
+ request.setAttribute("order", form.get("order"));
+ request.setAttribute("offset", form.get("offset"));
+ request.setAttribute(ServletConstants.DELETE, new Boolean(true));
+
+ if(url != null){
+ //construct a redirect
+ ActionForward actionForward =
+ new ForwardingActionForward("/" + url);
+ //return the redirect
+ return actionForward;
+ } else {
+ return actionMapping.findForward("failed");
+ }
+ }
+}
*/
package mir.core.ui.action.admin;
+import java.util.Date;
import java.util.List;
import javax.servlet.ServletContext;
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.Message;
+import mir.core.model.MirUser;
import mir.core.service.storage.MessageService;
+import mir.core.ui.action.DispatchAction;
import mir.core.ui.servlet.ServletConstants;
-
import multex.Failure;
-
import net.sf.hibernate.SessionFactory;
+import net.sf.hibernate.expression.Order;
-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;
/**
* AuthenticationAction
* @author idefix
- * @version $Id: MessageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ * @version $Id: MessageAction.java,v 1.2 2003/09/18 21:42:16 idfx Exp $
*/
-public class MessageAction extends Action {
+public class MessageAction extends DispatchAction {
private MirPropertiesConfiguration _configuration;
public MessageAction(){
+ super();
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,
+
+ private ActionForward add(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;
+ request.setAttribute(ServletConstants.NEW, new Boolean(true));
+ request.setAttribute(ServletConstants.ID, "");
+ request.setAttribute(ServletConstants.OFFSET, "");
+
+ //setting standard-values
+ Message message = new Message();
+ HttpSession session = request.getSession();
+ MirUser user = (MirUser) session.getAttribute(ServletConstants.USER);
+ message.setCreator(user.getLogin());
+ request.setAttribute("message", message);
+
+ // show the view
+ return actionMapping.findForward("success");
}
+ private ActionForward save(ActionMapping actionMapping, ActionForm actionForm,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ //access to persistence
+ ServletContext context = getServlet().getServletContext();
+ MessageService messageService =
+ new MessageService((SessionFactory)context
+ .getAttribute(ServletConstants.SESSION_FACTORY));
+
+ DynaActionForm form = (DynaActionForm) actionForm;
+ if(form == null){
+ return actionMapping.findForward("failed");
+ }
+ //check if new
+ Boolean isnew = (Boolean) form.get("new");
+
+ //retrieve id
+ Message message = null;
+ if(isnew.booleanValue()){
+ message = new Message();
+ } else {
+ Integer id = new Integer(request.getParameter(ServletConstants.ID));
+ message = (Message) messageService.load(id);
+ }
+
+ if(message == null){
+ return actionMapping.findForward("failed");
+ }
+
+ message.setTitle((String)form.get("title"));
+ message.setDescription((String)form.get("description"));
+ message.setCreator((String)form.get("creator"));
+
+ if(isnew.booleanValue()){
+ message.setWebdbCreate(new Date());
+ Integer id = messageService.save(message);
+ request.setAttribute(ServletConstants.OFFSET, "0");
+ } else {
+ messageService.update(message);
+ }
+
+ // show the view
+ return actionMapping.findForward("success");
+ }
+
+ private ActionForward delete(ActionMapping actionMapping, ActionForm actionForm,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ //access to persistence
+ ServletContext context = getServlet().getServletContext();
+ MessageService messageService =
+ new MessageService((SessionFactory)context
+ .getAttribute(ServletConstants.SESSION_FACTORY));
+
+ //retrieve id
+ Integer id = new Integer(request.getParameter(ServletConstants.ID));
+
+ //confirm the request
+ System.out.println(request.getAttribute(ServletConstants.DELETE));
+ if(request.getAttribute(ServletConstants.DELETE) == null){
+ System.out.println("call confirm");
+ return actionMapping.findForward("confirm");
+ }
+ System.out.println("komish confirm");
+ //load object
+ Message message = (Message) messageService.load(id);
+
+ if(message == null){
+ return actionMapping.findForward("failed");
+ }
+
+ messageService.delete(message);
+
+ // show the view
+ return actionMapping.findForward("success");
+ }
+
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){
+ if(offsetString != null && !offsetString.equals("")){
offset = new Integer(offsetString).intValue();
}
.getAttribute(ServletConstants.SESSION_FACTORY));
//retrieve entities
- List messages = messageService.list(offset);
+ Order order = Order.desc("webdbCreate");
+ List messages = messageService.list(offset, order);
//configure the data to send to view
int listSize = _configuration.getInt("ServletModule.Default.ListSize");
//show the view
return actionMapping.findForward("success");
}
+
+ private ActionForward edit(ActionMapping actionMapping, ActionForm actionForm,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ //retrieve parameters
+ Integer id = new Integer(request.getParameter(ServletConstants.ID));
+ String offset = request.getParameter(ServletConstants.OFFSET);
+
+
+ //access to persistence
+ ServletContext context = getServlet().getServletContext();
+ MessageService messageService =
+ new MessageService((SessionFactory)context
+ .getAttribute(ServletConstants.SESSION_FACTORY));
+
+ //retrieve entities
+ Message message = (Message) messageService.load(id);
+
+ //configure the data to send to view
+ request.setAttribute(ServletConstants.OFFSET, offset);
+ request.setAttribute(ServletConstants.NEW,"0");
+ request.setAttribute("message", message);
+
+ //show the view
+ return actionMapping.findForward("success");
+ }
}
import mir.core.service.storage.MessageService;
import mir.core.ui.servlet.ServletConstants;
import net.sf.hibernate.SessionFactory;
+import net.sf.hibernate.expression.Order;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
/**
* AuthenticationAction
* @author idefix
- * @version $Id: StartpageAction.java,v 1.1 2003/09/07 16:55:00 idfx Exp $
+ * @version $Id: StartpageAction.java,v 1.2 2003/09/18 21:42:16 idfx Exp $
*/
public class StartpageAction extends Action {
MessageService messageService =
new MessageService((SessionFactory)context
.getAttribute(ServletConstants.SESSION_FACTORY));
- List messages = messageService.list(0);
+ Order order = Order.desc("webdbCreate");
+ List messages = messageService.list(0, order);
request.setAttribute("messages", messages);
return actionMapping.findForward("success");
/**
* AuthenticationFilter
* @author idefix
- * @version $Id: AuthenticationFilter.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
+ * @version $Id: AuthenticationFilter.java,v 1.3 2003/09/18 21:42:17 idfx Exp $
*/
public class AuthenticationFilter implements Filter {
private FilterConfig _filterConfig;
HttpServletRequest request = (HttpServletRequest)servletRequest;
String requestUri = request.getRequestURI();
-
if(requestUri != null
&& requestUri.startsWith(request.getContextPath() + "/admin")
&& requestUri.indexOf("logon") == -1){
//send user to logon-page
servletRequest.getRequestDispatcher("/admin/logon.do")
.forward(servletRequest, servletResponse);
- }
- }
-
- filterChain.doFilter(servletRequest, servletResponse);
+ } else {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+ } else {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
}
/**
--- /dev/null
+/*
+ * CachingFilter.java created on 04.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.filter;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * CachingFilter
+ * @author idefix
+ * @version $Id: CachingFilter.java,v 1.1 2003/09/18 21:42:17 idfx Exp $
+ */
+public class CachingFilter implements Filter {
+ private final static String EXPIRATION_DATE;
+ private FilterConfig _filterConfig;
+
+ static {
+ // Generate expiration date that is one year from now in the past
+ GregorianCalendar expiration = new GregorianCalendar();
+ expiration.roll(Calendar.YEAR, -1);
+ SimpleDateFormat httpDate =
+ new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", java.util.Locale.US);
+ EXPIRATION_DATE = httpDate.format(expiration.getTime());
+ }
+
+ /**
+ *
+ */
+ public CachingFilter() {
+ super();
+ }
+
+ /**
+ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+ */
+ 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)
+ throws IOException, ServletException {
+
+ filterChain.doFilter(servletRequest, servletResponse);
+
+ HttpServletResponse response = (HttpServletResponse) servletResponse;
+ // HTTP 1.1 browsers should defeat caching on this header
+ response.setHeader( "Cache-Control" ,"no-cache" );
+ // HTTP 1.0 browsers should defeat caching on this header
+ response.setHeader( "Pragma" ,"no-cache" );
+ // Last resort for those that ignore all of the above
+ response.setHeader( "Expires" , EXPIRATION_DATE);
+ }
+
+ /**
+ * @see javax.servlet.Filter#destroy()
+ */
+ public void destroy() {
+ _filterConfig = null;
+ }
+
+}
/**
* HibernatePlugin
- * @version $Id: HibernatePlugin.java,v 1.1 2003/09/05 20:23:59 idfx Exp $
+ * @version $Id: HibernatePlugin.java,v 1.2 2003/09/18 21:42:17 idfx Exp $
* @author idefix
*/
public class HibernatePlugin implements PlugIn {
*/
public void init(ActionServlet actionServlet, ModuleConfig config)
throws ServletException {
- try {
- SessionFactory factory =
- new Configuration().configure().buildSessionFactory();
- actionServlet.getServletContext()
- .setAttribute(ServletConstants.SESSION_FACTORY, factory);
- } catch (HibernateException e) {
- throw new ServletException(e);
- }
+ try {
+ SessionFactory factory =
+ new Configuration().configure().buildSessionFactory();
+ actionServlet.getServletContext()
+ .setAttribute(ServletConstants.SESSION_FACTORY, factory);
+ } catch (HibernateException e) {
+ throw new ServletException(e);
+ }
}
}
* ServletConstants<br>
* Some constant string values needed as keys to store values in the servlet context.
* @author idefix
- * @version $Id: ServletConstants.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
+ * @version $Id: ServletConstants.java,v 1.3 2003/09/18 21:42:17 idfx Exp $
*/
public interface ServletConstants {
+ public static final String DELETE = "delete";
+
+ public static final String NEW = "new";
+
+ public static final String ID = "id";
+
public static final String REDIRECT_ACTION = "redirect action";
public static final String REDIRECT_QUERY_STRING = "redirect query string";
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
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.GeneratorStringFunctions;
import mir.util.ResourceBundleGeneratorFunction;
import mir.util.StringRoutines;
+import mircoders.global.MirGlobal;
import mircoders.servlet.ServletHelper;
+import multex.Failure;
import org.apache.struts.util.MessageResources;
/**
* TemplateServlet
* @author idefix
- * @version $Id: TemplateServlet.java,v 1.2 2003/09/07 16:55:00 idfx Exp $
+ * @version $Id: TemplateServlet.java,v 1.3 2003/09/18 21:42:17 idfx Exp $
*/
public class TemplateServlet extends HttpServlet {
-
+ private MirPropertiesConfiguration _configuration;
+
/**
*
*/
public TemplateServlet() {
super();
+ try {
+ _configuration = MirPropertiesConfiguration.instance();
+ } catch (PropertiesConfigExc e) {
+ throw new Failure("could not load config", e);
+ }
}
protected void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
+ setLoginLanguages(this.getServletContext());
+
Map requestData = new HashMap();
Enumeration keys = request.getAttributeNames();
while(keys.hasMoreElements()){
templateData.put("administeroperations", administerOperations);
String templateName = generateTemplateString(request);
-
+ System.out.println(templateName);
Locale[] locales = new Locale[2];
locales[0] = request.getLocale();
locales[1] = request.getLocale();
ServletHelper.generateOpenPostingResponse(printWriter, map, templateString);
}
}
+
+ 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());
+ }
+ }
/**
* @see javax.servlet.Servlet#destroy()