activiti5.13.1在线流程设计器生成图片中文乱码

最近在学习工作流,在整合在线流程设计器的时候,发现在流程设计器编辑出的模型数据后,部署时生成图片会中文乱码。在这里记录一下我尝试过的方法。

方法一   修改相关源码一:

org.activiti.engine.impl包中的RepositoryServiceImpl类的getModelEditorSource方法

public byte[] getModelEditorSource(String modelId) {
	  byte[] json_byte= commandExecutor.execute(new GetModelEditorSourceCmd(modelId));
	    try {
			if(!new String(json_byte).startsWith("{")){
              json_byte=new BASE64Decoder().decodeBuffer(new String(json_byte));
              return json_byte;
          }
		} catch (IOException e) {
			e.printStackTrace();
		}
      return json_byte;
  }

org.activiti.editor.rest.model包中的ModelSaveRestResource类的saveModel方法

public void saveModel(Form modelForm) {
    ObjectMapper objectMapper = new ObjectMapper();
    String modelId = (String) getRequest().getAttributes().get("modelId");
    //System.out.println("json " + modelForm.getFirstValue("json_xml"));
    
    try {
      
      /*ObjectNode modelNode = (ObjectNode) objectMapper.readTree(modelForm.getFirstValue("json_xml"));
      JsonToBpmnExport converter = new JsonToBpmnExport(modelNode);
      byte[] bpmnBytes = converter.convert();
      System.out.println("bpmn " + new String(bpmnBytes));*/
      
      RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
      Model model = repositoryService.getModel(modelId);
      
      ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
      
      modelJson.put(MODEL_NAME, modelForm.getFirstValue("name"));
      modelJson.put(MODEL_DESCRIPTION, modelForm.getFirstValue("description"));
      model.setMetaInfo(modelJson.toString());
      model.setName(modelForm.getFirstValue("name"));
      
      repositoryService.saveModel(model);
      
      //转成UTF-8 然后使用base64编码  
      String gbk=new String(modelForm.getFirstValue("json_xml").getBytes("GBK"));  
      String iso = new String(gbk.getBytes("UTF-8"),"ISO-8859-1");  
      String utf8=new String(iso.getBytes("ISO-8859-1"),"UTF-8");  
      byte[]  json_xml=new BASE64Encoder().encode(utf8.getBytes("UTF-8")).getBytes();
      
      repositoryService.addModelEditorSource(model.getId(), json_xml);
      
      InputStream svgStream = new ByteArrayInputStream(modelForm.getFirstValue("svg_xml").getBytes("utf-8"));
      TranscoderInput input = new TranscoderInput(svgStream);
      
      PNGTranscoder transcoder = new PNGTranscoder();
      // Setup output
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();
      TranscoderOutput output = new TranscoderOutput(outStream);
      
      // Do the transformation
      transcoder.transcode(input, output);
      final byte[] result = outStream.toByteArray();
      repositoryService.addModelEditorSourceExtra(model.getId(), result);
      outStream.close();
      
    } catch(Exception e) {
      LOGGER.error("Error saving model", e);
      setStatus(Status.SERVER_ERROR_INTERNAL);
    }
  }

org.activiti.editor.ui包中的EditorProcessDefinitionDetailPanel类的deployModelerModel方法

protected void deployModelerModel(final ObjectNode modelNode) {
		try {
			BpmnModel model = new BpmnJsonConverter()
					.convertToBpmnModel(modelNode);
			byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);

			String bpmnString = new String(bpmnBytes, "UTF-8");

			String processName = modelData.getName() + ".bpmn20.xml";
			Deployment deployment = repositoryService.createDeployment()
					.name(modelData.getName())
					.addString(processName, bpmnString)
					.deploy();

			ExplorerApp.get().getViewManager()
					.showDeploymentPage(deployment.getId());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


方法二    修改源码二:

org.activiti.engine.impl.bpmn.diagram.ProcessDiagramCanvas类中的 activityFontName 和 labelFontName的值为宋体。


方法三     在spring配置文件修改属性


	

	      
	      
	     
	


建议使用方法三,本人经过测试方法一和方法二并无效。

你可能感兴趣的:(activiti工作流)