Introduced in Feature Pack 1

Creating a feed formatting JSP file for the recipe Atom feed

Introduced in Feature Pack 1 In this lesson, you learn about feed formatting JSP files. The WebSphere Commerce RESTful framework uses feed formatting JSP files to format the content of an Atom feed. Each noun – Project and ProjectCollection – requires a feed formatting JSP file to get the feed data from the service data object (SDO), and to define the content of the Atom feed. The source code for each feed formatting JSP file is provided in the ZIP file you downloaded at the beginning of this tutorial.

Before you begin

For background information related to this lesson, read:

If you are not familiar with the Atom Syndication Format for feeds, consider doing some research on the Internet.

About this task

As explained in Feed formatting JSP files for Atom feeds, WebSphere Commerce includes several sets of feed formatting JSP files for WebSphere Commerce Web services that support Atom feeds. There is one set for e-Marketing Spot Atom feeds and another set for wish list and gift registry Atom feeds. Each set of feed formatting JSP files consists of a top-level feed formatting JSP file and a set of JSP fragments that perform different functions. These feed formatting JSP file sets are complex; they contain all mandatory Atom feed elements, many optional Atom feed elements, and many additional features to configure the feeds.

The feed formatting JSP files provided for this lesson in the ZIP file are much simpler. They provide only the necessary Atom elements and functions needed to generate a basic Atom feed for each noun. Each noun has only one feed formatting JSP file, rather than a set of files.

Procedure

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. Create the feed formatting JSP files for the Atom feed:
    1. Create a directory called project at the following path:

      WCDE_installdir/workspace/Rest/WebContent/atom/project

    2. Navigate to the directory into which you downloaded and unzipped the completed tutorial code.
    3. Locate the following two files, which are the feed formatting JSP files for this tutorial:

      /Rest/WebContent/atom/project/SerializeShowProjectDataAreaTypeAtom.jsp This is the feed formatting JSP file for the Project noun.

      /Rest/WebContent/atom/project/SerializeShowProjectCollectionDataAreaTypeAtom.jsp This is the feed formatting JSP file for the ProjectCollection noun.

    4. Copy the two feed formatting JSP files to the project directory you created in step 2a.
    5. Familiarize yourself with the contents of each feed formatting JSP file.

      The following sample is the SerializeShowProjectCollectionDataAreaTypeAtom.jsp file used to format recipe collection feeds. Sections of this feed formatting JSP file are marked with numbered call-outs and explained below the sample:

      <?xml version="1.0" encoding="UTF-8"?>
      <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
      <%@ include file="../site-default/FeedEnvironment.jspf"%> 1
      <feed xmlns="http://www.w3.org/2005/Atom" xmlns:ns2="http://a9.com/-/spec/opensearch/1.1/" xmlns:ns3="http://www.w3.org/1999/xhtml">
      <%-- 2 --%> 
      <%-- To get string for composing feed id. 
            if the requestUri is like http://servername/wcs/resources/stores/storeID/ProjectCollections?responseFormat=atom then
                 sting4feedId = "all" // the all means that all projects are returned.
             if the requestUri is like http://servername/wcs/resources/stores/storeID/ProjectCollections/ProjectCollectionID?responseFormat=atom
                  sting4feedId = ProjectCollectionID //ProjectCollectionID is the  project id in requestUri. 
        --%>
          <c:set var="requestUriArray" value="${fn:split(requestUri,'/')}"/>
        	 <c:forEach var="tempArrayValue" items="${requestUriArray}" varStatus="status_requestURI">
        	        <c:choose>
      	  	        <c:when test="${status_requestURI.last}">  	             
      	  	             <c:set var="lastValue" value="${tempArrayValue}"/>
      	  	        </c:when>
        	        </c:choose>
        	 </c:forEach>  	
            <c:choose>
            <%-- If the last value is ProjectCollections?responseFormat=atom --%>
        	        <c:when test="${fn:startsWith(lastValue, 'ProjectCollections')}">
        	                <c:set var="string4feedId" value="all"/>
        	        </c:when>
        	        <%-- If the last value is ProjectCollectionID?responseFormat=atom --%>
        	        <c:otherwise>  	            
        	        <%-- To get the ProjectCollectionID id from lastValue  ProjectCollectionID?responseFormat=atom --%>
        	            <c:set var="string4feedId" value="${fn:substringBefore(lastValue, '?')}"/>
        	        </c:otherwise>
        	   </c:choose>    
      
      <%-- 3 --%>
      <%-- necessary item in feed --%>
      <id>feed:id:${pageContext.request.serverName}/store/${storeId}/ProjectCollections/${string4feedId}/language/-1</id>
      <title type="text">Recipe Collections</title>
      <author>
      <name>${storeId}</name>
      </author>
      <link rel="self" href="<c:out value="${requestUri}" />"/>
      <updated><c:out value="${currentDate}" /></updated>
      
      <%-- 4 --%>
      <%-- Get data from response to list all entry --%>
      <c:forEach var="projectCollectionData" items="${dataObject.projectCollection}" varStatus="status">
      <c:set var="collectionName" value="${projectCollectionData.projectCollectionIdentifier.externalIdentifier.name}"/>
      <c:set var="collectionId" value="${projectCollectionData.projectCollectionIdentifier.uniqueID}"/>
      
      <%-- 5 --%>
      <c:set var="recipeCollectionURL"  value="${dynamicContextRoot}/RecipeCollection_0_${collectionId}_-1_${storeId}_${catalogId}_${collectionName}_Y"/>
      
      <%-- 6 --%>
      <entry xml:lang="en_US">
      <id>feed:id:${pageContext.request.serverName}/store/${storeId}/ProjectCollection/${collectionId}/language/-1</id>
      <title type="text">${collectionName} Collection </title>
      <link href="${recipeCollectionURL}" />
      <updated><c:out value="${currentDate}" /></updated>
      
      <%-- 7 --%>
      <content type="html">    
      		   <c:out value="<table border=\"1\" "/>	   
      			<c:out value="<tr><td>Name</td><td align=\"center\" height=\"45\"><a href=\"${recipeCollectionURL}\">${collectionName}</font></a></td></tr>" />
      			<c:out value="<tr><td>Description</td><td align=\"center\" height=\"25\"><font face=\"Arial\" size=\"3px\">${projectCollectionData.description[0].value}</font></td></tr>" />
      		   <c:out value="</table>"/>	  		  
      	</content>
      
      <%-- 8 --%>
      	<%-- xml format data --%>
      	<collectionName>${collectionName}</collectionName>
      	<collectionDescription>${projectCollectionData.description[0].value}</collectionDescription>
      </entry>
      </c:forEach>
      </feed>
      • 1 The FeedEnvironment.jspf file is an existing WebSphere Commerce file. This file is included in all default feed formatting JSP files to set common variables. Functions of this file include setting variables for the data passed to the feed, setting the location of static and dynamic content to include in the feed, and specifying the format for dates displayed in the feed according to the Atom standard.
      • 2 This section builds a unique ID for the feed. The code determines whether the URL contains an identifier:
        • If it does, then the client has requested a feed for a specific recipe collection.
        • If it does not, then the client has requested a feed for a list of all recipe collections.
      • 3 This section of the JSP file defines the mandatory and optional elements for the Atom <feed> element, based on the Atom Syndication Format requirements. The elements are <id>, <title>, <author>, <link>, and <updated>. These elements represent the text and data that the customer typically sees at the top of the feed, for example, the feed title, and the date the feed was last updated.
      • 4 This section of the JSP file gets the data from the service data object (SDO) returned from the Get ProjectCollection Web service.
      • 5 This section defines the feed link that opens the Madisons store page that displays a Recipe Collections list.
      • 6 This section marks the beginning of the Atom feed <entry> definition, based on the Atom Syndication Format requirements. The feed entry <id>, <title>, <link>, and <updated> elements are defined.
      • 7 This section defines the content of each feed entry. The <content> element is a recommended Atom feed <entry> element. In this example, the content of each feed entry is a simple table containing the recipe collection name as a link, and a description. Most browsers and feed readers display the <content> element. In the next lesson, when you view the feeds in a browser, you will see the tables displayed for each feed entry.
      • 8 This section defines two Atom extension elements, <collectionName> and <collectionDescription>. Notice that these two extension elements represent the same data as the <content> element. These Atom extension elements are included to make it easier to arrange and format feed data in a remote widget. You could use the <content> element in a remote widget; however, the collection name and collection description are lumped together in a single element. The Atom extension elements split the collection name and collection description into separate elements so that you can arrange and format them independently in the widget.
    6. Save and close the JSP files.
  3. Open the Struts configuration file for the RESTful framework at the following path:

    WCDE_installdir/workspace/Rest/WebContent/WEB-INF/struts-extension.xml

  4. To register the two feed formatting JSP files, add the following action mappings:
    <action path="/ShowProjectDataAreaTypeAtom/0"       
            forward="/atom/project/SerializeShowProjectDataAreaTypeAtom.jsp" />
    <action path="/ShowProjectCollectionDataAreaTypeAtom/0"     
            forward="/atom/project/SerializeShowProjectCollectionDataAreaTypeAtom.jsp" />
  5. Save and close the file.
  6. Restart the WebSphere Commerce test server to make the new configuration available.

Results

This lesson introduced the feed formatting JSP files that are used to format Atom feeds. In the next lesson, you will test the four Atom feed URLs to make sure the Java classes and feed formatting JSP files are working as expected.