blob: f07816271043cc7b3e2c247f7c2b122e717a7f25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* Copyright 2000-2022 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.server;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.UI;
/**
*
* @author Vaadin Ltd
* @since 7.0.0
*
* @deprecated As of 7.0. Used only to support LegacyApplication - will be
* removed when LegacyApplication support is removed.
*/
@Deprecated
public abstract class LegacyApplicationUIProvider extends UIProvider {
/**
* Ignore initial / and then get everything up to the next /
*/
private static final Pattern WINDOW_NAME_PATTERN = Pattern
.compile("^/?([^/]+).*");
@Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
UI uiInstance = getUIInstance(event);
if (uiInstance != null) {
return uiInstance.getClass();
}
return null;
}
@Override
public UI createInstance(UICreateEvent event) {
return getUIInstance(event);
}
@Override
public String getTheme(UICreateEvent event) {
LegacyApplication application = getApplication();
if (application != null) {
return application.getTheme();
} else {
return null;
}
}
@Override
public String getPageTitle(UICreateEvent event) {
UI uiInstance = getUIInstance(event);
if (uiInstance != null) {
return uiInstance.getCaption();
} else {
return super.getPageTitle(event);
}
}
private UI getUIInstance(UIProviderEvent event) {
VaadinRequest request = event.getRequest();
String pathInfo = request.getPathInfo();
String name = null;
if (pathInfo != null && !pathInfo.isEmpty()) {
Matcher matcher = WINDOW_NAME_PATTERN.matcher(pathInfo);
if (matcher.matches()) {
// Skip the initial slash
name = matcher.group(1);
}
}
LegacyApplication application = getApplication();
if (application == null) {
return null;
}
LegacyWindow window = application.getWindow(name);
if (window != null) {
return window;
}
return application.getMainWindow();
}
/**
* Hack used to return existing LegacyWindow instances without regard for
* out-of-sync problems.
*
* @param event
* @return
*/
public UI getExistingUI(UIClassSelectionEvent event) {
UI uiInstance = getUIInstance(event);
if (uiInstance == null || uiInstance.getUIId() == -1) {
// Not initialized -> Let go through createUIInstance to make it
// initialized
return null;
} else {
UI.setCurrent(uiInstance);
return uiInstance;
}
}
private LegacyApplication getApplication() {
LegacyApplication application = VaadinSession.getCurrent()
.getAttribute(LegacyApplication.class);
if (application == null) {
application = createApplication();
if (application == null) {
return null;
}
VaadinSession.getCurrent().setAttribute(LegacyApplication.class,
application);
URL applicationUrl;
try {
applicationUrl = VaadinService.getCurrent()
.getApplicationUrl(VaadinService.getCurrentRequest());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
application.doInit(applicationUrl);
}
if (application != null && !application.isRunning()) {
VaadinSession.getCurrent().setAttribute(LegacyApplication.class,
null);
// Run again without a current application
return getApplication();
}
return application;
}
protected abstract LegacyApplication createApplication();
}
|