1 23 24 package org.infoglue.deliver.applications.actions; 25 26 import java.security.Principal ; 27 import java.util.Enumeration ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import javax.servlet.http.HttpServletRequest ; 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 52 53 public class InfoGlueDefaultInputHandlerAction extends InfoGlueAbstractAction 54 { 55 private final static Logger logger = Logger.getLogger(InfoGlueDefaultInputHandlerAction.class.getName()); 56 57 private Integer siteNodeId = null; 58 private Integer languageId = null; 59 private Integer contentId = null; 60 61 private String redirectAddress = null; 62 private Integer formContentId = null; 63 64 65 public String doExecute() throws Exception 66 { 67 invokeHandler(); 68 getResponse().sendRedirect(this.redirectAddress); 69 70 return NONE; 71 } 72 73 74 78 79 protected void invokeHandler() throws Exception 80 { 81 DatabaseWrapper dbWrapper = new DatabaseWrapper(CastorDatabaseService.getDatabase()); 82 84 beginTransaction(dbWrapper.getDatabase()); 85 86 try 87 { 88 Principal principal = (Principal )this.getHttpSession().getAttribute("infogluePrincipal"); 89 if(principal == null) 90 { 91 try 92 { 93 Map arguments = new HashMap (); 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 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 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 object = Class.forName(inputHandlerClassName).newInstance(); 109 InfoGlueInputHandler infoGlueInputHandler = (InfoGlueInputHandler)object; 110 HashMap 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 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 127 128 private HashMap requestToHashtable(HttpServletRequest req) 129 { 130 HashMap parameters = new HashMap (); 131 132 for (Enumeration e = req.getParameterNames(); e.hasMoreElements() ;) 133 { 134 String name = (String )e.nextElement(); 135 String value = (String )req.getParameter(name); 136 parameters.put(name, value); 137 } 138 139 return parameters; 140 141 } 142 143 public String getRedirectAddress() 144 { 145 return this.redirectAddress; 146 } 147 148 public void setRedirectAddress(String redirectAddress) 149 { 150 this.redirectAddress = redirectAddress; 151 } 152 153 public Integer getContentId() 154 { 155 return contentId; 156 } 157 158 public Integer getFormContentId() 159 { 160 return formContentId; 161 } 162 163 public Integer getLanguageId() 164 { 165 return languageId; 166 } 167 168 public Integer getSiteNodeId() 169 { 170 return siteNodeId; 171 } 172 173 public void setContentId(Integer contentId) 174 { 175 this.contentId = contentId; 176 } 177 178 public void setFormContentId(Integer formContentId) 179 { 180 this.formContentId = formContentId; 181 } 182 183 public void setLanguageId(Integer languageId) 184 { 185 this.languageId = languageId; 186 } 187 188 public void setSiteNodeId(Integer siteNodeId) 189 { 190 this.siteNodeId = siteNodeId; 191 } 192 193 } | Popular Tags |