Here’s an example that defines a user defined property type in an XML repository definition file:

<item-descriptor name="images">
  <table name="book" id-column-names="book_id" type="primary">
    <property name="title"/>
    <property name="author"/>
    <property name="lastModifiedTime"/>
    <property name="contentFileName" data-type="string"/>
  </table>
  <property name="contentFile"
            property-type="atg.repository.FilePropertyDescriptor">
    <attribute name="pathNameProperty" value="contentFileName"/>
  </property>

</item-descriptor>

See the source code in <ATG2007.3dir>/Das/src/Java/atg/repository/FilePropertyDescriptor.java for the user defined property implementation used in this example.

If you extend the GSAPropertyDescriptor class, you have two additional methods that you can override. These methods convert data between the type that is stored in the database and the type that is stored in the cache. These methods are called only when the data is loaded from or stored to the database. If a cached value is found, it will be returned without calling these methods. Thus it is slightly more efficient to do conversion here than in the getPropertyValue or setPropertyValue methods.

//-------------------------------------
/**
 * Translate a raw property value to a real value. The real value is what
 * applications use. The raw value is what is stored in the DB.
 * @param pRawValue for a property
 * @return real value to use in applications for the property
 **/
public Object rawToReal(Object pRawValue)

//-------------------------------------
/**
 * Translate a property value to a raw value. The real value is what
 * applications use. The raw value is what is stored in the DB.
 * @param pRealValue for a property
 * @return raw value for storing this property in the DB
 **/
public Object realToRaw(Object pRealValue)

The following example is taken from the productCatalog.xml file in ATG Commerce. We define two user defined property descriptors. The first property descriptor is named data. It returns a java.io.File object when you call getPropertyValue("data") on one of the media-external items. The path name for this File object is computed by concatenating the value of the url property of the media-external item with the value of the pathPrefix attribute below, ./docs. Thus the path is of the form:

./docs/<value of the url property>

The second user defined property computes a MIME type from the url property. It returns a MIME type string like "text/html" from the value of the url property. It uses a MimeTyper component to convert the suffix to a MIME type.

<!-- Media, which is stored on the external file system -->
<item-descriptor name="media-external" display-name="Media - External"
                 super-type="media" sub-type-value="external"
                 item-cache-size="1000" query-cache-size="1000"
                 version-property="version" id-space-name="media"
                 content-property="data">
    <table name="dcs_media_ext" type="auxiliary" id-column-names="media_id">
       <property name="url" data-type="string" column-name="url"
                 required="true"/>
    </table>
    <property name="data" property-type="atg.repository.FilePropertyDescriptor"
              writable="false" queryable="false">
      <attribute name="pathNameProperty" value="url"/>
      <attribute name="pathPrefix" value="./docs"/>
    </property>
    <property name="mimeType"
              property-type="atg.repository.MimeTyperPropertyDescriptor"
              data-type="String" writable="false" queryable="false">
        <attribute name="identifier" value="url"/>
    </property>
</item-descriptor>

A new property type is defined by implementing a sub-class of the atg.repository.RepositoryPropertyDescriptor class. In this class, you can define values for the readable, writable, and queryable properties. They will also have the following additional methods that will typically be overridden by a user-defined property type:

//-------------------------------------
 // Ability to retrieve/save values to the repository item
 //-------------------------------------

 //-------------------------------------
 /**
  * This method is called to retrieve a read-only value for this property.
  *
  * Once a repository has computed the value it would like to return for
  * this property, this property descriptor gets a chance to modify it
  * based on how the property is defined.  For example, if null is to
  * be returned, we return the default value.
  */
 public Object getPropertyValue(RepositoryItemImpl pItem, Object pValue);

 //-------------------------------------
 /**
  * Sets the property of this type for the item descriptor provided.
  */
 public void setPropertyValue(RepositoryItemImpl pItem, Object pValue);

You can register user defined property types in a static registry so that they can be defined with a simple name, like tag converters. List your user defined properties in the userPropertyDescriptors property of the GSARepository component.

 
loading table of contents...