FilePathBuilder.java
4.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.aemfd.watchfolder.job;
import com.adobe.aemfd.watchfolder.job.TextUtil;
import com.adobe.aemfd.watchfolder.job.WatchedFolderUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
public class FilePathBuilder {
public static String getConcretePath(String filepathPattern) {
return FilePathBuilder.getConcretePath(filepathPattern, null, 0, null);
}
public static String getConcretePath(String filepathPattern, String inputFilepath, long millis, String processId) {
Calendar cal = Calendar.getInstance();
if (millis > 0) {
cal.setTimeInMillis(millis);
}
if (!TextUtil.isEmpty(inputFilepath)) {
filepathPattern = TextUtil.replace(filepathPattern, "%F", WatchedFolderUtils.getFilenameWithNoExtension(inputFilepath));
String _extension = WatchedFolderUtils.getFileExtensionLowerCase(inputFilepath);
String _modExt = TextUtil.isNull(_extension, "");
filepathPattern = TextUtil.replace(filepathPattern, "%E", _modExt);
}
filepathPattern = TextUtil.replace(filepathPattern, "%Y", String.valueOf(cal.get(1)));
filepathPattern = TextUtil.replace(filepathPattern, "%y", String.valueOf(cal.get(1)).substring(2));
filepathPattern = TextUtil.replace(filepathPattern, "%M", String.format("%1$tm", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%D", String.format("%1$td", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%d", String.format("%1$tj", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%H", String.format("%1$tH", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%h", String.format("%1$tI", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%m", String.format("%1$tM", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%s", String.format("%1$tS", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%l", String.format("%1$tL", cal));
filepathPattern = TextUtil.replace(filepathPattern, "%R", String.valueOf((int)(Math.random() * 10.0)));
if (!TextUtil.isEmpty(processId)) {
filepathPattern = TextUtil.replace(filepathPattern, "%P", processId);
} else if (!TextUtil.isEmpty(inputFilepath)) {
filepathPattern = TextUtil.replace(filepathPattern, "%P", WatchedFolderUtils.getFilenameWithNoExtension(inputFilepath));
}
filepathPattern = FilePathBuilder.replaceFolderWithFileSeparator(filepathPattern);
return filepathPattern;
}
public static boolean isFolderPath(String aFilePattern) {
if (aFilePattern.endsWith("/") || aFilePattern.endsWith("\\")) {
return true;
}
return false;
}
public static String replaceFolderWithFileSeparator(String aFilePattern) {
String _filepathPattern = aFilePattern;
if (FilePathBuilder.isFolderPath(_filepathPattern)) {
_filepathPattern = _filepathPattern.substring(0, _filepathPattern.length() - 1) + WatchedFolderUtils.FILE_SEPARATOR;
}
return _filepathPattern;
}
public static boolean makeDirectoryPath(File node) {
ArrayList<File> tree = new ArrayList<File>();
File _path = node;
while (!node.exists()) {
tree.add(node);
if ((node = node.getParentFile()) != null) continue;
throw new RuntimeException("Invalid URL " + _path);
}
if (!tree.isEmpty()) {
for (int i = tree.size() - 1; i >= 0; --i) {
node = (File)tree.get(i);
try {
node = new File(node.getParentFile().getCanonicalFile(), node.getName());
}
catch (IOException ioe) {
throw new RuntimeException("Error getting parent directory path!", ioe);
}
if (node.mkdir()) continue;
throw new RuntimeException("Error creating directory " + node.getPath());
}
}
return true;
}
}