/*** * replaceAttachment * * replaces an existing attachment in a richtext item with a newly uploaded attachment. * Only one attachment will be left in the richtext item. * * @author Sven Hasselbach * @param ds DataSource document which contains the target rich text item * @param fileUploadControlId id of the file upload control * @param rtItemName Name of target richtext item * ***/ function replaceAttachment( ds:NotesXspDocument, fileUploadControlId:String, rtItemName:String ){ var con = facesContext.getExternalContext(); var request:com.sun.faces.context.MyHttpServletRequestWrapper = con.getRequest(); var map:java.util.Map = request.getParameterMap(); var fileDataName = getClientId( fileUploadControlId ) ; var fileData:com.ibm.xsp.http.UploadedFile = map.get( fileDataName ); if( fileData == null ){ return; } var tempFile:java.io.File = fileData.getServerFile(); var correctedFile = new java.io.File( tempFile.getParentFile().getAbsolutePath() + java.io.File.separator + fileData.getClientFileName() ); var success = tempFile.renameTo(correctedFile); try{ ds.removeAllAttachments( rtItemName ); }catch(e){} var rtFiles:NotesRichTextItem = null; if(!(ds.getDocument().hasItem( rtItemName ))){ rtFiles = ds.getDocument().createRichTextItem( rtItemName ) }else{ rtFiles = ds.getDocument().getFirstItem( rtItemName); } rtFiles.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT, "", correctedFile.getAbsolutePath(), null); correctedFile.renameTo(tempFile); ds.save(); }