cancel
Showing results for 
Search instead for 
Did you mean: 

How to check, if Image source file exist in content management

Former Member
0 Kudos

Hi All

Before programmatically setting the source property of Image UI element, I want to know if this Image exists at the given path. If image is not available I need to set some other default image.

If I have the Image name and path how can I program the check of availability?

Thanks in Advance

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Tonmay,

when you know full path and name to file you can simply create a file object and check if file exist:

String fileName=<path>+<file name>;
File f=new File(name)
if (f.exist()){
   <action if exist>
}else{
   <action if not exist>
}

I hope that help

Regards

Bogdan

Former Member
0 Kudos

Hi Bogdan

I tried it but it did not worked.

String fileName= "http://gks09879.gkservices.com:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/g&k/catalog images/"material_Number".jpg";

File f=new File(fileName);

if (f.exists())

{

msgMgr.reportSuccess("file found");

}

else

{

msgMgr.reportSuccess("No file found");

}

When I use the Same URL in source property of Image it works but it is not working in above case.

Former Member
0 Kudos

Hi Tanmay,

If you are talking about an image from KM, you can do the following to check its existence: Use KM api to access a resource.

1)Get the logged in user and create a resource context (do this in init method)

try {

IUser user = WDClientUser.getLoggedInClientUser().getSAPUser();

resFac = ResourceFactory.getInstance();

com.sapportals.portal.security.usermanagement.IUser epuser = WPUMFactory.getUserFactory().getEP5User(user);

resContext = new ResourceContext(epuser);

} catch (ResourceException e) {

manager.reportException(new WDNonFatalException(e), false);

e.printStackTrace();

} catch (UserManagementException e) {

manager.reportException(new WDNonFatalException(e), false);

e.printStackTrace();

}

2)Specify the path to the image in KM and create a RID

try {

rid = RID.getRID("/images/icons/forms/substitute.gif");

IResource resource = resFac.getResource(rid, resContext);

if (resource == null) {

currentCtxEle.setSubsIconDisplay(false);

} else {

currentCtxEle.setSubsIconDisplay(!false);

}

} catch (Exception e) {

currentCtxEle.setSubsIconDisplay(false);

}

U might need to have these imports:

import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

import com.sapportals.portal.security.usermanagement.UserManagementException;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.IResourceContext;

import com.sapportals.wcm.repository.IResourceFactory;

import com.sapportals.wcm.repository.ResourceContext;

import com.sapportals.wcm.repository.ResourceException;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.util.uri.RID;

import com.sapportals.wcm.util.usermanagement.WPUMFactory;

Hope that helps.

Regards,

Rajit Srinivas

Former Member
0 Kudos

The above code is assuming you are displaying images from KM (i assumed it from your url) and the base folder for the images is the path /images in KM.

Regards,

Rajit Srinivas