KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > reporting > AbstractMavenMultiPageReport


1 package org.apache.maven.reporting;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.doxia.sink.Sink;
20 import org.apache.maven.doxia.siterenderer.RendererException;
21 import org.apache.maven.reporting.sink.MultiPageSink;
22 import org.apache.maven.reporting.sink.SinkFactory;
23
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * @author <a HREF="evenisse@apache.org">Emmanuel Venisse</a>
31  * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
32  */

33 public abstract class AbstractMavenMultiPageReport
34     extends AbstractMavenReport
35 {
36     private SinkFactory factory;
37
38     private List JavaDoc sinks = new ArrayList JavaDoc();
39
40     public void setSinkFactory( SinkFactory factory )
41     {
42         this.factory = factory;
43     }
44
45     public SinkFactory getSinkFactory()
46     {
47         return factory;
48     }
49
50     public boolean useDefaultSiteDescriptor()
51     {
52         return true;
53     }
54
55     public abstract boolean usePageLinkBar();
56
57     private Sink getSink( String JavaDoc outputName )
58         throws RendererException, IOException JavaDoc
59     {
60         return factory.getSink( outputName );
61     }
62
63     public MultiPageSink startPage( String JavaDoc outputName )
64         throws RendererException, IOException JavaDoc
65     {
66         return new MultiPageSink( outputName, getSink( outputName ) );
67     }
68
69     public void endPage( MultiPageSink sink )
70     {
71         if ( usePageLinkBar() )
72         {
73             sinks.add( sink );
74         }
75         else
76         {
77             sink.closeSink();
78         }
79     }
80
81     protected void closeReport()
82     {
83         if ( !sinks.isEmpty() )
84         {
85             for ( Iterator JavaDoc i = sinks.iterator(); i.hasNext(); )
86             {
87                 MultiPageSink currentSink = (MultiPageSink) i.next();
88
89                 currentSink.paragraph();
90
91                 for ( int counter = 1; counter <= sinks.size(); counter++ )
92                 {
93                     if ( counter > 1 )
94                     {
95                         currentSink.text( "&nbsp;" );
96                     }
97                     MultiPageSink sink = (MultiPageSink) sinks.get( counter - 1 );
98                     sink.link( sink.getOutputName() + ".html" );
99                     sink.text( String.valueOf( counter ) );
100                     sink.link_();
101                 }
102                 currentSink.paragraph_();
103                 currentSink.closeSink();
104             }
105         }
106
107         super.closeReport();
108     }
109 }
110
Popular Tags