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