BrightSide Workbench Full Report + Source Code
ApplicationFramework.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;
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.HttpSession;
25 import org.turro.action.IAgreements;
26 import org.turro.action.Interceptors;
27 import org.turro.auth.Authentication;
28 import org.turro.elephant.context.Application;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.i18n.I_;
31 import org.turro.zul.frame.Framework;
32 import org.zkoss.web.fn.ServletFns;
33 import org.zkoss.zk.ui.Executions;
34 import org.zkoss.zk.ui.GenericRichlet;
35 import org.zkoss.zk.ui.Page;
36 import org.zkoss.zk.ui.ext.AfterCompose;
37 
42 public class ApplicationFramework extends GenericRichlet {
43 
44  @Override
45  public void service(Page page) {
46  try {
48  setLocale(null);
50  if(app.getHttpSession(false).getAttribute("xp_user") == null) {
51  Executions.sendRedirect("/user?redir=/app/frame");
52  } else if(Authentication.isWebapp()) {
53  //Themes.setTheme(Executions.getCurrent(), "breeze");
54  app.getHttpSession(false).setMaxInactiveInterval(3 * 60 * 60);
55  Framework frame = new Framework();
56  frame.setPage(page);
57  if(frame instanceof AfterCompose) {
58  ((AfterCompose) frame).afterCompose();
59  }
60  if(frame.getPortalWindows().containsKey("welcome")) {
61  frame.addContent(frame.getPortalWindows().get("welcome"));
62  }
63  Interceptors.executeApp(app, Executions.getCurrent().getParameterMap());
64  } else {
65  Executions.sendRedirect("/user");
66  }
67  }
68  } catch (IOException ex) {
69  Logger.getLogger(ApplicationFramework.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
70  }
71  }
72 
73  public static void setLocale(HttpServletRequest request) {
74  if(request == null && org.zkoss.web.fn.ServletFns.getCurrentContext() != null) {
75  request = (HttpServletRequest) ServletFns.getCurrentRequest();
76  }
77  if(request != null) {
78  HttpSession session = request.getSession(false);
79  if(session != null) {
80  session.setAttribute("el_label", I_.compatibilityMap());
81  session.setAttribute("i_", I_.api());
82  session.setAttribute("i", I_.map());
83  session.setAttribute("k", I_.byKeyMap());
84  } else {
85  request.setAttribute("el_label", I_.compatibilityMap());
86  request.setAttribute("i_", I_.api());
87  request.setAttribute("i", I_.map());
88  request.setAttribute("k", I_.byKeyMap());
89  }
90  }
91  }
92 
93 }
static boolean executeApp(Application application, Map< String, String[]> parameterMap)
static void setLocale(HttpServletRequest request)
abstract HttpServletResponse getHttpServletResponse()
HttpSession getHttpSession(boolean create)
abstract HttpServletRequest getHttpServletRequest()
static I18nByKey byKeyMap()
Definition: I_.java:91
static I18nApiWrapper api()
Definition: I_.java:65
static I18nMapWrapper map()
Definition: I_.java:69
static I18nCompatibilityMap compatibilityMap()
Definition: I_.java:117
void addContent(String label, String src)
Definition: Framework.java:69
PortalWindows getPortalWindows()
Definition: Framework.java:128
static boolean checkAgreements(HttpServletRequest request, HttpServletResponse response)