📄 localizationmanagerejb.java
字号:
/**
* Get SubFocus caption
* @param languageId language id
* @param subFocusId Subfocus id attribute
* @return localized Caption
*/
public String getSubFocusCaption( String languageId, String subFocusId ) {
return getLocalizedCaption( languageId, subFocusId, LocalizedObjectTypes.SUB_FOCUS );
}
/**
* Get Tab caption
* @param languageId language id
* @param tabId tab id attribute
* @return localized Caption
*/
public String getTabCaption( String languageId, String tabId ) {
return getLocalizedCaption( languageId, tabId, LocalizedObjectTypes.TAB );
}
/**
* Get Form caption
* @param languageId language id
* @param formId form id attribute
* @return localized Caption
*/
public String getFormCaption( String languageId, String formId ) {
return getLocalizedCaption( languageId, formId, LocalizedObjectTypes.FORM );
}
/**
* Get Button caption
* @param languageId language id
* @param buttonId button id attribute
* @return localized Caption
*/
public String getButtonCaption( String languageId, String buttonId) {
return getLocalizedCaption( languageId, buttonId, LocalizedObjectTypes.BUTTON);
}
/**
* Get Popup Menu caption
* @param languageId language id
* @param captionId id
* @return localized Caption
*/
public String getPopupMenuCaption( String languageId, String captionId ) {
return getLocalizedCaption( languageId, captionId, LocalizedObjectTypes.POPUP_MENU );
}
/**
* Get server message
* @param languageId language id
* @param id message id
* @return localized Caption
*/
public String getServerMessage( String languageId, String id ) {
return getLocalizedCaption( languageId, id, LocalizedObjectTypes.SERVER );
}
/**
* Get menu item captions
* @param languageId language id
* @param menuId menu item id
* @return localized Caption
*/
public String getMenuItemCaption( String languageId, String menuId ) {
return getLocalizedCaption( languageId, menuId, LocalizedObjectTypes.CONTEXT_MENU );
}
/**
* Fill form's descriptions
* @param formId form id attribute
* @param descriptions Descriptions object
* @return id of Descriptions object
*/
public String fillFormDescriptions(String formId, Descriptions descriptions){
fillDescriptions(formId, LocalizedObjectTypes.FORM, descriptions);
return formId;
}
/**
* Get form's descriptions
* @param languageId language id
* @return localized Caption
*/
public String getFormDescription(String languageId, String formId){
return getLocalizedDescription( languageId, formId, LocalizedObjectTypes.FORM );
}
/**
* Fill html element's content
* @param htmlElementId html element id attribute
* @param htmlContents {@link Htmlcontents} object
* @return id of Htmlcontents object
*/
public String fillHtmlElementContents(String htmlElementId, Htmlcontents htmlContents){
fillHtmlContents(htmlElementId, LocalizedObjectTypes.HTML_ELEMENT, htmlContents);
return htmlElementId;
}
/**
* Get html element's content
* @param languageId language id
* @return localized html element's content
*/
public String getHtmlElementContent(String languageId, String htmlElementId){
return getLocalizedHtmlContent(languageId, htmlElementId, LocalizedObjectTypes.HTML_ELEMENT );
}
//---------------------------------------------------------------- private methods
private void fillLocalizedObjects(LocalizedObjectsId objectsId, LocalizedObject[] objects){
// Clear cache.
Cache cache = ConfigPropertyFactory.getInstance().getLocalizationCache();
cache.clear();
LocalizationDAO dao = ConfigPropertyFactory.getInstance().getLocalizationDAO();
// Clear localized objects.
dao.deleteLocalizedObjects(objectsId);
// Create Caption object.
dao.saveLocalizedObjects(objectsId, objects);
}
private void setupLocalizedObjectsId(LocalizedObjectsId objectId, String id,
LocalizedObjectTypes objectType, LocalizationTypes localizationType) {
objectId.setId(id);
objectId.setType(objectType.getId());
objectId.setLocalizationType(localizationType.getId());
}
//
// fill captions
//
private void fillCaptions(String captionsId,
LocalizedObjectTypes objectType, Captions captions) {
setupLocalizedObjectsId(
captions, captionsId, objectType, LocalizationTypes.CAPTION);
fillLocalizedObjects(captions, captions.getCaption());
}
//
// fill descriptions
//
private void fillDescriptions(String descriptionsId,
LocalizedObjectTypes objectType, Descriptions descriptions) {
setupLocalizedObjectsId(
descriptions, descriptionsId, objectType, LocalizationTypes.DESCRIPTION);
fillLocalizedObjects(descriptions, descriptions.getDescription());
}
//
// fill html content
//
private void fillHtmlContents(String htmlContentsId,
LocalizedObjectTypes objectType, Htmlcontents htmlContents) {
setupLocalizedObjectsId(
htmlContents, htmlContentsId, objectType, LocalizationTypes.HTML_CONTENT);
fillLocalizedObjects(htmlContents, htmlContents.getHtmlcontent());
}
@SuppressWarnings("unchecked")
private <C extends LocalizedObjectsId, T extends LocalizedObject> C getLocalizedObjects(
String objectsId, String langId, LocalizedObjectTypes objectType, LocalizationTypes localizationType,
Class<C> objectsContainerClass, Class<T> objectClass) {
if (objectsId == null) {
throw new NullPointerException("Localized objects id is null");
}
// Build unique key.
LocalizedObjectsCacheKey objectsKey = new LocalizedObjectsCacheKey(
objectsId, objectType, localizationType);
if( getLogger().isDebugEnabled() ) {
DEBUG( "Try to get localized objects: " + objectsKey );
}
// Try to find out in cache.
Cache cache = ConfigPropertyFactory.getInstance().getLocalizationCache();
C objectsContainer = (C) cache.get(objectsKey);
if(objectsContainer == null) {
// Load record from database.
try {
objectsContainer = objectsContainerClass.newInstance();
} catch (InstantiationException e) {
throw new GenericSystemException("InstantiationException: " + e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new GenericSystemException("IllegalAccessException: " + e.getMessage(), e);
}
setupLocalizedObjectsId(
objectsContainer, objectsId, objectType, localizationType);
T[] objects = ConfigPropertyFactory.getInstance().getLocalizationDAO()
.loadLocalizedObjects(objectsContainer, objectClass);
for (T object : objects) {
objectsContainer.putObject(langId, object);
}
// Store in cache.
cache.put(objectsKey, objectsContainer);
} else {
// Found in cache!
if( getLogger().isDebugEnabled() ) {
DEBUG( "Localized object: " + objectsKey + " found in the cache." );
}
}
return objectsContainer;
}
/**
* Returns localized content by given language.
* @param objectsContainer Container objects that contains collection of localized contents
* @param langId Language id.
* @return Localized content
*/
private String getLocalizedContent(LocalizedObjectsId objectsContainer, String langId){
// Get localized object for requested language.
LocalizedObject object = null;
if (objectsContainer != null) {
object = (LocalizedObject) objectsContainer.getObject(langId);
if (object == null) {
// ... try to find for 'default' language
object = (LocalizedObject) objectsContainer.getObject(SystemHelper.DEFAULT_LANGUAGE);
}
}
if (object == null) {
DEBUG("Localized content for object [" + objectsContainer.getId() + "], type [" + objectsContainer.getLocalizationType() + "] not found");
return "<" + objectsContainer.getId() + ">";
}
return object.getContent();
}
private String getLocalizedCaption(String langId,
String captionId, LocalizedObjectTypes objectType) {
Captions captions = getLocalizedObjects(captionId, langId, objectType,
LocalizationTypes.CAPTION, Captions.class, Caption.class);
// Complete captions container object
for (String key : captions.getObjectNames()) {
Caption caption = (Caption) captions.getObject(key);
captions.addCaption(caption);
}
return getLocalizedContent(captions, langId);
}
private String getLocalizedDescription(String langId,
String descriptionId, LocalizedObjectTypes objectType) {
Descriptions descriptions = getLocalizedObjects(descriptionId, langId, objectType,
LocalizationTypes.DESCRIPTION, Descriptions.class, Description.class);
// Complete descriptions container object
for (String key : descriptions.getObjectNames()) {
Description description = (Description) descriptions.getObject(key);
descriptions.addDescription(description);
}
return getLocalizedContent(descriptions, langId);
}
private String getLocalizedHtmlContent(String langId,
String htmlContentId, LocalizedObjectTypes objectType) {
Htmlcontents htmlContents = getLocalizedObjects(htmlContentId, langId, objectType,
LocalizationTypes.HTML_CONTENT, Htmlcontents.class, Htmlcontent.class);
// Complete descriptions container object
for (String key : htmlContents.getObjectNames()) {
Htmlcontent htmlContent = (Htmlcontent) htmlContents.getObject(key);
htmlContents.addHtmlcontent(htmlContent);
}
return getLocalizedContent(htmlContents, langId);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -