1 package org.apache.velocity.site.news;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.StringReader;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Locale;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.maven.doxia.parser.ParseException;
29 import org.apache.maven.doxia.sink.Sink;
30 import org.apache.velocity.site.news.model.Item;
31
32
33
34
35
36
37
38
39 public class NewsBlockGenerator
40 {
41
42 private final NewsReport newsReport;
43
44 private final Sink sink;
45
46 private final Locale locale;
47
48 private final DateFormat localeDateFormat;
49
50 public NewsBlockGenerator(final NewsReport newsReport, final Locale locale)
51 {
52 this.newsReport = newsReport;
53 this.locale = locale;
54 this.sink = newsReport.getSink();
55
56 localeDateFormat = new SimpleDateFormat(newsReport.getBundle(this.locale).getString("report.news.page.dateFormat"));
57 }
58
59 public void displayItem(final Item item) throws VelocityNewsException
60 {
61
62 sink.section2();
63 sink.sectionTitle2();
64
65 if (item.getDate() != null)
66 {
67 sink.text(localeDateFormat.format(VelocityNewsUtils.parseItemDate(item.getDate())) + " - ");
68 }
69
70 sink.text(item.getHeadline());
71 sink.sectionTitle2_();
72
73 addAptParagraph(item.getText(), item.getId());
74 sink.section2_();
75 }
76
77 private void addAptParagraph(final String text, final String itemId) throws VelocityNewsException
78 {
79
80
81 String[] textFields = StringUtils.splitByWholeSeparator(text, ". ");
82 String aptText = " " + textFields[0] + ". [{{{" + newsReport.getOutputName() + ".html#" + itemId + "}Read more...}}]";
83 try
84 {
85
86 newsReport.getAptParser().parse(new StringReader(aptText), sink);
87 }
88 catch (ParseException pe)
89 {
90 throw new VelocityNewsException("While parsing Apt: ", pe);
91 }
92 }
93 }