Java Code Examples for org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl#isEnableSafeBpmnXml()

The following examples show how to use org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl#isEnableSafeBpmnXml() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BpmnParse.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public BpmnParse execute() {
  try {

    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    BpmnXMLConverter converter = new BpmnXMLConverter();

    boolean enableSafeBpmnXml = false;
    String encoding = null;
    if (processEngineConfiguration != null) {
      enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
      encoding = processEngineConfiguration.getXmlEncoding();
    }

    if (encoding != null) {
      bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
    } else {
      bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
    }

    // XSD validation goes first, then process/semantic validation
    if (validateProcess) {
      ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
      if (processValidator == null) {
        LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
      } else {
        List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
        if (validationErrors != null && !validationErrors.isEmpty()) {

          StringBuilder warningBuilder = new StringBuilder();
          StringBuilder errorBuilder = new StringBuilder();

          for (ValidationError error : validationErrors) {
            if (error.isWarning()) {
              warningBuilder.append(error.toString());
              warningBuilder.append("\n");
            } else {
              errorBuilder.append(error.toString());
              errorBuilder.append("\n");
            }
          }

          // Throw exception if there is any error
          if (errorBuilder.length() > 0) {
            throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString());
          }

          // Write out warnings (if any)
          if (warningBuilder.length() > 0) {
            LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
          }

        }
      }
    }
    
    bpmnModel.setSourceSystemId(sourceSystemId);
    bpmnModel.setEventSupport(new ActivitiEventSupport());

    // Validation successful (or no validation)

    // Attach logic to the processes (eg. map ActivityBehaviors to bpmn model elements)
    applyParseHandlers();

    // Finally, process the diagram interchange info
    processDI();

  } catch (Exception e) {
    if (e instanceof ActivitiException) {
      throw (ActivitiException) e;
    } else if (e instanceof XMLException) {
      throw (XMLException) e;
    } else {
      throw new ActivitiException("Error parsing XML", e);
    }
  }

  return this;
}
 
Example 2
Source File: BpmnParse.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public BpmnParse execute() {
    try {

        ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
        BpmnXMLConverter converter = new BpmnXMLConverter();

        boolean enableSafeBpmnXml = false;
        String encoding = null;
        if (processEngineConfiguration != null) {
            enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
            encoding = processEngineConfiguration.getXmlEncoding();
        }

        if (encoding != null) {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
        } else {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
        }

        // XSD validation goes first, then process/semantic validation
        if (validateProcess) {
            ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
            if (processValidator == null) {
                LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
            } else {
                List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
                if (validationErrors != null && !validationErrors.isEmpty()) {

                    StringBuilder warningBuilder = new StringBuilder();
                    StringBuilder errorBuilder = new StringBuilder();

                    for (ValidationError error : validationErrors) {
                        if (error.isWarning()) {
                            warningBuilder.append(error);
                            warningBuilder.append("\n");
                        } else {
                            errorBuilder.append(error);
                            errorBuilder.append("\n");
                        }
                    }

                    // Throw exception if there is any error
                    if (errorBuilder.length() > 0) {
                        throw new ActivitiException("Errors while parsing:\n" + errorBuilder);
                    }

                    // Write out warnings (if any)
                    if (warningBuilder.length() > 0) {
                        LOGGER.warn("Following warnings encountered during process validation: {}", warningBuilder);
                    }

                }
            }
        }

        bpmnModel.setSourceSystemId(sourceSystemId);
        bpmnModel.setEventSupport(new FlowableEventSupport());

        // Validation successful (or no validation)
        transformProcessDefinitions();

    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        } else if (e instanceof XMLException) {
            throw (XMLException) e;
        } else {
            throw new ActivitiException("Error parsing XML", e);
        }
    }

    return this;
}