View Javadoc

1   package org.apache.maven.report.projectinfo;
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.reporting.AbstractMavenReportRenderer;
24  
25  import java.util.Locale;
26  
27  /**
28   * Generates the project index page.
29   *
30   * @author <a href="mailto:brett@apache.org">Brett Porter </a>
31   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
32   * @version $Id: ProjectIndexPageReport.java 1038048 2010-11-23 10:52:14Z vsiveton $
33   * @since 2.0
34   * @goal index
35   */
36  public class ProjectIndexPageReport
37      extends AbstractProjectInfoReport
38  {
39      // ----------------------------------------------------------------------
40      // Public methods
41      // ----------------------------------------------------------------------
42  
43      @Override
44      public String getName( Locale locale )
45      {
46          return getI18nString( locale, "title" );
47      }
48  
49      @Override
50      public String getDescription( Locale locale )
51      {
52          String desc;
53          if ( project.getDescription() != null )
54          {
55              // TODO How to handle i18n?
56              desc = project.getDescription();
57          }
58          else
59          {
60              return getI18nString( locale, "nodescription" );
61          }
62          return desc;
63      }
64  
65      @Override
66      public void executeReport( Locale locale )
67      {
68          ProjectIndexRenderer r =
69              new ProjectIndexRenderer( getName( locale ), project.getName(), getDescription( locale ), getSink() );
70  
71          r.render();
72      }
73  
74      /** {@inheritDoc} */
75      public String getOutputName()
76      {
77          return "index";
78      }
79  
80      @Override
81      protected String getI18Nsection()
82      {
83          return "index";
84      }
85  
86      // ----------------------------------------------------------------------
87      // Private
88      // ----------------------------------------------------------------------
89  
90      /**
91       * Internal renderer class
92       */
93      private static class ProjectIndexRenderer
94          extends AbstractMavenReportRenderer
95      {
96          private final String title;
97  
98          private final String description;
99  
100         private final String name;
101 
102         ProjectIndexRenderer( String title, String name, String description, Sink sink )
103         {
104             super( sink );
105 
106             this.title = title;
107 
108             this.description = description;
109 
110             this.name = name;
111         }
112 
113         @Override
114         public String getTitle()
115         {
116             return title;
117         }
118 
119         @Override
120         public void renderBody()
121         {
122             startSection( title.trim() + " " + name );
123 
124             paragraph( description );
125 
126             endSection();
127         }
128     }
129 }