TextExporter.java
1.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.SlingHttpServletResponse
*/
package com.adobe.granite.i18n.impl.bundle;
import com.adobe.granite.i18n.impl.bundle.ResourceBundleExporter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.sling.api.SlingHttpServletResponse;
public class TextExporter
implements ResourceBundleExporter {
private static final String CONTENT_TYPE_TEXT = "text/plain";
public void export(ResourceBundle bundle, SlingHttpServletResponse response) throws IOException {
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
PrintWriter w = response.getWriter();
String title = bundle.getString("Resources for Locale %s");
w.printf(title, bundle.getLocale());
w.println();
w.println();
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
Object resource = bundle.getObject(key);
if (resource == null) continue;
w.print(key);
w.print(" = ");
if (resource.getClass().isArray()) {
Object[] arrResource;
w.println('[');
for (Object res : arrResource = (Object[])resource) {
w.print(" ");
w.println(res);
}
w.print(']');
} else {
w.println(resource);
}
w.println();
}
}
}