Oracle9iAS Portal Developer Kit
How to Build a URL-Based Portlet that Uses XML Filtering

In the article How to Build a URL-Based Portlet, you learnt how to create a portlet that displayed the content of a URL-based application. The example used in that article was Google.com. With PDK-URL Services, you can also easily create portlets that filter and manipulate URL content before displaying it. Two types of filters are available:

- HtmlFilter (see How to Build a URL-Based Portlet that Uses HTML Filtering)
- XmlFilter (deals with applications that use XML content)

This article describes how to build a URL-based portlet that uses XML filtering. To make things easier, it uses the existing Google.com portlet framework and simply replaces the provider.xml file with an appropriate XML provider definition for creating an XML based portlet. It uses a sample XML file which is contained in the article below. It shows how you can use PDK-URL Services to transform this XML content into HTML and then render that content inside the portlet.

### ASSUMPTIONS

1. You have successfully installed the PDK-Java runtime and samples by following the article Installing the PDK-Java Framework and Samples.

2. You have successfully installed the PDK-URL Services runtime and samples by following the article Installing the PDK-URL Services Samples

3. You have successfully installed the Google.com URL-based portlet by following the article How to Build a URL-Based Portlet.

### THE SAMPLE XML/XSL FILES

Before building your XML based portlet, you will need an XML feed or XML file. Below is a sample file you can use. Copy the text and then save it as sample.xml.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <stock_quotes>
       <stock_quote>
          <symbol>ORCL</symbol>
          <date>11/19/2001</date>
          <time>4:01PM</time>
          <ask>14.87</ask>
          <open>14.82</open>
          <dayhigh>15.05</dayhigh>
          <daylow>14.50</daylow>
          <change>+0.32</change>
          <volume>30458900</volume>
       </stock_quote>

       <stock_quote>
          <symbol>CSCO</symbol>
          <date>11/19/2001</date>
          <time>4:01PM</time>
          <ask>20.72</ask>
          <open>20.14</open>
          <dayhigh>20.72</dayhigh>
          <daylow>20.06</daylow>
          <change>0.66</change>
          <volume>64166100</volume>
       </stock_quote>
       <stock_quote>
          <symbol>MSFT</symbol>
          <date>11/19/2001</date>
          <time>4:01PM</time>
          <ask>66.54</ask>
          <open>66.25</open>
          <dayhigh>66.97</dayhigh>
          <daylow>66.7</daylow>
          <change>0.27</change>
          <volume>28003800</volume>
       </stock_quote>
    </stock_quotes>

You will also need an XSL file which your portlet will use to display the XML content. You may use the sample XSL file below. It should be saved as sample.xsl.

Note: In your XSL file, you must specify the version in the <xsl:stylesheet> tag; for example <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <?xml version='1.0' encoding='utf-8' ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
       <xsl:template match="/">
          <center>
             <h1>Quotes:</h1>
             <table border="1" cellspacing="0" cellpadding="3">
                <tr bgcolor="dcdcdc">
                   <th>Symbol</th>
                   <th colspan="2">Date&amp;Time</th>
                   <th>Ask</th>
                   <th>Open</th>
                   <th>Day High</th>
                   <th>Day Low</th>
                   <th>Volume</th>
                </tr>
                <xsl:for-each select="stock_quotes/stock_quote">
                   <tr>
                      <td>
                         <B>
                            <font size="-1">
                               <xsl:value-of select="symbol"/>
                            </font>
                         </B>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="date"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="time"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="ask"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="open"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="dayhigh"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="daylow"/>
                         </font>
                      </td>
                      <td>
                         <font size="-1">
                            <xsl:value-of select="volume"/>
                         </font>
                      </td>
                   </tr>
                </xsl:for-each>
             </table>
          </center>
       </xsl:template>
    </xsl:stylesheet>

### CREATING AN XML PROVIDER DEFINITION

This section explains how to create an XML provider definition for your URL-based portlet provider.

1. Using a text editor, create an XML file for your portlet provider.

   This example introduces a new tag called filter to specify the type of filter being used.

2. Copy the sample.xml file to a location accessible to your Web server.

3. Copy the sample.xsl file to the same directory.

4. Edit the pageUrl and stylesheet tags in the provider defintion code given below to indicate the xml and xsl file locations respectively.

   Note: For the stylesheet tag, you can specify a URL or a path to the file on your file system (in the sample below, we use a URL). To indicate the type of content, use the urlContentType tag. In this case, we want to show xml content so the urlContentType will be text/xml. Please refer to the article Understanding provider.xml for PDK-URL Services for an explanation of the required XML tags and their functions.

       <?Xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
       <?providerDefinition version="2.0"?>
       <provider class="oracle.portal.provider.v1.http.URLProvider">
          <session>true</session>
          <proxyInfo class="oracle.portal.provider.v1.http.ProxyInformation">
             <httpProxyHost>www-proxy.us.oracle.com</httpProxyHost>
             <httpProxyPort>80</httpProxyPort>
          </proxyInfo>
          <portlet class="oracle.portal.provider.v1.http.URLPortlet">
             <id>1</id>
             <name>XML Portlet</name>
             <title>XML Portlet</title>
             <description>Display XML in a portlet.</description>
             <timeout>100</timeout>
             <timeoutMessage>Timed out waiting for XML Portlet.</timeoutMessage>
             <acceptContentType>text/html</acceptContentType>
             <showEdit>false</showEdit>
             <showEditToPublic>false</showEditToPublic>
             <showEditDefault>false</showEditDefault>
             <showPreview>false</showPreview>
             <showDetails>false</showDetails>
             <hasHelp>false</hasHelp>
             <hasAbout>false</hasAbout>
             <renderer class="oracle.portal.provider.v1.RenderManager">
                <contentType>text/html</contentType>
                <showPage class="oracle.portal.provider.v1.http.URLRenderer">
                   <contentType>text/html</contentType>
                   <charSet>ISO-8859-1</charSet>
                   <pageUrl>http://myserver.com/xml/sample.xml</pageUrl>
                   <filter class="oracle.portal.provider.v1.http.XmlFilter">
                      <stylesheet>http://myserver.com/xml/sample.xsl</stylesheet>
                      <urlContentType>text/xml</urlContentType>
                   </filter>
                </showPage>
             </renderer>
          </portlet>
       </provider>

1. Save the file as "provider.xml", making sure it overwrites the provider.xml file you created from the article How to Build a URL-Based Portlet (you may wish to make a backup copy of the older provider.xml file).

### ADDING THE URL-BASED PORTLET TO A PAGE

Since you configured and registered the Google.com portlet provider when following the article How to Build a URL-Based Portlet, you simply need to stop and restart the Oracle HTTP Server and refresh the portlet provider through the Edit Provider screen. Now you are ready to add the XML portlet to a page.

Now that you have successfully added XML filtering to your URL-based portlet, please look for other portlet development articles that describe how to add extra features to your portlet, including single sign-on to external URL-based applications, inline rendering of portlet links, parameter passing, and more.

Here are some reference articles to help you better understand the architecture and technical details of PDK-URL Services:

> - A Primer on PDK-URL Services
> - Understanding PDK-URL Services Runtime
> - Understanding provider.xml for PDK-URL Services

Revision History:

- November 2001