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