View Javadoc
1   package net.sf.logdistiller;
2   
3   /*
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  import java.io.IOException;
18  import java.io.Writer;
19  
20  /**
21   * Report formats' base class.
22   */
23  public abstract class ReportFormat
24  {
25      private final String id;
26  
27      protected ReportFormat( String id )
28      {
29          this.id = id;
30      }
31  
32      public String getId()
33      {
34          return id;
35      }
36  
37      public abstract String getContentType();
38  
39      public abstract String getFileExtension();
40  
41      public abstract void report( LogDistillation ld, Writer output )
42          throws IOException;
43  
44      public abstract void report( LogDistillation.Group group, Writer output )
45          throws IOException;
46  
47      protected int addPluginsGroupReport( LogDistillation.Group group, PluginReport report )
48      {
49          LogDistillation.Plugin[] plugins = group.getPlugins();
50          int len = plugins.length;
51          int count = 0;
52          for ( int i = 0; i < len; i++ )
53          {
54              LogDistillation.Plugin plugin = plugins[i];
55              if ( plugin.getDefinition().isGroupReportEnabled() )
56              {
57                  plugin.appendGroupReport( report );
58                  count++;
59              }
60          }
61          return count;
62      }
63  
64      protected int addPluginsGlobalReport( LogDistillation.Group group, PluginReport report )
65      {
66          LogDistillation.Plugin[] plugins = group.getPlugins();
67          int len = plugins.length;
68          int count = 0;
69          for ( int i = 0; i < len; i++ )
70          {
71              LogDistillation.Plugin plugin = plugins[i];
72              if ( plugin.getDefinition().isGlobalReportEnabled() )
73              {
74                  plugin.appendGlobalReport( report );
75                  count++;
76              }
77          }
78          return count;
79      }
80  
81      public static abstract class PluginReport
82      {
83          public abstract void beginPluginReport( LogDistillation.Plugin plugin, String description );
84  
85          public abstract void addLink( String filename, String description );
86  
87          public abstract void addParam( String param, String value );
88  
89          public abstract void addItem( int count, String description );
90  
91          public abstract void endPluginReport();
92      }
93  }