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.cms.core;
35
36 import info.magnolia.cms.util.SelectorUtil;
37 import info.magnolia.init.MagnoliaConfigurationProperties;
38 import info.magnolia.jcr.util.NodeNameHelper;
39 import info.magnolia.jcr.util.NodeUtil;
40 import info.magnolia.objectfactory.Components;
41
42 import java.io.File;
43 import java.nio.file.Paths;
44
45 import javax.jcr.Node;
46 import javax.jcr.RepositoryException;
47 import javax.jcr.Session;
48
49 import org.safehaus.uuid.UUIDGenerator;
50
51
52
53
54
55
56 @Deprecated
57 public final class Path {
58
59
60
61
62 public static final String SELECTOR_DELIMITER = SelectorUtil.SELECTOR_DELIMITER;
63
64
65
66
67 private Path() {
68
69 }
70
71
72
73
74 public static String getCacheDirectoryPath() {
75 return getCacheDirectory().getAbsolutePath();
76 }
77
78
79
80
81 public static File getCacheDirectory() {
82 String path = SystemProperty.getProperty(MagnoliaConfigurationProperties.MAGNOLIA_CACHE_STARTDIR);
83 File dir = isAbsolute(path) ? new File(path) : new File(getAppRootDir(), path);
84 dir.mkdirs();
85 return dir;
86 }
87
88
89
90
91 public static String getTempDirectoryPath() {
92 return Components.getComponent(FileSystemHelper.class).getTempDirectory().getAbsolutePath();
93 }
94
95
96
97
98 public static File getTempDirectory() {
99 return Components.getComponent(FileSystemHelper.class).getTempDirectory();
100 }
101
102
103
104
105
106
107
108 public static String getHistoryFilePath() {
109 return getHistoryFile().getAbsolutePath();
110 }
111
112
113
114
115 public static File getHistoryFile() {
116 String path = SystemProperty.getProperty(MagnoliaConfigurationProperties.MAGNOLIA_EXCHANGE_HISTORY);
117 return isAbsolute(path) ? new File(path) : new File(getAppRootDir(), path);
118 }
119
120
121
122
123 public static String getRepositoriesConfigFilePath() {
124 return getRepositoriesConfigFile().getAbsolutePath();
125 }
126
127
128
129
130 public static File getRepositoriesConfigFile() {
131 String path = SystemProperty.getProperty(MagnoliaConfigurationProperties.MAGNOLIA_REPOSITORIES_CONFIG);
132 return isAbsolute(path) ? new File(path) : new File(getAppRootDir(), path);
133 }
134
135
136
137
138 public static File getAppRootDir() {
139 return Components.getComponent(FileSystemHelper.class).getAppRootDir();
140 }
141
142
143
144
145 public static String getAbsoluteFileSystemPath(String path) {
146 return Components.getComponent(FileSystemHelper.class).getAbsoluteFileSystemPath(path);
147 }
148
149
150
151
152 public static String getUniqueLabel(Session session, String parentPath, String label) throws RepositoryException {
153 return Components.getComponent(NodeNameHelper.class).getUniqueName(session, parentPath, label);
154 }
155
156
157
158
159 public static String getUniqueLabel(Session session, String parentPath, String label, String extension) throws RepositoryException {
160 return Components.getComponent(NodeNameHelper.class).getUniqueName(session, parentPath, label, extension);
161 }
162
163
164
165
166
167 public static String getUniqueLabel(Node parent, String label) {
168 try {
169 return Components.getComponent(NodeNameHelper.class).getUniqueName(parent, label);
170 } catch (RepositoryException e) {
171 return UUIDGenerator.getInstance().generateRandomBasedUUID().toString();
172 }
173 }
174
175
176
177
178
179
180 public static boolean isAbsolute(String path) {
181 if (path == null) {
182 return false;
183 }
184
185 return path.startsWith("/") || Paths.get(path).isAbsolute();
186 }
187
188
189
190
191 public static String getValidatedLabel(String label) {
192 return Components.getComponent(NodeNameHelper.class).getValidatedName(label);
193 }
194
195
196
197
198 public static String getValidatedLabel(String label, String charset) {
199 return Components.getComponent(NodeNameHelper.class).getValidatedName(label, charset);
200 }
201
202
203
204
205 public static boolean isCharValid(int charCode, String charset) {
206
207
208
209
210
211
212
213
214
215
216
217 if ("UTF-8".equals(charset)) {
218
219
220 if (charCode != 32
221 && charCode != '['
222 && charCode != ']'
223 && charCode != '*'
224 && charCode != '"'
225 && charCode != ':'
226 && charCode != 92
227 && charCode != 39
228 && charCode != ';'
229 && charCode != '/'
230 && charCode != '?'
231 && charCode != '+'
232 && charCode != '%'
233 && charCode != '!'
234 && charCode != '#'
235 && charCode != '@'
236 && charCode != '='
237 && charCode != '&'
238 && charCode != SelectorUtil.SELECTOR_DELIMITER.charAt(0)) {
239 return true;
240 }
241 } else {
242
243 if (((charCode >= 48) && (charCode <= 57))
244 || ((charCode >= 65) && (charCode <= 90))
245 || ((charCode >= 97) && (charCode <= 122))
246 || charCode == 45
247 || charCode == 46
248 || charCode == 95) {
249 return true;
250 }
251
252 }
253 return false;
254
255 }
256
257
258
259
260 public static String getAbsolutePath(String path, String label) {
261 return NodeUtil.getAbsolutePath(path, label);
262 }
263
264
265
266
267 public static String getAbsolutePath(String path) {
268 if (!path.startsWith("/")) {
269 return "/" + path;
270 }
271 return path;
272 }
273 }