1 package net.sf.logdistiller.publishers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.*;
18
19 import org.apache.commons.io.IOUtils;
20
21 import net.sf.logdistiller.*;
22
23
24
25
26
27
28
29
30
31
32 public class FilePublisher
33 extends Publisher
34 {
35 public String getId()
36 {
37 return "file";
38 }
39
40 public void publish( LogDistillation logdistillation, LogDistiller.Report report )
41 throws IOException
42 {
43 ReportFormat format = ReportFormats.getReportFormat( report.getFormat() );
44 String filename = report.getParam( "filename", "result." + format.getFileExtension() );
45 Writer out = new FileWriter( logdistillation.newDestinationFile( filename ) );
46 try
47 {
48 format.report( logdistillation, out );
49 }
50 finally
51 {
52 IOUtils.closeQuietly( out );
53 }
54 }
55
56 public void publish( LogDistillation.Group group, LogDistiller.Report report )
57 throws IOException
58 {
59 ReportFormat format = ReportFormats.getReportFormat( report.getFormat() );
60 String filename = report.getParam( "filename" );
61 if ( filename == null )
62 {
63 filename = group.getDefinition().getId() + "." + format.getFileExtension();
64 }
65 Writer out = new FileWriter( group.getLogdistillation().newDestinationFile( filename ) );
66 try
67 {
68 format.report( group, out );
69 }
70 finally
71 {
72 IOUtils.closeQuietly( out );
73 }
74 }
75 }