Improved locale management in page and factories.

This commit is contained in:
Christian P. MOMON 2016-09-21 15:16:39 +02:00
parent c362d77fed
commit 8d0e72fe9a
2 changed files with 55 additions and 1 deletions

View file

@ -20,6 +20,7 @@ package fr.devinsy.xidyn.pages;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.Locale;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -66,6 +67,15 @@ public class Page extends TagDataManager
this(new FilePresenter(source)); this(new FilePresenter(source));
} }
/**
*
* @param source
*/
public Page(final File source, final Locale locale)
{
this(PresenterFactory.create(source, locale));
}
/** /**
* *
*/ */

View file

@ -135,7 +135,11 @@ public class PresenterFactory
{ {
Presenter result; Presenter result;
if (locale == null) if (source == null)
{
result = null;
}
else if (locale == null)
{ {
result = get(source); result = get(source);
} }
@ -148,6 +152,12 @@ public class PresenterFactory
if (result == null) if (result == null)
{ {
result = create(localizedSource); result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
this.cache.put(localizedSource, result); this.cache.put(localizedSource, result);
} }
} }
@ -280,6 +290,40 @@ public class PresenterFactory
return result; return result;
} }
/**
*
* @param source
* @param locale
* @return
*/
public static Presenter create(final File source, final Locale locale)
{
Presenter result;
if (source == null)
{
result = null;
}
else if (locale == null)
{
result = create(source);
}
else
{
File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = create(localizedSource);
if ((result == null) || (!result.isAvailable()))
{
result = create(source);
}
}
//
return result;
}
/** /**
* *
* @param source * @param source