001    package net.sf.logdistiller;
002    
003    /*
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    import java.io.IOException;
018    import java.io.Writer;
019    
020    /**
021     * Report formats' base class.
022     */
023    public abstract class ReportFormat
024    {
025        private final String id;
026    
027        protected ReportFormat( String id )
028        {
029            this.id = id;
030        }
031    
032        public String getId()
033        {
034            return id;
035        }
036    
037        public abstract String getContentType();
038    
039        public abstract String getFileExtension();
040    
041        public abstract void report( LogDistillation ld, Writer output )
042            throws IOException;
043    
044        public abstract void report( LogDistillation.Group group, Writer output )
045            throws IOException;
046    
047        protected int addPluginsGroupReport( LogDistillation.Group group, PluginReport report )
048        {
049            LogDistillation.Plugin[] plugins = group.getPlugins();
050            int len = plugins.length;
051            int count = 0;
052            for ( int i = 0; i < len; i++ )
053            {
054                LogDistillation.Plugin plugin = plugins[i];
055                if ( plugin.getDefinition().isGroupReportEnabled() )
056                {
057                    plugin.appendGroupReport( report );
058                    count++;
059                }
060            }
061            return count;
062        }
063    
064        protected int addPluginsGlobalReport( LogDistillation.Group group, PluginReport report )
065        {
066            LogDistillation.Plugin[] plugins = group.getPlugins();
067            int len = plugins.length;
068            int count = 0;
069            for ( int i = 0; i < len; i++ )
070            {
071                LogDistillation.Plugin plugin = plugins[i];
072                if ( plugin.getDefinition().isGlobalReportEnabled() )
073                {
074                    plugin.appendGlobalReport( report );
075                    count++;
076                }
077            }
078            return count;
079        }
080    
081        public static abstract class PluginReport
082        {
083            public abstract void beginPluginReport( LogDistillation.Plugin plugin, String description );
084    
085            public abstract void addLink( String filename, String description );
086    
087            public abstract void addParam( String param, String value );
088    
089            public abstract void addItem( int count, String description );
090    
091            public abstract void endPluginReport();
092        }
093    }