Configuring the XML Provider Definition Using a combination of tags in

Enhancing Java Portlets 7-69 Once you have the handle, you need to specify the cache key. In the cache key, you need to specify whether you want to invalidate a particular portlet instance, all the instances of a portlet, or all the portlets managed by a provider. To perform this task, you use the methods of the ServletInvalidationContext class or the methods of its super class, InvalidationContext. This is where you can specify whether the portlet should be cached for this particular user USER level. If there is no user specified in the cache key, then the cached content is returned to all users, which means you are using SYSTEM level caching. The following example invalidates a portlet instance and calls the setFullProviderPath and setPortletReference methods. When the caching key is set, you call the invalidate method on the InvalidationContext object that sends the invalidation message to Oracle Web Cache. ServletInvalidationContext inv = ServletInvalidationContextFactory.getServletInvalidationContext; inv.setFullProviderPath ServletPortletRenderRequestpReq; inv.setPortletReference pReq.getPortletReference; int num = inv.invalidate; Review the Web cache sample provider for more information.

7.2.9.5 Adding Validation-Based Caching

Adding validation-based caching requires slightly more effort, but gives you explicit control over exactly which requests to your provider are cache hits. As an example, you may want to update the cache only when data within the portlet has changed. To implement this algorithm, you need to override the prepareResponse method. The signature of the BaseManagedRenderer.prepareResponse method is: public boolean prepareResponsePortletRenderRequest pr throws PortletException, PortletNotFoundException In your version of prepareResponse, you need to do the following: ■ Retrieve the cached version identifier set by the PPE in the render request by calling the HttpPortletRendererUtil.getCachedVersion method: public static java.lang.String getCachedVersion PortletRenderRequest request ■ If the portlet finds the previously cached version valid, the appropriate header has to be set by calling the HttpPortletRendererUtil.useCachedVersion method. It also instructs the RenderManager that it wont be necessary to call renderBody to render the portlet body. public static void useCachedVersionPortletRenderRequest request Otherwise, use HttpPortletRendererUtil.setCachedVersion to generate a new version of the portlet, which will be cached. It also indicates to the PPE that the renderBody method has to be called to regenerate the portlet content. public static void setCachedVersionPortletRenderRequest request, java.lang.String version, int level throws java.lang.IllegalArgumentException 7-70 Oracle Fusion Middleware Developers Guide for Oracle Portal For validation-based caching, you need not update provider.xml. You can view the portlet by refreshing the page or adding the portlet to a page and updating the content. If the content has changed, the portlet shows the new content. If the content has not changed, a cached version of the portlet is displayed.

7.2.10 Enhancing Portlets for Mobile Devices

This section explains how to go about enhancing a PDK-Java portlet for a mobile device. Before proceeding with this section, you should familiarize yourself with the guidelines for building mobile-enabled portlets, Section 6.1.4, Guidelines for Mobile Portlets , and the methods of building portlets with PDK-Java, Section 7.2, Enhancing PDK-Java Portlets . To properly build a portlet for a mobile device, do the following: 1. Create a JSP to generate the OracleAS Wireless XML in response to the show request for the portlet. The portlets JSPs are managed and controlled by the built in renderer, oracle.portal.provider.v2.render.http.ResourceRenderer. With this renderer, you can define distinct resources JSPs for each Show mode as well as which JSP to call for each Show mode. Hence, you can define one JSP to handle the Show mode when the requested content is HTML and another when the requested content is OracleAS Wireless XML. For example, this capability enables you to put the lottery portlets mobile rendition in a separate JSP. In this sample, mlotto.jsp generates the mobile rendition. Note the contentType declaration in the first line of the source code. The content type of the JSPs response is set to textvnd.oracle.mobilexml. This is the MIME type name for OracleAS Wireless XML. All mobile responses must set their content type to this value to work properly. page session=false contentType=textvnd.oracle.mobilexml page import=oracle.portal.sample.v2.devguide.lottery.LottoPicker LottoPicker picker = new LottoPicker; picker.setIdentityrequest.getRemoteAddr ; SimpleText SimpleTextItem SimpleTextItemYour numbers:SimpleTextItem SimpleTextItem SimpleTextItem HALIGN=CENTER int [] picks = picker.getPicks; for int i = 0; i picks.length; i++ { out.printpicks[i] + ; } out.println; SimpleTextItem SimpleText 2. Modify provider.xml by adding the acceptContentType tag in the portlet definition to indicate that the portlet can generate OracleAS Wireless XML responses. Each acceptContentType tag defines a distinct content type that the portlet can render. The value is the MIME type of the content. In this case the lottery portlet declares that it can generate HTML texthtml and OracleAS Wireless XML textvnd.oracle.mobilexml. acceptContentTypetexthtmlacceptContentType