LocaleMapParser.java
2.52 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.util.localization.LocaleMap
* com.scene7.is.catalog.util.localization.LocaleMap$Builder
* com.scene7.is.util.text.Parser
* com.scene7.is.util.text.ParsingException
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider.parsers;
import com.scene7.is.catalog.util.localization.LocaleMap;
import com.scene7.is.util.text.Parser;
import com.scene7.is.util.text.ParsingException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.jetbrains.annotations.NotNull;
public class LocaleMapParser
implements Parser<LocaleMap> {
public static final LocaleMapParser DEFAULT = new LocaleMapParser();
@NotNull
public LocaleMap parse(@NotNull String value) throws ParsingException {
LocaleMap.Builder builder = new LocaleMap.Builder();
StringTokenizer itemTokenizer = new StringTokenizer(value, "|");
while (itemTokenizer.hasMoreTokens()) {
boolean expectDelimiter;
String itemToken = itemTokenizer.nextToken();
if (!itemToken.contains(",")) {
throw new ParsingException(7, "Each locale map item must contain at least one comma delimiter", null);
}
StringTokenizer suffixTokenizer = new StringTokenizer(itemToken, ",", true);
String localeId = suffixTokenizer.nextToken();
if (localeId.equals(",")) {
localeId = "";
expectDelimiter = false;
} else {
expectDelimiter = true;
}
if (builder.containsKey(localeId)) {
throw new ParsingException(4, "Duplicate localeId: " + localeId, null);
}
ArrayList<String> suffixList = new ArrayList<String>();
while (suffixTokenizer.hasMoreTokens()) {
String suffix = suffixTokenizer.nextToken();
if (suffix.equals(",")) {
if (!expectDelimiter) {
suffixList.add("");
}
expectDelimiter = false;
continue;
}
suffixList.add(suffix);
expectDelimiter = true;
}
if (itemToken.charAt(itemToken.length() - 1) == ',') {
suffixList.add("");
}
builder.add(localeId, suffixList);
}
return builder.getProduct();
}
private LocaleMapParser() {
}
}