org.broadleafcommerce.common.i18n.service
Class TranslationServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.common.i18n.service.TranslationServiceImpl
All Implemented Interfaces:
TranslationService

@Service(value="blTranslationService")
public class TranslationServiceImpl
extends Object
implements TranslationService


Field Summary
protected  net.sf.ehcache.Cache cache
           
protected  TranslationDao dao
           
protected static org.apache.commons.logging.Log LOG
           
protected  StatisticsService statisticsService
           
 
Constructor Summary
TranslationServiceImpl()
           
 
Method Summary
 void deleteTranslationById(Long translationId)
          Deletes the given translations
 Translation findTranslationById(Long id)
          Find a translation instance by its primary key value.
 net.sf.ehcache.Cache getCache()
          Get the translation specific cache (different than the level-2 hibernate cache)
protected  String getCacheKey(TranslatedEntity entityType, String entityId, String property, String localeCode)
           
protected  String getEntityId(Object entity, TranslatedEntity entityType)
           
protected  TranslatedEntity getEntityType(Class<?> entityClass)
           
protected  TranslatedEntity getEntityType(Object entity)
           
protected  TranslatedEntity getEntityType(String className)
           
 String getTranslatedValue(Object entity, String property, Locale locale)
          Returns the translated value of the property for the given entity.
 Translation getTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode)
          Attempts to find the translation object for the given parameters
 List<Translation> getTranslations(String ceilingEntityClassname, String entityId, String property)
          Finds all current translations for the specified field
 void removeTranslationFromCache(Translation translation)
          Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)
 Translation save(String entityType, String entityId, String fieldName, String localeCode, String translatedValue)
          Creates a new translation object for the requested parameters, saves it, and returns the saved instance.
 Translation save(Translation translation)
          Persists the given translation
 Translation update(Long translationId, String localeCode, String translatedValue)
          Updates the given translation id with the new locale code and translated value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG

dao

protected TranslationDao dao

statisticsService

protected StatisticsService statisticsService

cache

protected net.sf.ehcache.Cache cache
Constructor Detail

TranslationServiceImpl

public TranslationServiceImpl()
Method Detail

save

@Transactional(value="blTransactionManager")
public Translation save(Translation translation)
Description copied from interface: TranslationService
Persists the given translation

Specified by:
save in interface TranslationService
Returns:
the persisted translation

save

@Transactional(value="blTransactionManager")
public Translation save(String entityType,
                                      String entityId,
                                      String fieldName,
                                      String localeCode,
                                      String translatedValue)
Description copied from interface: TranslationService
Creates a new translation object for the requested parameters, saves it, and returns the saved instance. Note: This method will overwrite a previously existing translation if it matches on entityType, entityId, fieldName, and localeCode.

Specified by:
save in interface TranslationService
Returns:
the persisted translation

findTranslationById

public Translation findTranslationById(Long id)
Description copied from interface: TranslationService
Find a translation instance by its primary key value.

Specified by:
findTranslationById in interface TranslationService
Parameters:
id - the primary key value
Returns:

update

@Transactional(value="blTransactionManager")
public Translation update(Long translationId,
                                        String localeCode,
                                        String translatedValue)
Description copied from interface: TranslationService
Updates the given translation id with the new locale code and translated value

Specified by:
update in interface TranslationService
Returns:
the persisted translation

deleteTranslationById

@Transactional(value="blTransactionManager")
public void deleteTranslationById(Long translationId)
Description copied from interface: TranslationService
Deletes the given translations

Specified by:
deleteTranslationById in interface TranslationService

getTranslation

public Translation getTranslation(TranslatedEntity entity,
                                  String entityId,
                                  String fieldName,
                                  String localeCode)
Description copied from interface: TranslationService
Attempts to find the translation object for the given parameters

Specified by:
getTranslation in interface TranslationService
Returns:
the persisted translation

getTranslations

public List<Translation> getTranslations(String ceilingEntityClassname,
                                         String entityId,
                                         String property)
Description copied from interface: TranslationService
Finds all current translations for the specified field

Specified by:
getTranslations in interface TranslationService
Returns:
the list of translations

getTranslatedValue

public String getTranslatedValue(Object entity,
                                 String property,
                                 Locale locale)
Description copied from interface: TranslationService
Returns the translated value of the property for the given entity. For example, if entity is an instance of Product and property is equal to name, this method might return "Hoppin' Hot Sauce" if we are in an English locale and "Salsa de la Muerte Saltante" if we are in a Spanish locale. If a country is set on the locale (locale code en_GB for example), we will first look for a translation that matches en_GB, and then look for a translation for en. If a translated value for the given locale is not available, it will return null.

Specified by:
getTranslatedValue in interface TranslationService
Returns:
the translated value of the property for the given entity

removeTranslationFromCache

public void removeTranslationFromCache(Translation translation)
Description copied from interface: TranslationService
Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)

Specified by:
removeTranslationFromCache in interface TranslationService
Parameters:
translation - The translation instance to remove

getCache

public net.sf.ehcache.Cache getCache()
Description copied from interface: TranslationService
Get the translation specific cache (different than the level-2 hibernate cache)

Specified by:
getCache in interface TranslationService
Returns:
the translation specific cache

getEntityType

protected TranslatedEntity getEntityType(Class<?> entityClass)

getEntityType

protected TranslatedEntity getEntityType(Object entity)

getEntityType

protected TranslatedEntity getEntityType(String className)

getEntityId

protected String getEntityId(Object entity,
                             TranslatedEntity entityType)

getCacheKey

protected String getCacheKey(TranslatedEntity entityType,
                             String entityId,
                             String property,
                             String localeCode)


Copyright © 2013. All Rights Reserved.