Added locale management in factories (Presenter and Page).

This commit is contained in:
Christian P. MOMON 2016-09-21 04:24:53 +02:00
parent 550f2adb9d
commit ecedb8bbce
2 changed files with 48 additions and 4 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;
@ -65,7 +66,6 @@ public class PageFactory
/** /**
* *
* @param source * @param source
* @param parameters
* @return * @return
*/ */
public Page create(final CharSequence source) public Page create(final CharSequence source)
@ -81,7 +81,6 @@ public class PageFactory
/** /**
* *
* @param source * @param source
* @param parameters
* @return * @return
*/ */
public Page create(final Document source) public Page create(final Document source)
@ -97,7 +96,6 @@ public class PageFactory
/** /**
* *
* @param source * @param source
* @param parameters
* @return * @return
*/ */
public Page create(final File source) public Page create(final File source)
@ -113,7 +111,21 @@ public class PageFactory
/** /**
* *
* @param source * @param source
* @param parameters * @return
*/
public Page create(final File source, final Locale locale)
{
Page result;
result = new Page(PresenterFactory.instance().get(source, locale));
//
return result;
}
/**
*
* @param source
* @return * @return
*/ */
public Page create(final URL source) public Page create(final URL source)

View file

@ -20,11 +20,13 @@ package fr.devinsy.xidyn.presenters;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.Locale;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.util.FileTools;
import fr.devinsy.xidyn.utils.cache.Cache; import fr.devinsy.xidyn.utils.cache.Cache;
/** /**
@ -124,6 +126,36 @@ public class PresenterFactory
return result; return result;
} }
/**
*
* @param source
* @return
*/
public Presenter get(final File source, final Locale locale)
{
Presenter result;
if (locale == null)
{
result = get(source);
}
else
{
File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
if (result == null)
{
result = create(localizedSource);
this.cache.put(localizedSource, result);
}
}
//
return result;
}
/** /**
* *
* @param source * @param source