Sun Java System Portal Server 7.1 Developer's Guide

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.

ProcedureTo Extend the XMLProvider

  1. Develop the CustomXMLProvider class file and override the getXML() method in the CustomXMLProvider’s class file.

    The CustomXMLProvider class file (see below) extends the XMLProvider and includes only the overriding getXML() method.


    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;
        }
    }
  2. 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 PortalServer-DataDir/portals/portal-ID/desktop/classes. To compile the CustomXMLProvider.java file, type:

    javac -d PortalServer-DataDir/portals/portal-ID/desktop/classes -classpath PortalServer-base/sdk/desktop/desktopsdk.jar:AccessManager-base/lib/servlet.jar CustomXMLProvider.java

  3. 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 and the display profile fragment for the CustomXMLProvider’s channel is saved in CustomXMLChannel.xml file.


    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>

    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>
  4. Use the psadmin command to upload the display profile fragments for this provider.

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

  5. 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 the Portal Server administration console online help. To add the channel in the JSPTableContainer manually:

    1. Develop the CustomXMLProvider channel XML fragment (in the CustomXMLContainer.xml file) for the JSPTableContainer.

      The CustomXMLProvider container fragment is shown below.


      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>
    2. Use the psadmin modify-display-profile 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.

  6. Change directories to PortalServer-DataDir/portals/portal-ID/desktop/classes and copy the properties file for the provider into this directory.

    For example, for the CustomXMLProvider:

    1. Change directories to PortalServer-DataDir/portals/portal-ID/desktop/classes.

    2. Type cp XMLProvider.properties PortalServer-DataDir/portals/portal-ID/desktop/classes/CustomXMLProvider.properties.

  7. Login to the Desktop and specify the URL in your browser to access the CustomXMLProvider channel inside the JSPTableContainer.


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