1 /*
2 * PROJECT : DAR Runtime and Tools
3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE
5 * Version 2.1, February 1999
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 package org.enableit.db.darrt.ant;
22
23 import java.io.FileWriter;
24 import java.io.OutputStreamWriter;
25 import java.io.Writer;
26
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.types.EnumeratedAttribute;
29
30
31 /***
32 * A wrapper over a formatter for events reported by Darrt Schema tasks.
33 *
34 * @see AbstractSchemaTask
35 * @see XmldiffFormatter
36 * @see PlainDifformatter
37 * @see HtmlFormatter
38 */
39 public class FormatterElement {
40 private String classname;
41 private String extension;
42 private String outputFile;
43
44 /***
45 * Quick way to use a standard formatter.
46 *
47 * <p> At the moment, there are three supported standard formatters.
48 * <ul>
49 * <li> The <code>xml</code> type uses a <code>XmlFormatter</code>.
50 * <li> The <code>html</code> type uses a <code>HtmlFormatter</code>.
51 * <li> The <code>plain</code> type (the default)
52 * uses a <code>PlainFormatter</code>.
53 * </ul>
54 * </p>
55 *
56 * <p> Sets <code>classname</code> attribute - so you can't use that
57 * attribute if you use this one.</p>
58 */
59 public void setType(TypeAttribute type) {
60 if ("xml".equals(type.getValue())) {
61 setClassname("org.enableit.db.darrt.XmlFormatter");
62 setExtension(".xml");
63 } else if ("html".equals(type.getValue())) {
64 setClassname("org.enableit.db.darrt.HtmlFormatter");
65 setExtension(".html");
66 } else { // must be plain, ensured by TypeAttribute
67 setClassname("org.enableit.db.darrt.PlainFormatter");
68 setExtension(".txt");
69 }
70 }
71
72 /***
73 * Set name of class to be used as the formatter.
74 *
75 * <p> This class must implement <code>JUnitResultFormatter</code></p>
76 */
77 public void setClassname(String classname) {
78 this.classname = classname;
79 }
80
81 /***
82 * Get name of class to be used as the formatter.
83 */
84 public String getClassname() {
85 return classname;
86 }
87
88 public void setExtension(String ext) {
89 this.extension = ext;
90 }
91
92 public String getExtension() {
93 return extension;
94 }
95
96 /***
97 * <p> Set the file which the formatter should log to.
98 *
99 * <p> Note that logging to file must be enabled .
100 */
101 public void setOutputfile(String out) {
102 this.outputFile = out;
103 }
104
105 public Writer getOutputWriter()
106 throws BuildException {
107 Writer out = null;
108
109 try {
110 if (outputFile == null) {
111 out = new OutputStreamWriter(System.out);
112 } else {
113 out = new FileWriter(outputFile + getExtension());
114 }
115 } catch (Exception e) {
116 throw new BuildException("Unable to get an output writer.");
117 }
118
119 return out;
120 }
121
122 /***
123 * <p> Enumerated attribute with the values "plain", "xml" and "html".
124 *
125 * <p> Use to enumerate options for <code>type</code> attribute.
126 */
127 public static class TypeAttribute extends EnumeratedAttribute {
128 public String[] getValues() {
129 return new String[] { "plain", "xml", "html" };
130 }
131 }
132 }
This page was automatically generated by Maven