2017-03-08 86 views
0

我在ATG的配置文件之上添加了一些自定义属性。当我想读取jsp中的配置文件值时,我只是导入ATG配置文件,然后以profile.name身份访问该属性。查询用户配置文件存储库ATG

我正面临一种情况,我需要为一种类型的用户返回profile.lastName,为其他类型的用户返回profile.firstName。这是基于说profile.userType属性。

是否有可能在存储库中添加userType检查,以便当我读取profile.name时,它应该返回firstName或lastName。

由于名称在许多地方被引用(1000),我无法在任何地方添加用户类型检查并相应地显示名称。所以如果可能的话,我们可以在回购中处理。

回答

2

是的,你可以。只需使用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" />