Sun Java System Portal Server 7.1 Developer's Guide

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.

ProcedureTo Extend the JSPProvider

  1. Extend the JSPProvider and develop the AddressBookProvider class.

    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.

    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);
    	}
    }
  2. Develop the AddressBook class.

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

  3. Compile both classes and put them in the provider class base directory.

    The default directory for the class file is PortalServer-DataDir/portals/portal-ID/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.

  4. Develop the display profile XML fragment for this provider and this provider’s channel.

    The display profile fragment for the AddressBookProvider’s provider is saved in AddressBookProvider.xml file and the display profile fragment for the AddressBookProvider’s channel is saved in AddressBookChannel.xml file.

    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>

    In AddressBookChannel.xml, note that the AddressBookProvider channel definition is embedded in an existing table container, JSPTableContainer.

    AddressBookChannel.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 name="AddressBook"/>
    		</Collection>
    		<Collection name="channelsColumn">
    			<String name="AddressBook" value="3"/>
    		</Collection>
    	</Properties>
    	<Available>
    		<Reference value="AddressBook"/>
    	</Available>
    	<Selected>
    		<Reference value="AddressBook"/>
    	</Selected>
    	<Channels>
    		<Channel name="AddressBook" provider="AddressBookProvider">
    			<Properties>
    			</Properties>
    		</Channel>
    	</Channels>
    </Container>
  5. Use the psadmin command to upload the display profile fragments for this provider.

    For the AddressBookProvider, use the psadmin add-display-profile command to upload the AddressBookProvider.xml file and use the psadmin modify-display-profile command to upload the AddressBookChannel.xml file XML fragments in the display profile. For more information on these sub commands, see the Sun Java System Portal Server 7.1 Command Line Reference.

  6. Develop the JSP file for the provider.

    For the sample AddressBookProvider, the JSP in addressBook.jsp 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 addressBook.jsp.

    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 --%>
  7. Create a 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 an AddressBook directory under PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory.

  8. Copy all the JSP files over to the newly created directory (in Example 1). For example, type:


    cp addressBook.jsp PortalServer-DataDir/portals/portal-ID/desktop/desktoptype/AddressBook
  9. Login to the Desktop and specify the URL in your browser to access the AddressBook channel inside the JSPTableContainer.


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