Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

更新document新版本的内容

$
0
0

        Document是可版本化对象,在我们最初创建并check in一个新的document时,我们就初始化了一个新的版本,而当我们在将此版本check out编辑后进行check in,则我们便得到了该文档的一个新的版本。下面展现文档版本变化过程中添加文档内容和保留上个版本文档内容的过程。

	Connection conn = CEHelper.getConnection();
		CEHelper.pushSubject(conn, "Administrator", "filenet");
		ObjectStore os = CEHelper.getObjectStore(conn);
		
		Document doc = Factory.Document.fetchInstance(os, new Id("{1FC02DF6-7EDE-49BE-998A-801BB6012C75}"), null);
		Document doc0 = Factory.Document.fetchInstance(os, new Id("{1FC02DF6-7EDE-49BE-998A-801BB6012C75}"), null);
		
		logger.info(!doc.get_IsReserved());

		if(!doc.get_IsCurrentVersion()){
			doc = (Document)doc.get_CurrentVersion();
			doc0 = (Document)doc.get_CurrentVersion();
		}
		
		logger.info(!doc.get_IsReserved());
		if(!doc.get_IsReserved()){
			doc.checkout(ReservationType.EXCLUSIVE, null,null, doc.getProperties());
			doc.save(RefreshMode.REFRESH);
		}
		doc = (Document)doc.get_Reservation();
		
		logger.info(!doc.get_IsReserved());
		
		ContentElementList oldCEL = doc.get_ContentElements();
		logger.info(String.valueOf(oldCEL.size()));
		
		
		ContentElementList newCEL = Factory.ContentElement.createList();
		ContentTransfer ct = Factory.ContentTransfer.createInstance();
		try{
			ct.setCaptureSource(new FileInputStream("c:\\log4j1.log"));
		}catch(FileNotFoundException e){
			e.printStackTrace();
		}
		newCEL.add(ct);
		
		logger.info(doc0.get_ContentElements().size());
		InputStream is = doc0.accessContentStream(0);
		ContentTransfer ct2 = Factory.ContentTransfer.createInstance();
		ct2.setCaptureSource(is);
		newCEL.add(ct2);

		InputStream is3 = doc0.accessContentStream(1);
		ContentTransfer ct3 = Factory.ContentTransfer.createInstance();
		ct3.setCaptureSource(is3);
		newCEL.add(ct3);

		InputStream is4 = doc0.accessContentStream(1);
		ContentTransfer ct4 = Factory.ContentTransfer.createInstance();
		ct4.setCaptureSource(is4);
		newCEL.add(ct4);
		
		doc.set_ContentElements(newCEL);
		doc.save(RefreshMode.REFRESH);
		
		doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
		doc.save(RefreshMode.REFRESH);
			
		
		CEHelper.popSubject();


              在上述操作过程中,需要注意获取document的当前版本,并将其check out进入Reservation版本,进而更改其内容(content)。在获取之前版本的content时,不要直接引用其ContentTransfer,而要获取其accessContentStream重新建立ContentTransfer,完成document content的设置

作者:dongzi87 发表于2013-1-30 23:23:30 原文链接
阅读:133 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>