/**根据模型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(); }