Handling DisplayName and ResourceType Properties
The DisplayName and ResourceType properties are frequently used within the repository framework. This section gives you information on how to handle them efficiently, avoiding the creation and disposal of too many objects.
Accessing DisplayName
The class PropertyName offers several methods for retrieving the names of the most frequently used properties, for example, the property DisplayName . The call getProperty(PropertyName.createDisplayname()) returns the display name of a resource. However, instead of accessing the Property object to get the DisplayName , you can also use Resource.getDisplayName() . The getDisplayName() method has two signatures:
| Method | Explanation |
|---|---|
|
getDisplayName() |
Returns the DisplayName or null when the DisplayName is not set. If it returns null , you can specify a fallback as shown in the code extract below. |
|
getDisplayName(boolean) |
Returns the DisplayName . If no DisplayName is set:
|
The code extract illustrates the use of getDisplayName ().
// retrieving the display name or null if the name is not set set
String displayname = resource.getDisplayName();
if((displayname == null) && (!displayname.equals(""))){
// fallback - retrieve the RID’s name if display name is not set
displayname = resource.getRID().name().toString();
// use RID’s name as fallback
}
The code extract illustrates the use of getDisplayName(boolean) .
// retrieving the display name or RID’s name if not set String displayname = resource.getDisplayName(true);
Updating the DisplayName
To update the DisplayName , you use the the createDisplaynameProp() method of the Property class. This creates the DisplayName property with the specified string.
resource.setProperty(Property.createDisplaynameProp(displayname));
Retrieving ResourceType
The ResourceType property is handled in the same way as DisplayName. The method getProperty(PropertyName.createResourceType()) returns the ResourceType . To avoid accessing the property object, you can use resource.getResourceType() as shown:
String resourcetype = resource.getResourceType();
if( resourcetype == null ) {
// not set
}
Creating a ResourceType Property
To create a ResourceType property, you use the method Property.createResourceTypeProp() , specifying a java.lang.String as the value of the property.
The code extract shows how the application MyApp creates a ResourceType property with the value myResourceType using the correct naming conventions.
// myApp namespace public final String myTypeNS = IWcmConst.RESOURCE_TYPE_NAMESPACE.APPLICATIONS + IWcmConst.NAMESPACE_SEPARATOR + "myApp"; // myApp’s full resource type value public final String myTypeName = myTypeNS + IWcmConst.NAMESPACE_SEPARATOR + "myResourceType"; // setting a resource’s resource type property to myTypeName resource.setProperty(Property.createResourceTypeProp(myTypeName));