info.magnolia.cms.i18n
Class AbstractI18nContentSupport

java.lang.Object
  extended by info.magnolia.cms.i18n.AbstractI18nContentSupport
All Implemented Interfaces:
I18nContentSupport
Direct Known Subclasses:
DefaultI18nContentSupport, HierarchyBasedI18nContentSupport, RequestLocaleAwareI18nContentSupport

public abstract class AbstractI18nContentSupport
extends Object
implements I18nContentSupport

An abstract implementation of I18nContentSupport which stores the locale specific content in node data having a local suffix: <name>_<locale>. The detection of the current locale, based on the URI for instance, is left to the concrete implementation.

Author:
philipp

Field Summary
protected  Locale defaultLocale
          If no locale can be determined the default locale will be set.
 
Constructor Summary
AbstractI18nContentSupport()
           
 
Method Summary
 void addLocale(LocaleDefinition ld)
           
 Locale determineLocale()
          Extracts the language from the uri.
protected static Locale determineLocalFromString(String localeStr)
           
 Locale getDefaultLocale()
           
 Locale getFallbackLocale()
          The default locale to be used.
 Locale getLocale()
          Get the current locale used for rendering content.
 Collection<Locale> getLocales()
          Returns the available locales.
protected  Locale getNextContentLocale(Locale locale, Set<Locale> checkedLocales)
          Uses getNextLocale(Locale) to find the next locale.
protected  Locale getNextLocale(Locale locale)
          Returns the closest locale for which isLocaleSupported(Locale) is true.
 NodeData getNodeData(Content node, String name)
          Returns the nodedata with the name <name>_<current language> or <name>_<fallback language> otherwise returns <name>.
 NodeData getNodeData(Content node, String name, Locale locale)
          Returns the NodeData object based on the language passes.
protected  boolean isEmpty(NodeData nd)
          Checks if the nodedata field is empty.
 boolean isEnabled()
           
protected  boolean isLocaleSupported(Locale locale)
           
protected abstract  Locale onDetermineLocale()
           
 void setDefaultLocale(Locale defaultLocale)
           
 void setEnabled(boolean enabled)
           
 void setFallbackLocale(Locale fallbackLocale)
           
 void setLocale(Locale locale)
           
 String toI18NURI(String uri)
          Transform the internal uri to a i18n uri.
protected abstract  String toI18NURI(String uri, Locale locale)
           
 String toRawURI(String i18nURI)
          Removes the prefix.
protected abstract  String toRawURI(String i18nURI, Locale locale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultLocale

protected Locale defaultLocale
If no locale can be determined the default locale will be set. If no default locale is defined the fallback locale is used.

Constructor Detail

AbstractI18nContentSupport

public AbstractI18nContentSupport()
Method Detail

getLocale

public Locale getLocale()
Description copied from interface: I18nContentSupport
Get the current locale used for rendering content.

Specified by:
getLocale in interface I18nContentSupport

setLocale

public void setLocale(Locale locale)
Specified by:
setLocale in interface I18nContentSupport

getFallbackLocale

public Locale getFallbackLocale()
Description copied from interface: I18nContentSupport
The default locale to be used. Can be used to fix the system to a certain language.

Specified by:
getFallbackLocale in interface I18nContentSupport

setFallbackLocale

public void setFallbackLocale(Locale fallbackLocale)
Specified by:
setFallbackLocale in interface I18nContentSupport

getNextLocale

protected Locale getNextLocale(Locale locale)
Returns the closest locale for which isLocaleSupported(Locale) is true. Warning: if you have configured both (fr and fr_CH) this method will jiter between this two values.


determineLocale

public Locale determineLocale()
Extracts the language from the uri.

Specified by:
determineLocale in interface I18nContentSupport

onDetermineLocale

protected abstract Locale onDetermineLocale()

determineLocalFromString

protected static Locale determineLocalFromString(String localeStr)

toI18NURI

public String toI18NURI(String uri)
Description copied from interface: I18nContentSupport
Transform the internal uri to a i18n uri. This method may add a prefix or suffix

Specified by:
toI18NURI in interface I18nContentSupport

toI18NURI

protected abstract String toI18NURI(String uri,
                                    Locale locale)

toRawURI

public String toRawURI(String i18nURI)
Removes the prefix.

Specified by:
toRawURI in interface I18nContentSupport

toRawURI

protected abstract String toRawURI(String i18nURI,
                                   Locale locale)

getNodeData

public NodeData getNodeData(Content node,
                            String name,
                            Locale locale)
                     throws javax.jcr.RepositoryException
Description copied from interface: I18nContentSupport
Returns the NodeData object based on the language passes.

Specified by:
getNodeData in interface I18nContentSupport
Throws:
javax.jcr.RepositoryException

getNodeData

public NodeData getNodeData(Content node,
                            String name)
Returns the nodedata with the name <name>_<current language> or <name>_<fallback language> otherwise returns <name>.

Specified by:
getNodeData in interface I18nContentSupport

getNextContentLocale

protected Locale getNextContentLocale(Locale locale,
                                      Set<Locale> checkedLocales)
Uses getNextLocale(Locale) to find the next locale. If the returned locale is in the checkedLocales set it falls back to the fall-back locale. If the fall-back locale itself is passed to the method, the method returns null to signal the end of the chain.


isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface I18nContentSupport

setEnabled

public void setEnabled(boolean enabled)

getLocales

public Collection<Locale> getLocales()
Description copied from interface: I18nContentSupport
Returns the available locales.

Specified by:
getLocales in interface I18nContentSupport

addLocale

public void addLocale(LocaleDefinition ld)

isLocaleSupported

protected boolean isLocaleSupported(Locale locale)

isEmpty

protected boolean isEmpty(NodeData nd)
Checks if the nodedata field is empty.


getDefaultLocale

public Locale getDefaultLocale()

setDefaultLocale

public void setDefaultLocale(Locale defaultLocale)


Copyright © 2003-2012 Magnolia International Ltd.. All Rights Reserved.