Hi
I have been working on som code to upload information from a JSP page to a textfile in the KM repository. When the file is already present in the KM repository there is no problem, but if I delete the file and then want to create it again, my code fails. I have pasted the code below, can someone please have a look at it, to se what is wrong?
This line : col = (ICollection) ResourceFactory.getInstance().getResource(fileRid, ctx);
results on col beeing null and the following line throws an exception.
/Jakob
--- Code ---
public void SaveFile( String strTextArea ){
this.boolError = false;
this.strErrorTxt = "";
String strTest = strTextArea;
String strUserName;
IResource resourceFile;
IResourceFactory resourceFactory;
IUserContext epUser = (IUserContext) this.request.getUser();
IUser user = (IUser)epUser.getUser();
strUserName = epUser.getName();
ResourceContext ctx = new ResourceContext( user );
/*Give the path to KM in the variable path */
RID fileRid = RID.getRID( repository_km+strUserName + "/" + fileName);
try{
resourceFactory = ResourceFactory.getInstance();
resourceFile = resourceFactory.getResource(fileRid,ctx);
}
catch(ResourceException e){
this.boolError = true;
this.strErrorTxt = "Der er opstået en fejl ved opdatering af 'Gul note'
Genstart venligst dialogen
Level 3";
}
ICollection col;
IResource file;
ctx = new ResourceContext( user );
ByteArrayInputStream data = new ByteArrayInputStream(strTest.getBytes());
Content content = new Content(data, "text/plain", data.available());
try{
if(ResourceFactory.getInstance().checkExistence(RID.getRID(this.repository_km+strUserName + "/" + this.fileName), ctx))
{
ResourceFactory.getInstance().getResource(RID.getRID(this.repository_km+strUserName + "/" + this.fileName), ctx).updateContent(content);
}
else
{
//
col = (ICollection) ResourceFactory.getInstance().getResource(fileRid, ctx);
file = col.createResource(this.fileName, null, null);
file.updateContent(content);
}
}
catch(ResourceException e){
this.boolError = true;
this.strErrorTxt = "Der er opstået en fejl ved opdatering af 'Gul note'
Genstart venligst dialogen
Level 2";
}
}
}