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