1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.exceptions.i18n.message;
17
18 import java.util.Locale;
19 import java.util.ResourceBundle;
20
21
22
23
24
25 class StructuredTextHandler extends AbstractTextHandler
26 {
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public StructuredTextHandler(final String bundleBaseName,
45 final String resourceKey)
46 {
47 super(bundleBaseName, resourceKey);
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 @Override
70 public String getMessage(final Object bean, final Locale locale,
71 final ClassLoader loader)
72 {
73 final StringBuilder buffer = new StringBuilder();
74 final ResourceBundle messageBundle =
75 ResourceBundle.getBundle(
76 "de.smartics.exceptions.i18n.message.StructuredTextBundle", locale,
77 loader);
78
79 appendMessage(bean, locale, loader, buffer, MessageType.TITLE, null);
80
81 appendWhatHasHappendMessage(bean, locale, loader, buffer, messageBundle);
82
83 appendMessage(bean, locale, loader, buffer,
84 MessageType.IMPLICATIONS_ON_CURRENT_TASK,
85 messageBundle.getString("header.implications"));
86
87 appendMessage(bean, locale, loader, buffer, MessageType.WHAT_TO_DO_NOW,
88 messageBundle.getString("header.whatToDoNow"));
89
90 appendMessage(bean, locale, loader, buffer, MessageType.URL,
91 messageBundle.getString("header.url"));
92
93 return buffer.toString();
94 }
95
96
97 private void appendWhatHasHappendMessage(final Object bean,
98 final Locale locale, final ClassLoader loader,
99 final StringBuilder buffer, final ResourceBundle messageBundle)
100 {
101 final String summaryMessage =
102 internalGetLocalizedMessage(bean, resourceKey, locale,
103 MessageType.SUMMARY, loader);
104 final String detailsMessage =
105 internalGetLocalizedMessage(bean, resourceKey, locale,
106 MessageType.DETAILS, loader);
107 if (summaryMessage != null || detailsMessage != null)
108 {
109 buffer.append(' ')
110 .append(messageBundle.getString("header.whatHasHappened"))
111 .append('\n');
112 if (summaryMessage != null)
113 {
114 buffer.append(" ");
115 if (detailsMessage != null)
116 {
117 buffer.append(
118 messageBundle.getString("header.whatHasHappened.summary"))
119 .append(": ");
120 }
121
122 buffer.append(summaryMessage).append('\n');
123 }
124 if (detailsMessage != null)
125 {
126 buffer.append(" ");
127 if (summaryMessage != null)
128 {
129 buffer.append(
130 messageBundle.getString("header.whatHasHappened.details"))
131 .append(": ");
132 }
133 buffer.append(detailsMessage).append('\n');
134 }
135 }
136 }
137
138
139 private void appendMessage(final Object bean, final Locale locale,
140 final ClassLoader loader, final StringBuilder buffer,
141 final MessageType type, final String headline)
142 {
143 final String message =
144 internalGetLocalizedMessage(bean, resourceKey, locale, type, loader);
145 if (message != null)
146 {
147 if (headline != null)
148 {
149 buffer.append(' ').append(headline).append("\n ");
150 }
151
152 buffer.append(message).append('\n');
153 }
154 }
155
156
157
158
159 }