本文整理汇总了Java中org.activiti.bpmn.converter.BpmnXMLConverter.convertToXML方法的典型用法代码示例。如果您正苦于以下问题:Java BpmnXMLConverter.convertToXML方法的具体用法?Java BpmnXMLConverter.convertToXML怎么用?Java BpmnXMLConverter.convertToXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.bpmn.converter.BpmnXMLConverter
的用法示例。
在下文中一共展示了BpmnXMLConverter.convertToXML方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deploy
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 根据Model部署流程
*/
public String deploy(String id) {
String message = "";
try {
org.activiti.engine.repository.Model modelData = repositoryService.getModel(id);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
String processName = modelData.getName();
if (!StringUtils.endsWith(processName, ".bpmn20.xml")){
processName += ".bpmn20.xml";
}
// System.out.println("========="+processName+"============"+modelData.getName());
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
Deployment deployment = repositoryService.createDeployment().name(modelData.getName())
.addInputStream(processName, in).deploy();
// .addString(processName, new String(bpmnBytes)).deploy();
// 设置流程分类
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
for (ProcessDefinition processDefinition : list) {
repositoryService.setProcessDefinitionCategory(processDefinition.getId(), modelData.getCategory());
message = "部署成功,流程ID=" + processDefinition.getId();
}
if (list.size() == 0){
message = "部署失败,没有流程。";
}
} catch (Exception e) {
throw new ActivitiException("设计模型图不正确,检查模型正确性,模型ID="+id, e);
}
return message;
}
示例2: export
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 导出model的xml文件
* @throws IOException
* @throws JsonProcessingException
*/
public void export(String id, HttpServletResponse response) {
try {
org.activiti.engine.repository.Model modelData = repositoryService.getModel(id);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
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();
} catch (Exception e) {
throw new ActivitiException("导出model的xml文件失败,模型ID="+id, e);
}
}
示例3: convertToModelTest
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
@Test
public void convertToModelTest() throws Exception {
BpmnModel bpmnModel = buildModel();
BpmnXMLConverter converter = new BpmnXMLConverter();
String xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
byte[] bytes = xml.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(inputStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
bpmnModel = converter.convertToBpmnModel(xtr);
xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
System.out.println(xml);
}
示例4: export
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 导出model的xml文件
*/
@RequestMapping(value = "export/{modelId}")
public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
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();
} catch (Exception e) {
logger.error("导出model的xml文件失败:modelId={}", modelId, e);
}
}
示例5: testBpmnModelToXml
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 把BpmnModel转换为XML对象
* @throws Exception
*/
@Test
@Deployment(resources = "chapter6/dynamic-form/leave.bpmn")
public void testBpmnModelToXml() throws Exception {
// 验证是否部署成功
long count = repositoryService.createProcessDefinitionQuery().count();
assertEquals(1, count);
// 查询流程定义对象
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult();
// 获取BpmnModel对象
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
// 创建转换对象
BpmnXMLConverter converter = new BpmnXMLConverter();
// 把BpmnModel对象转换成字符(也可以输出到文件中)
byte[] bytes = converter.convertToXML(bpmnModel);
String xmlContent = new String(bytes);
System.out.println(xmlContent);
}
示例6: export
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 导出model对象为指定类型
*
* @param modelId 模型ID
* @param type 导出文件类型(bpmn\json)
*/
@RequestMapping(value = "export/{modelId}/{type}")
public void export(@PathVariable("modelId") String modelId,
@PathVariable("type") String type,
HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
byte[] modelEditorSource = repositoryService.getModelEditorSource(modelData.getId());
JsonNode editorNode = new ObjectMapper().readTree(modelEditorSource);
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
// 处理异常
if (bpmnModel.getMainProcess() == null) {
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
response.getOutputStream().println("no main process, can't export for type: " + type);
response.flushBuffer();
return;
}
String filename = "";
byte[] exportBytes = null;
String mainProcessId = bpmnModel.getMainProcess().getId();
if (type.equals("bpmn")) {
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
exportBytes = xmlConverter.convertToXML(bpmnModel);
filename = mainProcessId + ".bpmn20.xml";
} else if (type.equals("json")) {
exportBytes = modelEditorSource;
filename = mainProcessId + ".json";
}
ByteArrayInputStream in = new ByteArrayInputStream(exportBytes);
IOUtils.copy(in, response.getOutputStream());
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.flushBuffer();
} catch (Exception e) {
logger.error("导出model的xml文件失败:modelId={}, type={}", modelId, type, e);
}
}
示例7: jsonToModelTest
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
@Test
public void jsonToModelTest() throws Exception {
BpmnModel bpmnModel = buildModel();
BpmnJsonConverter jsonConverter = new BpmnJsonExConverter();
ObjectNode objectNode = jsonConverter.convertToJson(bpmnModel);
System.out.println(objectNode.toString());
bpmnModel = jsonConverter.convertToBpmnModel(objectNode);
BpmnXMLConverter converter = new BpmnXMLConverter();
String xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
System.out.println(xml);
}
示例8: exportXml
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 导出model的xml文件
*/
@RequestMapping(value = "/model/export/xml/{modelId}", method = RequestMethod.GET)
public void exportXml(@PathVariable("modelId") String modelId, HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = objectMapper.readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
//没有xml
if (bpmnModel.getProcesses().isEmpty()) {
response.setCharacterEncoding("utf-8");
response.getWriter().print("<script>modals.error('xml文件不存在,生成错误');</script>");
response.flushBuffer();
return;
}
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
IOUtils.copy(in, response.getOutputStream());
String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.model.xml";
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.flushBuffer();
} catch (Exception e) {
LOGGER.error("导出model的xml文件失败:modelId={}", modelId, e);
}
}
示例9: toBpmnXml
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
public String toBpmnXml(FlowDefinition definition) {
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
try {
return new String(bpmnXMLConverter.convertToXML(toBpmnModel(definition)), "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例10: bpmn20Stream
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
InputStream bpmn20Stream(BpmnModel bpmnModel) {
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
try {
String bpmn20Xml = new String(bpmnXMLConverter.convertToXML(bpmnModel), "UTF-8");
return new ByteArrayInputStream(bpmn20Xml.getBytes("UTF-8"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: addBpmnModel
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
public DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel) {
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
try {
String bpmn20Xml = new String(bpmnXMLConverter.convertToXML(bpmnModel), "UTF-8");
addString(resourceName, bpmn20Xml);
} catch (UnsupportedEncodingException e) {
throw new ActivitiException("Errot while transforming BPMN model to xml: not UTF-8 encoded", e);
}
return this;
}
示例12: export
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
/**
* 导出model对象为指定类型
*
* @param modelId 模型ID
* @param type 导出文件类型(bpmn\json)
*/
@RequestMapping(value = "export/{modelId}/{type}", method = RequestMethod.GET)
public void export(@PathVariable("modelId") String modelId,
@PathVariable("type") String type,
HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
byte[] modelEditorSource = repositoryService.getModelEditorSource(modelData.getId());
JsonNode editorNode = new ObjectMapper().readTree(modelEditorSource);
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
// 处理异常
if (bpmnModel.getMainProcess() == null) {
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
response.getOutputStream().println("no main process, can't export for type: " + type);
response.flushBuffer();
return;
}
String filename = "";
byte[] exportBytes = null;
String mainProcessId = bpmnModel.getMainProcess().getId();
if ("bpmn".equals(type)) {
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
exportBytes = xmlConverter.convertToXML(bpmnModel);
filename = mainProcessId + ".bpmn20.xml";
} else if ("json".equals(type)) {
exportBytes = modelEditorSource;
filename = mainProcessId + ".json";
}
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
/*创建输入流*/
ByteArrayInputStream in = new ByteArrayInputStream(exportBytes);
IOUtils.copy(in, response.getOutputStream());
response.flushBuffer();
in.close();
} catch (Exception e) {
// logger.error("导出model的xml文件失败:modelId={}, type={}", modelId, type, e);
}
}
示例13: convertToXmlTest
import org.activiti.bpmn.converter.BpmnXMLConverter; //导入方法依赖的package包/类
@Test
public void convertToXmlTest() throws Exception {
BpmnModel bpmnModel = buildModel();
BpmnXMLConverter converter = new BpmnXMLConverter();
String xml = new String(converter.convertToXML(bpmnModel), "UTF-8");
System.out.println(xml);
}