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.contentapp.browser;
35
36 import info.magnolia.ui.api.location.DefaultLocation;
37 import info.magnolia.ui.api.location.Location;
38
39 import org.apache.commons.lang3.StringUtils;
40
41
42
43
44 public class BrowserLocation extends DefaultLocation {
45
46 private String nodePath;
47 private String viewType;
48 private String query;
49
50 public BrowserLocation(String appName, String subAppId, String parameter) {
51 super(LOCATION_TYPE_APP, appName, subAppId, parameter);
52
53 setNodePath(extractNodePath(parameter));
54 setViewType(extractView(parameter));
55 setQuery(extractQuery(parameter));
56 }
57
58 public String getNodePath() {
59 return nodePath;
60 }
61
62
63
64
65 private void setNodePath(String nodePath) {
66 this.nodePath = (nodePath == null || nodePath.isEmpty()) ? "/" : nodePath;
67 }
68
69 public String getViewType() {
70 return viewType;
71 }
72
73 private void setViewType(String viewType) {
74 this.viewType = viewType;
75 }
76
77 public String getQuery() {
78 return query;
79 }
80
81 private void setQuery(String query) {
82 this.query = query;
83 }
84
85 private String extractNodePath(String parameter) {
86 int i = parameter.indexOf(':');
87 return i != -1 ? parameter.substring(0, i) : parameter;
88 }
89
90 private String extractView(String parameter) {
91
92 int i = parameter.indexOf(':');
93 if (i != -1) {
94
95 int j = parameter.indexOf(':', i + 1);
96 String view = (j != -1) ? parameter.substring(i + 1, j) : parameter.substring(i + 1);
97 if (StringUtils.isNotBlank(view)) {
98 return view;
99 }
100 }
101 return null;
102 }
103
104 public static String extractQuery(String fragment) {
105
106 int i = fragment.indexOf(':');
107 if (i == -1) {
108 return "";
109 }
110
111 int j = fragment.indexOf(':', i + 1);
112 if (j == -1) {
113 return "";
114 }
115
116 return fragment.substring(j + 1);
117 }
118
119 protected void updateParameter() {
120 StringBuilder sb = new StringBuilder();
121 sb.append(nodePath);
122 sb.append(":");
123 sb.append(viewType);
124 sb.append(":");
125 sb.append(query);
126 super.setParameter(sb.toString());
127 }
128
129 public static BrowserLocation wrap(Location location) {
130 return new BrowserLocation(location.getAppName(), location.getSubAppId(), location.getParameter());
131 }
132
133 public void updateNodePath(String newNodePath) {
134 setNodePath(newNodePath);
135 updateParameter();
136 }
137
138 public void updateViewType(String newViewType) {
139 setViewType(newViewType);
140 updateParameter();
141 }
142
143 public void updateQuery(String newQuery) {
144 setQuery(newQuery);
145 updateParameter();
146 }
147 }