Retrieving Resources
You retrieve a resource from the ResourceFactory , specifying the RID and context ( IResourceContext ) of the resource. The code extract below shows how you can retrieve a resource. You:
- Create a resource context for the user that wants to retrieve the resource
- Get an instance of IResourceFactory which supplies the resource
- Retrieve the resource for the RID /etc
com.sapportals.portal.security.usermanagement.IUser user = …
IResourceContext resourceContext = new ResourceContext(user);
RID rid = RID.getRID(″/etc″);
try {
IResource resource = ResourceFactory.getInstance()
.getResource(rid, resourceContext);
if( resource != null ) {
// resource found
System.out.println(″resource ″ + resource.getRID() + ″ found″);
} else {
// resource not found
System.out.println(″resource ″ + resource.getRID() + ″ does not exist″);
}
}
catch( ResourceException e ) {
// problem while retrieving the resource
System.out.println(
″exception while trying to get resource ″ + e.getRID()
+ ″: ″ + e.getMessage() );
}
You can retrieve a collection in the same way as a resource and then cast it to an ICollection:
if(resource.isCollection() ) {
ICollection collection = (ICollection)resource;
IResourceList children = collection.getChildren();
}