[英]Querying user profile repository ATG
我在ATG的配置文件上添加了一些自定义属性。 当我想读取jsp中的配置文件值时,我只是导入ATG配置文件,然后以profile.name的身份访问该属性。
我正面临一种情况,我需要为一种类型的用户返回profile.lastName,为其他类型的用户返回profile.firstName。 这是基于诸如profile.userType属性。
是否可以在存储库中添加userType检查,以便当我读取profile.name时应返回firstName或lastName。
由于在很多地方都引用了名称(1000),所以我无法在所有地方添加用户类型检查并相应地显示名称。 因此,如果可能,我们可以在回购中处理此问题。
是的你可以。 只需使用RepositoryPropertyDescriptor。 我匆忙将以下版本拼凑在一起(未经测试,但足以使您前进):
import atg.repository.RepositoryItem;
import atg.repository.RepositoryItemImpl;
import atg.repository.RepositoryPropertyDescriptor;
public class AcmeRealUserName extends RepositoryPropertyDescriptor{
@Override
public Object getPropertyValue(RepositoryItemImpl profile, Object pValue) {
String userType = (String) profile.getPropertyValue("userType");
String lastName = (String) profile.getPropertyValue("lastName");
String firstName = (String) profile.getPropertyValue("firstName");
if ("firstNameUser".equals(userType)) {
return firstName;
} else {
return lastName;
}
}
@Override
public void setValue(String pAttributeName, Object pValue) {
//Probably Do Nothing since this is a derived property
}
/**
* A class specific logDebug method to output log messages. Unfortunately
* using System.out as the mechanism.
*
* @param pMessage
*/
protected void logDebug(String pMessage) {
System.out.println("### DEBUG(:" + getClass().getName() + getName() + ")" + pMessage);
}
}
然后,您可以在userprofiling.xml中引用此新属性,如下所示:
<property name="name" property-type="com.acme.propertydescriptor.AcmeRealUserName" item-type="string" writable="false" readable="true" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.