maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r663363 - in /maven/sandbox/trunk/plugins/maven-pdf-plugin: pom.xml src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
Date Wed, 04 Jun 2008 20:09:21 GMT
Author: ltheussl
Date: Wed Jun  4 13:09:21 2008
New Revision: 663363

URL: http://svn.apache.org/viewvc?rev=663363&view=rev
Log:
Make use of maven-doxia-tools

Modified:
    maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml
    maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
    maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java

Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml?rev=663363&r1=663362&r2=663363&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml Wed Jun  4 13:09:21 2008
@@ -81,6 +81,12 @@
       <version>2.0.4</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-doxia-tools</artifactId>
+      <version>1.0</version>
+    </dependency>
+
     <!-- doxia -->
     <dependency>
       <groupId>org.apache.maven.doxia</groupId>
@@ -171,7 +177,7 @@
       <plugin>
         <artifactId>maven-site-plugin</artifactId>
         <version>2.0-beta-6</version>
-        <!--<version>2.0-beta-7-SNAPSHOT</version>-->
+        <!--<version>2.0-beta-8-SNAPSHOT</version>-->
       </plugin>
       <plugin>
         <artifactId>maven-plugin-plugin</artifactId>
@@ -190,7 +196,7 @@
       <plugin>
         <artifactId>maven-project-info-reports-plugin</artifactId>
         <version>2.0.1</version>
-        <!--<version>2.1-SNAPSHOT</version>-->
+        <!--<version>2.2-SNAPSHOT</version>-->
       </plugin>
     </plugins>
   </reporting>

Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java?rev=663363&r1=663362&r2=663363&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
(original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
Wed Jun  4 13:09:21 2008
@@ -19,17 +19,10 @@
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
+import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.plugin.AbstractMojo;
 
 import org.codehaus.plexus.i18n.I18N;
-import org.codehaus.plexus.util.StringUtils;
 
 
 /**
@@ -39,139 +32,58 @@
 public abstract class AbstractPdfMojo
     extends AbstractMojo
 {
-    /**
-     * The locale by default for all default bundles
-     */
-    private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
 
     /**
-     * A comma separated list of locales supported by Maven. The first valid token will be
the default Locale
-     * for this instance of the Java Virtual Machine.
+     * A comma separated list of locales supported by Maven.
+     * The first valid token will be the default Locale for this instance of the Java Virtual
Machine.
      *
      * @parameter expression="${locales}"
      */
     private String locales;
 
     /**
+     * SiteTool.
+     *
+     * @component
+     */
+    private SiteTool siteTool;
+
+    /**
      * Internationalization.
      *
      * @component
      */
     private I18N i18n;
 
+
     /**
-     * Init the <code>localesList</code> variable.
-     * <p>If <code>locales</code> variable is available, the first valid
token will be the <code>defaultLocale</code>
-     * for this instance of the Java Virtual Machine.</p>
+     * Gets the SiteTool.
      *
-     * @return a list of <code>Locale</code>
-     * @todo that's not specific to pdf, move it somewhere to make it re-usable.
+     * @return the SiteTool.
      */
-    protected List initLocalesList()
+    protected SiteTool getSiteTool()
     {
-        List localesList = new ArrayList();
-        if ( locales != null )
-        {
-            String[] localesArray = StringUtils.split( locales, "," );
-
-            for ( int i = 0; i < localesArray.length; i++ )
-            {
-                Locale locale = codeToLocale( localesArray[i] );
-
-                if ( locale != null )
-                {
-                    if ( !Arrays.asList( Locale.getAvailableLocales() ).contains( locale
) )
-                    {
-                        StringBuffer sb = new StringBuffer();
-
-                        sb.append( "The locale '" ).append( locale );
-                        sb.append( "' is not available in this Java Virtual Machine (" );
-                        sb.append( System.getProperty( "java.version" ) ).append(  "from"
 );
-                        sb.append( System.getProperty( "java.vendor" ) ).append( ") - IGNORING"
);
-
-                        getLog().warn( sb.toString() );
-
-                        continue;
-                    }
-
-                    // Default bundles are in English
-                    if ( !locale.getLanguage().equals( DEFAULT_LOCALE.getLanguage() ) )
-                    {
-                        if ( !i18n.getBundle( "site-plugin", locale ).getLocale().getLanguage().equals(
locale
-                            .getLanguage() ) )
-                        {
-                            StringBuffer sb = new StringBuffer();
-
-                            sb.append( "The locale '" ).append( locale ).append( "' (" );
-                            sb.append( locale.getDisplayName( Locale.ENGLISH ) );
-                            sb.append( ") is not supported IGNORING. " );
-
-                            getLog().warn( sb.toString() );
-
-                            continue;
-                        }
-                    }
-
-                    localesList.add( locale );
-                }
-            }
-        }
-
-        if ( localesList.isEmpty() )
-        {
-            localesList = Collections.singletonList( DEFAULT_LOCALE );
-        }
-
-        return localesList;
+        return siteTool;
     }
 
     /**
-     * Converts a locale code like "en", "en_US" or "en_US_win" to a <code>java.util.Locale</code>
-     * object.
-     * <p>If localeCode = <code>default</code>, return the current value
of the default locale for this instance
-     * of the Java Virtual Machine.</p>
-     *
-     * @param localeCode the locale code string.
-     * @return a java.util.Locale object instancied or null if errors occurred
-     * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
-     * @todo that's not specific to pdf, move it somewhere to make it re-usable.
+     * Gets the locales.
+     *
+     * @return the locales.
      */
-    private Locale codeToLocale( String localeCode )
+    protected String getLocales()
     {
-        if ( localeCode == null )
-        {
-            return null;
-        }
-
-        if ( "default".equalsIgnoreCase( localeCode ) )
-        {
-            return Locale.getDefault();
-        }
-
-        String language = "";
-        String country = "";
-        String variant = "";
-
-        StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
-        if ( tokenizer.countTokens() > 3 )
-        {
-            getLog().warn( "Invalid java.util.Locale format for '" + localeCode + "' entry
- IGNORING" );
-            return null;
-        }
-
-        if ( tokenizer.hasMoreTokens() )
-        {
-            language = tokenizer.nextToken();
-            if ( tokenizer.hasMoreTokens() )
-            {
-                country = tokenizer.nextToken();
-                if ( tokenizer.hasMoreTokens() )
-                {
-                    variant = tokenizer.nextToken();
-                }
-            }
-        }
+        return locales;
+    }
 
-        return new Locale( language, country, variant );
+    /**
+     * Gets the i18n.
+     *
+     * @return the i18n.
+     */
+    protected I18N getI18n()
+    {
+        return i18n;
     }
+
 }

Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=663363&r1=663362&r2=663363&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
(original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
Wed Jun  4 13:09:21 2008
@@ -142,7 +142,7 @@
 
         try
         {
-            List localesList = initLocalesList();
+            List localesList = getSiteTool().getAvailableLocales( getLocales() );
 
             // Default is first in the list
             Locale defaultLocale = (Locale) localesList.get( 0 );



Mime
View raw message