Sun Java System Portal Server 7 Developer's Guide

ProcedureTo Create a Provider by Extending the ProfileProviderAdapter Class

This section provides the instructions for creating a custom provider by extending the ProfileProviderAdapter class. The sample HelloWorldProvider reads a string property from the user’s display profile and allows the user to edit the string. This sample also includes an example about using the resource bundle.

Steps
  1. Create a new Java class which extends the ProfileProviderAdapter class.

    For the sample HelloWorldProvider, create the class file.


    HelloWorldProviderPPA1.java File
    
    package custom;
    
    import java.net.URL;
    import java.util.Hashtable;
    import java.util.ResourceBundle;
    import javax.servlet.http.HttpServletRequest;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.sun.portal.providers.ProfileProviderAdapter;
    import com.sun.portal.providers.ProviderException;
    
    public class HelloWorldProviderPPA1 extends ProfileProviderAdapter {
        private ResourceBundle bundle = null;
    
        // Implement the getContent method
        public StringBuffer getContent(
            HttpServletRequest req, HttpServletResponse res
        ) throws ProviderException {
            Hashtable<String,Object> tags = new Hashtable<String,Object>();
            if (bundle == null) {
                bundle = getResourceBundle();
            }
            tags.put("welcome", bundle.getString("welcome"));
            tags.put("message", getStringProperty("message", true));
            tags.put("properties", getMapProperty("aMap", true));
            StringBuffer b = getTemplate("content.template", tags);
            return b;
        }
    
        // Implement the getEdit method
        public StringBuffer getEdit(
            HttpServletRequest req, HttpServletResponse res
        ) throws ProviderException {
                Hashtable<String,String> tags = new Hashtable<String,String>();
                tags.put("message", getStringProperty("message"));
                tags.put("properties", "");
                StringBuffer b = getTemplate("edit.template", tags);
                return b;
        }
    
        // Implement the processEdit method
        public URL processEdit (
            HttpServletRequest req, HttpServletResponse res
        ) throws ProviderException {
            String message = req.getParameter("message");
            if(message != null) {
                if (!message.equals(getStringProperty("message"))) {
                    // Set the new message
                    setStringProperty("message",message);
                    return null;
                }
            } else {
                    setStringProperty("message","");
                }
            return null;
        }
    }
  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 HelloWorldProviderPPA1.java file, type:


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

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


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    
    <Provider name="HelloWorldProviderPPA1" class="custom.HelloWorldProviderPPA1">
        <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"/>
            <Collection name="aMap">
                <String name="title" value="Ramag"/>
                <String name="desc" value="My Map"/>
                <Boolean name="removable" value="true"/>
                <Boolean name="renamable" value="true"/>
            </Collection>
            <String name="message" value="Hello World Test Provider"/>
        </Properties>
    </Provider>

    The following is the sample HelloWorldProvider XML fragment for the channel in the HelloChannelPPA1.xml file.


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    
    <Channel name="HelloWorldPPA1" provider="HelloWorldProviderPPA1">
        <Properties>
            <String name="title" value="Hello World Channel"/>
            <String name="description">This is a test of the hello world provider</String>
            <String name="width" value="thin"/>
            <String name="message" value="Hello World Test!!! - non-localized "/>
            <Locale language="en" country="US">
                <String name="message" value="Hello World - I am speaking English in the United States!!!"/>
            </Locale>
        </Properties>
    </Channel>
  4. Upload the provider and channel XML fragments using the psadmin add-display-profile subcommand.

    For the sample HelloWorldProvider, upload the HelloProviderPPA1.xml file and HelloChannelPPA1.xml file XML fragments using the psadmin add-display-profile subcommand. See the Sun Java System Portal Server 7 Command-Line Reference for more information on the psadmin add-display-profile subcommand.

  5. Include the provider’s channel in one of the existing containers.

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

    1. Create the HelloWorldProvider channel XML fragment (in the HelloContainerPPA1.xml file) for the JSPTableContainer as shown in below.


      <?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="HelloWorldPPA1"/>
      			</Collection>
      			<Collection name="channelsRow">
      				<String name="HelloWorldPPA1" value="3"/>
      			</Collection>
      		</Properties>
       		<Available>
        		<Reference value="HelloWorldPPA1"/>
       		</Available>
       		<Selected>
       			<Reference value="HelloWorldPPA1"/>
       		</Selected>
       		<Channels>
       		</Channels>
       </Container>
    2. Use the psadmin modify-display-profile subcommand to add the channel to a container.

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

  6. Create the template files if the new provider requires template files.

    The sample HelloWorldProvider requires content.template and edit.template files.

    1. Create the content.template file for the HelloWorldProvider.

      The contents of content.template file is shown below:.


      <html>
      <head></head>
      <body bgcolor="white">
      [tag:welcome]<br><br>
      [tag:message]<br><br>
      [tag:properties]
      </body>
      </html>
    2. Create the edit.template file for the HelloWorldProvider.

      The contents of edit.template file is shown below:


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
      <HTML>
          <HEAD>
              [tag:noCache]
              <TITLE>[tag:productName]</TITLE>
          </HEAD>
          <BODY BGCOLOR="#FFFFFF">
              <FONT SIZE=+0 FACE="[tag:fontFace1]">
              <LINK REL="stylesheet" TYPE="text/css" HREF="[surl:/desktop/css/style.css]" TITLE="fonts">
              <CENTER>
      
              [tag:bulletColor]
              [tag:banner]
      
              <FORM ACTION="dt" NAME="edit_form" METHOD=POST ENCTYPE="application/x-www-form-urlencoded">
              <INPUT TYPE=HIDDEN NAME="action" SIZE=-1 VALUE="process">
              <INPUT TYPE=HIDDEN NAME="provider" SIZE=-1 VALUE="[tag:providerName]">
      
              [tag:inlineError]
      
              <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=3 WIDTH="100%">
                  <TR>
                      <TD WIDTH="100%" VALIGN=TOP>
                          <CENTER>
                              <BR>
                              <FONT SIZE="+2" FACE="[tag:fontFace1]">
                              <B>
                              Edit [tag:title]</B></FONT>
                              <BR>
                              [tag:contentOptions]
                          </CENTER>
                      </TD>
                      </TR>
              </TABLE>
      
              <BR>
      
              <FONT SIZE=+0 FACE="[tag:fontFace1]">
              <INPUT TYPE=SUBMIT NAME="Submit" VALUE="Finished" CLASS="button">
              <INPUT TYPE=BUTTON OnClick="location=’[tag:desktop_url]’" VALUE="Cancel" CLASS="button">
              </font>
      
              <br>
      
              <P>
              </FORM>
              <BR>
              [tag:menubar]
              </font>
          </BODY>
      </HTML>
  7. Create the channel directory under the template root directory.

    By default, the template root directory is PortalServer-DataDir/portals/portal-ID/desktop/desktoptype. For this example, create a HelloWorldPPA1 directory under /var/opt/SUNWportal/portals/portal-ID/desktop/desktoptype directory.

  8. Copy all the template files over to the newly created directory. For example:


    cp content.template PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/HelloWorldPPA1
    cp edit.template /var/opt/SUNWportal/portals/portal-ID/desktop/desktoptype/HelloWorldPPA1
  9. Create a resource bundle properties file.

    The sample HelloWorldProvider includes a HelloWorldProviderPPA1.properties file.

    1. Create a HelloWorldProviderPPA1.properties properties file.

    2. Include the following property in the file:

      welcome=Welcome to Hello World!!

    3. Copy the resource bundle to the user defined class directory.

      By default, the class directory to copy the resource bundle into is PortalServer-DataDir/portals/portal-ID/desktop/classes.

  10. Access the HelloWorld channel inside the JSPTableContainer. To access, log in to the Desktop and type the following URL in your browser:


    http://hostname:port/portal-ID/dt?provider=JSPTableContainer