01 /*
02 * Copyright 2007 Roberto Fasciolo
03 *
04 * This file is part of vsitegen.
05 *
06 * vsitegen is free software; you can redistribute it and/or modify
07 * it under the terms of the GNU General Public License as published by
08 * the Free Software Foundation; either version 2 of the License, or
09 * (at your option) any later version.
10 *
11 * vsitegen is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with vsitegen; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 package net.robyf.vsitegen.ant;
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25
26 import org.apache.tools.ant.Task;
27 import org.apache.tools.ant.types.LogLevel;
28
29 import net.robyf.vsitegen.engine.GeneratorException;
30 import net.robyf.vsitegen.engine.SiteGenerator;
31
32 public final class VSiteGenTask extends Task {
33
34 private String projectName;
35
36 private String template;
37
38 private File navigationFile;
39
40 private File contentDir;
41
42 private File outputDir;
43
44 public void setContent(final File contentDir) {
45 this.contentDir = contentDir;
46 }
47
48 public void setNavigation(final File navigationFile) {
49 this.navigationFile = navigationFile;
50 }
51
52 public void setOutput(final File outputDir) {
53 this.outputDir = outputDir;
54 }
55
56 public void setProject(final String projectName) {
57 this.projectName = projectName;
58 }
59
60 public void setTemplate(final String template) {
61 this.template = template;
62 }
63
64 @Override
65 public void execute() {
66 try (FileInputStream inputStream = new FileInputStream(navigationFile)) {
67 SiteGenerator generator = new SiteGenerator(inputStream,
68 this.contentDir.getAbsolutePath(),
69 this.outputDir.getAbsolutePath(),
70 this.projectName,
71 this.template);
72 generator.generate();
73 } catch (IOException e) {
74 throw new GeneratorException("Error getting navigation file", e);
75 } catch (RuntimeException e) {
76 this.log("Unexpected error executing the task", e, LogLevel.ERR.getLevel());
77 throw e;
78 }
79 }
80
81 }
|