jford       2004/04/09 08:52:46

  Added:       tutorial/xdocs/6 mediatypes.xml
  Log:
  Chapter 6 conversion to xdoc
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/tutorial/xdocs/6/mediatypes.xml
  
  Index: mediatypes.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
  <document>
  
    <properties>
      <author email="[EMAIL PROTECTED]">David Sean Taylor</author>
      <title>Media Types</title>
    </properties>
  
  <body>
  
  <section name="Media Types">
  
  <p>
  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 <a href="http://www.nacs.uci.edu/indiv/ehood/MIME/MIME.html";>MIME types</a> and 
languages it supports. 
  Jetspeed packages this all up in a request object call <a 
href="http://portals.apache.org/jetspeed-1/apidocs/org/apache/jetspeed/services/rundata/JetspeedRunData.html";>JetspeedRunData</a>.
 
  You can check the request for the media type by getting the <a 
href="http://portals.apache.org/jetspeed-1/apidocs/org/apache/jetspeed/capability/CapabilityMap.html";>CapabilityMap</a>
 associated with the request (<b>rundata.getCapabilityMap</b>) and the checking the 
media type against the supported media types for your portlet.
  </p>
  
  <p>
  <img src="../images/image006-2.jpg"/>
  </p>
  
  <p>
  Let's take a look at how the HelloPortletInterface portlet checks the media type 
during content fragment generation:
  </p>
  
  <p>
  <source>
  <![CDATA[
      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);
          }
          else
          {
              text.append("Doesn't support preferred MimeType: "
              + mimeType);
          }
  ...
  ]]>
  </source>
  </p>
  
  <p>
  Every portlet has the <b>supportsType</b> 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 <b>HelloPortletInterface</b>, we see the supported 
media types are directly in the registry definition:
  </p>
  
  <p>
  <source>
  <![CDATA[
      <portlet-entry name="HelloPortletInterface"
               hidden="false" type="instance" application="false">
          <meta-info>
              <title>Hello Portlet Interface</title>
              <description>JPortal Tutorial - Hello Portlet Interface
               </description>
          </meta-info>
          
<classname>com.bluesunrise.jportal.portal.portlets.HelloPortletInterface</classname>
          <parameter name="version" value="1.4b4" hidden="false"/>
          <media-type ref="html"/>
          <media-type ref="wml"/>
          <category>tutorial</category>
          <category>portlet</category>
      </portlet-entry>        
  ]]>
  </source>
  </p>
  
  <p>
  There can be multiple &lt;media-type&gt; entries per portlet.
  </p>
  
  <p>
  Media types are defined in the <a 
href="http://portals.apache.org/jetspeed-1/client-media.html";>Media Type Registry</a>. 
  Four media types are currently supported in the registry:
  </p>
  
  <p>
  <ul>
  <li>HTML</li>
  <li>WML</li>
  <li>XML</li>
  <li>VXML</li>
  </ul>
  </p>
  
  <p>
  <source>
  <![CDATA[
    <media-type-entry name="html">
      <mime-type>text/html</mime-type>
      <character-set>UTF-8</character-set>
      <meta-info>
        <title>HTML</title>
        <description>Rich HTML for HTML 4.0 compliants browsers
        </description>
      </meta-info>
    </media-type-entry>
  ]]>
  </source>
  </p>
  
  <p>
  Also note that the <b>getContent</b> method returns a class called 
<b>ConcreteElement</b>.
  </p>
  
  <p>
  <source>
  <![CDATA[
  import org.apache.ecs.ConcreteElement;
  import org.apache.ecs.StringElement;
  ]]>
  </source>
  </p>
  
  <p>
  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.
  </p>
  
  <p>
  For more information on <b>RunData</b> class and ECS elements, see <a 
href="../AppendixB/index.html">Appendix B - Turbine and ECS</a>.
  </p>
  
  </section>
  </body>
  </document>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to