KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > InfoGlueDefaultInputHandlerAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.deliver.applications.actions;
25
26 import java.security.Principal JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
35 import org.infoglue.cms.applications.structuretool.actions.ViewStructureTreeForInlineLinkAction;
36 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
37 import org.infoglue.cms.exception.SystemException;
38 import org.infoglue.cms.security.InfoGluePrincipal;
39 import org.infoglue.cms.util.CmsPropertyHandler;
40 import org.infoglue.deliver.applications.databeans.DatabaseWrapper;
41 import org.infoglue.deliver.applications.databeans.DeliveryContext;
42 import org.infoglue.deliver.applications.inputhandlers.InfoGlueInputHandler;
43 import org.infoglue.deliver.controllers.kernel.impl.simple.ContentDeliveryController;
44 import org.infoglue.deliver.controllers.kernel.impl.simple.ExtranetController;
45
46 /**
47  * This is the action that receives most input from the outside and invokes the appropriate class
48  * to ensure that the data is treated correctly.
49  *
50  * @author Mattias Bogeblad
51  */

52
53 public class InfoGlueDefaultInputHandlerAction extends InfoGlueAbstractAction
54 {
55     private final static Logger logger = Logger.getLogger(InfoGlueDefaultInputHandlerAction.class.getName());
56
57     private Integer JavaDoc siteNodeId = null;
58     private Integer JavaDoc languageId = null;
59     private Integer JavaDoc contentId = null;
60     
61     private String JavaDoc redirectAddress = null;
62     private Integer JavaDoc formContentId = null;
63     
64     
65     public String JavaDoc doExecute() throws Exception JavaDoc
66     {
67         invokeHandler();
68         getResponse().sendRedirect(this.redirectAddress);
69         
70         return NONE;
71     }
72     
73     
74     /**
75      * This method invokes the right handler for this input. The handler is declared by the caller but it must
76      * conform with the interface of InfoGlueInputHandler.
77      */

78     
79     protected void invokeHandler() throws Exception JavaDoc
80     {
81         DatabaseWrapper dbWrapper = new DatabaseWrapper(CastorDatabaseService.getDatabase());
82         //Database db = CastorDatabaseService.getDatabase();
83

84         beginTransaction(dbWrapper.getDatabase());
85
86         try
87         {
88             Principal JavaDoc principal = (Principal JavaDoc)this.getHttpSession().getAttribute("infogluePrincipal");
89             if(principal == null)
90             {
91                 try
92                 {
93                     Map JavaDoc arguments = new HashMap JavaDoc();
94                     arguments.put("j_username", CmsPropertyHandler.getAnonymousUser());
95                     arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword());
96                     
97                     principal = ExtranetController.getController().getAuthenticatedPrincipal(dbWrapper.getDatabase(), arguments);
98                 }
99                 catch(Exception JavaDoc e)
100                 {
101                     throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again.", e);
102                 }
103             }
104             
105             String JavaDoc inputHandlerClassName = ContentDeliveryController.getContentDeliveryController().getContentAttribute(dbWrapper.getDatabase(), formContentId, languageId, "InputHandlerClassName", siteNodeId, true, DeliveryContext.getDeliveryContext(), (InfoGluePrincipal)principal, false);
106
107             logger.info("Trying to invoke " + inputHandlerClassName);
108             Object JavaDoc object = Class.forName(inputHandlerClassName).newInstance();
109             InfoGlueInputHandler infoGlueInputHandler = (InfoGlueInputHandler)object;
110             HashMap JavaDoc parameters = requestToHashtable(this.getRequest());
111             infoGlueInputHandler.processInput(dbWrapper, this.siteNodeId, this.languageId, this.contentId, this.formContentId, parameters, this.getRequest(), (InfoGluePrincipal)principal);
112         
113             closeTransaction(dbWrapper.getDatabase());
114         }
115         catch(Exception JavaDoc e)
116         {
117             logger.error("An error occurred so we should not complete the transaction:" + e, e);
118             rollbackTransaction(dbWrapper.getDatabase());
119             throw new SystemException(e.getMessage());
120         }
121         
122     }
123     
124     /**
125      * A simple convenience method that converts the request-values into a hashmap.
126      */

127     
128     private HashMap JavaDoc requestToHashtable(HttpServletRequest JavaDoc req)
129     {
130         HashMap JavaDoc parameters = new HashMap JavaDoc();
131                 
132         for (Enumeration JavaDoc e = req.getParameterNames(); e.hasMoreElements() ;)
133         {
134             String JavaDoc name = (String JavaDoc)e.nextElement();
135             String JavaDoc value = (String JavaDoc)req.getParameter(name);
136             parameters.put(name, value);
137         }
138         
139         return parameters;
140         
141     }
142  
143     public String JavaDoc getRedirectAddress()
144     {
145         return this.redirectAddress;
146     }
147
148     public void setRedirectAddress(String JavaDoc redirectAddress)
149     {
150         this.redirectAddress = redirectAddress;
151     }
152
153     public Integer JavaDoc getContentId()
154     {
155         return contentId;
156     }
157
158     public Integer JavaDoc getFormContentId()
159     {
160         return formContentId;
161     }
162
163     public Integer JavaDoc getLanguageId()
164     {
165         return languageId;
166     }
167
168     public Integer JavaDoc getSiteNodeId()
169     {
170         return siteNodeId;
171     }
172
173     public void setContentId(Integer JavaDoc contentId)
174     {
175         this.contentId = contentId;
176     }
177
178     public void setFormContentId(Integer JavaDoc formContentId)
179     {
180         this.formContentId = formContentId;
181     }
182
183     public void setLanguageId(Integer JavaDoc languageId)
184     {
185         this.languageId = languageId;
186     }
187
188     public void setSiteNodeId(Integer JavaDoc siteNodeId)
189     {
190         this.siteNodeId = siteNodeId;
191     }
192
193 }
Popular Tags