close

Filter

loading table of contents...

Studio Developer Manual / Version 2304

Table Of Contents

9.27.3 Content Hub Content Creation

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

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. ContentModels are used as placeholders for contents to be created. A ContentHubTransformer should never create content on its own but always use ContentModels. This ensures that all existing ContentWriteInterceptors 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 a Content 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, a CMArticle should be created for the text content, but also CMPicture documents for the images of it. ContentHubTransformers support this by ContentModelReferences. They allow developers to create contents incrementally.

The example below shows the usage of ContentModelReferences 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

Note

ContentModelReferences 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.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.