Support "file://" prefixed flow registry base path

Issue: SWF-1617
This commit is contained in:
Rossen Stoyanchev
2014-03-28 16:44:50 -04:00
parent a802c383fc
commit b70f1045bd
2 changed files with 13 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2004-2012 the original author or authors.
* Copyright 2004-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,8 @@ public class FlowDefinitionResourceFactory {
private static final String CLASSPATH_STAR_SCHEME = "classpath*:";
private static final String FILESYSTEM_SCHEME = "file:";
private static final String SLASH = "/";
private ResourceLoader resourceLoader;
@@ -193,7 +195,7 @@ public class FlowDefinitionResourceFactory {
if (basePath == null) {
return getFlowIdFromFileName(flowResource);
}
String basePath = removeClasspathScheme(this.basePath);
String basePath = removeScheme(this.basePath);
String filePath;
if (flowResource instanceof ContextResource) {
filePath = ((ContextResource) flowResource).getPathWithinContext();
@@ -246,9 +248,11 @@ public class FlowDefinitionResourceFactory {
}
}
private String removeClasspathScheme(String basePath) {
private String removeScheme(String basePath) {
if (basePath.startsWith(CLASSPATH_SCHEME)) {
return basePath.substring(CLASSPATH_SCHEME.length());
} else if (basePath.startsWith(FILESYSTEM_SCHEME)) {
return basePath.substring(FILESYSTEM_SCHEME.length());
} else if (basePath.startsWith(CLASSPATH_STAR_SCHEME)) {
return basePath.substring(CLASSPATH_STAR_SCHEME.length());
} else {

View File

@@ -46,6 +46,12 @@ public class FlowDefinitionResourceFactoryTests extends TestCase {
assertEquals("booking-flow", factory.getFlowId(resource));
}
public void testGetFlowIdFileSystemResourceBasePathMatch() {
Resource resource = new FileSystemResource("/the/path/on/the/file/system/sample-flow.xml");
factory.setBasePath("file:/the/path");
assertEquals("on/the/file/system", factory.getFlowId(resource));
}
public void testGetFlowIdCustomBasePath() {
Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml");
factory.setBasePath("WEB-INF");