Author: vsiveton
Date: Fri Feb 15 15:20:20 2008
New Revision: 628201
URL: http://svn.apache.org/viewvc?rev=628201&view=rev
Log:
o moved AbstractSiteMojo.codeToLocale() see
http://www.nabble.com/Move-AbstractSiteMojo.codeToLocale()-into-SiteTool-of-maven-doxia-tools--td15445934s177.html
Modified:
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
Modified:
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=628201&r1=628200&r2=628201&view=diff
==============================================================================
---
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
(original)
+++
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
Fri Feb 15 15:20:20 2008
@@ -26,6 +26,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -905,6 +906,71 @@
}
}
+ /** [EMAIL PROTECTED] */
+ public List getAvailableLocales( String locales )
+ {
+ 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 ) )
+ {
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().warn( "The locale parsed defined by '"
+ locale
+ + "' is not available in this Java Virtual
Machine (" + System.getProperty( "java.version" )
+ + " from " + System.getProperty( "java.vendor"
) + ") - IGNORING" );
+ }
+ 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 currently support by Maven -
IGNORING. " );
+ sb.append( "\n" );
+ sb.append( "Contribution are welcome and greatly
appreciated! " );
+ sb.append( "\n" );
+ sb.append( "If you want to contribute a new
translation, please visit " );
+ sb.append(
"http://maven.apache.org/plugins/maven-site-plugin/i18n.html " );
+ sb.append( "for detailed instructions." );
+
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().warn( sb.toString() );
+ }
+
+ continue;
+ }
+ }
+
+ localesList.add( locale );
+ }
+ }
+ }
+
+ if ( localesList.isEmpty() )
+ {
+ localesList = Collections.singletonList( DEFAULT_LOCALE );
+ }
+
+ return localesList;
+ }
+
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
@@ -1180,5 +1246,57 @@
private static boolean isEmptyList( List list )
{
return list == null || list.isEmpty();
+ }
+
+ /**
+ * 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>
+ */
+ private Locale codeToLocale( String localeCode )
+ {
+ 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 )
+ {
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().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 new Locale( language, country, variant );
}
}
Modified:
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java?rev=628201&r1=628200&r2=628201&view=diff
==============================================================================
---
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
(original)
+++
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
Fri Feb 15 15:20:20 2008
@@ -43,6 +43,11 @@
String ROLE = SiteTool.class.getName();
/**
+ * The locale by default for all default bundles
+ */
+ Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+ /**
* @param localRepository the Maven local repository, not null.
* @param remoteArtifactRepositories the Maven remote repositories, not
null.
* @param decoration the Doxia site descriptor model, not null.
@@ -204,4 +209,16 @@
void populateModules( MavenProject project, List reactorProjects,
ArtifactRepository localRepository,
DecorationModel decorationModel, Locale locale,
boolean keepInheritedRefs )
throws SiteToolException;
+
+ /**
+ *
+ * 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>
+ *
+ * @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>
+ */
+ List getAvailableLocales( String locales );
}