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.vaadin.gwt.client.shared.magnoliashell;
35
36 import java.io.Serializable;
37
38
39
40
41 public class Fragment implements Serializable {
42
43 private ViewportType appViewportType = ViewportType.SHELL_APP;
44
45 private String appName = "";
46
47 private String subAppId = "";
48
49 private String parameter = "";
50
51 public Fragment() {
52 }
53
54 public static Fragment fromString(final String fragment) {
55 Fragmenti/vaadin/gwt/client/shared/magnoliashell/Fragment.html#Fragment">Fragment dto = new Fragment();
56 String type = extractAppType(fragment);
57 if (type.equals("shell")) {
58 dto.appViewportType = ViewportType.SHELL_APP;
59 dto.appName = ShellAppType.getTypeByFragmentId(extractAppName(fragment));
60 dto.subAppId = extractSubAppId(fragment);
61 dto.parameter = extractSubAppId(fragment);
62 } else if (type.equals("app")) {
63 dto.appViewportType = ViewportType.APP;
64 dto.appName = extractAppName(fragment);
65 dto.subAppId = extractSubAppId(fragment);
66 dto.parameter = extractParameter(fragment);
67 }
68 return dto;
69 }
70
71 public ShellAppType resolveShellAppType() {
72 if (isApp()) {
73 return null;
74 }
75 try {
76 return ShellAppType.valueOf(appName.toUpperCase());
77 } catch (IllegalArgumentException e) {
78 return ShellAppType.APPLAUNCHER;
79 }
80 }
81
82 public void setParameter(String parameter) {
83 this.parameter = parameter;
84 }
85
86 public void setSubAppId(String subAppId) {
87 this.subAppId = subAppId;
88 }
89
90 public void setAppName(String appName) {
91 this.appName = appName;
92 }
93
94 public void setAppViewportType(ViewportType type) {
95 this.appViewportType = type;
96 }
97
98 public ViewportType getAppViewportType() {
99 return appViewportType;
100 }
101
102 public String getAppName() {
103 return appName;
104 }
105
106 public String getSubAppId() {
107 return subAppId;
108 }
109
110 public String getParameter() {
111 return parameter;
112 }
113
114
115
116 public String toFragment() {
117 return toString();
118 }
119
120 public boolean isSameApp(Fragment other) {
121 return other != null && appViewportType == other.appViewportType && appName.equals(other.appName);
122 }
123
124 @Override
125 public String toString() {
126 return appViewportType.getFragmentPrefix() + appName + ":" + subAppId + ";" + parameter;
127 }
128
129 public static String extractAppType(String fragment) {
130 int i = fragment.indexOf(':');
131 String result = i != -1 ? fragment.substring(0, i) : fragment;
132 return result == null || result.isEmpty() ? "shell" : result;
133 }
134
135 public static String extractAppName(String fragment) {
136 fragment = removeParameter(fragment);
137 int i = fragment.indexOf(':');
138 if (i == -1) {
139 return "";
140 }
141 int j = fragment.indexOf(':', i + 1);
142 return j != -1 ? fragment.substring(i + 1, j) : fragment.substring(i + 1);
143 }
144
145 public static String extractSubAppId(String fragment) {
146 fragment = removeParameter(fragment);
147
148 int i = fragment.indexOf(':');
149 if (i == -1) {
150 return "";
151 }
152 int j = fragment.indexOf(':', i + 1);
153 if (j == -1) {
154 return "";
155 }
156 return fragment.substring(j + 1);
157 }
158
159 public static String extractParameter(String fragment) {
160 int i = fragment.indexOf(';');
161 if (i == -1) {
162 return "";
163 }
164 return fragment.substring(i + 1);
165 }
166
167 private static String removeParameter(String fragment) {
168 int i = fragment.indexOf(';');
169 return i != -1 ? fragment.substring(0, i) : fragment;
170 }
171
172 public boolean isShellApp() {
173 return appViewportType == ViewportType.SHELL_APP;
174 }
175
176 public boolean isApp() {
177 return !isShellApp();
178 }
179
180 public boolean sameSubApp(Fragment other) {
181 return isSameApp(other) && subAppId.equals(other.subAppId);
182 }
183
184 @Override
185 public boolean equals(Object o) {
186 if (this == o) return true;
187 if (!(o instanceof Fragment)) return false;
188
189 Fragment./../../../../../../info/magnolia/ui/vaadin/gwt/client/shared/magnoliashell/Fragment.html#Fragment">Fragment fragment = (Fragment) o;
190
191 if (!appName.equals(fragment.appName)) return false;
192 if (appViewportType != fragment.appViewportType) return false;
193 if (!parameter.equals(fragment.parameter)) return false;
194 if (!subAppId.equals(fragment.subAppId)) return false;
195
196 return true;
197 }
198
199 @Override
200 public int hashCode() {
201 int result = appViewportType.hashCode();
202 result = 31 * result + appName.hashCode();
203 result = 31 * result + subAppId.hashCode();
204 result = 31 * result + parameter.hashCode();
205 return result;
206 }
207 }