Sun Java System Portal Server 7 Developer's Guide

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.

ProcedureTo Extend the JSPProvider

Steps
  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 subcommands, see the Sun Java System Portal Server 7 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. Access the AddressBook 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

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:

ProcedureTo Develop the SimpleUserInfoProvider

Steps
  1. Extend the JSPProvider and develop the SimpleUserInfoProvider class.

    The SimpleUserInfoProvider class overrides the JSPProvider processEdit() method as shown in Example 2.


    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;
        }
    }
  2. Compile the class and put it in the provider class base directory.

    The default directory for the class file is PortalServer-DataDir/portals/portal-ID/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 PortalServer-DataDir/portals/portal-ID/desktop/classes -classpath PortalServer-base/sdk/desktop/desktopsdk.jar:AccessManager-base/lib/servlet.jar SimpleUserInfoProvider.java
  3. Develop the display profile XML fragment for this provider and this provider’s channel.

    The display profile fragment for the SimpleUserInfoProvider’s provider is saved in SimpleUIProvider.xml file and the display profile fragment for the SimpleUserInfoProvider’s channel is saved in SimpleUIPChannel.xml file.


    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>

    In SimpleUIPChannel.xml, note that the SimpleUserInfoProvider channel definition is embedded inside JSPTableContainer thus making the channel only visible via the container.


    SimpleUIPChannel.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="SimpleUserInfo"/>
            </Collection>
            <Collection name="channelsColumn">
                <String name="SimpleUserInfo" value="3"/>
            </Collection>
        </Properties>
        <Available>
            <Reference value="SimpleUserInfo"/>
        </Available>
        <Selected>
            <Reference value="SimpleUserInfo"/>
        </Selected>
        <Channels>
            <Channel name="SimpleUserInfo" provider="SimpleUserInfoProvider">
                <Properties>
                    <String name="processPage" value="simpleUserInfoDoedit.jsp"/>
                </Properties>
            </Channel>
        </Channels>
    </Container>
  4. Use the psadmin command to upload the display profile fragments for this provider.

    For the SimpleUserInfoProvider, use the psadmin add-display-profile command to upload the SimpleUIProvider.xml file and use the psadmin modify-display-profile command to upload the SimpleUIPChannel.xml file XML fragments in the display profile. For more information on these subcommands, see the Sun Java System Portal Server 7 Command-Line Reference.

  5. 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 SimpleUserInfo directory under PortalServer-DataDir/portals/portal-ID/desktop/desktoptype directory.

  6. Develop and copy all the JSP files over to the newly created directory (in Step 5).

    For example, develop the simpleUserInfoContent.jsp and simpleUserInfoEdit.jsp files and copy them over to the newly created PortalServer-DataDir/portals/portal-ID/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:


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