public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml) { return convertToBpmnModel(inputStreamProvider, validateSchema, enableSafeBpmnXml, DEFAULT_ENCODING); }
protected boolean validateModel(Resource resource, final RepositoryService repositoryService) { try { BpmnXMLConverter converter = new BpmnXMLConverter(); BpmnModel bpmnModel = converter.convertToBpmnModel(new InputStreamSource(resource.getInputStream()), true, false); List<ValidationError> validationErrors = repositoryService.validateProcess(bpmnModel);
return convertToBpmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new XMLException("The bpmn 2.0 xml is not UTF8 encoded", e);
bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding); } else { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
public static void importModel(RepositoryService repositoryService, File modelFile) throws IOException, XMLStreamException { InputStreamReader reader = new InputStreamReader(new FileInputStream(modelFile), "utf-8"); String fileContent = IOUtils.readStringAndClose(reader, (int) modelFile.length()); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(new StringStreamSourceEx(fileContent), false, false); String processName = bpmnModel.getMainProcess().getName(); if (processName == null || processName.isEmpty()) { processName = bpmnModel.getMainProcess().getId(); } Model modelData = repositoryService.newModel(); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelData.setMetaInfo(modelObjectNode.toString()); modelData.setName(processName); modelData.setKey(modelFile.getName()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), fileContent.getBytes("utf-8")); Logger.getLogger(ModelUtils.class) .info(String.format("importing model file: %s", modelFile.getCanonicalPath())); } }
public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml) { return convertToBpmnModel(inputStreamProvider, validateSchema, enableSafeBpmnXml, DEFAULT_ENCODING); }
/** * Constructs BPMN model from the XML string and validates * * @param xmlString the Activiti XML * * @return the BPMN Model. * @throws UnsupportedEncodingException if the encoding wasn't supported. * @throws XMLStreamException if the XML couldn't be streamed. */ public BpmnModel constructBpmnModelFromXmlAndValidate(String xmlString) throws UnsupportedEncodingException, XMLStreamException { InputStreamSource source = new InputStreamSource(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8))); return new BpmnXMLConverter().convertToBpmnModel(source, true, true); } }
/** * Constructs BPMN model from the XML string and validates * * @param xmlString the Activiti XML * * @return the BPMN Model. * @throws UnsupportedEncodingException if the encoding wasn't supported. * @throws XMLStreamException if the XML couldn't be streamed. */ public BpmnModel constructBpmnModelFromXmlAndValidate(String xmlString) throws UnsupportedEncodingException, XMLStreamException { InputStreamSource source = new InputStreamSource(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8))); return new BpmnXMLConverter().convertToBpmnModel(source, true, true); } }
return convertToBpmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new RuntimeException("The bpmn 2.0 xml is not UTF8 encoded", e);
final BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(bpmnInputStreamSource, false, false);
@RequiresPermissions("flowdefine") @RequestMapping("/admin/flowdefine/deploy") public String deploy(Long id, ModelMap model) { String view = REDIRECT_LIST_HTML; try { FlowDefine flow = manager.findById(id); BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(flow.getContent())); BpmnModel bpmnModel = bpmnXMLConverter.convertToBpmnModel(reader); Deployment deployment = repositoryService.createDeployment() .addBpmnModel("dynamic-model.bpmn", bpmnModel).name(flow.getName()) .deploy(); } catch (Exception e) { log.error("部署失败", e); model.addAttribute("erro", e.getMessage()); } return view; }
return convertToBpmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new XMLException("The bpmn 2.0 xml is not UTF8 encoded", e);
bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding); } else { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
bpmnModel = converter.convertToBpmnModel(streamSource, true, enableSafeBpmnXml);
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnXMLConverter converter = new BpmnXMLConverter(); BpmnModel bpmnModel = converter.convertToBpmnModel(xtr); process = bpmnModel.getProcesses().get(0); } catch (Exception e) {
public BpmnModel execute(CommandContext commandContext) { if (processDefinitionId == null) { throw new ActivitiIllegalArgumentException("processDefinitionId is null"); } // Find the bpmn 2.0 xml resource name which is stored on the process definition ProcessDefinitionEntity processDefinitionEntity = commandContext .getProcessDefinitionEntityManager() .findProcessDefinitionById(processDefinitionId); if (processDefinitionEntity == null) { throw new ActivitiObjectNotFoundException("Process definition does not exist: " + processDefinitionId, ProcessDefinitionEntity.class); } // Fetch the resource String resourceName = processDefinitionEntity.getResourceName(); ResourceEntity resource = commandContext.getResourceEntityManager() .findResourceByDeploymentIdAndResourceName(processDefinitionEntity.getDeploymentId(), resourceName); if (resource == null) { if (commandContext.getDeploymentEntityManager().findDeploymentById(processDefinitionEntity.getDeploymentId()) == null) { throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: " + processDefinitionEntity.getDeploymentId(), Deployment.class); } else { throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName + "' in deployment '" + processDefinitionEntity.getDeploymentId() + "'", InputStream.class); } } // Convert the bpmn 2.0 xml to a bpmn model BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); return bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false); // no need to validate schema, it was already validated on deploy }