Extended locale in factories.

This commit is contained in:
Christian P. MOMON 2016-09-21 15:41:45 +02:00
parent ae44360e9e
commit 693a9d6d83
2 changed files with 181 additions and 0 deletions

View file

@ -138,6 +138,21 @@ public class PageFactory
return result;
}
/**
*
* @param source
* @return
*/
public Page create(final URL source, final Locale locale)
{
Page result;
result = new Page(PresenterFactory.instance().get(source, locale));
//
return result;
}
/**
*
* @param source

View file

@ -19,6 +19,7 @@
package fr.devinsy.xidyn.presenters;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
@ -84,6 +85,46 @@ public class PresenterFactory
return result;
}
/**
*
* @param source
* @return
*/
public Presenter get(final CharSequence source, final Locale locale)
{
Presenter result;
if (source == null)
{
result = null;
}
else if (locale == null)
{
result = get(source);
}
else
{
String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = this.cache.get(localizedSource);
if (result == null)
{
result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
this.cache.put(localizedSource, result);
}
}
//
return result;
}
/**
*
* @param source
@ -187,6 +228,57 @@ public class PresenterFactory
return result;
}
/**
*
* @param source
* @return
* @throws MalformedURLException
*/
public Presenter get(final URL source, final Locale locale)
{
Presenter result;
try
{
if (source == null)
{
result = null;
}
else if (locale == null)
{
result = get(source);
}
else
{
URL localizedSource;
localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
if (result == null)
{
result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
this.cache.put(localizedSource, result);
}
}
}
catch (MalformedURLException exception)
{
logger.error(exception.getMessage(), exception);
result = null;
}
//
return result;
}
/**
*
* @return
@ -246,6 +338,39 @@ public class PresenterFactory
return result;
}
/**
*
* @param source
* @return
*/
public static Presenter create(final CharSequence source, final Locale locale)
{
Presenter result;
if (source == null)
{
result = null;
}
else if (locale == null)
{
result = create(source);
}
else
{
String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
}
//
return result;
}
/**
*
* @param source
@ -346,6 +471,47 @@ public class PresenterFactory
return result;
}
/**
*
* @param source
* @return
*/
public static Presenter create(final URL source, final Locale locale)
{
Presenter result;
try
{
if (source == null)
{
result = null;
}
else if (locale == null)
{
result = create(source);
}
else
{
URL localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
}
}
catch (MalformedURLException exception)
{
logger.error(exception.getMessage(), exception);
result = null;
}
//
return result;
}
/**
*
* @return