![]() |
Sun ONE Portal Server Developer's Guide |
Chapter 3 Using Leaf Providers
A portal provider is a generic connector to the resource in a channel and is the programmatic entity responsible for generating channels on the Desktop. A single provider can be used to create multiple channel instances. The leaf providers are tools for building channels for the portal.
Out of the box, the software includes the following building block leaf providers:
- JSPProvider - Serves JavaServer PagesTM (JSPTM)
- URLScraperProvider - Serves data from a URL (HTTP or file path)
- XMLProvider - Enables XSL transformation of an XML document
These providers are public and you can extend the Java class to provide customized functionality based on these providers. This chapter also includes detailed instructions for:
- Extending the building block leaf providers
- Deploying JSP Tags and Tag Libraries
Introduction
Figure 3-1 shows the relationship between the PAPI base class and the leaf providers discussed in this chapter. The JSPProvider and URLScraperProvider extend the ProfileProviderAdapter to include support for retrieving content from JavaServer Pages and URLs respectively. The XMLProvider extends the URLScraperProvider's functionality to scrape XML content from the named source and translate it into the markup language supported by the requesting client. The XMLProvider uses the URLScraperProvider's built-in functionality to fetch the XML contents from HTTP, HTTPs, and file URLs.
Figure 3-1   
![]()
The Building Block ProvidersJSPProvider
A JSPProvider is a content provider that can use JavaServer Pages to create the content for a channel on the Desktop.
Invoking a JSP
The following is a description of the step-by-step process of the JSPProvider invoking a JSP.
- The JSPProvider.getContent() method is called and the JSPProvider looks up the JSP to be executed. It calls a common private method to service the JSP.
- The provider then creates request and response objects, copies information (such as cookies) from the Desktop request to those objects, initializes the session information, and checks to see if a servlet wrapper for the JSP already exists. If not, a servlet wrapper is created. The service method is then called on the wrapper.
- The servlet wrapper service method loads the JSP. Before loading, it checks to see if the JSP class file is out of date with the class file. If the JSP class file is out of date with the class file, it invokes the compiler to compile the JSP into a class file and read the class file into memory and uses the class loader to define the new class.
- Finally, the JSP servlet is instantiated and the init() method is called on the JSP.
- Once the JSP is loaded, the JSP's service method is called by the servlet wrapper service method.
- After the JSP's service method completes, the JSPProvider getContent() method extracts the response body from the processed JSP file and returns it as a StringBuffer.
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:
- 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 SunTM ONE Portal Server Desktop.
- Develop the AddressBook class.
The class AddressBook is responsible for making a connection to the database and get the user's address book from the database.
- Compile both classes and put them in the provider class base directory.
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.
- 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 (see Code Example 3-2) and the display profile fragment for the AddressBookProvider's channel is saved in AddressBookChannel.xml file (see Code Example 3-3). In Code Example 3-3, note that the AddressBookProvider channel definition is embedded in an existing table container, JSPTableContainer.
- Use the dpadmin command to upload the display profile fragments for this provider.
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:
dpadmin add -u dn_amadmin -w password -d distinguishedname AddressBookProvider.xml
dpadmin modify -m -p "JSPTableContainer" -u dn_amadmin -w password -d distinguishedname AddressBookChannel.xml
- Develop the JSP file for the provider.
For the sample AddressBookProvider, the JSP in Code Example 3-4 can be used to display the content of the address book for each user. However, the details of displaying the address book is not shown in Code Example 3-4.
- Create a channel directory under the template root directory.
By default, the template root directory is /etc/opt/SUNWps/desktop/default. For this example, create an AddressBook directory under /etc/opt/SUNWps/desktop/default directory.
- Copy all the JSP files over to the newly created directory (in Step 7). For example, type:
cp addressBook.jsp /etc/opt/SUNWps/desktop/default/AddressBook
- Access the AddressBook channel inside the JSPTableContainer. To access, type the following URL in your browser:
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:
- Extend the JSPProvider and develop the SimpleUserInfoProvider class.
The SimpleUserInfoProvider class overrides the JSPProvider processEdit() method as shown in Code Example 3-5.
- Compile the class and put it in the provider class base directory.
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 BaseDir/SUNWps/sdk/desktop/desktopsdk.jar:BaseDir/SUNWam/lib/servlet.jar SimpleUserInfoProvider.java
- 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 (see Code Example 3-6) and the display profile fragment for the SimpleUserInfoProvider's channel is saved in SimpleUIPChannel.xml file (see Code Example 3-7). In Code Example 3-7, note that the SimpleUserInfoProvider channel definition is embedded inside JSPTableContainer thus making the channel only visible via the container.
- Use the dpadmin command to upload the display profile fragments for this provider.
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:
dpadmin add -u dn_amadmin -w password -d distinguishedname SimpleUIProvider.xml
dpadmin modify -m -p "JSPTableContainer" -u dn_amadmin -w password -d distinguishedname SimpleUIPChannel.xml
- Create a channel directory under the template root directory.
By default, the template root directory is /etc/opt/SUNWps/desktop/default. For this example, create an SimpleUserInfo directory under /etc/opt/SUNWps/desktop/default directory.
- Develop and copy all the JSP files over to the newly created directory (in Step 7).
For example, develop the simpleUserInfoContent.jsp and simpleUserInfoEdit.jsp files and copy them over to the newly created /etc/opt/SUNWps/desktop/default/SimpleUserInfo directory.
- Access the SimpleUserInfo channel inside the JSPTableContainer. To access, type the following URL in your browser:
http://hostname:port/portal/dt?provider=JSPTableContainer
Deploying JSP Tags and Tag Libraries
To make custom JSP tags, refer to a document to write custom tag libraries (for example, see http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html) and use this section to deploy the customized tag library into Sun ONE Portal Server software.
- Copy the class files or JAR files that are required by the tag library under providerClassBaseDir where providerClassBaseDir is the directory defined in /etc/opt/SUNWps/desktop/desktopconfig.properties file.
- Make the custom tag library.
For example, see the custom.tld shown in Code Example 0-1.
The shortname can be anything. The name must be the same as your custom tag name and the tagclass must point to the correct class.
- Copy the tld file in templateBaseDir/default/tld where templateBaseDir is the directory defined in /etc/opt/SUNWps/desktop/desktopconfig.properties file.
- Modify the JSP files to use the custom tags.
URLScraperProvider
The URLScraperProvider can retrieve and display content from a given URL.
Scraping Content from the URL
The following is a step-by-step description of how the URLScraperProvider retrieves and displays content from the specified URL:
- Gets the timeout property for the provider.
- Gets the url property for the provider.
This is the URL source for the content to be fetched.
- Gets the urlScraperRulesetID to be used by rewriter as a string.
- Determines if the cookieName can be forwarded.
To determine, it checks the value of cookiesToForwardAll attribute value in the display profile. If this value is false, it checks the cookiesToForwardList attribute value in the display profile.
- Determines if cookies from the request should be forwarded.
- Gets the content by:
- Retrieving content from the specified URL.
That is, it sends an HTTP request that contains information related to this request for content and gets an HTTP response that allows the provider to influence the overall response for the Desktop page (besides generating the content).
Or, by:
- Taking the fully qualified path name of the file and returning StringBuffer containing the data from the specified file or null if file does not exist or cannot be read.
Extending the URLScraperProvider
Consider extending the URLScraperProvider if, for example, the URL that the provider is going to scrape is based on some runtime values like clientType, or if you want your URLScraperProvider to get the required properties from somewhere other than display profile.
In the following example, the URLScraperProvider getURL() method is overridden to dynamically compute the URL to use. In the CustomURLScraperProvider, the URL is dynamically computed based on the clientType. To accomplish this:
- Extend the URLScraperProvider and develop the CustomURLScraperProvider class file.
The CustomURLScraperProvider class file overrides the URLScraperProvider getURL() method as shown in Code Example 3-9.
- Compile the class and put it in the provider class base directory.
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 BaseDir/SUNWps/sdk/desktop/desktopsdk.jar:BaseDir/SUNWam/lib/servlet.jar CustomURLScraperProvider.java
- Develop the display profile XML fragment for this provider and this provider's channel.
The display profile fragment for the CustomURLScraperProvider's provider is saved in CustomURLSProvider.xml file (see Code Example 3-10) and the display profile fragment for the CustomURLScraperProvider's channel is saved in CustomURLSChannel.xml file (see Code Example 3-11).
- Use the dpadmin command to upload the display profile fragments for this provider.
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:
dpadmin add -u dn_amadmin -w password -d distinguishedname CustomURLSProvider.xml
dpadmin add -u dn_amadmin -w password -d distinguishedname CustomURLSChannel.xml
- Include the new channel in one of the existing containers.
The CustomURLScraperProvider channel will be displayed in JSPTableContainer. To add the channel in the JSPTableContainer from the administration console, follow instructions in section "To Add a Channel or Container Channel" in Chapter 5 of the Sun ONE Portal Server 6.0 Administrator's Guide. To add the channel in the JSPTableContainer manually:
- Add the CustomURLScraperProvider channel XML fragment (in the CustomURLSContainer.xml file) for the JSPTableContainerProvider.
The CustomURLScraperProvider container XML fragment is shown in Code Example 3-16.
- Use the dpadmin add 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.
dpadmin modify -m -p "JSPTableContainer" -u dn_amadmin -w password -d distinguishedname CustonURLSContainer.xml
- Access the CustomURLScraperProvider channel inside the JSPTableContainer. To access, type the following URL in your browser:
http://hostname:port/portal/dt?provider=JSPTableContainer
XMLProvider
The XML Provider can be used to convert and display an XML file according to the specified style sheet.
Retrieving XML Content
The XMLProvider first determines whether or not content is available for the requesting client. This is determined by checking on the availability of the XSL stylesheet for the requesting client via the File lookup API.
The path to the XML content can be specified as HTTP, HTTPs, or file URL. The path to the XML source is stored as a value of the property url. If the path is HTTP or HTTPs, the provider uses the super.getContent() method to fetch the XML content. If the path is a file URL, the provider reads the file into a StringBuffer.
The value for XSL file name to use for transformation is stored as value of the string property xslFileName. The value for the attribute can be either the absolute path (such as /export/home/xsl/abc.xsl) or just the file name. If just the filename has been specified, the provider will use the File Lookup API to locate the XSL file. If the absolute path is specified, it takes precedence and file lookup will not be performed to locate the XSL file.
If both the XML and the XSL files are present, the XMLProvider does the transformation using the XSLT engine. The generated contents are displayed in the channel. In order to transform the XML file, the provider uses JAXP 1.1.
The XMLProvider:
- Takes the fully qualified path name of the XML file and returns the file, specified by the argument, as a StringBuffer.
It returns null if the file does not exists or cannot be read.
- Gets the XSL file. If just an XSL filename has been specified, the getXSL method locates the XSL file using the File Lookup API.
- Takes the XML and XSL files and does the transformation.
- Gets the XML contents after converting the xml file according to the specified XSL stylesheet. In order to do this, it takes the HttpServletRequest and returns an HttpServletResponse with the XML file contents as a buffer.
- Gets and displays the XML file contents in the channel using the getContent() method.
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:
- Develop the CustomXMLProvider class file and override the getXML method in the CustomXMLProvider's class file.
The CustomXMLProvider class file (see Code Example 3-13) extends the XMLProvider and includes only the overriding getXML method.
- Compile the class and put it in the provider class base directory.
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 BaseDir/SUNWps/sdk/desktop/desktopsdk.jar:BaseDir/SUNWam/lib/servlet.jar CustomXMLProvider.java
- Develop the display profile XML fragment for this provider and this provider's channel.
The display profile fragment for the CustomXMLProvider's provider is saved in CustomXMLProvider.xml file (see Code Example 3-14) and the display profile fragment for the CustomXMLProvider's channel is saved in CustomXMLChannel.xml file (see Code Example 3-15).
- Use the dpadmin command to upload the display profile fragments for this provider.
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:
dpadmin add -u dn_amadmin -w password -d distinguishedname CustomXMLProvider.xml
dpadmin add -u dn_amadmin -w password -d distinguishedname CustomXMLChannel.xml
- Include the new channel in one of the existing containers.
The CustomXMLProvider channel will be displayed in JSPTableContainer. To add the channel in the JSPTableContainer from the administration console, follow instructions in section "To Add a Channel or Container Channel" in Chapter 5 of the Sun ONE Portal Server 6.0 Administrator's Guide. To add the channel in the JSPTableContainer manually:
- Develop the CustomXMLProvider channel XML fragment (in the CustomXMLContainer.xml file) for the JSPTableContainer.
The CustomXMLProvider container fragment is shown in Code Example 3-16.
- Use the dpadmin add 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.
dpadmin modify -m -u dn_amadmin -w password -d distinguishedname CustonXMLContainer.xml
- Access the CustomXMLProvider channel inside the JSPTableContainer. To access, type the following URL in your browser:
http://hostname:port/portal/dt?provider=JSPTableContainer