[转]使用Joinwork Process Studio创建jBpm和Activiti流程定义文件 [url]http://arronzhen.iteye.com/blog/1545862[/url]

将JBPM5流程文件Flow File BPMN 2.0/BPMN (*.bpmn) 转换为 PNG (*.png) 图片文件的解决方案

最近在利用JBPM5开发流程应用,在eclipse安装的插件工具drools jbpm tools 5.2.0里面没有将流程文件导出为PNG格式的图片功能。这样没有图片就不能较直观地查看到当前流程走到了哪些节点。几经周折,找了很久,终于发现一个可以变通的方法,借助其它的流程工具来做到这一点。
[color=red][b]joinwork-process-studio[/b][/color]正好是这样的工具。下载地址:
[url]http://www.bpmn123.net/bpmn/20110823/joinwork-process-studio-v31%E5%8F%91%E5%B8%83.html[/url]
或者 [url]http://www.bpmn123.net/bpmn/20110823/joinwork-process-studio-%E4%B8%8B%E8%BD%BD.html[/url]

将joinwork-process-studio安装后,可以打开eclipse的workspace中已经建好的Flow File(BPMN 2.0/BPMN 文件),接下来可以选择"生成图片文件",可以生成PNG格式的图片。另外,选定节点后可以在“外观”中对节点填充颜色。

@RequestMapping(value = "/viewWorkFlow")
  public void getCurrentNode(@RequestParam("processId") long processInstanceId, HttpServletRequest request,
                             HttpServletResponse response) throws IOException {

    JBPM5Engine engine = new JBPM5Engine(entityManagerFactory,taskEntityManagerFactory,LEAVE_WORKFLOW_LEAVE);
    ProcessInstance process = engine.getProcessInstance(processInstanceId);

    WorkflowProcessInstance wfInstance = (WorkflowProcessInstance) process;
    Iterator<NodeInstance> iterator = wfInstance.getNodeInstances().iterator();
    NodeInstance nodeInstance = iterator.next();

    //-------------------- send the work flow image ----------------------------------
    PrintWriter out = response.getWriter();

    //********** get the attributes eg : x,y,width,height .. *****************
    String xpathFile = "leave.bpmn";
    String nodeStr = "//bpmndi:BPMNDiagram/bpmndi:BPMNPlane/bpmndi:BPMNShape[@bpmnElement='_"+nodeInstance.getNodeId()+"']/dc:Bounds";
    XPathUtils xPathUtils = new XPathUtils(xpathFile,nodeStr);
    Map<String, String> attributes = xPathUtils.getAttributes();
    Element rootEl = xPathUtils.getRootElement();

    //************************************************************************


     show the work flow image in page 
    int imageWidth = Integer.parseInt(rootEl.attributeValue("width") == null? "910" : rootEl.attributeValue("width"));
    int imageHeight = Integer.parseInt(rootEl.attributeValue("height")== null ? "710" : rootEl.attributeValue("height"));


    int nodeWidth = Integer.parseInt(attributes.get("width"));
    int nodeHeight = Integer.parseInt(attributes.get("height"));
    int nodeX = Integer.parseInt(attributes.get("x"));
    int nodeY = Integer.parseInt(attributes.get("y"));
    String imageUrl = request.getContextPath()+"/processImageServlet"; //流程URL
    //流程图作为背景
    out.println("<div style=\"position:relative;background-image:url("+imageUrl+");width:"+imageWidth+"px;height:"+imageHeight+"px;\">");
    //输出当前节点位置
    out.println("<div style=\"position:absolute;left:"+nodeX+"px;top:"+nodeY+"px;width:"+(nodeWidth-1)+"px;height:"+(nodeHeight-2)+"px;border:3px solid red\">");
    out.println("</div>");
    out.println("</div>");
    out.flush();
    out.close();


    //!-------------------------------------------------------------------------------
  }