This section describes how to get and set attributes using the IAttributeSet interface, which provides the following benefits over working with attributes with PCD APIs:
IAttributeSet returns all attributes associated with the current object, not just those stored in the PCD.
For example, the implementation of IAttributeSet for an iView gathers attributes and values for the current object from the following sources:
PCD, which stores a small set of basic attributes, as well as any changes made by administrators to any attribute
Component from which the iView is derived, for example, the properties defined in the portalapp.xml for a portal component.
Core iView, located at
. All iViews inherit from this iView.The priority is in the order shown. If an attribute is defined in the PCD and in the portalapp.xml , the PCD value takes precedence.
The implementation of IAttributeSet can enforce rules on modifying attributes, whether general rules for all semantic objects or for the current semantic object.
For example, IAttributeSet can restrict you from modifying the Merge Priority property if the Can Be Merged property is false .
Information about obtaining an IAttributeSet object for a PCD object: Working with Administration Objects
The following gets the Object is a Template attribute, and its Inheritance meta-attribute:
IAdminBase myAdmin = (IAdminBase)iCtx.lookup(myObject); IAttributeSet attrSet = (IAttributeSet) myAdmin.getImplementation(IAdminBase.ATTRIBUTE_SET); // Display Object is a Template attribute response.write(attrSet.getAttribute( IAttrPcmGeneral.ATTRIBUTE_IS_TEMPLATE) ); // Display Inheritance meta-attribute of Object is a Template attribute response.write(attrSet.getMetaAttribute( IAttrPcmGeneral.ATTRIBUTE_IS_TEMPLATE, IAttrPcmGeneral.META_ATTRIBUTE_INHERITANCE));
The following sets the Object is a Template attribute to true :
attrSet.putAttribute(IAttrPcmGeneral.ATTRIBUTE_IS_TEMPLATE,true); attrSet.save();
If the attribute does not exist, it is created.
Text Attributes
Text attributes are translatable and, therefore, require an additional parameter that indicates the locale. To find out the type of an attribute, you use the getAttributeType method. In the following example, if the attribute type is text, then you use the getAttribute method with a locale:
. . . IattributeSet attrSet = (IAttributeSet) myAdmin.getImplementation(IAdminBase.ATTRIBUTE_SET); if (attrSet.getAttributeType("MyAttribute") == IAttributeSet.TEXT_ATTRIBUTE) { attributeValue = attrSet.getAttribute("MyAttribute", new Locale("en")); } . . .
The following attributes require the use of the locale:
com.sap.portal.pcm.Title
com.sap.portal.pcm.Description
The following meta-attributes require the use of the locale:
plainDescription
longDescription
category
validValueTitle0 , validValueTitle1 , and so forth.
The following gets the Title text attribute:
response.write (attrSet.getAttribute( IAttrPcmGeneral.ATTRIBUTE_TITLE,request.getLocale()));
Attribute Constants
To specify an attribute, use the designated constant for that attribute. The constants for each semantic type are located in a corresponding interface in the com.sap.portal.pcm.attributes package.
For example, the constants for iView attributes are located in the IAttriView interface. The following code checks whether the current iView allows browser caching:
response.write( attrSet.getAttribute(IAttriView.ATTRIBUTE_ALLOW_BROWSER));