Sun Java logo     Previous      Contents      Index      Next     

Sun logo
Sun Java System Portal Server 6 2004Q2 Developer's Guide 

Chapter 8
Extending the Leaf Providers

This chapter includes detailed instructions for:


Extending the JSPProvider

This sections contains some sample extensions to the JSPProvider.

Example 1

In the following example, the JSPProvider getContent() method is overridden to make a connection to the database to get the address book from the database and use a JSP to display the content of the address book for each user. To accomplish this:

  1. Extend the JSPProvider and develop the AddressBookProvider class.
  2. The AddressBookProvider class overrides the JSPProvider’s getContent() method which reads the user’s address book. The getContent() method gets the address book for the user who is logged in to the Desktop.

    Code Example 8-1  AddressBookProvider.java File  

    package custom;

    import javax.servlet.http.HttpServletResponse;

    import javax.servlet.http.HttpServletRequest;

    import com.sun.portal.providers.ProviderException;

    import com.sun.portal.providers.jsp.JSPProvider;

    public class AddressBookProvider extends JSPProvider {

        public StringBuffer getContent (

        HttpServletRequest req, HttpServletResponse res

        ) throws ProviderException {

            AddressBook addrBook = new custom.AddressBook(getProviderContext().getUserID());

            req.setAttribute("addressBook", addrBook);

            return super.getContent(req, res);

        }

    }

  3. Develop the AddressBook class.
  4. The class AddressBook is responsible for making a connection to the database and getting the user’s address book from the database.

  5. Compile both classes and put them in the provider class base directory.
  6. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. That is, build a JAR and copy the JAR into the provider class base directory. Or, just copy the class files into the provider class base directory.

  7. Develop the display profile XML fragment for this provider and this provider’s channel.
  8. The display profile fragment for the AddressBookProvider’s provider is saved in AddressBookProvider.xml file (see Code Example 8-2) and the display profile fragment for the AddressBookProvider’s channel is saved in AddressBookChannel.xml file (see Code Example 8-3).

    Code Example 8-2  AddressBookProvider.xml File  

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

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

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

        <Properties>

            <String name="title" value="Address Book Provider"/>

            <String name="description" value="My Addressbook"/>

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

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

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

            <String name="width" value="thin" advanced="true"/>

            <String name="helpURL" value="desktop/usedesk.htm" advanced="true"/>

            <String name="fontFace1" value="Sans-serif"/>

            <String name="productName" value="Sun Java System Portal Server"/>

            <String name="contentPage" value="addressBook.jsp"/>

        </Properties>

    </Provider>

  1. Use the dpadmin command to upload the display profile fragments for this provider.
  2. For the AddressBookProvider, use the dpadmin command to upload the AddressBookProvider.xml file and AddressBookChannel.xml file XML fragments in the display profile. That is, type:

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

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

  3. Develop the JSP file for the provider.
  4. For the sample AddressBookProvider, the JSP in Code Example 8-4 can be used to display the content of the address book for each user. However, the details of displaying the address book are not shown in Code Example 8-4.

    Code Example 8-4  addressBook.jsp File  

    <%-- addressBook.jsp --%>

    <%@page import="custom.AddressBookProvider" %>

    <%@page import="custom.AddressBook" %>

    <%

    AddressBookProvider addressBookProvider = (AddressBookProvider)pageContext.getAttribute("JSPProvider");

    AddressBook addrBook = (AddressBook)pageContext.getAttribute("addressBook",PageContext.REQUEST_SCOPE);

    %>

    <%-- Display the address book --%>

  5. Create a channel directory under the template root directory.
  6. By default, the template root directory is /etc/opt/SUNWps/desktop/desktoptype. For this example, create an AddressBook directory under /etc/opt/SUNWps/desktop/desktoptype directory.

  7. Copy all the JSP files over to the newly created directory (in Step 7). For example, type:
  8. cp addressBook.jsp /etc/opt/SUNWps/desktop/desktoptype/AddressBook

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

Example 2

In the following example, the SimpleUserInfoProvider overrides the processEdit() method of the JSPProvider. It reads the common name that is input in the edit page JSP, and then it is read from the processEdit() method. The value is set to the backend store. To accomplish this:

  1. Extend the JSPProvider and develop the SimpleUserInfoProvider class.
  2. The SimpleUserInfoProvider class overrides the JSPProvider processEdit() method as shown in Code Example 8-5.

    Code Example 8-5  SimpleUserInfoProvider.java File  

    package custom;

    import java.net.URL;

    import javax.servlet.http.HttpServletResponse;

    import javax.servlet.http.HttpServletRequest;

    import com.sun.portal.providers.ProviderException;

    import com.sun.portal.providers.jsp.JSPProvider;

    public class SimpleUserInfoProvider extends JSPProvider {

        public URL processEdit(

        HttpServletRequest req, HttpServletResponse res

        ) throws ProviderException {

            //get the common name from the request and set it into the backend store

            getProviderContext().setStringAttribute("cn",(String)req.getParameter("cn"));

            return null;

        }

    }

  3. Compile the class and put it in the provider class base directory.
  4. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. That is, build the JAR and copy the JAR into the provider class base directory. Or, just copy the class as a file into the provider class base directory. To compile the SimpleUserInfoProvider.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 SimpleUserInfoProvider.java

  5. Develop the display profile XML fragment for this provider and this provider’s channel.
  6. The display profile fragment for the SimpleUserInfoProvider’s provider is saved in SimpleUIProvider.xml file (see Code Example 8-6) and the display profile fragment for the SimpleUserInfoProvider’s channel is saved in SimpleUIPChannel.xml file (see Code Example 8-7).

    Code Example 8-6  SimpleUIProvider.xml File  

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

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

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

        <Properties>

            <String name="title" value="Simple User Information Provider"/>

            <String name="description" value="My UserInformation"/>

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

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

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

            <String name="width" value="thin" advanced="true"/>

            <String name="helpURL" value="desktop/usedesk.htm" advanced="true"/>

            <String name="fontFace1" value="Sans-serif"/>

            <String name="productName" value="Sun Java System Portal Server"/>

            <String name="contentPage" value="simpleUserInfoContent.jsp"/>

            <String name="editPage" value="simpleUserInfoEdit.jsp"/>

        </Properties>

    </Provider>


  1. Use the dpadmin command to upload the display profile fragments for this provider.
  2. For the SimpleUserInfoProvider, use the dpadmin command to upload the SimpleUIProvider.xml file and SimpleUIPChannel.xml file XML fragments in the display profile. That is, type:

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

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

  3. Create a channel directory under the template root directory.
  4. By default, the template root directory is /etc/opt/SUNWps/desktop/desktoptype. For this example, create an SimpleUserInfo directory under /etc/opt/SUNWps/desktop/desktoptype directory.

  5. Develop and copy all the JSP files over to the newly created directory (in Step 5).
  6. For example, develop the simpleUserInfoContent.jsp and simpleUserInfoEdit.jsp files and copy them over to the newly created /etc/opt/SUNWps/desktop/desktoptype/SimpleUserInfo directory.

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


Extending the URLScraperProvider

The following sample extends the URLScraperProvider and overrides the getURL() method to get a random URL from a pool of URLs defined in the display profile. This sample can be used to display a random image from a pool of images; that is, the following getURL() method selects an URL at random from a pool of URLs where each URL is pointing to a HTML file containing the image.

  1. Extend the URLScraperProvider and develop the custom class file.
  2. The CustomURLScraperProvider class file overrides the URLScraperProvider getURL() method as shown in Code Example 8-8. The CustomURLScraperProvider gets the URL property for the provider. This is the URL from where the contents are fetched.

    Code Example 8-8  CustomURLScraperProvider.java File  

    package custom;

    import java.util.List;

    import java.util.Hashtable;

    import java.util.Random;

    import com.sun.portal.providers.urlscraper.URLScraperProvider;

    import com.sun.portal.providers.ProviderException;

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

    public class CustomURLScraperProvider

    extends URLScraperProvider {

        protected String getURL() throws ProviderException {

            List urlList = getListProperty("urlPool");

            int size = urlList.size();

            if ( size == 1) {

                return (String)urlList.get(0);

            }

            Random rand = new Random();

            int r = rand.nextInt(size-1);

            return (String)urlList.get(r);

        }

    }

  3. Compile the class and put it in the provider class base directory.
  4. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. That is, build the JAR and copy the JAR into the provider class base directory. Or, just copy the class as a file into the provider class base directory. To compile the CustomURLScraperProvider.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 CustomURLScraperProvider.java

  5. Develop the display profile XML fragment for this provider and this provider’s channel.
  6. The display profile fragment for the CustomURLScraperProvider’s provider is saved in CustomURLSProvider.xml file (see Code Example 8-9) and the display profile fragment for the CustomURLScraperProvider’s channel is saved in CustomURLSChannel.xml file (see Code Example 8-10).

    Code Example 8-9  CustomURLSProvider.xml File  

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

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

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

        <Properties>

            <String name="title" value=" Custom UrlScraper Channel"/>

            <String name="description" value="This channel displays the urls at random."/>

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

            <String name="urlScraperRulesetID" value="default_ruleset"/>

            <String name="width" value="thick"/>

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

            <Collection name="urlPool">

                <String value="http://localhost:port/file1.html"/>

                <String value="http://localhost:port/file2.html"/>

            </Collection>

            <String name="fontFace1" value="Sans-serif"/>

            <String name="productName" value="Sun Java System Portal Server"/>

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

            <String name="inputEncoding" value="UTF-8"/>

            <Collection name="cookiesToForwardList">

            </Collection>

            <Integer name="timeout" value="100"/>

        </Properties>

    </Provider>

    Code Example 8-10  CustomURLSChannel.xml File  

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

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

    <Channel name="CustomURLScraper" provider="CustomURLScraperProvider">

        <Properties>

            <String name="refreshTime" value="600" advanced="true"/>

            <Collection name="urlPool">

                <String value="http://localhost:port/file1.html"/>

                <String value="http://localhost:port/file2.html"/>

            </Collection>

        </Properties>

    </Channel>

  7. Use the dpadmin command to upload the display profile fragments for this provider.
  8. For the CustomURLScraperProvider, use the dpadmin command to upload the CustomURLSProvider.xml and CustomURLSChannel.xml file XML fragments in the display profile. That is, type:

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

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

  9. Include the new channel in one of the existing containers.
  10. The CustomURLScraperProvider channel will be displayed in JSPTableContainer. To add the channel in the JSPTableContainer from the administration console, follow instructions in Portal Server Administration Guide. To add the channel in the JSPTableContainer manually:

    1. Add the CustomURLScraperProvider channel XML fragment (in the CustomURLSContainer.xml file) for the JSPTableContainerProvider.
    2. The CustomURLScraperProvider container XML fragment is shown in Code Example 8-11.

      Code Example 8-11  CustomURLSContainer.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="CustomURLScraper"/>

              </Collection>

              <Collection name="channelsRow">

                  <String name="CustomURLScraper" value="3"/>

              </Collection>

          </Properties>

          <Available>

              <Reference value="CustomURLSscraper"/>

          </Available>

          <Selected>

              <Reference value="CustomURLScraper"/>

          </Selected>

          <Channels>

          </Channels>

      </Container>

    3. Use the dpadmin modify sub command 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 CustomURLSContainer.xml

  11. Change directories to /etc/opt/SUNWps/desktop/classes and copy the properties file for the provider into this directory.
  12. For example, for the CustomURLScraperProvider:

    1. Change directories to WebContainer/portal/web-apps/WEB-INF/classes.
    2. Type cp URLScraperProvider.properties /etc/opt/SUNWps/desktop/classes/CustomURLScraperProvider.properties.
  13. Access the CustomURLScraperProvider channel inside the JSPTableContainer. To access, log in to the Desktop and type the following URL in your browser:
  14. http://hostname:port/portal/dt?provider=JSPTableContainer


Extending the XMLProvider

In the following example, the XMLProvider getXML() method is overridden to get the content out of a database. In the CustomXMLProvider, the XML content is retrieved from a database. To accomplish this:

  1. Develop the CustomXMLProvider class file and override the getXML() method in the CustomXMLProvider’s class file.
  2. The CustomXMLProvider class file (see Code Example 8-12) extends the XMLProvider and includes only the overriding getXML() method.

    Code Example 8-12  CustomXMLProvider.java File  

    package custom;

    import com.sun.portal.providers.ProviderException;

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

    import com.sun.portal.providers.xml.XMLProvider;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    public class CustomXMLProvider extends XMLProvider {

        protected StringBuffer getXML(

        HttpServletRequest req,HttpServletResponse res

        ) throws ProviderException {

            String xmlURL = getURL();

            StringBuffer xmlbuf = new StringBuffer();

            // It must be http, https or file i.e http://<url>, https://<url>

            // or file:////<path>

            if (xmlURL != null && xmlURL.length() != 0) {

                String proto = xmlURL.substring(0,xmlURL.indexOf(’:’));

                if((proto.equalsIgnoreCase("http")) || (proto.equalsIgnoreCase("https")) || (proto.equalsIgnoreCase("file"))) {

                    try {

                        xmlbuf = super.getXML(req, res);

                    } catch(ProviderException pr) {

                        getProviderContext().debugError("XMLProvider:getXML(): ",pr);

                    }

                    if (xmlbuf != null) {

                        return xmlbuf;

                    } else {

                        throw new ProviderException("XMLProvider.getXML(): Getting XML failed from source");

                    }

                }

            } else {

                // Open database connection

                // Read the XML contents into a stringbuffer (xmlbuf)

                // Close the database connection

            }

            return xmlbuf;

        }

    }

  3. Compile the class and put it in the provider class base directory.
  4. That is, build the JAR and copy the JAR into the provider class base directory. Or, just copy the class as a file into the provider class base directory. The default directory for the class file is /etc/opt/SUNWps/desktop/classes. To compile the CustomXMLProvider.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 CustomXMLProvider.java

  5. Develop the display profile XML fragment for this provider and this provider’s channel.
  6. The display profile fragment for the CustomXMLProvider’s provider is saved in CustomXMLProvider.xml file (see Code Example 8-13) and the display profile fragment for the CustomXMLProvider’s channel is saved in CustomXMLChannel.xml file (see Code Example 8-14).

    Code Example 8-13  CustomXMLProvider.xml File  

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

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

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

        <Properties>

            <String name="title" value="*** XML Provider ***"/>

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

            <String name="width" value="thick"/>

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

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

            <String name="helpURL" value="desktop/xmlchann.htm" advanced="true"/>

            <String name="fontFace1" value="Sans-serif"/>

            <String name="productName" value="Sun Java System Portal Server"/>

            <String name="url" value=""/>

            <String name="xslFileName" value="html_stockquote.xsl"/>

            <Integer name="timeout" value="100"/>

            <String name="inputEncoding" value="iso-8859-1"/>

            <String name="urlScraperRulesetID" value="default_ruleset"/>

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

            <Collection name="cookiesToForwardList">

            </Collection>

        </Properties>

    </Provider>

      

    Code Example 8-14  CustomXMLChannel.xml File  

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

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

    <Channel name="CustomXML" provider="CustomXMLProvider">

        <Properties>

            <String name="refreshTime" value="600" advanced="true"/>

            <String name="title" value="XML Test Channel"/>

            <String name="description" value="This is a test of the CustomXMLProvider"/>

            <String name="url" value=""/>

            <String name="xslFileName" value="html_stockquote.xsl"/>

        </Properties>

    </Channel>

  7. Use the dpadmin command to upload the display profile fragments for this provider.
  8. For the CustomXMLProvider, use the dpadmin command to upload the CustomXMLProvider.xml and CustomXMLChannel.xml file XML fragments in the display profile. That is, type:

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

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

  9. Include the new channel in one of the existing containers.
  10. The CustomXMLProvider channel will be displayed in JSPTableContainer. To add the channel in the JSPTableContainer from the administration console, follow instructions in the Portal Server Administration Guide. To add the channel in the JSPTableContainer manually:

    1. Develop the CustomXMLProvider channel XML fragment (in the CustomXMLContainer.xml file) for the JSPTableContainer.
    2. The CustomXMLProvider container fragment is shown in Code Example 8-15.

      Code Example 8-15  CustomXMLContainer.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="CustomXML"/>

              </Collection>

              <Collection name="channelsRow">

                  <String name="CustomXML" value="3"/>

              </Collection>

          </Properties>

          <Available>

              <Reference value="CustomXML"/>

          </Available>

          <Selected>

              <Reference value="CustomXML"/>

          </Selected>

          <Channels>

          </Channels>

      </Container>

    3. Use the dpadmin modify sub command 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 CustomXMLContainer.xml

  11. Change directories to /etc/opt/SUNWps/desktop/classes and copy the properties file for the provider into this directory.
  12. For example, for the CustomXMLProvider:

    1. Change directories to WebContainer/portal/web-apps/WEB-INF/classes.
    2. Type cp XMLProvider.properties /etc/opt/SUNWps/desktop/classes/CustomXMLProvider.properties.
  13. Access the CustomXMLProvider channel inside the JSPTableContainer. To access, log in to the Desktop and type the following URL in your browser:
  14. http://hostname:port/portal/dt?provider=JSPTableContainer



Previous      Contents      Index      Next     


Copyright 2004 Sun Microsystems, Inc. All rights reserved.