PlatformNameFormat.java
4.31 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Decompiled with CFR 0_118.
*/
package com.day.jcr.vault.util;
import com.day.jcr.vault.util.Text;
public class PlatformNameFormat {
public static String getPlatformName(String repositoryName) {
StringBuffer buf = new StringBuffer("_");
boolean escapeColon = false;
boolean useUnderscore = false;
int numUnderscore = 0;
block5 : for (int i = 0; i < repositoryName.length(); ++i) {
char c = repositoryName.charAt(i);
switch (c) {
case ':': {
if (!escapeColon && i > 0) {
escapeColon = true;
useUnderscore = true;
numUnderscore = 2;
buf.append('_');
continue block5;
}
buf.append("%3a");
continue block5;
}
case '_': {
if (i == 0) {
useUnderscore = true;
}
++numUnderscore;
escapeColon = true;
buf.append(c);
continue block5;
}
case '\"':
case '%':
case '/':
case '<':
case '>':
case '?':
case '\\':
case '|': {
buf.append('%');
buf.append(Character.forDigit(c / 16, 16));
buf.append(Character.forDigit(c % 16, 16));
continue block5;
}
default: {
buf.append(c);
}
}
}
if (useUnderscore && numUnderscore > 1) {
return buf.toString();
}
return buf.substring(1);
}
public static String getPlatformPath(String repoPath) {
String[] elems = Text.explode(repoPath, 47, true);
for (int i = 0; i < elems.length; ++i) {
if (elems[i].length() <= 0) continue;
elems[i] = PlatformNameFormat.getPlatformName(elems[i]);
}
return Text.implode(elems, "/");
}
public static String getRepositoryName(String platformName) {
StringBuffer buffer = new StringBuffer("_");
boolean firstUnderscore = false;
for (int i = 0; i < platformName.length(); ++i) {
char c = platformName.charAt(i);
if (c == '%') {
if (platformName.length() > i + 2) {
int a = Character.digit(platformName.charAt(++i), 16);
int b = Character.digit(platformName.charAt(++i), 16);
c = (char)(a * 16 + b);
}
} else if (c == '_') {
if (i == 0) {
firstUnderscore = true;
if (platformName.length() <= 1) continue;
if ((c = (char)platformName.charAt(++i)) == '_') {
buffer.append('_');
firstUnderscore = false;
continue;
}
buffer.append(c);
continue;
}
if (firstUnderscore) {
c = ':';
firstUnderscore = false;
}
}
buffer.append(c);
}
if (firstUnderscore) {
return buffer.toString();
}
return buffer.substring(1);
}
public static String getRepositoryPath(String path) {
String[] elems = Text.explode(path, 47, true);
for (int i = 0; i < elems.length; ++i) {
if (elems[i].length() <= 0) continue;
elems[i] = PlatformNameFormat.getRepositoryName(elems[i]);
}
return Text.implode(elems, "/");
}
public static String getRepositoryPath(String path, boolean respectDotDir) {
String[] elems = Text.explode(path, 47, true);
for (int i = 0; i < elems.length; ++i) {
if (elems[i].length() <= 0) continue;
elems[i] = respectDotDir && elems[i].endsWith(".dir") ? PlatformNameFormat.getRepositoryName(elems[i].substring(0, elems[i].length() - 4)) : PlatformNameFormat.getRepositoryName(elems[i]);
}
return Text.implode(elems, "/");
}
}