Studio Developer Manual / Version 2304
Table Of Contents
With Content Hub it is possible to create CoreMedia content from Content Hub Items.
Therefore, you need to implement the interface ContentHubTransformer
.
Pressing the "Create Content" button in the library's toolbar, or dragging and dropping a selection of Content Hub items
or folders to the Studio library will trigger a content import from the selected Content Hub Objects to CoreMedia content.
Warning
When importing content from an external system to CoreMedia, it is the responsibility of the ContentHubTransformer
to deliver a valid ContentModel
. Also, a ContentHubTransformer
should check the content that is about to be imported
for security issues!
A ContentHubAdapter
must implement the transformer()
method,
which returns a ContentHubTransformer
suitable for the adapter's items.
A ContentHubTransformer
returns a ContentModel
. ContentModel
s are used as placeholders
for contents to be created. A ContentHubTransformer
should never create content on its own but
always use ContentModel
s. This ensures that all existing ContentWriteInterceptor
s
of Studio are executed for the newly created content as well.
The following example shows a Transformer implementation for RSS:
public ContentModel transform(Item item, Content targetFolder, ContentHubAdapter contentHubAdapter, ContentHubContext contentHubContext) { RSSItem rssItem = (RSSItem) item; ContentModel contentModel = new ContentModel(targetFolder, rssItem.getRssEntry().getTitle(), item.getId()); //set standard properties String description = rssItem.getRssEntry().getDescription().getValue(); Markup markup = contentCreationUtil.convertStringToMarkup(description); contentModel.put("title", rssItem.getName()); contentModel.put("detailText", markup); //collect images references SyndEntry rssEntry = rssItem.getRssEntry(); List<String> imageUrls = FeedImageExtractor.extractImageUrls(rssEntry); List<ContentModelRef> refs = new ArrayList<>(); for (String imageUrl : imageUrls) { ContentModelRef contentModelRef = ContentModelRef .create(contentModel, "CMPicture", imageUrl); refs.add(contentModelRef); } contentModel.put("pictures", refs); return contentModel; }
Example 9.111. Implementing a ContentHubTransformer (1)
The example method can be separated into two steps:
Setting the default content properties for the target content via the
ContentModel
.Since the
ContentModel
is aContent
representation, it is possible to add properties, just like for regular content. These properties will be used for the actual content creation by the Content Hub.Collecting additional references
Some adapters for the Content Hub may want to create additional content for a single
transform
call, maybe even recursively. An RSS feed for example can contain text and images. Therefore, aCMArticle
should be created for the text content, but alsoCMPicture
documents for the images of it.ContentHubTransformer
s support this byContentModelReference
s. They allow developers to create contents incrementally.
The example below shows the usage of ContentModelReference
s for the RSS Content Hub adapter:
public ContentModel resolveReference(ContentModelReference reference, ContentHubAdapter contentHubAdapter, ContentHubContext contentHubContext) { String imageUrl = (String) reference.getData(); String imageName = contentCreationUtil.extractNameFromUrl(imageUrl); ContentHubObjectId contentHubObjectId = reference.getOwner().getContentHubObjectId(); ContentHubObjectId referenceId = ContentHubObjectId .createReference(contentHubObjectId, imageName); Content targetFolder = reference.getOwner().getTargetFolder(); ContentModel contentModel = new ContentModel(targetFolder, imageName, referenceId); Blob pictureBlob = contentCreationUtil.createPictureFromUrl(imageUrl, "Image " + imageName, "image/jpeg"); contentModel.put("data", pictureBlob); contentModel.put("title", "Image " + imageName); return contentModel; }
Example 9.112. Implementing a ContentHubTransformer (2)
For every ContentModelReference
that has been created within the transform
method,
the resolveReference
method is called. Since the reference data is an image URL, create
a new ContentModel
of type CMPicture
and put the image blob into it.
Note
ContentModelReference
s are resolved recursively. That means if the ContentModel
that is returned by the resolveReference
method contains a ContentModelReference
again,
the resolveReference
method will be called again.