activiti 根据模型ID导出、预览 xml文件

December 17, 2023
测试
测试
测试
测试
4 分钟阅读
	/**根据模型ID导出xml文件
	 * @param response
	 * @param modelId	//模型ID
	 * @from  fhadmin.cn
	 */
	protected void exportXmlFromModelId(HttpServletResponse response, String modelId) throws Exception{
		Model modelData = repositoryService.getModel(modelId);  
		BpmnJsonConverter jsonConverter = new BpmnJsonConverter();  
		ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
		BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(modelNode);  
		BpmnXMLConverter xmlConverter = new BpmnXMLConverter();  
		byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);  
		ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);  
		//IOUtils.copy(in, response.getOutputStream());  
		String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";  
		/*response.setHeader("Content-Disposition", "attachment; filename=" + filename);  
		response.flushBuffer(); */
		FileUpload.copyFile(in,PathUtil.getProjectpath()+Const.FILEACTIVITI,filename); 		//把文件上传到文件目录里面
		FileDownload.fileDownload(response, PathUtil.getProjectpath()+Const.FILEACTIVITI+filename, filename);
		in.close();
	}
	
	/**根据模型ID预览xml文件
	 * @param response
	 * @param modelId	//模型ID
	 * @from  fhadmin.org
	 */
	protected String viewXmlFromModelId(String modelId) throws Exception{
		Model modelData = repositoryService.getModel(modelId);  
		BpmnJsonConverter jsonConverter = new BpmnJsonConverter();  
		ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
		BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(modelNode);  
		BpmnXMLConverter xmlConverter = new BpmnXMLConverter();  
		byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);  
		ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);  
		InputStreamReader isr = new InputStreamReader(in,"utf-8");
		BufferedReader bufferedReader = new BufferedReader(isr);
		StringBuffer xmlContent = new StringBuffer(); 
		String lineTxt = null;
		while ((lineTxt = bufferedReader.readLine()) != null) {
			xmlContent.append(lineTxt);
			xmlContent.append("\n");
		}
		isr.close();
		return xmlContent.toString();
	}

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多