WorkflowAction.java
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. package com.bjsxt.oa.web.actions;
  2. import java.io.ByteArrayInputStream;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import org.dom4j.io.SAXReader;
  9. import com.bjsxt.oa.managers.WorkflowManager;
  10. import com.bjsxt.oa.model.Workflow;
  11. import com.bjsxt.oa.web.forms.WorkflowActionForm;
  12. public class WorkflowAction extends BaseAction {
  13. private WorkflowManager workflowManager;
  14. /**
  15.  * 打开流程管理主界面,列出当前所有的流程
  16.  */
  17. @Override
  18. protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  19. request.setAttribute("workflows", workflowManager.searchAllWorkflows());
  20. return mapping.findForward("index");
  21. }
  22. //添加流程定义
  23. public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  24. WorkflowActionForm waf = (WorkflowActionForm)form;
  25. //TODO 做一些判断,判断上传的文件是否为空,决定是否抛出异常,等等!!
  26. //部署流程
  27. workflowManager.deployProcessDefinition(
  28. waf.getProcessDefinition().getFileData(), 
  29. waf.getProcessImage().getFileData()
  30. );
  31. return mapping.findForward("add_success");
  32. }
  33. //删除流程定义
  34. public ActionForward del(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  35. WorkflowActionForm waf = (WorkflowActionForm)form;
  36. workflowManager.delWorkflow(waf.getId());
  37. return mapping.findForward("pub_del_success");
  38. }
  39. //打开查看流程图片的界面
  40. public ActionForward openViewImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  41. return mapping.findForward("flow_image");
  42. }
  43. //查看图片(此请求由flow_image.jsp中的<img src="workflow.do?method=viewImage">发起的请求)
  44. public ActionForward viewImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  45. WorkflowActionForm waf = (WorkflowActionForm)form;
  46. Workflow wf = workflowManager.findWorkflow(waf.getId());
  47. response.setContentType("image/jpeg");
  48. response.getOutputStream().write(wf.getProcessImage());
  49. return null;
  50. }
  51. //查看流程定义文件的内容
  52. public ActionForward viewFlowDef(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  53. WorkflowActionForm waf = (WorkflowActionForm)form;
  54. Workflow wf = workflowManager.findWorkflow(waf.getId());
  55. byte[] defs = wf.getProcessDefinition();
  56. //将byte[]转换为字符串
  57. //String defString = new String(defs,"UTF-8");
  58. //为了避免硬编码encoding,可以利用dom4j工具来帮助我们转换xml文件
  59. String defString = new SAXReader().read(
  60. new ByteArrayInputStream(defs)
  61. ).asXML();
  62. request.setAttribute("def", defString);
  63. return mapping.findForward("flow_def");
  64. }
  65. public void setWorkflowManager(WorkflowManager workflowManager) {
  66. this.workflowManager = workflowManager;
  67. }
  68. }