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,

The cloneItem method’s parameters are as follows:




Item to copy.


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 only works if the source and destination repositories are the same.


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


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


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


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

loading table of contents...