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 java.util.Locale;
23  import java.util.regex.Pattern;
24  
25  import org.apache.maven.doxia.sink.Sink;
26  import org.apache.maven.reporting.AbstractMavenReportRenderer;
27  import org.codehaus.plexus.i18n.I18N;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  public abstract class AbstractProjectInfoRenderer
31      extends AbstractMavenReportRenderer
32  {
33      protected I18N i18n;
34  
35      protected Locale locale;
36  
37      public AbstractProjectInfoRenderer( Sink sink, I18N i18n, Locale locale )
38      {
39          super( sink );
40  
41          this.i18n = i18n;
42  
43          this.locale = locale;
44      }
45  
46      @Override
47      public String getTitle()
48      {
49          return getI18nString( "title" );
50      }
51  
52      protected String getI18nString( String key )
53      {
54          return getI18nString( getI18Nsection(), key );
55      }
56  
57      protected String getI18nString( String section, String key )
58      {
59          return i18n.getString( "project-info-report", locale, "report." + section + '.' + key );
60      }
61  
62      @Override
63      protected void text( String text )
64      {
65          if ( StringUtils.isEmpty( text ) ) // Take care of spaces
66          {
67              sink.text( "-" );
68          }
69          else
70          {
71              // custombundle text with xml?
72              String regex = "(.+?)<(\"[^\"]*\"|'[^']*'|[^'\">])*>(.+?)";
73              if ( Pattern.matches( regex, text ) )
74              {
75                  sink.rawText( text );
76              }
77              else
78              {
79                  sink.text( text );
80              }
81          }
82      }
83  
84      protected abstract String getI18Nsection();
85  }