Entering content frame

Component documentation Content Conversion Service Locate the document in its SAP Library structure

Purpose

Application name: com.sap.portal.runtime.application.contentconversion.

Portal components generate HTML content, but a portal component can also generate content of another type, such as XML or WML. Such a component can also participate in a Web service scenario.

The Content Conversion Service enables the portal components to generate alternative content types.

Implementation Considerations

A component that wants to generate a content type other than HTML must specify the property: ContentType in its configuration. The value of ContentType must be the text representation of an instance of PortalComponentContentType, text/wml.

At runtime, such a component receives a PortalComponentResponse, in which the component can write multiple content types. After the component has finished its content generation, the content is converted. The target content type of this conversion is the content type defined by the PortalResponse.

The content type defined by the property ContentType is the content type a component generates at the beginning of the content generation. If a component wants to change the content type during generation, it can call the method setContentType(PortalComponentContentType type) that is defined in IPortalComponentResponse. Everything written from this point is treated as if it belongs to the content type set. With this mechanism, a component can even generate multiple content types during one content generation. The Content Conversion Service will convert them all to the target type, the PortalResponse.

Integration

The service uses content converters to perform the conversion. A content converter is capable of converting content of one content type to another. It implements the interface IContentConverter that defines the method:

String convert(String content, IPortalComponentRequest request)

Using the parameter request, the converter has access to the components resources and can locate any scripts/parameters that the component might provide to perform the conversion.

Content converters are provided to the PRT by content converter factories that implement IContentConverterFactory. This interface contains the method:

public IContentConverter getConverter(

   PortalComponentContentType fromType,

   PortalComponentContentType toType)

The factory must be registered in the portal registry. The path in the registry can be obtained by calling getContentConverterRegistryRoot() defined on IContentConversionService.

The key to register the factory must be the concatenation of the two content types for which the factory can provide a converter. The two content types must be URL encoded.

Example

This example registers myFactory, in order to provide a converter for converting from RSS to HTML:

IContentConversionService contentConversion =

   (IContentConversionService) mm_serviceContext.getService(

      IContentConversionService.KEY);

String mm_rootKey = contentConversion.getContentConverterRegistryRoot();

String fromType = URLEncoder.encode(PortalComponentContentType.RSS.toString());

String toType = URLEncoder.encode(PortalComponentContentType.HTML.toString());

String mm_RSSToHTMLConverterRegistryString = fromType + toType;

PortalRegistry.getInstance().bind(

   mm_rootKey + "/" + mm_RSSToHTMLConverterRegistryString,

   myFactory);

 

 

Leaving content frame