Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member188556
Active Contributor
0 Kudos
Recently in my project I came across a scenario where my Web Dynpro Project had to pick the image from KM. The images to be displayed will be placed in KM. This will avoid loading the images into the Web DynPro project. More over when you have KM installed on your EP server, one can use it for storing backend data and resources. The KM Admin will be undertaking this task of uploading the images to predefined folder structures. Through the application path to the image will be provided dynamically giving you the flexibility to decide which image to be displayed according to the business logic. Advantage: If the image is in KM repository, admin can change the image at any point of time without redeploying the application. Content Managers can have much more flexibility. Let's begin from the KM configuration. 1) Create a folder in KM with name Alice In Wonderland. 2) Upload the image alice.gif. 3) Create a Web Dynpro project. The first thing one need to configure is the Web Dynpro Sharing Reference. This can be done by selecting the project->Properties->Web Dynpro Refernces-> Sharing References. Add the following entry here PORTAL:sap.com/com.sap.km.application 4) Jar files to be added. bc.rf.framework_api.jar bc.rf.global.service.urlgenerator_api.jar bc.sf.framework_api.jar bc.util.public_api.jar com.sap.security.api.ep5.jar com.sap.security.api.jar prtapi.jar Now the project you create can access KM. 5) Add a UI Element for Image in the view. Create a context attribute-String type with name "image". Map the image ui element(Property->Source) to the context attribute "image" just created. In the normal scenario we used to provide the image name here and image will be included with the project. But here we will take the image dynamically from KM. 6) Detailed coding. I have written a java class ImageInfo, where a method "IWDWebResource getImage(String path)" which get called from the webdynpro view. The method will "return IWDWebResource" Method IWDWebResource getImage(String path) Imports to be added java.io.BufferedInputStream; java.io.IOException; com.sap.security.api.IUser; com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser; com.sap.tc.webdynpro.services.sal.um.api.WDClientUser; com.sap.tc.webdynpro.services.sal.um.api.WDUMException; com.sap.tc.webdynpro.services.sal.url.api.IWDWebResource; com.sap.tc.webdynpro.services.sal.url.api.WDURLException; com.sap.tc.webdynpro.services.sal.url.api.WDWebResource; com.sap.tc.webdynpro.services.sal.url.api.WDWebResourceType; com.sapportals.portal.security.usermanagement.UserManagementException; com.sapportals.wcm.repository.AccessDeniedException; com.sapportals.wcm.repository.IResource; com.sapportals.wcm.repository.IResourceContext; com.sapportals.wcm.repository.IResourceFactory; com.sapportals.wcm.repository.ResourceContext; com.sapportals.wcm.repository.ResourceFactory; com.sapportals.wcm.util.content.ContentException; com.sapportals.wcm.util.uri.RID; com.sapportals.wcm.util.usermanagement.WPUMFactory; //Getting the user…… IWDClientUser wdClientUser = WDClientUser.getCurrentUser(); IUser sapUser = wdClientUser.getSAPUser(); com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser); //Getting the Resource……… IResourceContext resourseContext = new ResourceContext(ep5User); IResourceFactory resourseFactory = ResourceFactory.getInstance(); //path to the KM Folder ("/documents/Alice In Wonderland/alice.gif") RID pathRIDimg = RID.getRID(path); com.sapportals.wcm.repository.IResource resourceimg = resourseFactory.getResource(pathRIDimg, resourseContext); //Reading the image file…… BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream()); byte[] imagebyte = new byte[bufIn.available()]; bufIn.read(imagebyte); //Mapping the image as a WebResource…. IWDWebResource webResource = WDWebResource.getWebResource( imagebyte, WDWebResourceType.JPG_IMAGE); 7)In the view we use following code to call the above method of the class-ImageInfo ImageInfo imageInfo = new ImageInfo (); IWDWebResource webResource = imageInfo.getimage("/documents/Alice In Wonderland/alice.gif "); 😎 Now finally webResource is being mapped to context attribute image wdContext.currentContextElement().setImage(webResource.getURL()); 9)The image will be displayed.
9 Comments