BrightSide Workbench Full Report + Source Code
ElephantApplication.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.context;
19 
20 import java.io.IOException;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 
30 public class ElephantApplication extends Application {
31 
32  public static Application getCurrent(HttpServletRequest request, HttpServletResponse response) {
33  Application application = (Application) request.getAttribute("el_app");
34  if(application == null) {
35  application = new ElephantApplication(request, response);
36  request.setAttribute("el_app", application);
37  }
38  app.set(application);
39  return application;
40  }
41 
42  public static Application getCurrent(IConstructor constructor) {
43  return getCurrent(constructor.getRequest(), constructor.getResponse());
44  }
45 
46  private ElephantApplication() {}
47 
48  public ElephantApplication(HttpServletRequest request, HttpServletResponse response) {
49  super();
50  this.request = request;
51  this.response = response;
52  request.setAttribute("el_app", this);
53  }
54 
55  @Override
60  constructor.setRequestAttribute("el_cons", constructor);
61  return constructor;
62  }
63 
64  @Override
65  public HttpServletRequest getHttpServletRequest() {
66  return request;
67  }
68 
69  @Override
70  public HttpServletResponse getHttpServletResponse() {
71  return response;
72  }
73 
74 // @Override
75 // public void fillConfigured() {
76 // for(String s : ElContextMap.getCurrent().getDefaultLocales()) {
77 // locales.addConfigured(s);
78 // }
79 // }
80 
81  @Override
82  public void sendRedirect(String uri) {
83  try {
84  getConstructor().redirect(uri);
85  } catch (IOException ex) {
86  Logger.getLogger(ElephantApplication.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
87  }
88  }
89 
90  @Override
91  public void navigateBack() {
92  try {
94  } catch (IOException ex) {
95  Logger.getLogger(ElephantApplication.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
96  }
97  }
98 
99 }
static ThreadLocal< Application > app
static Application getCurrent(IConstructor constructor)
ElephantApplication(HttpServletRequest request, HttpServletResponse response)
static Application getCurrent(HttpServletRequest request, HttpServletResponse response)
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
void setRequestAttribute(String key, Object value)