01: package de.schlund.pfixcore.example;
02:
03: import java.io.File;
04: import java.io.UnsupportedEncodingException;
05: import java.net.URLEncoder;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import org.w3c.dom.Element;
10:
11: import de.schlund.pfixcore.workflow.Context;
12: import de.schlund.pfixxml.ResultDocument;
13:
14: /**
15: * @author mleidig@schlund.de
16: */
17: public class ContextEncodingTestImpl implements ContextEncodingTest {
18:
19: private final static String DEFAULT_TEXT = "abcdäöüß";
20:
21: private String text = DEFAULT_TEXT;
22: private String encoding = "";
23: private File file;
24:
25: public String getText() {
26: return text;
27: }
28:
29: public void setText(String text) {
30: this .text = text;
31: }
32:
33: public File getFile() {
34: return file;
35: }
36:
37: public void setFile(File file) {
38: this .file = file;
39: }
40:
41: public String getEncoding() {
42: return encoding;
43: }
44:
45: public void setEncoding(String encoding) {
46: this .encoding = encoding;
47: }
48:
49: public void init(Context ctx) {
50: }
51:
52: public void insertStatus(ResultDocument resDoc, Element elem) {
53: ResultDocument.addTextChild(elem, "encoding", encoding);
54: ResultDocument.addTextChild(elem, "original", text);
55: if (file != null)
56: ResultDocument.addTextChild(elem, "file", file
57: .getAbsolutePath());
58: try {
59: String utfEnc = URLEncoder.encode(text, "UTF-8");
60: ResultDocument.addTextChild(elem, "urlenc-utf", utfEnc);
61: String isoEnc = URLEncoder.encode(text, "ISO-8859-1");
62: ResultDocument.addTextChild(elem, "urlenc-iso", isoEnc);
63: } catch (UnsupportedEncodingException x) {
64: }
65: ResultDocument.addObject(elem, "alphabet",
66: new RussianAlphabet());
67: }
68:
69: public class RussianAlphabet {
70:
71: private String description;
72: private List<String> characters;
73:
74: public RussianAlphabet() {
75: description = "Basic Russian Alphabet";
76: characters = new ArrayList<String>();
77: for (char ch = '\u0410'; ch < '\u0430'; ch++) {
78: characters.add(ch + " " + Character.toLowerCase(ch));
79: }
80: }
81:
82: public String getDescription() {
83: return description;
84: }
85:
86: public List<String> getCharacters() {
87: return characters;
88: }
89:
90: }
91:
92: }
|