The Web Resource Repository enables portal administrators to upload and manage web resources in the portal.
The resources in the repository are stored in the Portal Content Directory (PCD), and can be accessed using the PCD APIs.
The resources are also available for portal applications at runtime through the IResourceRepositoryService interface, contained in the com.sap.portal.resource.repository package.
The following examples illustrate how to access and use the resources with the help of this API.
Including Web Resources in Portal Responses
Resource files stored in the portal Web Resource Repository can be included in portal component responses, as follows:
//The repository path of the resource to include in the response: //can either be a full PCD path or relative to the resource repository root String resourcePath = "/my_resources/main.css"; //Getting a reference to the resource repository service IResourceRepositoryService resourceRepository = (IResourceRepositoryService) PortalRuntime.getRuntimeResources() .getService(IResourceRepositoryService.KEY); try { //Getting an IResource object for the resource IResource resource = resourceRepository .getResource(resourcePath, IResource.CSS, false); //Including the resource in the response response.include(request, resource); } catch (WebResourceException e){ //Failure to load the requested resource, which can happen //if the resource doesn't exist or when the resource path is invalid //Handle the exception... }
Accessing Resources Using URIs
A portal application can access resources that are stored in the Web Resource Repository using their web URIs, as follows:
//The repository path of the resource to include in the response: //can either be a full PCD path or relative to the resource repository root String resourcePath = "/my_resources/logo.png"; //Getting a reference to the resource repository service IResourceRepositoryService resourceRepository = (IResourceRepositoryService) PortalRuntime.getRuntimeResources() .getService(IResourceRepositoryService.KEY); //Getting the URI of the resource URI resourceURI = resourceRepository.getResourceURI(resourcePath, false); //Using the resource URI response.getWriter().write("<image src=\"" + resourceURI + "\"/");
You can get the resource's last modification timestamp appended to the created IResource object by passing true in the timestampRequired parameter. This is useful when you want resources to be updated on client browsers without having to clear the browser cache.
However, be aware that the last modification timestamp check may impact performance.
Using the Web Resource Repository API to enable branding of your portal applications
Working with the Web Resource Repository
Administering Web resources in the portal