mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
Upgrade to Vaadin 7, ControllerUtils #PL-1809
This commit is contained in:
parent
21a5235ff8
commit
4be51c8559
@ -32,6 +32,8 @@ import java.util.Locale;
|
||||
*/
|
||||
public abstract class App implements Serializable {
|
||||
|
||||
public static final String USER_SESSION_ATTR = "userSessionId";
|
||||
|
||||
private static Log log = LogFactory.getLog(App.class);
|
||||
|
||||
private AppLog appLog;
|
||||
|
@ -2,42 +2,51 @@
|
||||
* Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
*
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 11.03.2011 12:27:03
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.controllers;
|
||||
|
||||
import com.haulmont.cuba.core.global.ConfigProvider;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Configuration;
|
||||
import com.haulmont.cuba.core.global.GlobalConfig;
|
||||
import com.haulmont.cuba.gui.ServiceLocator;
|
||||
import com.haulmont.cuba.security.app.LoginService;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
//import com.haulmont.cuba.web.AppUI;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.AppUI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author gorodnov
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class ControllerUtils {
|
||||
private static final String DISPATCHER = "dispatch";
|
||||
|
||||
// public static String getWebControllerURL(String mapping) {
|
||||
// if (mapping == null) throw new IllegalArgumentException("Mapping cannot be null");
|
||||
//
|
||||
// String baseUrl = AppUI.getInstance().getURL().toExternalForm();
|
||||
// StringBuilder url = new StringBuilder(baseUrl).append(getDispatcher());
|
||||
// if (!mapping.startsWith("/")) {
|
||||
// url.append("/");
|
||||
// }
|
||||
// url.append(mapping);
|
||||
// return url.toString();
|
||||
// }
|
||||
public static String getWebControllerURL(String mapping) {
|
||||
if (mapping == null) throw new IllegalArgumentException("Mapping cannot be null");
|
||||
|
||||
URI location = AppUI.getCurrent().getPage().getLocation();
|
||||
String baseUrl;
|
||||
try {
|
||||
baseUrl = location.toURL().toExternalForm();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
StringBuilder url = new StringBuilder(baseUrl).append(getDispatcher());
|
||||
if (!mapping.startsWith("/")) {
|
||||
url.append("/");
|
||||
}
|
||||
url.append(mapping);
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
public static String getControllerURL(String mapping) {
|
||||
if (mapping == null) throw new IllegalArgumentException("Mapping cannot be null");
|
||||
GlobalConfig globalConfig = ConfigProvider.getConfig(GlobalConfig.class);
|
||||
GlobalConfig globalConfig = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class);
|
||||
|
||||
StringBuilder sb = new StringBuilder(globalConfig.getWebAppUrl()).append(getContollerPrefix());
|
||||
if (!mapping.startsWith("/")) {
|
||||
@ -62,9 +71,9 @@ public abstract class ControllerUtils {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
/*
|
||||
|
||||
public static UserSession getUserSession(HttpServletRequest req) {
|
||||
UserSession userSession = (UserSession) req.getSession().getAttribute(AppUI.USER_SESSION_ATTR);
|
||||
UserSession userSession = (UserSession) req.getSession().getAttribute(App.USER_SESSION_ATTR);
|
||||
if (userSession != null) {
|
||||
return userSession;
|
||||
} else {
|
||||
@ -72,10 +81,10 @@ public abstract class ControllerUtils {
|
||||
if (s != null) {
|
||||
try {
|
||||
UUID id = UUID.fromString(s);
|
||||
LoginService service = ServiceLocator.lookup(LoginService.NAME);
|
||||
LoginService service = AppBeans.get(LoginService.class);
|
||||
UserSession session = service.getSession(id);
|
||||
if (session != null) {
|
||||
req.getSession().setAttribute(AppUI.USER_SESSION_ATTR, session);
|
||||
req.getSession().setAttribute(App.USER_SESSION_ATTR, session);
|
||||
return session;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -84,5 +93,5 @@ public abstract class ControllerUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user