Slightly enhanced implementation to determine a content types' Label: if the associated ressource file can be found, use the globalized name, otherwise use the not globalized name from database.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2734 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2014-07-02 10:06:10 +00:00
parent a4e194fadf
commit 740f9b208a
1 changed files with 32 additions and 10 deletions

View File

@ -178,24 +178,46 @@ public class ContentType extends ACSObject {
*/ */
public GlobalizedMessage getLabel() { public GlobalizedMessage getLabel() {
GlobalizedMessage label;
// We assume the name of the resource bundle is the same as the // We assume the name of the resource bundle is the same as the
// ObjectType "Resources" appended. // ObjectType with "Resources" appended.
String objectTypeName = getAssociatedObjectType(); String objectTypeName = getAssociatedObjectType();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug( s_log.debug(
"Object Type is " + objectTypeName ); "Object Type is " + objectTypeName );
} }
String bundleName = objectTypeName.concat("Resources"); String bundleName = objectTypeName.concat("Resources");
// We assume the name of the key is the same as the ObjectType
// minus the domain part ("com.arsdigita.") and staring with "cms" // First try: check, if the resource file really exists, and if it does,
// and ".type_label" appended // use it.
int keyBegin = objectTypeName.indexOf("cms"); String resourcePath = "/" + bundleName.replace(".","/")
String labelKey = objectTypeName.substring(keyBegin) .concat(".properties");
.concat(".type_label") if (s_log.isDebugEnabled()) {
.toLowerCase(); s_log.debug(
"resource path is " + resourcePath );
}
if (this.getClass().getClassLoader().getResource(resourcePath)!=null) {
// Property file exists, use it!
// We assume the name of the key is the same as the ObjectType
// minus the domain part ("com.arsdigita.") and staring with "cms"
// and ".type_label" appended
int keyBegin = objectTypeName.indexOf("cms");
String labelKey = objectTypeName.substring(keyBegin)
.concat(".type_label")
.toLowerCase();
// Create the globalized label // Create the globalized label
GlobalizedMessage label = new GlobalizedMessage(labelKey, bundleName); label = new GlobalizedMessage(labelKey, bundleName);
} else {
// As a fall back use the (not globalized) "name" of the type as
// stored in the database to display the type to the user. Is is
// used as the "key" in a GloablizedMessage, which it is definitely
// not. But GlobalizedMessage displayse the key if it could not be
// found in a resource file.
label = new GlobalizedMessage(getName());
}
return label; return label;
} }