@Override public List<Translation> getTranslations(String ceilingEntityClassname, String entityId, String property) { TranslatedEntity entityType = getAssignableEntityType(ceilingEntityClassname); return dao.readTranslations(entityType, entityId, property); }
protected TranslatedEntity getEntityType(Object entity) { return getEntityType(entity.getClass()); }
@Override public String getDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue) { if (returnBlankTranslationForNotDefaultLocale && !localeMatchesDefaultLocale(locale) && !propertyInDefaultLocaleExceptionList(entity, property)) { return ""; } return requestedDefaultValue; }
@Override @Transactional("blTransactionManager") public Translation save(String entityType, String entityId, String fieldName, String localeCode, String translatedValue) { TranslatedEntity te = getAssignableEntityType(entityType); Translation translation = getTranslation(te, entityId, fieldName, localeCode); if (translation == null) { translation = dao.create(); translation.setEntityType(te); translation.setEntityId(entityId); translation.setFieldName(fieldName); translation.setLocaleCode(localeCode); } translation.setTranslatedValue(translatedValue); return save(translation); }
@Override public void removeTranslationFromCache(Translation translation) { if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) { ResultType resultType = ResultType.STANDARD; if (extensionManager != null) { ExtensionResultHolder<ResultType> response = new ExtensionResultHolder<ResultType>(); extensionManager.getProxy().getResultType(translation, response); resultType = response.getResult(); if (ResultType.STANDARD == resultType) { String key = getCacheKey(resultType, translation.getEntityType()); LOG.debug("Removing key [" + key + "] for STANDARD site"); getCache().remove(key); } else { List<String> cacheKeysList = getCacheKeyListForTemplateSite(translation.getEntityType().getFriendlyType()); for (String key: cacheKeysList) { LOG.debug("Removing key [" + key + "] for TEMPLATE site"); getCache().remove(key); } } } } }
String generalPropertyKey = property + "_" + localeCode; String response = null; String cacheKey = getCacheKey(ResultType.STANDARD, entityType); LocalePair override = null; for (TranslationOverrideStrategy strategy : strategies) { response = (String) specificTranslation.getCacheItem(); return replaceEmptyWithNullResponse(response); return replaceEmptyWithNullResponse(response); String templateResponse = getTemplateTranslatedValue(cacheKey, property, entityType, entityId, localeCode, localeCountryCode, specificPropertyKey, generalPropertyKey); if (templateResponse != null) {
protected String getTemplateTranslatedValue(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) { String cacheKey = getCacheKey(ResultType.TEMPLATE, entityType); StandardCacheItem translation = null; LocalePair override = null; for (TranslationOverrideStrategy strategy : strategies) { override = strategy.getLocaleBasedTemplateValue(cacheKey, property, entityType, entityId, localeCode, localeCountryCode, specificPropertyKey, generalPropertyKey); if(override != null) { translation = override.getSpecificItem(); if (!strategy.validateTemplateProcessing(standardCacheKey, cacheKey)) { return null; } break; } } if (override == null) { throw new IllegalStateException("Expected at least one TranslationOverrideStrategy to return a valid value"); } return translation==null?null:replaceEmptyWithNullResponse(((Translation) translation.getCacheItem()).getTranslatedValue()); }
@Override public String getTranslatedValue(Object entity, String property, Locale locale) { TranslatedEntity entityType = getEntityType(entity); String entityId = dao.getEntityId(entityType, entity); return getOverrideTranslatedValue(property, entityType, entityId, localeCode, localeCountryCode);
public TranslatedEntity getAssignableEntityType(String className) { try { Class<?> clazz = Class.forName(className); return getEntityType(clazz); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(className + " is not a known translatable class"); } }
/** * Returns true if the passed in entity / property combination is in the defaultLocaleExceptionList * * The default implementation checks the "translationExceptionProperties" list to see if the * property matches one of the regularExpressions in that list. * * Implementors are expected to override this method for implementation specific needs. * * @param entity * @param property * @return */ protected boolean propertyInDefaultLocaleExceptionList(Object entity, String property) { TranslatedEntity entityType = getEntityType(entity); if (entityType != null && entityType.getFriendlyType() != null) { for (String exceptionProperty : translationExceptionProperties) { if (property.matches(exceptionProperty)) { return true; } } } return false; }