- 浏览: 186172 次
- 性别:
- 来自: 上海
-
文章分类
最新评论
-
springdata_spring:
java程序语言学习教程 地址http://www.zuida ...
JAVA开发者最常去的20个英文网站 -
love-_-java:
那么请问怎么单独导出jar包?我刚单独到处时:Unhandle ...
解决Eclipse中Java工程间循环引用而报错的问题 -
Hello_June:
...
使用Spring2.5的Autowired实现注释型的IOC -
两两ACE:
棒棒哒
使用Spring2.5的Autowired实现注释型的IOC -
liubang201010:
Foglight 监控OC4j 旧系统9.0.3/9.0.4等 ...
OC4J
把jbpm流程图显示在jsp页面中2008-07-10 15:08把jbpm流程图显示在jsp页面中
---------------------------------------------------------------------------------------------------------------------------
1 首先找到jbpm项目自带的 org.jbpm.webapp.servlet下的三个servlet:
deployServlet,ProcessImageServlet, UploadServlet 和org.jbpm.webapp.servlet下的processImageTag。
把这些东东copy到你的项目的src中
2 配置项目下的web.xml,代码如下:
---------------------------------------------------------------------------------------------------------------------------
<!-- jBPM -->
<servlet>
<servlet-name>ProcessImageServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.ProcessImageServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProcessImageServlet</servlet-name>
<url-pattern>/processimage</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DeployServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.DeployServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeployServlet</servlet-name>
<url-pattern>/deploy</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.UploadServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
---------------------------------------------------------------------------------------------------------------------------
3 把jbpm自带的标签定义 jbpm.tld copy到你的项目的/web-info 目录下
4 找到jbpm自带的deploy.html(把这个html放在项目的webroot根目录下,牵涉到servlet的解析问题),这就是流程定义的部署页面。
5 流程定义文件的打包:在eclipse的process definition的设计界面下打开你设计好的流程定义图,
利用designer的 “deployment”把三个文件(gpd.xml processdefiniton.xml. processimage.jpg)打包,
点击“save process archive locally”,选定“location”,点击“save without deplying”保存流程定义文件包
(当然你也可以利用desinger中的deployment server setting ,只要能把这三个文件部署到你的数据库中即可)
6 利用deploy.html部署打包好的流程定义文件包 到数据库。可以查看jbjpm_bytearray表中是否有数据,有的话则表明部署成功,
否则就是没有部署成功
7一定要把显示流程图的jsp页面(假设名字为show.jsp)放在webroot根目录下(因为牵涉到servlet的解释问题),
在jsp页面中调用 即可显示出流程图及当前节点的位置。
8如果有nullpointexception,修改UploadServlet,代码如下:
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if(jbpmContext == null)
{
jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
}
8 运行试试吧,应该能够成功的。
---------------------------------------------------------------------------------------------------------------------------
UploadServlet .java改写
---------------------------------------------------------------------------------------------------------------------------
package org.jbpm.webapp.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
public class UploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html; charset=utf-8");
response.getWriter().println(handleRequest(request));
}
public void printInput(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
StringBuffer buffer = new StringBuffer();
int read;
while ((read = inputStream.read()) != -1) {
buffer.append((char) read);
}
log.debug(buffer.toString());
}
private String handleRequest(HttpServletRequest request) {
if (!FileUpload.isMultipartContent(request)) {
log.debug("Not a multipart request");
return "Not a multipart request";
}
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
if (!iterator.hasNext()) {
log.debug("No process file in the request");
return "No process file in the request";
}
FileItem fileItem = (FileItem) iterator.next();
if (fileItem.getContentType().indexOf(
"application/x-zip-compressed") == -1) {
log.debug("Not a process archive");
return "Not a process archive";
}
return doDeployment(fileItem);
} catch (FileUploadException e) {
e.printStackTrace();
return "FileUploadException";
}
}
private String doDeployment(FileItem fileItem) {
System.out.println("文件" + fileItem.getName());
try {
ZipInputStream zipInputStream = new ZipInputStream(fileItem
.getInputStream());
//
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
// 添加代码
if (jbpmContext == null) {
JbpmConfiguration config = JbpmConfiguration.getInstance();
jbpmContext = config.createJbpmContext();
}
//
ProcessDefinition processDefinition = ProcessDefinition
.parseParZipInputStream(zipInputStream);
log.debug("创建Created a processdefinition : "
+ processDefinition.getName());
jbpmContext.deployProcessDefinition(processDefinition);
zipInputStream.close();
jbpmContext.close();
return "上传 " + processDefinition.getName() + " 成功";
} catch (IOException e) {
return "IOException";
}
}
private static Log log = LogFactory.getLog(UploadServlet.class);
}
---------------------------------------------------------------------------------------------------------------------------
ProcessImageTag 改写
---------------------------------------------------------------------------------------------------------------------------
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.tag;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.xpath.DefaultXPath;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class ProcessImageTag extends TagSupport {
private static final long serialVersionUID = 1L;
private long taskInstanceId = -1;
private long tokenInstanceId = -1;
private byte[] gpdBytes = null;
private byte[] imageBytes = null;
private Token currentToken = null;
private ProcessDefinition processDefinition = null;
static String currentTokenColor = "red";
static String childTokenColor = "blue";
static String tokenNameColor = "blue";
public void release() {
taskInstanceId = -1;
gpdBytes = null;
imageBytes = null;
currentToken = null;
}
public int doEndTag() throws JspException {
try {
initialize();
retrieveByteArrays();
if (gpdBytes != null && imageBytes != null) {
writeTable();
}
} catch (IOException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
} catch (DocumentException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
}
release();
return EVAL_PAGE;
}
private void retrieveByteArrays() {
try {
FileDefinition fileDefinition = processDefinition
.getFileDefinition();
gpdBytes = fileDefinition.getBytes("gpd.xml");
imageBytes = fileDefinition.getBytes("processimage.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeTable() throws IOException, DocumentException {
int borderWidth = 4;
Element rootDiagramElement = DocumentHelper.parseText(
new String(gpdBytes)).getRootElement();
int[] boxConstraint;
int[] imageDimension = extractImageDimension(rootDiagramElement);
String imageLink = "processimage?definitionId="
+ processDefinition.getId();
JspWriter jspOut = pageContext.getOut();
if (tokenInstanceId > 0) {
List allTokens = new ArrayList();
walkTokens(currentToken, allTokens);
jspOut
.println("<div style='position:relative; background-image:url("
+ imageLink
+ "); width: "
+ imageDimension[0]
+ "px; height: " + imageDimension[1] + "px;'>");
for (int i = 0; i < allTokens.size(); i++) {
Token token = (Token) allTokens.get(i);
// check how many tokens are on teh same level (= having the
// same parent)
int offset = i;
if (i > 0) {
while (offset > 0
&& ((Token) allTokens.get(offset - 1)).getParent()
.equals(token.getParent())) {
offset--;
}
}
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
// Adjust for borders
// boxConstraint[2]-=borderWidth*2;
// boxConstraint[3]-=borderWidth*2;
jspOut.println("<div style='position:absolute; left: "
+ boxConstraint[0] + "px; top: " + boxConstraint[1]
+ "px; ");
if (i == (allTokens.size() - 1)) {
jspOut.println("border: " + currentTokenColor);
} else {
jspOut.println("border: " + childTokenColor);
}
jspOut.println(" " + borderWidth + "px groove; " + "width: "
+ boxConstraint[2] + "px; height: " + boxConstraint[3]
+ "px;'>");
if (token.getName() != null) {
jspOut.println("<span style='color:" + tokenNameColor
+ ";font-style:italic;position:absolute;left:"
+ (boxConstraint[2] + 10) + "px;top:"
+ ((i - offset) * 20) + ";'> "
+ token.getName() + "</span>");
}
jspOut.println("</div>");
}
jspOut.println("</div>");
} else {
boxConstraint = extractBoxConstraint(rootDiagramElement);
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width="
+ imageDimension[0] + " height=" + imageDimension[1] + ">");
jspOut.println(" <tr>");
jspOut.println(" <td width=" + imageDimension[0] + " height="
+ imageDimension[1] + " style=\"background-image:url("
+ imageLink + ")\" valign=top>");
jspOut
.println(" <table border=0 cellspacing=0 cellpadding=0>");
jspOut.println(" <tr>");
jspOut.println(" <td width="
+ (boxConstraint[0] - borderWidth) + " height="
+ (boxConstraint[1] - borderWidth)
+ " style=\"background-color:transparent;\"></td>");
jspOut.println(" </tr>");
jspOut.println(" <tr>");
jspOut
.println(" <td style=\"background-color:transparent;\"></td>");
jspOut
.println(" <td style=\"border-color:"
+ currentTokenColor
+ "; border-width:"
+ borderWidth
+ "px; border-style:groove; background-color:transparent;\" width="
+ boxConstraint[2] + " height="
+ (boxConstraint[3] + (2 * borderWidth))
+ "> </td>");
jspOut.println(" </tr>");
jspOut.println(" </table>");
jspOut.println(" </td>");
jspOut.println(" </tr>");
jspOut.println("</table>");
}
}
private int[] extractBoxConstraint(Element root) {
int[] result = new int[4];
String nodeName = currentToken.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue())
.intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue())
.intValue();
return result;
}
private int[] extractBoxConstraint(Element root, Token token) {
int[] result = new int[4];
String nodeName = token.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue())
.intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue())
.intValue();
return result;
}
private int[] extractImageDimension(Element root) {
int[] result = new int[2];
result[0] = Integer.valueOf(root.attribute("width").getValue())
.intValue();
result[1] = Integer.valueOf(root.attribute("height").getValue())
.intValue();
return result;
}
private void initialize() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
// 添加代码
if (jbpmContext == null) {
JbpmConfiguration config = JbpmConfiguration.getInstance();
jbpmContext = config.createJbpmContext();
}
//
if (this.taskInstanceId > 0) {
TaskInstance taskInstance = jbpmContext.getTaskMgmtSession()
.loadTaskInstance(taskInstanceId);
currentToken = taskInstance.getToken();
} else {
if (this.tokenInstanceId > 0)
currentToken = jbpmContext.getGraphSession().loadToken(
this.tokenInstanceId);
}
processDefinition = currentToken.getProcessInstance()
.getProcessDefinition();
}
private void walkTokens(Token parent, List allTokens) {
Map children = parent.getChildren();
if (children != null && children.size() > 0) {
Collection childTokens = children.values();
for (Iterator iterator = childTokens.iterator(); iterator.hasNext();) {
Token child = (Token) iterator.next();
walkTokens(child, allTokens);
}
}
allTokens.add(parent);
}
public void setTask(long id) {
this.taskInstanceId = id;
}
public void setToken(long id) {
this.tokenInstanceId = id;
}
}
--------------------------------------------------------------------------------------------------------------------------
viewFlow.jsp
---------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html;charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/jbpm.tld" prefix="jbpm" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
long tokenId = Long.parseLong(request.getParameter("tokenId"));
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'viewFlow.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
---------------------------------------------------------------------------------------------------------------------------
1 首先找到jbpm项目自带的 org.jbpm.webapp.servlet下的三个servlet:
deployServlet,ProcessImageServlet, UploadServlet 和org.jbpm.webapp.servlet下的processImageTag。
把这些东东copy到你的项目的src中
2 配置项目下的web.xml,代码如下:
---------------------------------------------------------------------------------------------------------------------------
<!-- jBPM -->
<servlet>
<servlet-name>ProcessImageServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.ProcessImageServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProcessImageServlet</servlet-name>
<url-pattern>/processimage</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DeployServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.DeployServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeployServlet</servlet-name>
<url-pattern>/deploy</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>
org.jbpm.webapp.servlet.UploadServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
---------------------------------------------------------------------------------------------------------------------------
3 把jbpm自带的标签定义 jbpm.tld copy到你的项目的/web-info 目录下
4 找到jbpm自带的deploy.html(把这个html放在项目的webroot根目录下,牵涉到servlet的解析问题),这就是流程定义的部署页面。
5 流程定义文件的打包:在eclipse的process definition的设计界面下打开你设计好的流程定义图,
利用designer的 “deployment”把三个文件(gpd.xml processdefiniton.xml. processimage.jpg)打包,
点击“save process archive locally”,选定“location”,点击“save without deplying”保存流程定义文件包
(当然你也可以利用desinger中的deployment server setting ,只要能把这三个文件部署到你的数据库中即可)
6 利用deploy.html部署打包好的流程定义文件包 到数据库。可以查看jbjpm_bytearray表中是否有数据,有的话则表明部署成功,
否则就是没有部署成功
7一定要把显示流程图的jsp页面(假设名字为show.jsp)放在webroot根目录下(因为牵涉到servlet的解释问题),
在jsp页面中调用 即可显示出流程图及当前节点的位置。
8如果有nullpointexception,修改UploadServlet,代码如下:
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if(jbpmContext == null)
{
jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
}
8 运行试试吧,应该能够成功的。
---------------------------------------------------------------------------------------------------------------------------
UploadServlet .java改写
---------------------------------------------------------------------------------------------------------------------------
package org.jbpm.webapp.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
public class UploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html; charset=utf-8");
response.getWriter().println(handleRequest(request));
}
public void printInput(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
StringBuffer buffer = new StringBuffer();
int read;
while ((read = inputStream.read()) != -1) {
buffer.append((char) read);
}
log.debug(buffer.toString());
}
private String handleRequest(HttpServletRequest request) {
if (!FileUpload.isMultipartContent(request)) {
log.debug("Not a multipart request");
return "Not a multipart request";
}
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
if (!iterator.hasNext()) {
log.debug("No process file in the request");
return "No process file in the request";
}
FileItem fileItem = (FileItem) iterator.next();
if (fileItem.getContentType().indexOf(
"application/x-zip-compressed") == -1) {
log.debug("Not a process archive");
return "Not a process archive";
}
return doDeployment(fileItem);
} catch (FileUploadException e) {
e.printStackTrace();
return "FileUploadException";
}
}
private String doDeployment(FileItem fileItem) {
System.out.println("文件" + fileItem.getName());
try {
ZipInputStream zipInputStream = new ZipInputStream(fileItem
.getInputStream());
//
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
// 添加代码
if (jbpmContext == null) {
JbpmConfiguration config = JbpmConfiguration.getInstance();
jbpmContext = config.createJbpmContext();
}
//
ProcessDefinition processDefinition = ProcessDefinition
.parseParZipInputStream(zipInputStream);
log.debug("创建Created a processdefinition : "
+ processDefinition.getName());
jbpmContext.deployProcessDefinition(processDefinition);
zipInputStream.close();
jbpmContext.close();
return "上传 " + processDefinition.getName() + " 成功";
} catch (IOException e) {
return "IOException";
}
}
private static Log log = LogFactory.getLog(UploadServlet.class);
}
---------------------------------------------------------------------------------------------------------------------------
ProcessImageTag 改写
---------------------------------------------------------------------------------------------------------------------------
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.tag;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.xpath.DefaultXPath;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class ProcessImageTag extends TagSupport {
private static final long serialVersionUID = 1L;
private long taskInstanceId = -1;
private long tokenInstanceId = -1;
private byte[] gpdBytes = null;
private byte[] imageBytes = null;
private Token currentToken = null;
private ProcessDefinition processDefinition = null;
static String currentTokenColor = "red";
static String childTokenColor = "blue";
static String tokenNameColor = "blue";
public void release() {
taskInstanceId = -1;
gpdBytes = null;
imageBytes = null;
currentToken = null;
}
public int doEndTag() throws JspException {
try {
initialize();
retrieveByteArrays();
if (gpdBytes != null && imageBytes != null) {
writeTable();
}
} catch (IOException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
} catch (DocumentException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
}
release();
return EVAL_PAGE;
}
private void retrieveByteArrays() {
try {
FileDefinition fileDefinition = processDefinition
.getFileDefinition();
gpdBytes = fileDefinition.getBytes("gpd.xml");
imageBytes = fileDefinition.getBytes("processimage.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeTable() throws IOException, DocumentException {
int borderWidth = 4;
Element rootDiagramElement = DocumentHelper.parseText(
new String(gpdBytes)).getRootElement();
int[] boxConstraint;
int[] imageDimension = extractImageDimension(rootDiagramElement);
String imageLink = "processimage?definitionId="
+ processDefinition.getId();
JspWriter jspOut = pageContext.getOut();
if (tokenInstanceId > 0) {
List allTokens = new ArrayList();
walkTokens(currentToken, allTokens);
jspOut
.println("<div style='position:relative; background-image:url("
+ imageLink
+ "); width: "
+ imageDimension[0]
+ "px; height: " + imageDimension[1] + "px;'>");
for (int i = 0; i < allTokens.size(); i++) {
Token token = (Token) allTokens.get(i);
// check how many tokens are on teh same level (= having the
// same parent)
int offset = i;
if (i > 0) {
while (offset > 0
&& ((Token) allTokens.get(offset - 1)).getParent()
.equals(token.getParent())) {
offset--;
}
}
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
// Adjust for borders
// boxConstraint[2]-=borderWidth*2;
// boxConstraint[3]-=borderWidth*2;
jspOut.println("<div style='position:absolute; left: "
+ boxConstraint[0] + "px; top: " + boxConstraint[1]
+ "px; ");
if (i == (allTokens.size() - 1)) {
jspOut.println("border: " + currentTokenColor);
} else {
jspOut.println("border: " + childTokenColor);
}
jspOut.println(" " + borderWidth + "px groove; " + "width: "
+ boxConstraint[2] + "px; height: " + boxConstraint[3]
+ "px;'>");
if (token.getName() != null) {
jspOut.println("<span style='color:" + tokenNameColor
+ ";font-style:italic;position:absolute;left:"
+ (boxConstraint[2] + 10) + "px;top:"
+ ((i - offset) * 20) + ";'> "
+ token.getName() + "</span>");
}
jspOut.println("</div>");
}
jspOut.println("</div>");
} else {
boxConstraint = extractBoxConstraint(rootDiagramElement);
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width="
+ imageDimension[0] + " height=" + imageDimension[1] + ">");
jspOut.println(" <tr>");
jspOut.println(" <td width=" + imageDimension[0] + " height="
+ imageDimension[1] + " style=\"background-image:url("
+ imageLink + ")\" valign=top>");
jspOut
.println(" <table border=0 cellspacing=0 cellpadding=0>");
jspOut.println(" <tr>");
jspOut.println(" <td width="
+ (boxConstraint[0] - borderWidth) + " height="
+ (boxConstraint[1] - borderWidth)
+ " style=\"background-color:transparent;\"></td>");
jspOut.println(" </tr>");
jspOut.println(" <tr>");
jspOut
.println(" <td style=\"background-color:transparent;\"></td>");
jspOut
.println(" <td style=\"border-color:"
+ currentTokenColor
+ "; border-width:"
+ borderWidth
+ "px; border-style:groove; background-color:transparent;\" width="
+ boxConstraint[2] + " height="
+ (boxConstraint[3] + (2 * borderWidth))
+ "> </td>");
jspOut.println(" </tr>");
jspOut.println(" </table>");
jspOut.println(" </td>");
jspOut.println(" </tr>");
jspOut.println("</table>");
}
}
private int[] extractBoxConstraint(Element root) {
int[] result = new int[4];
String nodeName = currentToken.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue())
.intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue())
.intValue();
return result;
}
private int[] extractBoxConstraint(Element root, Token token) {
int[] result = new int[4];
String nodeName = token.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue())
.intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue())
.intValue();
return result;
}
private int[] extractImageDimension(Element root) {
int[] result = new int[2];
result[0] = Integer.valueOf(root.attribute("width").getValue())
.intValue();
result[1] = Integer.valueOf(root.attribute("height").getValue())
.intValue();
return result;
}
private void initialize() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
// 添加代码
if (jbpmContext == null) {
JbpmConfiguration config = JbpmConfiguration.getInstance();
jbpmContext = config.createJbpmContext();
}
//
if (this.taskInstanceId > 0) {
TaskInstance taskInstance = jbpmContext.getTaskMgmtSession()
.loadTaskInstance(taskInstanceId);
currentToken = taskInstance.getToken();
} else {
if (this.tokenInstanceId > 0)
currentToken = jbpmContext.getGraphSession().loadToken(
this.tokenInstanceId);
}
processDefinition = currentToken.getProcessInstance()
.getProcessDefinition();
}
private void walkTokens(Token parent, List allTokens) {
Map children = parent.getChildren();
if (children != null && children.size() > 0) {
Collection childTokens = children.values();
for (Iterator iterator = childTokens.iterator(); iterator.hasNext();) {
Token child = (Token) iterator.next();
walkTokens(child, allTokens);
}
}
allTokens.add(parent);
}
public void setTask(long id) {
this.taskInstanceId = id;
}
public void setToken(long id) {
this.tokenInstanceId = id;
}
}
--------------------------------------------------------------------------------------------------------------------------
viewFlow.jsp
---------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html;charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/jbpm.tld" prefix="jbpm" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
long tokenId = Long.parseLong(request.getParameter("tokenId"));
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'viewFlow.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
发表评论
-
jboss ESB 服务编排
2011-05-02 20:03 4105jboss ESB 是企业服务总线,应用很广,但资料很少,而且 ... -
spring2.5.4+hibernate3.2.6+struts2+jbpm3.2.2
2009-07-25 00:52 19721.首先我们要介绍 web.xml文件: <?xml ... -
jBPM相关概念
2009-06-18 10:54 1094jBPM相关概念 1. JPDL的流程定义元 ... -
jBPM相关概念
2008-11-25 16:53 1343jBPM相关概念2008-07-10 17:15关键字:jbp ... -
jbpm]在JSP页面中显示JBPM流程图
2008-11-25 16:50 6730[jbpm]在JSP页面中显示JBPM流程图2008-07-1 ...
相关推荐
本主题将详细介绍如何将jbpm流程图显示在JSP(JavaServer Pages)页面上,这涉及到jbpm的图像标签库(taglib)和`web.xml`配置文件的使用。 首先,jbpm提供的图像标签库允许开发者在JSP页面中直接嵌入流程图。`jbpm...
1. 设计和建模:使用BPMN(Business Process Model and Notation)工具绘制工作流程图,并导出为jbpm可识别的格式。 2. 编码:编写Java服务类实现业务逻辑,以及Servlet处理HTTP请求。 3. 配置:设置数据库连接,...
- **节点与连接**: 流程图中的节点表示流程的步骤,连接则表示步骤之间的转移条件。 2. **jbpm4.4 API 使用** - **ProcessEngine**: jbpm的核心组件,负责流程的生命周期管理,如启动、暂停、继续和结束流程。 -...
在JBoss JBPM4中,我们可以使用jbpm-designer工具来设计流程图,然后将其导出为XML格式的.bpel文件。 2. **请假申请任务**:流程开始时,员工提交请假申请,这对应于一个任务节点。任务数据可能包括请假人、请假...
在请假流程的实现中,jbPM提供了一种方式来定义流程图,即BPML(Business Process Modeling Notation),这是一种图形化的表示方法,用于描述业务流程中的各个步骤和决策。流程图中包含了开始事件、结束事件、用户...
jBPM(Java Business Process Management)是一个开源的工作流和业务流程管理框架,它允许开发者在Java应用程序中实现复杂的业务流程。jBPM4.4是该框架的一个较早版本,但仍然具有广泛的适用性和学习价值。在这个...
在这个借款例子中,JSP页面可能包含了用户输入表单、显示流程状态、处理用户请求等功能。开发者可能使用JSP标签库(Tag Libraries)来简化代码,例如JSTL(JavaServer Pages Standard Tag Library),它提供了一系列...
- **图形化界面**:以拖放方式创建流程图,使得非技术人员也能理解流程结构。 - **任务编辑**:定义任务属性,如参与者、优先级和截止日期。 - **连接线编辑**:设置条件分支和顺序流,控制流程的流转。 - **预览...
- **设计jsp页面**: 设计用户交互界面,显示任务列表,提供完成任务的按钮。 - **流程交互**: 通过servlet与jbpm服务交互,如调用`RuntimeManager`和`RuntimeEngine`启动流程,使用`TaskService`进行任务操作。 **4...
9. **编写人机交互页面**:使用SSH框架的视图层(如JSP)开发用户界面,用于展示流程状态和进行操作。 10. **编写后台程序**:结合Spring的依赖注入,编写服务层代码来处理流程的启动、审批等业务逻辑。 在实际...
流程设计器是JBPM提供的一种图形化工具,用户可以通过拖拽和配置节点来直观地创建流程图。这个工具使得非技术人员也能参与到流程设计中,提高了工作效率。在视频中,讲解者将引导你逐步操作流程设计器,创建并保存...
4. **workflow.JPG** - 可能是一个流程图,展示jBPM4中的工作流实例,帮助开发者理解和跟踪流程执行。 5. **FillLeaveForm.jsp** - 这是一个JSP(Java Server Pages)文件,可能用于员工填写请假申请的界面,用户...
通过jbpm,你可以设计流程图,定义流程中的各个步骤、决策点、并行分支和事件,并将其转换为可执行的代码。 项目中包含的"web版"部分意味着你将在Web应用程序中实现jbpm的功能。这通常涉及到在Java应用服务器(如...
jbpm学习笔记主要涵盖了jbpm(Java Business Process Management)的多个方面,包括Signavio的使用和配置、jBPM数据库的安装、Graphical Process Designer(GPD)的安装以及jBPM在Eclipse环境中的配置。以下是这些...
- **流程建模**:使用图形化的BPMN编辑器设计流程图,并生成XML流程定义文件。 - **任务管理**:提供任务分配、任务查询、任务完成等功能,支持多用户协作。 - **事件处理**:支持事件触发流程的开始、结束或转移...
根据提供的信息,我们可以总结并生成相关的IT知识点,但首先需要明确的是,“abcdef语言宝典介绍”的标题和描述中提到的“abc语言”并未在提供的内容中详细解释或定义。因此,我们将围绕已有的信息,尤其是关于Java...
开发者可以通过jbpm-gwt-console(通常包含在webjbpm中)来设计流程图,并将其转换为XML格式的流程定义文件(.bpmn20.xml)。这些文件随后可以在应用程序中加载,供用户启动和跟踪流程实例。 在这个例子中,webjbpm...
1. **流程定义(Process Definition)**: 在JBPM4中,业务流程以BPMN2(Business Process Model and Notation 2.0)的XML文件形式进行定义,包含了流程图中的各个节点和连接线,如任务(Task)、事件(Event)、网关...