要想显示JBPM的流程图,首先将流程定义文件*.jpdl.xml 和 对应的*.png图片打包为*.zip文件以备上传。
上传的Servlet代码如下:
对应的Servlet代码:
这样只要将流程定义的id传给processview.jsp页面就可以了
上传的Servlet代码如下:
Code
protected void deployWithImage(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException
{
File tmpDir = null;//初始化上传文件的临时存放目录
File saveDir = null;//初始化上传文件后的保存目录
//初始化目录
String tmpPath = "c:\\tmpdir";
String savePath = "c:\\updir";
tmpDir = new File(tmpPath);
saveDir = new File(savePath);
if(!tmpDir.isDirectory())
tmpDir.mkdir();
if(!saveDir.isDirectory())
saveDir.mkdir();
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(tmpDir);//临时目录
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
servletFileUpload.setHeaderEncoding("UTF-8");
servletFileUpload.setFileSizeMax(1 * 1024 * 1024);//单个文件大小限制
List fileItems = new ArrayList();
try {
fileItems = servletFileUpload.parseRequest(request);
} catch (Exception e) {
// TODO: handle exception
System.out.println("文件上传发生错误" + e.getMessage());
}
Iterator iter = fileItems.iterator();
if (iter.hasNext()) {
FileItem item = (FileItem)iter.next();
if (!item.isFormField()) {
String name = item.getName().substring(item.getName().lastIndexOf("\\"));
long size = item.getSize();
System.out.println("name: " + name);
if (name != null && !name.equals("") && size >0) {
repositoryService.createDeployment()
.addResourcesFromZipInputStream(new ZipInputStream(item.getInputStream())).deploy();//发布流程
}
BufferedInputStream in = new BufferedInputStream(item.getInputStream());
//获得文件输出流
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(saveDir+"\\"+name)));
//把流程zip复制到指定文件夹存档
Streams.copy(in, out, true);
}
}
}
显示流程图代码如下:protected void deployWithImage(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException
{
File tmpDir = null;//初始化上传文件的临时存放目录
File saveDir = null;//初始化上传文件后的保存目录
//初始化目录
String tmpPath = "c:\\tmpdir";
String savePath = "c:\\updir";
tmpDir = new File(tmpPath);
saveDir = new File(savePath);
if(!tmpDir.isDirectory())
tmpDir.mkdir();
if(!saveDir.isDirectory())
saveDir.mkdir();
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(tmpDir);//临时目录
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
servletFileUpload.setHeaderEncoding("UTF-8");
servletFileUpload.setFileSizeMax(1 * 1024 * 1024);//单个文件大小限制
List fileItems = new ArrayList();
try {
fileItems = servletFileUpload.parseRequest(request);
} catch (Exception e) {
// TODO: handle exception
System.out.println("文件上传发生错误" + e.getMessage());
}
Iterator iter = fileItems.iterator();
if (iter.hasNext()) {
FileItem item = (FileItem)iter.next();
if (!item.isFormField()) {
String name = item.getName().substring(item.getName().lastIndexOf("\\"));
long size = item.getSize();
System.out.println("name: " + name);
if (name != null && !name.equals("") && size >0) {
repositoryService.createDeployment()
.addResourcesFromZipInputStream(new ZipInputStream(item.getInputStream())).deploy();//发布流程
}
BufferedInputStream in = new BufferedInputStream(item.getInputStream());
//获得文件输出流
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(saveDir+"\\"+name)));
//把流程zip复制到指定文件夹存档
Streams.copy(in, out, true);
}
}
}
页面processview.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程图</title>
</head>
<body>
<img style="position:absolute;left:0px;top:0px;" src="/myjbpm/WfManage?managemark=view&id=<%= request.getParameter("id") %>">
</body>
</html>
这里的id为流程定义的id<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程图</title>
</head>
<body>
<img style="position:absolute;left:0px;top:0px;" src="/myjbpm/WfManage?managemark=view&id=<%= request.getParameter("id") %>">
</body>
</html>
对应的Servlet代码:
输出流程图
if (managemark.equals("view")) {
String id = request.getParameter("id");//流程定义ID
processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).uniqueResult();
//获取流程图
InputStream io = repositoryService
.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getImageResourceName());
if(io!=null)
{
byte[] bytes = new byte[1024*4];
int size = 0;
//输出流程图
while ((size = io.read(bytes, 0, 1024*4)) != -1) {
response.getOutputStream().write(bytes,0,size);
}
}
}
if (managemark.equals("view")) {
String id = request.getParameter("id");//流程定义ID
processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).uniqueResult();
//获取流程图
InputStream io = repositoryService
.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getImageResourceName());
if(io!=null)
{
byte[] bytes = new byte[1024*4];
int size = 0;
//输出流程图
while ((size = io.read(bytes, 0, 1024*4)) != -1) {
response.getOutputStream().write(bytes,0,size);
}
}
}
这样只要将流程定义的id传给processview.jsp页面就可以了