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