Author: hboutemy
Date: Fri Dec 11 18:22:01 2015
New Revision: 1719485
URL: http://svn.apache.org/viewvc?rev=1719485&view=rev
Log:
[DOXIASITETOOLS-122] reworked API on Locales: getSiteLocales(String)
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=1719485&r1=1719484&r2=1719485&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
Fri Dec 11 18:22:01 2015
@@ -805,7 +805,7 @@ public class DefaultSiteTool
}
/** {@inheritDoc} */
- public List<Locale> getAvailableLocales( String locales )
+ public List<Locale> getSiteLocales( String locales )
{
if ( locales == null )
{
@@ -815,9 +815,9 @@ public class DefaultSiteTool
String[] localesArray = StringUtils.split( locales, "," );
List<Locale> localesList = new ArrayList<Locale>( localesArray.length
);
- for ( int i = 0; i < localesArray.length; i++ )
+ for ( String localeString : localesArray )
{
- Locale locale = codeToLocale( localesArray[i] );
+ Locale locale = codeToLocale( localeString );
if ( locale == null )
{
@@ -828,7 +828,7 @@ public class DefaultSiteTool
{
if ( getLogger().isWarnEnabled() )
{
- getLogger().warn( "The locale parsed defined by '" + locale
+ getLogger().warn( "The locale defined by '" + locale
+ "' is not available in this Java Virtual Machine ("
+ System.getProperty( "java.version" )
+ " from " + System.getProperty( "java.vendor" ) + ")
- IGNORING" );
@@ -844,10 +844,10 @@ public class DefaultSiteTool
if ( getLogger().isWarnEnabled() )
{
getLogger().warn( "The locale '" + locale + "' (" +
locale.getDisplayName( Locale.ENGLISH )
- + ") is not currently support by Maven - IGNORING."
- + "\nContribution are welcome and greatly appreciated!"
+ + ") is not currently supported by Maven Site -
IGNORING."
+ + "\nContributions are welcome and greatly
appreciated!"
+ "\nIf you want to contribute a new translation,
please visit "
- +
"http://maven.apache.org/plugins/maven-site-plugin/i18n.html for detailed
instructions." );
+ + "http://maven.apache.org/plugins/localization.html
for detailed instructions." );
}
continue;
@@ -864,8 +864,17 @@ public class DefaultSiteTool
return localesList;
}
- /** {@inheritDoc} */
- public Locale codeToLocale( String localeCode )
+ /**
+ * 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 instanced 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>
+ */
+ private Locale codeToLocale( String localeCode )
{
if ( localeCode == null )
{
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java?rev=1719485&r1=1719484&r2=1719485&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
Fri Dec 11 18:22:01 2015
@@ -43,7 +43,7 @@ public interface SiteTool
String ROLE = SiteTool.class.getName();
/**
- * The locale by default for all default bundles
+ * The locale by default for a Maven Site
* @see Locale#ENGLISH
*/
Locale DEFAULT_LOCALE = Locale.ENGLISH;
@@ -269,25 +269,12 @@ public interface SiteTool
throws SiteToolException;
/**
- * Init the <code>localesList</code> variable.
- * <p>If the <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>
+ * Extracts from a comma-separated list the locales that are available in
<code>site-tool</code>
+ * resource bundle. Notice that <code>default</code> value will be changed
to the default locale of
+ * the JVM.
*
- * @param locales 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.
- * @return a list of <code>Locale</code>
+ * @param locales A comma separated list of locales
+ * @return a list of <code>Locale</code>, which at least contains the
Maven default locale which is english
*/
- List<Locale> getAvailableLocales( String locales );
-
- /**
- * 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 instanced 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>
- */
- Locale codeToLocale( String localeCode );
+ List<Locale> getSiteLocales( String locales );
}
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java?rev=1719485&r1=1719484&r2=1719485&view=diff
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
(original)
+++
maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
Fri Dec 11 18:22:01 2015
@@ -36,6 +36,8 @@ import org.apache.maven.project.MavenPro
import org.codehaus.plexus.PlexusTestCase;
+import edu.emory.mathcs.backport.java.util.Arrays;
+
/**
* @author <a href="mailto:[email protected]">Vincent Siveton</a>
* @version $Id$
@@ -290,4 +292,18 @@ public class SiteToolTest
assertNotNull( model );
}
+
+ public void testGetAvailableLocales()
+ throws Exception
+ {
+ SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+
+ assertEquals( Arrays.asList( new Locale[] { SiteTool.DEFAULT_LOCALE }
), tool.getSiteLocales( "en" ) );
+
+ assertEquals( Arrays.asList( new Locale[] { SiteTool.DEFAULT_LOCALE,
Locale.FRENCH, Locale.ITALIAN } ),
+ tool.getSiteLocales( "en,fr,it" ) );
+
+ // by default, only DEFAULT_LOCALE
+ assertEquals( Arrays.asList( new Locale[] { SiteTool.DEFAULT_LOCALE }
), tool.getSiteLocales( "" ) );
+ }
}