43
43
import org .grlea .log .SimpleLogger ;
44
44
import org .stringtemplate .v4 .ST ;
45
45
import org .stringtemplate .v4 .STGroup ;
46
- import org .stringtemplate .v4 .STGroupDir ;
47
46
import org .stringtemplate .v4 .STGroupFile ;
48
47
import org .uncommons .zeitgeist .Article ;
49
48
import org .uncommons .zeitgeist .ArticleFetcher ;
@@ -87,11 +86,7 @@ public Publisher()
87
86
*/
88
87
public Publisher (File templateDir )
89
88
{
90
- if (!templateDir .isDirectory ())
91
- {
92
- throw new IllegalArgumentException ("Template path must be a directory." );
93
- }
94
- this .group = new STGroupDir (templateDir .getAbsolutePath ());
89
+ this .group = new STGroupFile (templateDir .getAbsolutePath ());
95
90
}
96
91
97
92
@@ -117,44 +112,25 @@ public void publish(List<Topic> topics,
117
112
118
113
// Publish HTML.
119
114
ST htmlTemplate = group .getInstanceOf ("news" );
120
- publishTemplate (topics , title , feedCount , articleCount , htmlTemplate , new File ("index.html" ));
121
- if (group instanceof STGroupDir )
122
- {
123
- StreamUtils .copyFile (outputDir ,
124
- new File (((STGroupDir ) group ).groupDirName , "zeitgeist.css" ), "zeitgeist.css" );
125
- }
126
- else
127
- {
128
- StreamUtils .copyClasspathResource (outputDir , "zeitgeist.css" , "zeitgeist.css" );
129
- }
115
+ htmlTemplate .add ("topics" , topics );
116
+ htmlTemplate .add ("title" , title );
117
+ htmlTemplate .add ("dateTime" , new Date ());
118
+ htmlTemplate .add ("feedCount" , feedCount );
119
+ htmlTemplate .add ("articleCount" , articleCount );
120
+ publishTemplate (htmlTemplate , new File ("index.html" ));
130
121
131
122
if (group .isDefined ("snippet" ))
132
123
{
133
124
List <Topic > snippetTopics = topics .subList (0 , Math .min (5 , topics .size ())); // Include no more than 5 topics.
134
125
ST syndicateTemplate = group .getInstanceOf ("snippet" );
135
- publishTemplate (snippetTopics ,
136
- title ,
137
- feedCount ,
138
- articleCount ,
139
- syndicateTemplate ,
140
- new File ("snippet.html" ));
126
+ syndicateTemplate .add ("topics" , snippetTopics );
127
+ publishTemplate (syndicateTemplate , new File ("snippet.html" ));
141
128
}
142
129
}
143
130
144
131
145
- private void publishTemplate (List <Topic > topics ,
146
- String title ,
147
- int feedCount ,
148
- int articleCount ,
149
- ST template ,
150
- File outputFile ) throws IOException
132
+ private void publishTemplate (ST template , File outputFile ) throws IOException
151
133
{
152
- Date date = new Date ();
153
- template .add ("topics" , topics );
154
- template .add ("title" , title );
155
- template .add ("dateTime" , date );
156
- template .add ("feedCount" , feedCount );
157
- template .add ("articleCount" , articleCount );
158
134
Writer writer = new OutputStreamWriter (new FileOutputStream (outputFile ), ENCODING );
159
135
try
160
136
{
@@ -370,8 +346,8 @@ public static void main(String[] args) throws IOException
370
346
Integer .parseInt (properties .getProperty ("zeitgeist.minSourcesPerTopic" )),
371
347
Integer .parseInt (properties .getProperty ("zeitgeist.minArticleRelevance" ))).getTopics ();
372
348
LOG .info (topics .size () + " topics identified." );
373
- String templatesDir = properties .getProperty ("zeitgeist.templatesDir " );
374
- Publisher publisher = templatesDir != null ? new Publisher (new File (templatesDir )) : new Publisher ();
349
+ String templatesFile = properties .getProperty ("zeitgeist.templatesFile " );
350
+ Publisher publisher = templatesFile != null ? new Publisher (new File (templatesFile )) : new Publisher ();
375
351
publisher .publish (topics ,
376
352
properties .getProperty ("zeitgeist.title" ),
377
353
feeds .size (),
0 commit comments