on 08-28-2006 6:25 PM
Hello everyone,
I'm still having some problems with the KM API. Now my problem is the following: i want to move a file from a specific directory to another.
This is how i'm doing it (of course, it doesn't work):
try {
// create an user object from the current user
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
// create an ep5 user from the retrieved user
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
// establish resource context
IResourceContext resourceContext = new ResourceContext(ep5User);
// get a resource factory
IResourceFactory resourceFactory = ResourceFactory.getInstance();
// get a RID from the current path to display the according content
RID pathRID = RID.getRID("/share");
// get a Iresource object to work on
com.sapportals.wcm.repository.IResource resource = resourceFactory.getResource(pathRID, resourceContext);
// cast the object to a Collection
ICollection collection = (ICollection) resource;
// Create folder destination before moving files
try {
IPropertyMap prop = new PropertyMap();
collection.createCollection("NEWDIR", prop);
} catch (NameAlreadyExistsException e) {
}
// Now define new created folder as destination
RID pathRIDdest = RID.getRID("/share/NEWDIR");
ICopyParameter copyparams = new CopyParameter(true);
int size = wdContext.nodeFicheiros().size();
for (int i = 0; i < size; i++) {
IResource tmpResource = wdContext.nodeFicheiros().getFicheirosElementAt(i).getResource();
tmpResource.move(pathRIDdest, copyparams);
}
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException("Exception: "+e,false);
}
In the node Ficheiros i have a list of attributes from type IResource, each one referring to a file i want to move to the new NEWDIR folder.
What happens is that the source files are moved, but "concatenated" to a big file named NEWDIR, not a folder.
Can anyone tell me what am i doing wrong ??
Thanks in advance to everyone.
Hi,
You can try creating an empty resource in the destination folder and copy the resource to this empty resource. I have modified your code a bit, especially the last part.
try {
//create an user object from the current user
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
//create an ep5 user from the retrieved user
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
//establish resource context
IResourceContext resourceContext = new ResourceContext(ep5User);
//get a resource factory
IResourceFactory resourceFactory = ResourceFactory.getInstance();
//get a RID from the current path to display the according content
RID pathRID = RID.getRID("/share");
//get a Iresource object to work on
com.sapportals.wcm.repository.IResource resource = resourceFactory.getResource(pathRID, resourceContext);
//cast the object to a Collection
ICollection collection = (ICollection) resource;
// Create folder destination before moving files
try {
IPropertyMap prop = new PropertyMap();
collection.createCollection("NEWDIR", prop);
} catch (NameAlreadyExistsException e) {
}
//Now define new created folder as destination
RID pathRIDdest = RID.getRID("/share/NEWDIR");
//Check if folder exists
ICollection destFolder = (ICollection) resourceFactory.getResource( pathRIDdest, resourceContext );
if(destFolder != null){
ICopyParameter copyparams = new CopyParameter(true);
int size = wdContext.nodeFicheiros().size();
for (int i = 0; i < size; i++) {
IResource tmpResource = wdContext.nodeFicheiros().getFicheirosElementAt(i).getResource();
destFolder.createResource(tmpResource.getName(),null,null);
RID destResourceRID = RID.getRID
(
destFolder.getRID().toString() +,
RID.PATH_SEPARATOR +
tmpResource.getName()
);
tmpResource.copy(destResourceRID, copyparams);
}
}
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException("Exception: "+e,false);
}
Regards,
Satyajit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
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.