From 740f9b208a3db0801dd438837ff063ddd6ae0861 Mon Sep 17 00:00:00 2001 From: pb Date: Wed, 2 Jul 2014 10:06:10 +0000 Subject: [PATCH] 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 --- .../src/com/arsdigita/cms/ContentType.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/ContentType.java b/ccm-cms/src/com/arsdigita/cms/ContentType.java index e82cc5c2e..84842e064 100755 --- a/ccm-cms/src/com/arsdigita/cms/ContentType.java +++ b/ccm-cms/src/com/arsdigita/cms/ContentType.java @@ -178,24 +178,46 @@ public class ContentType extends ACSObject { */ public GlobalizedMessage getLabel() { + GlobalizedMessage label; + // We assume the name of the resource bundle is the same as the - // ObjectType "Resources" appended. + // ObjectType with "Resources" appended. String objectTypeName = getAssociatedObjectType(); if (s_log.isDebugEnabled()) { s_log.debug( "Object Type is " + objectTypeName ); } 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" - // and ".type_label" appended - int keyBegin = objectTypeName.indexOf("cms"); - String labelKey = objectTypeName.substring(keyBegin) - .concat(".type_label") - .toLowerCase(); + + // First try: check, if the resource file really exists, and if it does, + // use it. + String resourcePath = "/" + bundleName.replace(".","/") + .concat(".properties"); + if (s_log.isDebugEnabled()) { + 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 - GlobalizedMessage label = new GlobalizedMessage(labelKey, bundleName); + // Create the globalized label + 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; }