on 06-13-2006 10:28 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.