activiti5学习资料(5.12版本流程图的生成)

activiti5学习资料(5.12版本流程图的生成)

描述:

activiti5.12版本,流程图的生成,在servlet将图片流输出到div层中,然后在页面上显示图形。

activiti版本:5.12版本

导入jar包:

<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-spring</artifactId>
			<version>${activiti-version}</version>
		</dependency>
		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-engine</artifactId>
			<version>${activiti-version}</version>
		</dependency>
		<dependency>
			<groupId>org.activiti</groupId>
			<artifactId>activiti-bpmn-model</artifactId>
			<version>${activiti-version}</version>
		</dependency>
		<dependency>
		    <groupId>org.activiti</groupId>
		    <artifactId>activiti-bpmn-converter</artifactId>
		    <version>${activiti-version}</version>
		</dependency>

jsp页面代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程图</title>
<%@ include file="/inc.jsp"%>
</head>
<body>
	<h2>流程图x=${point.x},y=${point.y}</h2>
	<div style="position: relative;background:url('${ctx}/bpmImage?processDefinitionId=${processDefinitionId}')  no-repeat;width:${point.x}px;height:${point.y}px;">
	</div>
</body>
</html>

servlet代码:

@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String proDefId = req.getParameter("processDefinitionId");
		// 生成图片
		InputStream is = null;
		if (StringUtils.isNotEmpty(proDefId)) {
			BpmnModel bpmnModel = repositoryService.getBpmnModel(proDefId);
			is = ProcessDiagramGenerator.generatePngDiagram(bpmnModel);
		}
		if (is != null) {
			resp.setContentType("image/png");
			OutputStream out = resp.getOutputStream();
			try {
				byte[] bs = new byte[1024];
				int n = 0;
				while ((n = is.read(bs)) != -1) {
					out.write(bs, 0, n);
				}
				out.flush();
			} catch (Exception ex) {
				ex.printStackTrace();
			} finally {
				is.close();
				out.close();
			}
		}
	}

如果想设置流程图的div的大小:

遍历流程节点的元素大小,然后获取最大的坐标信息。

代码:

import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.GraphicInfo;

/**
 * @description 流程图片辅助类
 * @description BpmImageUtil
 * @author 不了了之之了之
 * @data 2013-3-31
 */
public class BpmImageUtil {

	/**
	 * 获取流程节点元素中,最大的x,y坐标信息
	 * 
	 * @param bpmnModel
	 *            BpmnModel对象
	 * @return Point
	 */
	public static Point getPoint(BpmnModel bpmnModel) {
		Point point = null;
		if (bpmnModel != null && bpmnModel.getFlowLocationMap().size() > 0) {
			int maxX = 0;
			int maxY = 0;
			for (String key : bpmnModel.getLocationMap().keySet()) {
				GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
				double elementX = graphicInfo.getX() + graphicInfo.getWidth();
				if (maxX < elementX) {
					maxX = (int) elementX;
				}
				double elementY = graphicInfo.getY() + graphicInfo.getHeight();
				if (maxY < elementY) {
					maxY = (int) elementY;
				}
			}
			point = new Point(maxX, maxY);
		} else {
			point = new Point(100, 100);
		}
		return point;
	}
}

效果图:




你可能感兴趣的:(Activiti,业务流程,不了了之)