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;
35
36 import info.magnolia.cms.security.User;
37 import info.magnolia.context.Context;
38 import info.magnolia.ui.api.app.launcherlayout.AppLauncherLayout;
39 import info.magnolia.ui.api.app.launcherlayout.AppLauncherLayoutManager;
40 import info.magnolia.ui.api.location.DefaultLocation;
41 import info.magnolia.ui.api.location.Location;
42 import info.magnolia.ui.api.location.LocationHistoryMapper;
43
44
45
46
47 public class DefaultLocationHistoryMapper implements LocationHistoryMapper {
48
49 private final User user;
50 private final AppLauncherLayoutManager appLauncherLayoutManager;
51
52 public DefaultLocationHistoryMapper(final AppLauncherLayoutManager appLauncherLayoutManager, final Context context) {
53 this.appLauncherLayoutManager = appLauncherLayoutManager;
54 this.user = context.getUser();
55 }
56
57 @Override
58 public Location getLocation(String fragment) {
59
60 String appType = DefaultLocation.extractAppType(fragment);
61 String appName = DefaultLocation.extractAppName(fragment);
62 String subAppId = DefaultLocation.extractSubAppId(fragment);
63 String parameter = DefaultLocation.extractParameter(fragment);
64
65 if (!supported(appType, appName, subAppId, parameter)) {
66 return null;
67 }
68
69 return new DefaultLocation(appType, appName, subAppId, parameter);
70 }
71
72 @Override
73 public String getFragment(Location location) {
74
75 if (!supported(location.getAppType(), location.getAppName(), location.getSubAppId(), location.getParameter())) {
76 return null;
77 }
78
79 return location.toString();
80 }
81
82 private boolean supported(String appType, String appName, String subAppId, String parameter) {
83
84 if (appType.equals(Location.LOCATION_TYPE_SHELL_APP) && (appName.equals("applauncher") || appName.equals("pulse") || appName.equals("favorite"))) {
85 return true;
86 }
87
88 if (!appType.equals(Location.LOCATION_TYPE_APP)) {
89 return false;
90 }
91
92 AppLauncherLayout appLauncherLayout = appLauncherLayoutManager.getLayoutForUser(user);
93 return appLauncherLayout.containsApp(appName);
94 }
95 }