/// <summary> /// Parse a camunda:resource attribute and loads the resource depending on the url scheme. /// Supported Uri schemes are <code>classpath://</code> and <code>deployment://</code>. /// If the scheme is omitted <code>classpath://</code> is assumed. /// </summary> /// <param name="resourcePath"> the path to the resource to load </param> /// <param name="deployment"> the deployment to load resources from </param> /// <returns> the resource content as <seealso cref="string" /> </returns> public static string LoadResourceContent(string resourcePath, DeploymentEntity deployment) { var pathSplit = resourcePath.Split("://", true); string resourceType; if (pathSplit.Length == 1) { resourceType = "classpath"; } else { resourceType = pathSplit[0]; } var resourceLocation = pathSplit[pathSplit.Length - 1]; byte[] resourceBytes = null; if (resourceType.Equals("classpath")) { Stream resourceAsStream = null; try { resourceAsStream = ReflectUtil.GetResourceAsStream(resourceLocation); if (resourceAsStream != null) { resourceBytes = IoUtil.ReadInputStream(resourceAsStream, resourcePath); } } finally { IoUtil.CloseSilently(resourceAsStream); } } else if (resourceType.Equals("deployment")) { ResourceEntity resourceEntity = deployment.GetResource(resourceLocation); if (resourceEntity != null) { resourceBytes = resourceEntity.Bytes; } } if (resourceBytes != null) { return(StringHelperClass.NewString(resourceBytes, Encoding.UTF8.ToString())); } throw Log.CannotFindResource(resourcePath); }
public virtual void TestProcessDiagramResource() { IProcessDefinition processDefinition = repositoryService.CreateProcessDefinitionQuery().First(); Assert.AreEqual("resources/Bpmn/Deployment/BpmnDeploymentTest.TestProcessDiagramResource.bpmn20.xml".ToLower(), processDefinition.ResourceName.ToLower()); Assert.True(processDefinition.GetHasStartFormKey()); string diagramResourceName = processDefinition.DiagramResourceName; Assert.AreEqual("resources/Bpmn/Deployment/BpmnDeploymentTest.TestProcessDiagramResource.jpg".ToLower(), diagramResourceName.ToLower()); System.IO.Stream diagramStream = repositoryService.GetResourceAsStream(DeploymentId, "resources/Bpmn/Deployment/BpmnDeploymentTest.TestProcessDiagramResource.jpg"); byte[] diagramBytes = IoUtil.ReadInputStream(diagramStream, "diagram stream"); Assert.AreEqual(33343, diagramBytes.Length); }
private string ReadInputStreamToString(System.IO.Stream inputStream) { byte[] bytes = IoUtil.ReadInputStream(inputStream, "input stream"); return(StringHelperClass.NewString(bytes)); }