新しい添付をアップロードする際に既存の添付から置き換える方法

/***
 * 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();
}





この関数はリッチテキストアイテムにある既存の添付ファイルをアップロードした新しい添付ファイルに置き換えるものです。リッチテキストアイテムには常にひとつの添付しか存在しない形になります。

送信ボタン内の SSJS コードで次の関数をコールします。: replaceAttachment( document1, 'fileUpload1' , 'Body' )

詳細は以下を参照してください:
http://stackoverflow.com/questions/9925666/replace-attachment-when-uploading-a-new-attachment


XPage の例はこちらです:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

 <xp:this.data>
    <xp:dominoDocument var="document1" formName="TestRT"
       action="editDocument" documentId="2D8A8AB0DD77C895C12579E4004E594A">
    </xp:dominoDocument>
 </xp:this.data>

 <xp:fileUpload id="fileUpload1" value="#{document1.Body}"></xp:fileUpload>
 <xp:br></xp:br>
 <xp:br></xp:br>
 <xp:fileDownload rows="30" id="fileDownload1" displayLastModified="false" value="#{document1.Body}"></xp:fileDownload>
 <xp:br></xp:br>
 <xp:br></xp:br>
 <xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
       refreshMode="complete" immediate="false" save="true">
          <xp:this.action>
             <![CDATA[#{javascript:replaceAttachment( document1, 'fileUpload1' , 'Body' )}]]>
          </xp:this.action>
    </xp:eventHandler>
 </xp:button>

</xp:view>

JavaScript (Server)
katoman
August 19, 2015 at 2:29 PM
Rating
0





No comments yetLogin first to comment...