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.detail;
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
49
50
51
52
53
54
55
56 @Deprecated
57 public class DetailLocation extends DefaultLocation {
58
59 private DetailView.ViewType viewType;
60 private String nodePath;
61 private String version;
62
63 private final static int NODE_PATH_PARAM_POSITION = 0;
64 private final static int VIEW_TYPE_PARAM_POSITION = 1;
65 private final static int VERSION_PARAM_POSITION = 2;
66
67 public DetailLocation(String appName, String subAppId, String parameter) {
68 super(LOCATION_TYPE_APP, appName, subAppId, parameter);
69
70 setNodePath(extractNodePath(parameter));
71 setViewType(extractViewType(parameter));
72 setVersion(extractVersion(parameter));
73 }
74
75 public DetailLocation(String appName, String subAppId, DetailView.ViewType viewType, String nodePath, String version) {
76 super(LOCATION_TYPE_APP, appName, subAppId);
77
78 setNodePath(nodePath);
79 setViewType(viewType);
80 setVersion(version);
81 updateParameter();
82 }
83
84 public String getNodePath() {
85 return unescapeSpecialCharacters(nodePath);
86 }
87
88
89
90
91 private void setNodePath(String nodePath) {
92 this.nodePath = (nodePath == null || nodePath.isEmpty()) ? "/" : escapeSpecialCharacters(nodePath);
93 }
94
95 public DetailView.ViewType getViewType() {
96 return viewType;
97 }
98
99 public void setViewType(DetailView.ViewType viewType) {
100 this.viewType = viewType;
101 }
102
103 public String getVersion() {
104 return unescapeSpecialCharacters(version);
105 }
106
107 public void setVersion(String version) {
108 this.version = escapeSpecialCharacters(version);
109 }
110
111 public boolean hasVersion() {
112 return StringUtils.isNotBlank(version);
113 }
114
115
116
117
118
119
120
121 private String extractNodePath(String parameter) {
122 return getParameter(parameter, NODE_PATH_PARAM_POSITION);
123 }
124
125
126
127
128
129
130
131 private DetailView.ViewType extractViewType(String parameter) {
132 String action = getParameter(parameter, VIEW_TYPE_PARAM_POSITION);
133 return DetailView.ViewType.fromString(action);
134 }
135
136
137
138
139
140
141
142 private String extractVersion(String parameter) {
143 return getParameter(parameter, VERSION_PARAM_POSITION);
144 }
145
146 protected String getParameter(String parameter, int position) {
147 String arguments[] = StringUtils.split(parameter, ':');
148 if (position <= arguments.length - 1) {
149 return arguments[position];
150 }
151 return "";
152 }
153
154 protected void updateParameter() {
155 StringBuilder sb = new StringBuilder();
156 sb.append(nodePath);
157 sb.append(":");
158 sb.append(viewType.getText());
159 if (StringUtils.isNotBlank(version)) {
160 sb.append(":");
161 sb.append(version);
162 }
163 super.setParameter(sb.toString());
164 }
165
166 public static DetailLocation wrap(Location location) {
167 return new DetailLocation(location.getAppName(), location.getSubAppId(), location.getParameter());
168 }
169
170 public void updateNodePath(String newNodePath) {
171 setNodePath(newNodePath);
172 updateParameter();
173 }
174
175 public void updateViewtype(DetailView.ViewType newViewType) {
176 setViewType(newViewType);
177 updateParameter();
178 }
179
180 public void updateVersion(String newVersion) {
181 setVersion(newVersion);
182 updateParameter();
183 }
184
185 }