View Javadoc

1   package org.apache.maven.reporting;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.doxia.siterenderer.RendererException;
24  import org.apache.maven.reporting.sink.MultiPageSink;
25  import org.apache.maven.reporting.sink.SinkFactory;
26  
27  import java.io.IOException;
28  import java.util.ArrayList;
29  import java.util.Iterator;
30  import java.util.List;
31  
32  /**
33   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
34   * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
35   */
36  public abstract class AbstractMavenMultiPageReport
37      extends AbstractMavenReport
38  {
39      private SinkFactory factory;
40  
41      private List sinks = new ArrayList();
42  
43      public void setSinkFactory( SinkFactory factory )
44      {
45          this.factory = factory;
46      }
47  
48      public SinkFactory getSinkFactory()
49      {
50          return factory;
51      }
52  
53      public boolean useDefaultSiteDescriptor()
54      {
55          return true;
56      }
57  
58      public abstract boolean usePageLinkBar();
59  
60      private Sink getSink( String outputName )
61          throws RendererException, IOException
62      {
63          return factory.getSink( outputName );
64      }
65  
66      public MultiPageSink startPage( String outputName )
67          throws RendererException, IOException
68      {
69          return new MultiPageSink( outputName, getSink( outputName ) );
70      }
71  
72      public void endPage( MultiPageSink sink )
73      {
74          if ( usePageLinkBar() )
75          {
76              sinks.add( sink );
77          }
78          else
79          {
80              sink.closeSink();
81          }
82      }
83  
84      protected void closeReport()
85      {
86          if ( !sinks.isEmpty() )
87          {
88              for ( Iterator i = sinks.iterator(); i.hasNext(); )
89              {
90                  MultiPageSink currentSink = (MultiPageSink) i.next();
91  
92                  currentSink.paragraph();
93  
94                  for ( int counter = 1; counter <= sinks.size(); counter++ )
95                  {
96                      if ( counter > 1 )
97                      {
98                          currentSink.text( "&nbsp;" );
99                      }
100                     MultiPageSink sink = (MultiPageSink) sinks.get( counter - 1 );
101                     sink.link( sink.getOutputName() + ".html" );
102                     sink.text( String.valueOf( counter ) );
103                     sink.link_();
104                 }
105                 currentSink.paragraph_();
106                 currentSink.closeSink();
107             }
108         }
109 
110         super.closeReport();
111     }
112 }