MCPcopy Create free account
hub / github.com/apache/tomcat / Utils

Class Utils

java/org/apache/tomcat/buildutil/translate/Utils.java:38–236  ·  view source on GitHub ↗

Utility class for translation operations.

Source from the content-addressed store, hash-verified

36 * Utility class for translation operations.
37 */
38public class Utils {
39
40 private static final Pattern ESCAPE_LEADING_SPACE = Pattern.compile("^( )", Pattern.MULTILINE);
41
42 private static final Set<String> KEYS_WITH_UNNECESSARY_ESCAPING = new HashSet<>();
43
44 // Package private so it is visible to tests
45 static final String PADDING = "POEDITOR_EXPORT_PADDING_DO_NOT_DELETE";
46
47 static {
48 KEYS_WITH_UNNECESSARY_ESCAPING.add("arrays.malformed.arrays");
49 KEYS_WITH_UNNECESSARY_ESCAPING.add("jsp.error.attribute.deferredmix");
50 KEYS_WITH_UNNECESSARY_ESCAPING.add("jsp.error.el.template.deferred");
51 }
52
53
54 private Utils() {
55 // Utility class. Hide default constructor.
56 }
57
58
59 static String getLanguage(String name) {
60 return name.substring(Constants.L10N_PREFIX.length(), name.length() - Constants.L10N_SUFFIX.length());
61 }
62
63
64 static Properties load(File f) {
65 Properties props = new Properties();
66
67 try (FileInputStream fis = new FileInputStream(f);
68 Reader r = new InputStreamReader(fis, StandardCharsets.UTF_8)) {
69 props.load(r);
70 } catch (IOException ioe) {
71 ioe.printStackTrace();
72 }
73 return props;
74 }
75
76
77 /*
78 * This is the formatting applied when exporting values from Tomcat to POE.
79 *
80 * The values have been read from Tomcat's property files (so the input is the actual value with none of the
81 * escaping required to represent that value in a property file) and are being written back out in a single file to
82 * be imported into POEditor. The padding for blank lines needs to be added followed by the common formatting
83 * required to convert a property value to the representation of that value in a file.
84 */
85 static String formatValueExport(String in) {
86 String result;
87
88 if (in.startsWith("\n")) {
89 result = PADDING + in;
90 } else {
91 result = in;
92 }
93
94 return formatValueCommon(result);
95 }

Callers

nothing calls this directly

Calls 2

addMethod · 0.65
compileMethod · 0.45

Tested by

no test coverage detected