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 package info.magnolia.ui.framework.app.embedded;
35
36 import info.magnolia.context.MgnlContext;
37 import info.magnolia.ui.api.app.SubAppContext;
38 import info.magnolia.ui.api.location.Location;
39 import info.magnolia.ui.framework.app.BaseSubApp;
40
41 import javax.inject.Inject;
42
43 import org.apache.commons.lang3.StringUtils;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47
48
49
50
51 public class EmbeddedPageSubApp extends BaseSubApp<EmbeddedPageView> {
52
53 private static final Logger log = LoggerFactory.getLogger(EmbeddedPageSubApp.class);
54 private Location lastLocation;
55
56 @Inject
57 public EmbeddedPageSubApp(SubAppContext subAppContext, EmbeddedPageView pageView) {
58 super(subAppContext, pageView);
59 }
60
61 @Override
62 public EmbeddedPageView start(Location location) {
63 this.lastLocation = location;
64 String url = location.getParameter();
65 if (StringUtils.isEmpty(url)) {
66 EmbeddedPageSubAppDescriptor subAppDescriptor = ((EmbeddedPageSubAppDescriptor) getSubAppContext().getSubAppDescriptor());
67 url = subAppDescriptor.getUrl();
68 }
69
70 url = updateUrl(url);
71 getView().setUrl(url);
72 return super.start(location);
73 }
74
75
76
77
78 @Override
79 public void locationChanged(Location location) {
80 String url = location.getParameter();
81 if (StringUtils.isNotBlank(url) && !url.equals(lastLocation.getParameter())) {
82 getView().setUrl(updateUrl(url));
83 }
84 this.lastLocation = location;
85 super.locationChanged(location);
86 }
87
88
89
90
91 protected String updateUrl(String url) {
92 boolean isInternalPage = !url.startsWith("http");
93
94 if(isInternalPage) {
95 url = url.startsWith("/") ? MgnlContext.getContextPath() + url : MgnlContext.getContextPath() + "/" + url;
96 }
97 return url;
98 }
99 }