You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

In This Topic

 


 

The Content Repository in XperienCentral is used to store Images, downloads and Flash animations and custom media items. Access to these content items is exposed through the MediaRepositoryManagementService. The MediaRepositoryManagementService contains methods for creating and deleting items in the Content Repository. It also contains methods for coupling the actual file to the item that has been created in the Content Repository.

 

Creating an Image, Download or Flash

To create an item for the Content Repository, use one of the three create methods. All of them take one argument: the name of the website for which the media item will be created. The following code example shows how to create an Image, Download or Flash:

 

MediaItem image = myMediaRepositoryService.createImageMediaItem(mySession.getXperienCentralApplication().getWebsites()[0]);
MediaItem download = myMediaRepositoryService.createDownloadMediaItem(mySession.getXperienCentralApplication().getWebsites()[0]);
MediaItem flash = myMediaRepositoryService.createFlashMediaItem(mySession.getXperienCentralApplication().getWebsites()[0]);

 

Back to Top

 


Attaching a File to the Image, Download or Flash

After creating a content item, the actual file needs to be attached to it. The is done using the attachFile method, which takes a MultiPartFile as argument and only works on versions of the content items that can be created. To make this work, the follwing steps must be performed:

  1. Obtain the version of the content item.
  2. Create a MultiPartFile.
  3. Attach the MultiPartFile to the content item version.

The following code example shows how to do so for an Image:

 

// Create the media item
MediaItem image = myMediaRepositoryService.createImageMediaItem(mySession.getXperienCentralApplication().getWebsites()[0]);

// Create the version of the media item (in this example for an Image)
MediaItemImageVersion imageversion = null;
if (image.getCurrent() != null) {
	imageversion = (MediaItemImageVersion) image.getCurrent();
} else {
	imageversion = (MediaItemImageVersion) image.getPlanned();
}

// Create a MultiPartFile, based on a file on disk
fileToAttach = "C:\\temp\\image.jpg";
MultipartFile mpfile = null;
try {
	File file = new File(fileToAttach);
    InputStream inputstream = new FileInputStream(file);
	try {
		mpfile = new MockMultipartFile(fileToAttach, fileToAttach, "image/jpeg", inputstream);
	} catch (IOException e) {
		//Handle the exception
}
} catch (FileNotFoundException e) {
	// Handle the exception
}

// Attach the MultiPartFile to the MediaItemImageVersion
if (mpfile != null) {
	imageversion.attachFile(mpfile);
}

 

In the example above, a MockMultipartFile is created to attach to the image media item. If the file to be attached is uploaded to XperienCentral by the editor, it will be available as MultipartFile directly using Spring binding on a file input field. The procedure for attaching a file to a Download (MediaItemDownloadVersion) or Flash (MediaItemFlashVersion) media item is identical.

 

 Back to Top

 


Detaching a File from an Image, Download or Flash

Detaching a file from a media item is handled by the detachFile method which has has no arguments. It works exactly the same for a MediaItemImageVersion, MediaItemDownloadVersion and MediaItemFlashVersion. For example:

 

MediaItemImageVersion imageversion = null;
// Long piece of code that attaches a file to the imageversion object
imageversion.detachFile();

 

Back to Top

 


Attaching a Backup Image to the Flash Content Item

The Flash media item also has the property of a backup image file. This image will be used that have problems showing the Flash file. The method attachBackupImage works exactly the same as the attachFile method as explained in the previously in this topic. For example:

 

MediaItemFlashVersion flashversion = null;
// Long piece of code that creates a MultiPartFile containing the backup image
flashversion. attachBackupImage(mpfileOfTheBackupImage);

 

 

 

 

 

 

 

  • No labels