最近研究activiti的高亮流程图,发现中文是乱码,为了让大家少走弯路共享出来。

本文包含三个主要技术点:

1、spring MVC架构下输出动态图片

2、获得activiti流程图的stream流

3、实现执行的任务高亮和中文无乱码

首先修改activiti.cfg.xml文件

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

          <!-- 配置数据源,和系统使用同一个数据源 -->
<property name="dataSource" ref="dataSource" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" /> <property name="transactionManager" ref="transactionManager" />
<!-- 下面这两行是关于中文乱码的,不知道为什么选择微软雅黑不生效,可能和tomcat容器下找不到字库有关系,切忌,修改这里后还要修改java代码 -->
<property name="activityFontName" value="宋体" />
<property name="labelFontName" value="宋体" />
</bean>

然后是java代码

@RequestMapping(value = "/taskImg", method = RequestMethod.GET)
@ResponseBody
protected String taskImg(
HttpServletResponse response,
@RequestParam(value = "processInstanceId", required = true) String processInstanceId)
throws IOException {
//根据流程定义ID获得流程实例
ProcessInstance pi = this.engine.getRuntimeService()
.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
BpmnModel bpmnModel = this.engine.getRepositoryService().getBpmnModel(
pi.getProcessDefinitionId()); // 得到正在执行的环节
List<String> activeIds = this.engine.getRuntimeService()
.getActiveActivityIds(pi.getId());
DefaultProcessDiagramGenerator dpg = new DefaultProcessDiagramGenerator();
//获得流程图的流对象,这里显示的加载了字体
InputStream is = dpg.generateDiagram(bpmnModel, "png", activeIds,
Collections.<String> emptyList(), this.engine
.getProcessEngineConfiguration().getActivityFontName(),
this.engine.getProcessEngineConfiguration().getLabelFontName(),
null, 1.0);
//输出流准备
int readSize = 0;
byte[] data = new byte[8192];
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
//每次读出8192字节
while ((readSize = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, readSize);
}
is.close();//关闭原始流 //根据response的输出流,即客户端流
ServletOutputStream toClient = response.getOutputStream(); // 得到向客户端输出二进制数据的对象 toClient.write(buffer.toByteArray()); // 输出数据
toClient.flush();
//关闭输出流
toClient.close();
//图片流已经从response对象输出了,函数返回null就可以了
return null;
}

Activiti 5.16 流程图高亮追踪 中文乱码问题解决方法的更多相关文章

  1. WingIDE中文乱码问题解决方法

    WingIDE中文乱码问题解决方法 安装完WingIDE后,首次运行python脚本时,若脚本中含有UTF-8中文,在Debug I/O输出框中,全部变成了乱码. 这时其实我们设置下WingIDE的编 ...

  2. 【转】asp.net Cookie值中文乱码问题解决方法

    来源:脚本之家.百度空间.网易博客 http://www.jb51.net/article/34055.htm http://hi.baidu.com/honfei http://tianminqia ...

  3. soapUI参数中文乱码问题解决方法 (groovy脚本中文乱码)

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  4. LoadRunner中文乱码问题解决方法

    LoadRunner中文乱码问题解决方法 前段时间在录制,增强,整合LoadRunner脚本,期间两次遇到了中文乱码问题.在此记录一下中文乱码问题的解决办法. 一.录制回放中文乱码 我录制登陆的脚本, ...

  5. python3 库pandas写入csv格式文件出现中文乱码问题解决方法

    python3 库pandas写入csv格式文件出现中文乱码问题解决方法 解决方案: 问题是使用pandas的DataFrame的to_csv方法实现csv文件输出,但是遇到中文乱码问题,已验证的正确 ...

  6. soapUI参数中文乱码问题解决方法&soap UI工具进行web接口测试

    soapUI参数中文乱码问题解决方法 可能方案1: 字体不支持中文,将字体修改即可: file-preferences-editor settings-select font 修改字体,改成能显示中文 ...

  7. tomcat启动控制台中文乱码问题解决方法

    tomcat启动控制台中文乱码问题解决方法,修改tomcat安装路径/conf/logging.properties文件 java.util.logging.ConsoleHandler.encodi ...

  8. tomcat项目中文乱码问题解决方法

    在部署tomcat项目时经常会遇到中文乱码问题,解决的方法可参考以下步骤. 1.更改Tomcat安装目录下的conf\server.xml,指定浏览器的编码格式为"utf-8"格式 ...

  9. JSP中文乱码问题解决方法小结

    在使用JSP的过程中,最使人头疼的一个问题就是中文乱码问题,以下是我在软件开发中遇到的乱 码问题以及解决方法. 1.JSP页面乱码 这种乱码的原因是应为没有在页面里指定使用的字符集编码,解决方法:只要 ...

随机推荐

  1. Notes from Data Guard

    There are two types of Standby databases: 1, Physical standby database block-for-block basis the phy ...

  2. iptables修改

    https://fedoraproject.org/wiki/How_to_edit_iptables_rules?rd=User_talk:Rforlot Listing Rules Current ...

  3. 用VMware 8安装Ubuntu 12.04具体过程(图解)

    图解演示环境版本号: 本机系统: WIN7 虚拟机:VMware Workstation 8 (英文版) 安装目标:Ubuntu Desktop 12.04 LTS  (请点击这里)先下载好iso镜像 ...

  4. .align

    .align的作用是针对指令或数据的存放地址对齐.但不同的CPU架构,指令和数据的存储方式不同,也就导致对齐的计量单位不一样. i386:n对齐 ARM:2^n 对齐,ARM架构下,指令都是占32位, ...

  5. iOS自定义转场动画实战讲解

    iOS自定义转场动画实战讲解   转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...

  6. 转载-好用的linux软件合集

    音频 Airtime – Airtime 是一款用于调度和远程站点管理的开放广播软件  Ardour – 在 Linux 上录音,编辑,和混音  Audacious – 开源音频播放器,按你想要的方式 ...

  7. java - day15 - NonameInner

    匿名内部类 public interface Inter {} interface Inter2{ void show(); } main(){ //错误,接口不能实例化 Inter t = new ...

  8. Debian run jar like a native program

    sudo apt install binfmt-support jarwrapper 比如 swagger-codegen wget -O ~/.local/bin/swagger-codegen h ...

  9. driver makefile

    1.单模块单文件//*********************************************obj-m := hello.o KDIR := /home/akaedu/kernel/ ...

  10. oracle数据库中VARCHAR2(50 CHAR) 和VARCHAR2(50) 有啥区别?

    VARCHAR2(50 char)这种类型的字段最多放50个字符,不够50个用空格填充:而VARCHAR2(50)最大允许存放50个字符,但是不足50个也不用空格填充.varchar2是变长字符串,与 ...