Sun logo      Previous      Contents      Index      Next     

Sun ONE Portal Server 6.2 Developer's Guide

Chapter 3
Extending the Base Providers

This chapter includes instructions for creating a custom provider by:

Examples are provided for developing a sample HelloWorldProvider that will display a message (“Hello World”). This is to illustrate the fundamentals of how the Provider interface works first, followed by examples of how ProviderAdapter and ProfileProviderAdapter classes make the implementation easier. Use the instructions (provided with the sample HelloWorldProvider) for developing your custom provider by extending any one of these APIs.


Implementing the Provider Interface

The Provider interface defines the interface for implementing the provider component of a channel. If you want to directly implement the Provider interface, code should be written to implement all of the methods in this interface. You will not have access to the ProviderContext and the properties in the display profile cannot be accessed. If you are implementing this interface, it’s up to the provider implementation to get the properties.

For more information on this interface, see the Javadocs at http://hostname.port/portal/javadocs.

To create a custom provider by implementing the Provider Interface:


Note

This section provides the instructions for creating a custom provider by implementing the Provider interface. 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 implements the Provider interface.
  2. For the sample HelloWorldProvider, create the class file as shown in Code Example 3-1.

    Code Example 3-1  HelloWorldProviderP.java File  

    package custom;

    import java.net.URL;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import com.sun.portal.providers.Provider;

    import com.sun.portal.providers.ProviderException;

    import com.sun.portal.providers.UnknownEditTypeException;

    public class HelloWorldProviderP implements Provider {

        public void init(

            String name, HttpServletRequest req

        ) throws ProviderException { }

        public StringBuffer getContent(

            HttpServletRequest request, HttpServletResponse response

            ) throws ProviderException {

            return new StringBuffer("Hello World!");

        }

        public java.lang.StringBuffer getContent(java.util.Map m) throws ProviderException {

            return new StringBuffer("Hello, world!");

        }

        public StringBuffer getEdit(HttpServletRequest request, HttpServletResponse response) throws ProviderException {

            // Get the edit page and return it is as a StringBuffer.

            return null;

        }

        public java.lang.StringBuffer getEdit(java.util.Map m) throws ProviderException {

            return null;

        }

        public int getEditType() throws UnknownEditTypeException {

            return 0;

        }

        public URL processEdit(HttpServletRequest request, HttpServletResponse response) throws ProviderException {

            return null;

        }

        public java.net.URL processEdit(java.util.Map m) throws ProviderException {

            return null;

        }

        public boolean isEditable() throws ProviderException {

            return false;

        }

        public boolean isPresentable() {

            return true;

        }

        public boolean isPresentable(HttpServletRequest req) {

            return true;

        }

        public java.lang.String getTitle() throws ProviderException {

            return "HelloWorld Channel";

        }

        public java.lang.String getName() {

            return "HelloWorld!";

        }

        public java.lang.String getDescription() throws ProviderException {

            return "This is a sample HelloWorld channel";

        }

        public java.net.URL getHelp(javax.servlet.http.HttpServletRequest req) throws ProviderException {

            return null;

        }

        public long getRefreshTime() throws ProviderException {

            return 0;

        }

        public int getWidth() throws ProviderException {

            return 0;

        }

    }

  3. Compile the class and put it in the user defined class directory.
  4. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. To compile the HelloWorldProviderP.java file, type:

    javac -d /etc/opt/SUNWps/desktop/classes -classpath portal-server-install-root/SUNWps/sdk/desktop/desktopsdk.jar:identity-server-install-root/S UNWam/lib/servlet.jar HelloWorldProviderP.java

  5. Define the new provider and channel definition in a temporary XML file.
  6. The sample HelloWorldProvider provider and channel definitions are in the HelloProviderP.xml (see Code Example 3-2) and HelloChannelP.xml (see Code Example 3-3) files.

    Code Example 3-2  HelloProviderP.xml File  

    <?xml version="1.0" encoding="utf-8" standalone="no"?>

    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

    <Provider name="HelloWorldProviderP" class="custom.HelloWorldProviderP">

        <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"/>

        </Properties>

    </Provider>

    Code Example 3-3  HelloChannelP.xml File  

    <?xml version="1.0" encoding="utf-8" standalone="no"?>

    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

    <Channel name="HelloWorldP" provider="HelloWorldProviderP">

        <Properties>

            <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>

  7. Upload the provider and channel XML fragments using the dpadmin command.
  8. For the sample HelloWorldProvider, upload the HelloProviderP.xml and HelloChannelP.xml XML fragments using the dpadmin command. That is, for example, type:

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloProviderP.xml

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloChannelP.xml

  9. Access the channel from a browser. To access, type the following URL in your browser:
  10. http://hostname:port/portal/dt?provider=HelloWorldP


Extending the ProviderAdapter Class

As the ProviderAdapter class has implemented many of the methods of the Provider interface, the custom provider can extend ProviderAdapter and can override some of the methods or define any new methods. The advantage of extending this class versus implementing the Provider interface directly is that you will maintain forward compatibility as additions are made to the PAPI. Existing code will by default call the methods in this class. Also, the ProviderAdapter contains default implementations of methods in the Provider interface that you can use.

To create a custom provider by extending the ProviderAdapter class:


Note

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.
  2. For the sample HelloWorldProvider, create the class file as shown in Code Example 3-4.

    Code Example 3-4  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!");

        }

    }

  3. Compile the class and put it in the user defined class directory.
  4. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. To compile the HelloWorldProviderPA.java file, type:

    javac -d /etc/opt/SUNWps/desktop/classes -classpath portal-server-install-root/SUNWps/sdk/desktop/desktopsdk.jar:identity-server-install-root/S UNWam/lib/servlet.jar HelloWorldProviderPA.java

  5. Define the new provider and provider’s channel definition in a temporary XML file.
  6. The sample HelloWorldProvider XML fragment for the provider in the HelloProviderPA.xml is shown in Code Example 3-5.

    Code Example 3-5  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 ONE Portal Server"/>

            <Collection name="aList">

                <String value="i’m aList"/>

            </Collection>

            <String name="message" value="Sample Hello World Provider"/>

        </Properties>

    </Provider>

  7. Upload the provider and channel XML fragments using the dpadmin command.
  8. For the sample HelloWorldProvider, upload the HelloProviderPA.xml XML fragments using the dpadmin command. That is, for example, type:

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloProviderPA.xml

  9. Include the new channel in one of the existing containers.
  10. 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 section Sun ONE Portal Server 6.2 Administrator’s Guide. To add the channel in the JSPTableContainer manually:

    1. Add the HelloWorldProvider channel XML fragment (in the HelloChannelPA.xml file) for the JSPTableContainer as shown in Code Example 3-6.
    2. Code Example 3-6  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>

    3. Use the dpadmin modify 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.
    4. portal-server-install-root/SUNWps/bin/dpadmin modify -u dn_amadmin -w password -d distinguishedname HelloChannelPA.xml

  11. Access the HelloWorld channel inside the JSPTableContainer. To access, type the following URL in your browser:
  12. http://hostname:port/portal/dt?provider=JSPTableContainer/HelloWorldPA


Extending the ProfileProviderAdapter Class

ProfileProviderAdapter has the default implementation of the Provider interface and extends the ProviderAdapter class. It includes some convenient methods that allow the providers to get the channel data from the ProviderContext object. Developers who wish to create a new provider can take advantage of this, by extending the ProfileProviderAdapter class, and create their customized provider class.

To create a provider by extending the ProfileProviderAdapter Class:

Example 1

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.

  1. Create a new Java class which extends the ProfileProviderAdapter class.
  2. For the sample HelloWorldProvider, create the class file as shown in Code Example 3-7.

    Code Example 3-7  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 tags = new Hashtable();

            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 tags = new Hashtable();

                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;

        }

    }

  3. Compile the class and put it in the user defined class directory.
  4. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. To compile the HelloWorldProviderPPA1.java file, type:

    javac -d /etc/opt/SUNWps/desktop/classes -classpath portal-server-install-root/SUNWps/sdk/desktop/desktopsdk.jar:identity-server-install-root/S UNWam/lib/servlet.jar HelloWorldProviderPPA1.java

  5. Define the new provider and provider’s channel definition in a temporary XML file.
  6. The sample HelloWorldProvider XML fragment for the provider in the HelloProviderPPA1.xml file and the XML fragment for the channel in the HelloChannelPPA1.xml file are shown in Code Example 3-8 and Code Example 3-9 respectively.

    Code Example 3-8  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>

    Code Example 3-9  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>

  7. Upload the provider and channel XML fragments using the dpadmin command.
  8. For the sample HelloWorldProvider, upload the HelloProviderPPA1.xml file and HelloChannelPPA1.xml file XML fragments using the dpadmin command. That is, for example, type:

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloProviderPPA1.xml

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloChannelPPA1.xml

  9. Include the provider’s channel in one of the existing containers.
  10. 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 Sun ONE Portal Server 6.2 Administrator’s Guide. To add the channel in the JSPTableContainer manually:

    1. Add the HelloWorldProvider channel XML fragment (in the HelloContainerPPA1.xml file) for the JSPTableContainer as shown in Code Example 3-10.
    2. Code Example 3-10  HelloContainerPPA1.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="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>

    3. Use the dpadmin modify 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.
    4. portal-server-install-root/SUNWps/bin/dpadmin modify -m -u dn_amadmin -w password -d distinguishedname HelloContainerPPA1.xml

  11. Create the template files if the new provider requires template files.
  12. The sample HelloWorldProvider requires content.template and edit.template files.

    1. Create the content.template file for the HelloWorldProvider.
    2. The contents of content.template file is shown in Code Example 3-11.

      Code Example 3-11  HelloWorldProviderPPA1 content.template File  

      <html>

      <head></head>

      <body bgcolor="white">

      [tag:welcome]<br><br>

      [tag:message]<br><br>

      [tag:properties]

      </body>

      </html>

    3. Create the edit.template file for the HelloWorldProvider.
    4. The contents of edit.template file is shown in Code Example 3-12.

      Code Example 3-12  HelloWorldProviderPPA1 edit.template File  

      <!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>

  13. Create the channel directory under the template root directory.
  14. By default, the template root directory is /etc/opt/SUNWps/desktop/desktoptype. For this example, create a HelloWorldPPA1 directory under /etc/opt/SUNWps/desktop/desktoptype directory.

  15. Copy all the template files over to the newly created directory (in Step 7). For example:
  16. cp content.template /etc/opt/SUNWps/desktop/desktoptype/HelloWorldPPA1

    cp edit.template /etc/opt/SUNWps/desktop/desktoptype/HelloWorldPPA1

  17. Create a resource bundle properties file.
  18. The sample HelloWorldProvider includes a HelloWorldProviderPPA1.properties file.

    1. Create a HelloWorldProviderPPA1.properties properties file.
    2.   Include the following property in the file:
    3. welcome=Welcome to Hello World!!

  19. Copy the resource bundle to the user defined class directory.
  20. By default, the class directory to copy the resource bundle into is /etc/opt/SUNWps/desktop/classes.

  21. Access the HelloWorld channel inside the JSPTableContainer. To access, log in to the Desktop and type the following URL in your browser:
  22. http://hostname:port/portal/dt?provider=JSPTableContainer

Example 2

This section provides the instructions for creating a custom provider by extending the ProfileProviderAdapter. The process includes creating a sample provider that prints “Hello World!” on the provider’s channel. The following sample HelloWorldProvider reads a string property from the user’s display profile and allows the user to edit the string.

The sample HelloWorldProvider described here will also support EDIT_COMPLETE, which means this provider is responsible for generating the complete edit form with header, footer, and handling of the form submit actions. To accomplish this:

  1. Create the Java class, which will generate the content for the channels backed by this provider.
  2. For the sample HelloWorldProvider, create the class file as shown in Code Example 3-13.

    Code Example 3-13  HelloWorldProviderPPA2.java File  

    package custom.helloworld;

    import java.util.Hashtable;

    import java.util.ResourceBundle;

    import java.net.URL;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import com.sun.portal.providers.ProfileProviderAdapter;

    import com.sun.portal.providers.ProviderException;

    import com.sun.portal.providers.context.ProviderContext;

    import com.sun.portal.providers.context.ProviderContextException;

    import com.sun.portal.providers.context.Theme;

    public class HelloWorldProviderPPA2 extends ProfileProviderAdapter {

        private ResourceBundle bundle = null;

        private final static String BANNER = "banner";

        private final static String BANNER_TEMPLATE = "banner.template";

        private final static String BORDER_COLOR = "borderColor";

        private final static String BORDER_WIDTH = "borderWidth";

        private final static String BULLET_COLOR = "bulletColor";

        private final static String BULLET_COLOR_JS = "bulletColor.js";

        private final static String BG_COLOR = "bgColor";

        private final static String CONTENT_LAYOUT = "contentLayout";

        private final static String CONTENT_LAYOUT_TEMPLATE = "contentLayout.template";

        private final static String DESKTOP_URL = "desktop_url";

        private final static String EDIT_PROVIDER_TEMPLATE = "editTemplate.template";

        private final static String ERR_MESSAGE = "errMessage";

        private final static String FONT_COLOR = "fontColor";

        private final static String FONT_FACE = "fontFace";

        private final static String FONT_FACE1 = "fontFace1";

        private final static String FRONT_CONTAINER_NAME = "frontContainerName";

        private final static String INLINE_ERROR = "inlineError";

        private final static String MENUBAR = "menubar";

        private final static String MENUBAR_TEMPLATE = "menubar.template";

        private final static String MESSAGE = "message";

        private final static String NO_CACHE = "noCache";

        private final static String NO_CACHE_TEMPLATE = "noCache.template";

        private final static String PARENT_CONTAINER_NAME = "parentContainerName";

        private final static String PRODUCT_NAME = "productName";

        private final static String THEME_CHANNEL = "theme_channel";

        private final static String TITLE_BAR_COLOR = "titleBarColor";

        private final static String TOOLBAR_ROLLOVER = "toolbarRollover";

        private final static String TOOLBAR_ROLLOVER_JS = "toolbarRollovers.js";

    /*Implement the getContent method*/

         public StringBuffer getContent(

         HttpServletRequest req, HttpServletResponse res

         ) throws ProviderException {

            Hashtable tags = getStandardTags(req);

            if (bundle == null) {

                 bundle = getResourceBundle();

            } tags.put("welcome", bundle.getString("welcome"));

            tags.put("message", getStringProperty("message"));

            StringBuffer b = getTemplate("content.template", tags);

            return b;

        }

    /*Implement the getEdit method*/

        public StringBuffer getEdit(

        HttpServletRequest req, HttpServletResponse res)

        throws ProviderException {

            String containerName = req.getParameter("containerName");

            String providerName = req.getParameter("targetprovider");

            String editChannelName = req.getParameter("provider");

            // Get the standard tags, which will include the menubar, footer, etc.

            Hashtable tags = getStandardTags(req);

            tags.put("help_link", getHelpLink("editPage",req));

            // Provider specific tags

            tags.put(MESSAGE, getStringProperty(MESSAGE));

            tags.put("title", getTitle());

            tags.put( "providerName", providerName);

            tags.put( "contentOptions", getTemplate("edit.template", tags).toString());

            if (containerName != null) {

                 tags.put(FRONT_CONTAINER_NAME, containerName);

            }

             StringBuffer b = getTemplate(EDIT_PROVIDER_TEMPLATE, tags);;

             return b;

        }

        /* Implement Process Edit Method */

        public URL processEdit(

        HttpServletRequest req, HttpServletResponse res

        ) throws ProviderException {

            String message = req.getParameter(MESSAGE);

            if(message != null) {

                if( !message.equals(getStringProperty(MESSAGE)) ) {

                    setStringProperty(MESSAGE,message);

                    return null;

                }

            } else {

                 setStringProperty(MESSAGE,"");

            }

            return null;

        }

    /* HelloWorld Provider supports, edit_type=edit_complete which means, the provider is responsible for generating a complete edit form with header,footer and html buttons. getStandardTags method populates the hashtable with all the standard tags */

        protected Hashtable getStandardTags(HttpServletRequest req) throws ProviderException {

            Hashtable tags = new Hashtable();

            ProviderContext pc = getProviderContext();

            String property = null;

            property = FONT_FACE1;

            tags.put(FONT_FACE1, getStringProperty(FONT_FACE1));

            property = PRODUCT_NAME;

            tags.put(PRODUCT_NAME, getStringProperty(PRODUCT_NAME));

            tags.put(PARENT_CONTAINER_NAME, pc.getDefaultChannelName());

            // templates

            tags.put(MENUBAR, getTemplate(MENUBAR_TEMPLATE));

            tags.put(CONTENT_LAYOUT, getTemplate(CONTENT_LAYOUT_TEMPLATE));

            tags.put(TOOLBAR_ROLLOVER, getTemplate(TOOLBAR_ROLLOVER_JS));

            tags.put(NO_CACHE, getTemplate(NO_CACHE_TEMPLATE));

            tags.put(DESKTOP_URL, pc.getDesktopURL(req));

            tags.put(BULLET_COLOR, getTemplate(BULLET_COLOR_JS));

             tags.put(BANNER, getTemplate(BANNER_TEMPLATE));

            // error tags (if any)

             String err = req.getParameter("error");

             if (err != null) {

                 tags.put(ERR_MESSAGE, err);

                 tags.put("inlineError", getTemplate("inlineError.template"));

             } else {

                 // no error, put in dummy tags so lookup doesn’t fail

                 tags.put(ERR_MESSAGE, "");

                 tags.put(INLINE_ERROR, "");

            }

            // theme attributes

                try {

                    tags.put( BG_COLOR, Theme.getAttribute( getName(), pc, BG_COLOR ));

                    tags.put( TITLE_BAR_COLOR, Theme.getAttribute( getName(), pc, TITLE_BAR_COLOR ));

                    tags.put( BORDER_COLOR, Theme.getAttribute( getName(), pc, BORDER_COLOR ));

                    tags.put( FONT_COLOR, Theme.getAttribute( getName(), pc, FONT_COLOR ));

                    tags.put( BORDER_WIDTH, Theme.getAttribute( getName(), pc, BORDER_WIDTH ));

                    tags.put( FONT_FACE, Theme.getAttribute( getName(), pc, FONT_FACE));

                    if( Theme.getSelectedName(getName(), pc).equals( Theme.CUSTOM_THEME ) ) {

                        tags.put(THEME_CHANNEL, getStringProperty("customThemeChannel"));

                    } else {

                        tags.put(THEME_CHANNEL, getStringProperty("presetThemeChannel"));

                    }

                } catch (ProviderContextException pce) {

                    throw new ProviderException( "TemplateContainerProvider.getStardardTags(): failed to obtain theme related attribute ", pce );

                }

                 return tags;

            }

    /* GetHelpLink for the Help button in the banner and footer of the edit page */

            protected String getHelpLink(String key, HttpServletRequest req) throws ProviderException{

                try {

                    URL helpLink = getHelp(req, key);

                    if (helpLink != null) {

                        return helpLink.toString();

                    }

                    else {

                        return "";

                }

            } catch (Throwable t ) {

                throw new ProviderException("HelloWorldProvider.getHelpLink(): could not get help URL for " + key, t);

            }

        }

    }

  3. Compile the class file.
  4. To compile the HelloWorldProviderPPA2.java file, type:

    javac -d /etc/opt/SUNWps/desktop/classes -classpath portal-server-install-root/SUNWps/sdk/desktop/desktopsdk.jar:identity-server-install-root/S UNWam/lib/servlet.jar HelloWorldProviderPPA2.java

  5. Create the provider and channel definition for the display profile.
  6. The HelloWorldProvider provider display profile XML fragment (in file HelloProviderPPA2.xml) is shown in Code Example 3-14.

    Code Example 3-14  HelloProviderPPA2.xml File  

    <?xml version="1.0" encoding="utf-8" standalone="no"?>

    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

    <Provider name="HelloWorldProviderPPA2" class="custom.helloworld.HelloWorldProviderPPA2">

        <Properties>

            <String name="title" value="*** TITLE ***"/>

            <String name="presetThemeChannel" value="JSPPresetThemeContainer" advanced="true"/>

            <String name="customThemeChannel" value="JSPCustomThemeContainer" advanced="true"/>

            <String name="description" value="*** DESCRIPTION ***"/>

            <String name="refreshTime" value="0"/>

            <Boolean name="isEditable" value="true"/>

            <String name="editType" value="edit_subset"/>

            <Collection name="aList">

                <String value="i’m aList"/>

            </Collection>

            <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>

  1. Load the provider and channel display profile definitions using the dpadmin command.
  2. To load the sample HelloProviderPPA2 provider and channel definitions, type:

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloProviderPPA2.xml

    portal-server-install-root/SUNWps/bin/dpadmin add -u dn_amadmin -w password -d distinguishedname HelloChannelPPA2.xml

  3. Create the resource bundle properties file for the HelloWorldProvider (HelloWorldProviderPPA2.properties) and include the following string:
  4. welcome=Welcome to Hello World!!

  5. Copy the resource bundle properties file, HelloWorldProviderPPA2.properties, into /etc/opt/SUNWps/desktop/classes directory.
  6. Develop the template files for the provider.
  7. The HelloWorldProvider requires the following template files:

    • content.template (see Code Example 3-16)
    • edit.template (see Code Example 3-17) - This file generates the editable fields in the form
    • editTemplate.template (see Code Example 3-18) - This file generates a complete form
    • Code Example 3-16  HelloWorldProviderPPA2 content.template File  

      <head></head>

      <body bgcolor="white">

          [tag:welcome]<br><br>

          [tag:message]<br><br>

      </body>

      </html>

      Code Example 3-17  HelloWorldProviderPPA2 edit.template File  

      <p>

      <table border="0" cellpadding="2" cellspacing="0" width="100%">

          <tr>

              <td colspan="3" bgcolor="#333366">

                  <font size=+1 face="[tag:fontFace1]" color="#FFFFFF"><b>Welcome</b></font>

              </td>

          </tr>

          <tr><td><br><br><br></td></tr>

          <tr>

              <td width="20%" align="RIGHT" NOWRAP>

                  <font face="[tag:fontFace1]" color="#000000"><label for="message"><b>Greeting:</b></label></font>

              </td>

              <td width="45%">

                  <font face="[tag:fontFace1]" size="+0">

                      <input type="TEXT" name="message" size="50" maxlength="50" value="[tag:message]" id="message">

                  </font>

              </td>

          </tr>

          <tr>

              <td width="20%">&nbsp;</td>

              <td width="45%">&nbsp;</td>

          </tr>

      </table>

      Code Example 3-18  HelloWorldProviderPPA2 editTemplate.template File  

      <!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>

  8. Create the channel directory under the template root directory.
  9. By default, the template root directory is /etc/opt/SUNWps/desktop/desktoptype. For this example, create a HelloWorldPPA2 directory under /etc/opt/SUNWps/desktop/desktoptype directory.

  10. Copy the templates for the provider into the channel directory under the templates root directory. For example:
  11. cp content.template /etc/opt/SUNWps/desktop/desktoptype/HelloWorldPPA2

    cp edit.template /etc/opt/SUNWps/desktop/desktoptype/HelloWorldPPA2

    cp editTemplate.template /etc/opt/SUNWps/desktop/desktoptype/HelloWorldPPA2

  12. Access the channel from a browser. To access, type the following URL in your browser:
  13. http://hostname:port/portal/dt?provider=HelloWorldPPA2

To display the provider’s channel as one of the leaf channels for a container, you have to add the channel into the container’s available and selected list. To accomplish this:

  1. Add it to the Available and Selected list for the container.
  2. For example, to add the HelloWorldProvider to the TemplateTableContainer, type the following:

    • To add to the Available list, type the following:
    • portal-server-install-root/SUNWps/bin/SUNWps/bin/dpadmin modify -m -p “TemplateTableContainer” -u dn_amadmin -w password -d distinguishedname << EOF

      <?xml version="1.0" encoding="utf-8" standalone="no"?>

      <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

      <Available>

      <Reference value="HelloWorldPPA2"/>

      </Available>

      EOF

    • To add to the Selected list, type the following:
    • portal-server-install-root/SUNWps/bin/SUNWps/bin/dpadmin modify -m -p “TemplateTableContainer” -u dn_amadmin -w password -d distinguishedname << EOF

      <?xml version="1.0" encoding="utf-8" standalone="no"?>

      <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

      <Selected>

      <Reference value="HelloWorldPPA2"/>

      </Selected>

      EOF

  3. Access the HelloWorld Channel inside the TemplateTableContainer. To access, log in to the Desktop and type the following URL in your browser:
  4. http://hostname:port/portal/dt?provider=TemplateTableContainer

Utilize the par utility for transporting channels and providers. For example, the following command can be used to export the HelloWorld channel and provider into a par file which can be imported to another Sun ONE Portal Server system.

par export -r dn_amadmin -p password -v helloworld.par distinguishednode helloworld.txt

Here, helloworld.txt contains the following:

from: channel+provider HelloWorldPPA2

file: providerClassBaseDir HelloWorldProviderPPA2.properties provider

class: custom.helloworld.HelloWorldProviderPPA2

directory: templateBaseDir . HelloWorldPPA2

desc: HelloWorld Provider

Using the following command, the contents of the helloworld.par can be imported to as HelloWorld channel in a different Sun ONE Portal Server software installation.

par import -r dn_amadmin -p password -v helloworld.par distinguishednode provider=HelloWorldProvider,channel=HelloWorld,avail=TemplateTableContaine r,selected

The above command, apart from installing the channel and provider, will also include the HelloWorld channel as one of the selected and available channels in the TemplateTableContainer. For more information on the par utility and its subcommands, see the Sun ONE Portal Server 6.2 Administrator’s Guide.


Extending the PropertiesFilter Class

Developers who wish to implement an arbitrary filter to selectively look up properties with certain criteria and/or to store properties that are specific to certain setting can extend the PropertiesFilter class.

This section provides the instructions for creating a custom filter by extending the PropertiesFilter class.

  1. Create the Java class, which will implement the filter.
  2. The class file for the sample DateLaterThanPropertiesFilter is shown in Code Example 3-19.

    Code Example 3-19  DateLaterThanPropertiesFilter.java File  

    import com.acme.filters.DateLaterThanPropertiesFilter; (susu-2)

    import java.util.Iterator;

    import java.util.Date;

    import java.text.DateFormat;

    import java.text.ParseException;

    import com.sun.portal.providers.context.PropertiesFilter;

    import com.sun.portal.providers.context.PropertiesFilterException;

    import com.sun.portal.providers.context.ProviderContext;

    public class DateLaterThanPropertiesFilter extends PropertiesFilter {

        private static final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

        private Date date = null;

        public DateLaterThanPropertiesFilter() {

            super();

        }

        protected void init(String value, boolean required) throws PropertiesFilterException {

            super.init(value, required);

            try {

                date = dateFormat.parse(value);

            } catch (ParseException pe) {

            throw new PropertiesFilterException("DateLaterThanPropertiesFilter: ", pe);

            }

        }

        public String getCondition() {

            return "dateLaterThan";

        }

        public boolean match(String condition, String value) throws PropertiesFilterException {

            if (!condition.equals("dateLaterThan")) {

                return false;

            }

            Date cdate = null;

            try {

                cdate = dateFormat.parse(value);

            } catch (ParseException pe) {

                throw new PropertiesFilterException("DateLaterThanPropertiesFilter.match(): ", pe);

            }

            return cdate.after(date);

        }

    }

  3. Compile the class file.
  4. To compile the DateLaterThanPropertiesFilter.java file, type:

    javac -d /etc/opt/SUNWps/desktop/classes -classpath portal-server-install-root/SUNWps/sdk/desktop/desktopsdk.jar:identity-server-install-root/S UNWam/lib/servlet.jar DateLaterThanPropertiesFilter.java

  5. Create the provider display profile XML fragment for the conditional properties.
  6. Code Example 3-20 contains the sample display profile XML fragment for the DateLaterThanPropertiesFilter.

    Code Example 3-20  DateLaterThanPropertiesFilter.xml File

    <?xml version="1.0" encoding="utf-8" standalone="no"?>

    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

    <Properties>

        <String name="foo" value="bar">

        <ConditionalProperties condition="locale" value="en">

            <String name="foo" value="bar"/>

            <ConditionalProperties condition="dateLaterThan" value="03/03/2003">

                <ConditionalProperties condition="client" value="nokia">

                    <String name="foo" value="en 03/03/2003 nokia">

                </ConditionalProperties>

            </ConditionalProperties>

            <ConditionalProperties condition="client" value="nokia">

                <String name="foo" value="en nokia">

            </ConditionalProperties>

        </ConditionalProperties>

    </Properties>

  7. Load the display profile using the dpadmin command.
  8. For example, to load the DateLaterThanPropertiesFilter.xml into the provider display profile, type:

    portal-server-install-root/SUNWps/bin/dpadmin modify -m -p channelName -u dn_amadmin -w password -d distinguishedname DateLaterThanPropertiesFilter.xml

  1. Implement the code to access the filter in your custom provider class file where you wish to implement this filter.
  2. For example, in your provider, you can access the sample DateLaterThanPropertiesFilter by doing one of the following:

    • Code Example 3-21 includes an implementation that will return “en 03/03/2003 nokia”
    • Code Example 3-21  Provider Implementation for DateLaterThanPropertiesFilter

      List pflist = new List();

      pflist.add(getProviderContext().getLocalePropertiesFilter( "en", true));

      String filter = "com.acme.filters.DateLaterThanPropertiesFilter" ;

      pflist.add(getProviderContext().getPropertiesFilter( filter, "02/02/2003", true));

      pflist.add(getProviderContext().getClientPropertiesFilter( "nokia", true));

      getStringProperty(getName(), "foo", pflist);

    • Code Example 3-22 includes an implementation that will return “en nokia”
    • Code Example 3-22  Provider Implementation for DateLaterThanPropertiesFilter

      List pflist = new List();

      pflist.add(getProviderContext().getLocalePropertiesFilter( "en", true));

      String filter = "com.acme.filters.DateLaterThanPropertiesFilter" ;

      pflist.add(getProviderContext().getPropertiesFilter( filter, "04/04/2003", false)); // this filter is optional

      pflist.add(getProviderContext().getClientPropertiesFilter( "nokia", true));

      getStringProperty(getName(), "foo", pflist);



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.