This document describes how the code in com.ptc.core.foundation.content.server and com.ptc.core.foundation.content.common may be used for various content-management scenarios. Each scenario will be described, and a sequential description of steps or an actual code fragment will be provided.
To attach a file to a ContentHolder as an ApplicationData content item, you must first upload it to a staging area, then in a subsequent step, attach it to the holder. The next scenario shows how to upload the file content. The second scenario, shows how to add the ContentItem to the holder.
Upload file content to the staging area.
The ApplicationData TypeInstance that is obtained from the StageContentCommand will contain the file name, the uploaded from path, the size of the file, and a checksum. It will also contain a URI that can be used to locate the file data in the staging area later, when the ApplicationData is attached to the ContentHolder. The caller, however, does not need to worry about the URI value. This ApplicationData should be attached to the ContentHolder as in the next scenario...
Given a ContentHolder that is persisted, add a new ContentItem to the holder.
ContentConstants.contentHolderModContentItemAti(...). TypeInstance content_holder = ...;
TypeInstance app_data = ...; // assumed to be an ApplicationData
// make the content item a secondary content item
CommandUtility.putAttributeContent(ContentConstants.CONTENT_ITEM_ROLE_NAME_ATI,
app_data, "SECONDARY");
// Add the content item as a new attribute value
ContentUtil.markContentItemAsNew(content_holder, app_data);
// Update the holder that bears the ContentItem
UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
update_command.setSource(content_holder);
...; // set other inputs
// execute the update - performs the add
update_command = (UpdatePersistentEntityCommand)update_command.execute();
Given a ContentHolder and a ContentItem on that holder, remove the ContentItem.
ContentConstants.contentHolderModContentItemAti(...). TypeInstance content_holder = ...;
TypeInstance app_data = ...;
// Mark the content item as a removed attribute value.
// The utility method vastly simplifies this task.
ContentUtil.markContentItemAsDeleted(content_holder, content_item);
// Update the holder that bears the ContentItem
UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
update_command.setSource(content_holder);
...; // set other inputs
// execute the update - performs the delete
update_command = (UpdatePersistentEntityCommand)update_command.execute();
Given a ContentHolder as a TypeInstance obtain the set of ContentItems associated with it.
Given a ContentHolder as a TypeInstance obtain just the set of secondary ContentItems associated with it. This scenario is nearly identical to the previous, the difference in code is emphasized.
TypeInstance content_holder = ...;
GetContentItemsCommand get_cmd = new GetContentItemsCommand();
get_cmd.setContentHolder(content_holder);
get_cmd.setRole(ContentRoleType.SECONDARY.toString()); // use the simple internal value
get_cmd = (GetContentItemsCommand)get_cmd.execute();
// get the updated content holder
content_holder = get_cmd.getContentHolder();
// get the content items
TypeInstance[] content_items = get_cmd.getContentItems();
... // do something with them
full documentation forthcoming
TypeInstance content_holder = ...;
TypeInstance old_app_data = ...; // the item to replace
// Stage the content for the new item - the result is
// the new ApplicationData instance.
StageContentCommand stage_command = ...;
stage_command = (StageContentCommand)stage_command.execute();
TypeInstance new_app_data = stage_comand.getApplicationData();
// Make the new content item a secondary content item (or whatever
// other role type you'd like)
CommandUtility.putAttributeContent(
ContentConstants.CONTENT_ITEM_ROLE_NAME_ATI,
new_app_data, "SECONDARY");
// Mark the old content item as a deleted attribute value.
// The utility method vastly simplifies this task.
ContentUtil.markContentItemAsDeleted(content_holder, old_app_data);
// Mark the new content item as a mew attribute value.
// The utility method vastly simplifies this task.
ContentUtil.markContentItemAsNew(content_holder, new_app_data);
// Update the holder that bears the ContentItems
UpdatePersistentEntityCommand update_command = new UpdatePersistentEntityCommand();
update_command.setSource(content_holder);
...; // set other inputs
// execute the update - performs the delete and add
update_command = (UpdatePersistentEntityCommand)update_command.execute();
documentation forthcoming
documentation forthcoming
documentation forthcoming