The atg.repository.RepositoryUtils class includes a method you can use to clone a repository item. This creates a copy of a repository item in a repository without adding the item to the repository. A copy can be a deep copy or a shallow copy. Furthermore, you can specify a list of properties to exclude from the copy.

The full signature of the cloneItem method is:

public static MutableRepositoryItem cloneItem(RepositoryItem pItem,
                                              boolean pDeepCopy,
                                              Map pPropExceptions,
                                              Map pExcludedProperties,
                                              MutableRepository pDestRepository,
                                              String pId)
                                       throws RepositoryException,
                                              DuplicateIdException

The cloneItem method’s parameters are as follows:

Parameter

Description

pItem

Item to copy.

pDeepCopy

The mode of the copy. If true, the method creates a deep copy of the item and its properties. Otherwise, the method creates a shallow copy, only getting references of child RepositoryItems. Note that shallow copying will only work if the source and destination repositories are the same.

pPropExceptions

Hierarchical map of property name exceptions to the above mode. Keys are property names, while values are either null or, if the property is another repository item, another Map. For example, if you clone a product item using pDeepCopy=true, you could add the key parentCategory with a null value into pPropExceptions. This would result in a shallow copy of the product.parentCategory. Alternatively, you could add the key parentCategory but set the value to another map of exceptions that included the key/value pair keywords=null. This would result in a deep copy of product.parentCategory but a shallow copy of the product.parentCategory.keywords. Optional.

pExcludedProperties

Properties to exclude from the clone. Keys are item descriptor names and the values are collections of property names to exclude. Optional.

pDestRepository

Repository to copy the new item into. If the source and destination repositories are the same, properties that are items will be cloned to the repository of the source item-property. Optional; if null, the new item is copied to source repository.

pId

Repository ID to use in the copy of the item. Optional; if null, a unique ID is automatically generated.

 
loading table of contents...