
You can use the Content API to integrate content from external sources into workspaces. To do this, you need to implement a content provider that represents the content from the external source in workspaces. Through this provider, you can create workspace modules based on external content items and control their appearance in the content galleries, such as the Module Gallery or Link Gallery. You implement a content provider as a portal service.
The Content API is contained in the com.sap.workspaces.content package.
The following code samples illustrate how to implement an external content provider.
Extend the AbstractModule class to represent a module based on an external content item, and define its properties:
private class Module extends AbstractModule {
private String url;
public Module(String URL) {
this.url = URL;
}
public String getID() {
return "moduleID";
}
public String getName(Locale locale) {
return "moduleTitle";
}
public String getContent(IPortalComponentRequest request) throws WorkspacesRuntimeException {
//Return the module's URL
return url;
}
public String getContentForIndexing() throws WorkspacesRuntimeException {
//Return the module's title for indexing
return "moduleTitle";
}
}Extend the AbstractContentProvider class to represent your content provider.
public class ExternalContentProvider extends AbstractContentProvider implements IService {
private static final String KEY = "tc~spaces~contentproviders.ExternalContentProvider";
private static final String SHARED_ID = "sharedModuleID";
private static final String PERSONAL_ID = "personalModuleID";
private static final String SHARED_URL = "/sharedURL";
private static final String PERSONAL_URL = "/personalURL";
ContentDescriptor[] sharedWSDescriptors = new ContentDescriptor[1];
ContentDescriptor[] personalWSDescriptors = new ContentDescriptor[1];
private String[] sharedCurCategories;
private String[] personalCurCategories;
private Date sharedCreationDate;
private Date personalCreationDate;
private void initDescriptors() {
sharedWSDescriptors[0] = new ContentDescriptor("sharedTitle", "sharedDesc", "sharedImageUrl", SHARED_ID, this.sharedCurCategories, this.sharedCreationDate, "sharedUrl");
personalWSDescriptors[0] = new ContentDescriptor("personalTitle", "personalDesc", "personalImageUrl", PERSONAL_ID, this.personalCurCategories, this.personalCreationDate, "personalUrl");
}
public String getID() {
//Content Provider ID
return "contentProviderSampleID";
}
/**
* In the content descriptor, define in which content galleries and types of workspaces
* the content item should be available for the specified user and locale
*/
public ContentDescriptor getContentDescriptor( String contentID, IUser user, Locale locale ) {
ContentFilter filter = new ContentFilter( new Availability[]{Availability.APPLICATION_LIST, Availability.GALLERY, Availability.REPORT_LIST}, new Type[]{Type.PERSONAL, Type.SHARED} );
ContentDescriptor[] descriptors = getContentDescriptors( filter, user, locale );
if (descriptors != null) {
for ( int i = 0; i < descriptors.length; i++ ) {
if ( descriptors[i].getContentID().equals( contentID ) ) {
return descriptors[i];
}
}
}
throw new WorkspacesRuntimeException( "Descriptor not found for ID: " + contentID, null );
}
// Define separate content descriptors for shared and personal workspaces
public ContentDescriptor[] getContentDescriptors( ContentFilter filter, IUser user, Locale locale ) {
if ( filter.getWorkspaceAvailability()[0].equals(Type.SHARED) ) {
return sharedWSDescriptors;
}
else {
return personalWSDescriptors;
}
}
// Create a module based on the content item using the Module class
public AbstractModule getModule(String moduleID, IUser user) {
if ( SHARED_ID.equals(moduleID) ) {
return new Module( SHARED_URL );
}
else {
return new Module( PERSONAL_URL );
}
}To enable your content provider, you need to deploy and configure it, as follows:
Finalize and deploy your service to the portal.
Navigate to .
In the Content tab, choose .
In the Content Provider field, enter prt_service:<your service key>.
Navigate to Workspaces, open a workspace in which you are a manager, and choose Add Content. Check that your external content appears in the Module Gallery.