GUI search: regorg done
[nikiroo-utils.git] / src / be / nikiroo / fanfix / output / InfoText.java
1 package be.nikiroo.fanfix.output;
2
3 import java.io.IOException;
4
5 import be.nikiroo.fanfix.Instance;
6 import be.nikiroo.fanfix.bundles.StringId;
7 import be.nikiroo.fanfix.data.Chapter;
8 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
9
10 class InfoText extends Text {
11 // quote chars
12 private char openQuote = Instance.getTrans().getCharacter(
13 StringId.OPEN_SINGLE_QUOTE);
14 private char closeQuote = Instance.getTrans().getCharacter(
15 StringId.CLOSE_SINGLE_QUOTE);
16 private char openDoubleQuote = Instance.getTrans().getCharacter(
17 StringId.OPEN_DOUBLE_QUOTE);
18 private char closeDoubleQuote = Instance.getTrans().getCharacter(
19 StringId.CLOSE_DOUBLE_QUOTE);
20
21 @Override
22 public String getDefaultExtension(boolean readerTarget) {
23 return "";
24 }
25
26 @Override
27 protected void writeChapterHeader(Chapter chap) throws IOException {
28 writer.write("\n");
29
30 if (chap.getName() != null && !chap.getName().isEmpty()) {
31 writer.write(Instance.getTrans().getString(StringId.CHAPTER_NAMED,
32 chap.getNumber(), chap.getName()));
33 } else {
34 writer.write(Instance.getTrans().getString(
35 StringId.CHAPTER_UNNAMED, chap.getNumber()));
36 }
37
38 writer.write("\n\n");
39 }
40
41 @Override
42 protected void writeTextLine(ParagraphType type, String line)
43 throws IOException {
44 switch (type) {
45 case NORMAL:
46 case QUOTE:
47 StringBuilder builder = new StringBuilder();
48 for (char car : line.toCharArray()) {
49 if (car == '—') {
50 builder.append("---");
51 } else if (car == '–') {
52 builder.append("--");
53 } else if (car == openDoubleQuote) {
54 builder.append("\"");
55 } else if (car == closeDoubleQuote) {
56 builder.append("\"");
57 } else if (car == openQuote) {
58 builder.append("'");
59 } else if (car == closeQuote) {
60 builder.append("'");
61 } else {
62 builder.append(car);
63 }
64 }
65
66 line = builder.toString();
67 break;
68 default:
69 break;
70 }
71
72 super.writeTextLine(type, line);
73 }
74 }