1 16 17 package org.apache.struts.faces.util; 18 19 20 import java.util.Locale ; 21 22 import javax.faces.context.ExternalContext; 23 import javax.faces.context.FacesContext; 24 import javax.faces.event.ActionEvent; 25 26 import javax.sql.DataSource ; 27 28 import org.apache.struts.Globals; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.action.ActionMessages; 31 import org.apache.struts.action.ActionServlet; 32 import org.apache.struts.config.ModuleConfig; 33 import org.apache.struts.faces.Constants; 34 import org.apache.struts.util.MessageResources; 35 36 37 43 44 public class StrutsContext { 45 46 47 49 50 53 private FacesContext fcontext = 54 FacesContext.getCurrentInstance(); 55 56 57 60 private ExternalContext econtext = 61 fcontext.getExternalContext(); 62 63 64 66 67 71 public ActionEvent getActionEvent() { 72 73 return ((ActionEvent) econtext.getRequestMap(). 74 get(Constants.ACTION_EVENT_KEY)); 75 76 } 77 78 79 83 public ActionMapping getActionMapping() { 84 85 return ((ActionMapping) econtext.getRequestMap(). 86 get(Globals.MAPPING_KEY)); 87 88 } 89 90 91 95 public ActionMessages getActionMessages() { 96 97 return ((ActionMessages) econtext.getRequestMap(). 98 get(Globals.MESSAGE_KEY)); 99 100 } 101 102 103 107 public ActionServlet getActionServlet() { 108 109 return ((ActionServlet) econtext.getApplicationMap(). 110 get(Globals.ACTION_SERVLET_KEY)); 111 112 } 113 114 115 120 public boolean isCancelled() { 121 122 Object value = econtext.getRequestMap().get(Globals.CANCEL_KEY); 123 if (value instanceof Boolean ) { 124 return (((Boolean ) value).booleanValue()); 125 } else { 126 return (false); 127 } 128 129 } 130 131 132 133 137 public Throwable getException() { 138 139 return ((Throwable ) econtext.getRequestMap(). 140 get(Globals.EXCEPTION_KEY)); 141 142 } 143 144 145 148 public ExternalContext getExternalContext() { 149 150 return (econtext); 151 152 } 153 154 155 158 public FacesContext getFacesContext() { 159 160 return (fcontext); 161 162 } 163 164 165 169 public Locale getLocale() { 170 171 if (econtext.getSession(false) != null) { 172 return ((Locale ) econtext.getSessionMap(). 173 get(Globals.LOCALE_KEY)); 174 } else { 175 return (null); 176 } 177 178 } 179 180 181 185 public MessageResources getMessageResources() { 186 187 return ((MessageResources) econtext.getRequestMap(). 188 get(Globals.MESSAGES_KEY)); 189 190 } 191 192 193 197 public ModuleConfig getModuleConfig() { 198 199 return ((ModuleConfig) econtext.getRequestMap(). 200 get(Globals.MODULE_KEY)); 201 202 } 203 204 205 } 206 207 | Popular Tags |