`

Activiti在linux上出现流程图中文乱码的问题

阅读更多
第一种解决方案就是将linux的添加中文的font
public InputStream tracePhoto(String processDefinitionId, String executionId) {
		List<String> activeActivityIds = Lists.newArrayList(), highLightedFlows = new ArrayList<String>();
		if (runtimeService.createExecutionQuery().executionId(executionId).count() > 0) {
			activeActivityIds = runtimeService.getActiveActivityIds(executionId);
		}
		/**
		 * 获得当前活动的节点
		 */
		if (this.isFinished(executionId)) {// 如果流程已经结束,则得到结束节点
			activeActivityIds.add(historyService.createHistoricActivityInstanceQuery().executionId(executionId)
					.activityType("endEvent").singleResult().getActivityId());
		} else {// 如果流程没有结束,则取当前活动节点
			// 根据流程实例ID获得当前处于活动状态的ActivityId合集
			activeActivityIds = runtimeService.getActiveActivityIds(executionId);
		}
		// 获得历史活动记录实体(通过启动时间正序排序,不然有的线可以绘制不出来)
		List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
				.executionId(executionId).orderByHistoricActivityInstanceStartTime().asc().list();
		// 计算活动线
		highLightedFlows = this
				.getHighLightedFlows((ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
						.getDeployedProcessDefinition(processDefinitionId), historicActivityInstances);
		/**
		 * 绘制图形
		 */
		InputStream imageStream = null;
		if (null != activeActivityIds) {
			try {
				// 获得流程引擎配置
				ProcessEngineConfiguration processEngineConfiguration = processEngine.getProcessEngineConfiguration();
				// 根据流程定义ID获得BpmnModel
				BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
				// 输出资源内容到相应对象
				imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png", activeActivityIds,
						highLightedFlows, processEngineConfiguration.getActivityFontName(),
						processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getClassLoader(),
						1.0);
				return imageStream;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}


第二种是在tomcat中直接适应一下linux的系统建议使用第二种。
在jdk15以后,只需在~/jre/lib/fonts/下建一个fallback目录,把你想在java中使用的字体烤贝到这个目录中即可
以下方法在fc6下测试通过,假设用户的jre路径为 /usr/java/jdk1.7.63/jre/
  cd /usr/java/jdk1.7.63/jre/lib/fonts
  sudo mkdir fallback
将C:\WINDOWS\Fonts\simsun.ttc拷贝到   /usr/java//jdk1.7.63/jre/lib/fonts/fallback文件夹内
  好的你重启服务器试试。估计是OK的了

新版出现属性名称中文乱码问题
在新版的中文属性名字的title时候出现中文乱码是由于你返回的流转化为jsonString时候需要指定解析编码格式,
在requestMap上添加method = RequestMethod.GET, produces = "application/json;charset=utf-8"
@RequestMapping(value = "editor/stencilset", 
			method = RequestMethod.GET, produces = "application/json;charset=utf-8")
	@ResponseBody
	public String stencilset() {
		InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
		try {
			return IOUtils.toString(stencilsetStream, "utf-8");
		} catch (Exception e) {
			throw new RuntimeException("Error while loading stencil set", e);
		} finally {
			IOUtils.closeQuietly(stencilsetStream);
		}
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics