Media Types

The content generated is dependent on the media type supported by the browser. Browsers (devices) supply request parameters describing the capabilities of device. For instance, a web browser would provide in its request parameters a description of which MIME types and languages it supports. Jetspeed packages this all up in a request object call JetspeedRunData. You can check the request for the media type by getting the CapabilityMap associated with the request (rundata.getCapabilityMap) and the checking the media type against the supported media types for your portlet.

Let's take a look at how the HelloPortletInterface portlet checks the media type during content fragment generation:

    public ConcreteElement getContent(RunData rundata)
        JetspeedRunData jrun = (JetspeedRunData) rundata;
        CapabilityMap map = jrun.getCapability();
        StringBuffer text = new StringBuffer();
        String mimeType = map.getPreferredType().toString();
        if (this.supportsType(map.getPreferredType()))
            text.append("Supports preferred MimeType: " + mimeType);
            text.append("Doesn't support preferred MimeType: "
            + mimeType);

Every portlet has the supportsType method for checking a browser device's MIME type. The Media Types are looked up from the portlet definition in the registry. Looking at the registry entry for HelloPortletInterface, we see the supported media types are directly in the registry definition:

    <portlet-entry name="HelloPortletInterface"
             hidden="false" type="instance" application="false">
            <title>Hello Portlet Interface</title>
            <description>JPortal Tutorial - Hello Portlet Interface
        <parameter name="version" value="1.6" hidden="false"/>
        <media-type ref="html"/>
        <media-type ref="wml"/>

There can be multiple <media-type> entries per portlet.

Media types are defined in the Media Type Registry. Four media types are currently supported in the registry:

  • HTML
  • WML
  • XML
  • VXML

  <media-type-entry name="html">
      <description>Rich HTML for HTML 4.0 compliants browsers

Also note that the getContent method returns a class called ConcreteElement.

import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;

Unfortunately, Jetspeed is coupled to the Element Construction Set, a Java-based HTML mark-up generator. As you will see in the tutorials 7 and onwards, you shouldn't have to work much with ECS or the low level methods of the Portlet interface. Jetspeed provides a better way of getting content using templating engines such as Velocity or JSP, along with RSS and XSLT ready-written portlets that you can extend.

For more information on RunData class and ECS elements, see Appendix B - Turbine and ECS.