Sun Java System Portal Server 7.1 Developer's Guide

ProcedureTo create a custom provider by extending the ProviderAdapter class

This section provides the instructions for creating a custom provider by extending the ProviderAdapter class. The process described here includes creating a sample HelloWorldProvider that prints “Hello World!” on the provider’s channel.

  1. Create a new java class which extends the ProviderAdapter class.

    For the sample HelloWorldProvider, create the class file as shown here.

    HelloWorldProviderPA.java File


    package custom;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.sun.portal.providers.ProviderAdapter;
    import com.sun.portal.providers.ProviderException;
    
    public class HelloWorldProviderPA extends ProviderAdapter {
        public java.lang.StringBuffer getContent (HttpServletRequest request,
    		HttpServletResponse response) throws ProviderException  {
            return new StringBuffer("Hello, world!");
        }
    }
  2. Compile the class and put it in the user defined class directory.

    The default directory for the class file is PortalServer-DataDir/portals/portal-ID/desktop/classes. To compile the HelloWorldProviderPA.java file, type:


    javac -d PortalServer-DataDir/portals/portal-ID/desktop/classes -classpath PortalServer-base
    /sdk/desktop/desktopsdk.jar:AccessManager-base/lib/servlet.jar HelloWorldProviderPA.java
  3. Define the new provider and provider’s channel definition in a temporary XML file.

    The sample HelloWorldProvider XML fragment for the provider is in the HelloProviderPA.xml file.

    HelloProviderPA.xml File


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    
    <Provider name="HelloWorldProviderPA" class="custom.HelloWorldProviderPA">
        <Properties>
            <String name="title" value="*** TITLE ***"/>
            <String name="description" value="*** DESCRIPTION ***"/>
            <String name="refreshTime" value="0"/>
            <Boolean name="isEditable" value="true"/>
            <String name="editType" value="edit_subset"/>
            <String name="width" value="thin" advanced="true"/>
            <ConditionalProperties condition="locale" value="en">
                <String name="helpURL" value="desktop/HelloWorld.htm" advanced="true"/>
            </ConditionalProperties>
            <String name="helpURL" value="desktop/HelloWorld.htm" advanced="true"/>
            <String name="fontFace1" value="Sans-serif"/>
            <String name="productName" value="Sun Java System Portal Server"/>
            <Collection name="aList">
                <String value="i’m aList"/>
            </Collection>
            <String name="message" value="Sample Hello World Provider"/>
        </Properties>
    </Provider>
  4. Upload the provider and channel XML fragments using the psadmin add-display-profile command.

    For the sample HelloWorldProvider, upload the HelloProviderPA.xml XML fragments using the psadmin add-display-profile command. See the Sun Java System Portal Server 7.1 Command Line Reference for more information on psadmin add-display-profile command.

  5. Include the new channel in one of the existing containers.

    The sample HelloWorldProvider will be displayed only in a Table Desktop layout. To add the channel in the JSPTableContainer from the administration console, follow instructions in the Portal Server administation console online help. To add the channel in the JSPTableContainer manually:

    1. Add the HelloWorldProvider channel XML fragment (in the HelloChannelPA.xml file) for the JSPTableContainer.

      HelloChannelPA.xml File


      <?xml version="1.0" encoding="utf-8" standalone="no"?>
      <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd"> 
      <Container name="JSPTableContainer" provider="JSPTableContainerProvider">
      <Properties> 
      	<Collection name="Personal Channels">
      		<String value="HelloWorldPA"/>
      	</Collection>
      	<Collection name="channelsRow">
      		<String name="HelloWorldPA" value="3"/>
      	</Collection>
      	<Collection name="channelsColumn">
      		<String name="HelloWorldPA" value="3"/>
      	</Collection>
      </Properties>
      <Available>
      	<Reference value="HelloWorldPA"/>
      </Available>
      <Selected>
      	<Reference value="HelloWorldPA"/>
      </Selected>
      <Channels>
      	<Channel name="HelloWorldPA" provider="HelloWorldProviderPA">
      		<Properties>
      			<String name="message" value="Hello World Test!!! - non-localized "/>
      		</Properties>
      	</Channel>
      </Channels>
      </Container>
    2. Use the psadmin modify-display-profile sub command to add the changes to the container.

      If you do not specify a parent object with the -p option, the channel is added at the root level.

  6. Specify the URL in your browser to access the HelloWorld channel inside the JSPTableContainer.


    http://hostname:port/portal/dt?provider=JSPTableContainer/HelloWorldPA