From b70f1045bd390b4bc174df0292c9353d463495e7 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 28 Mar 2014 16:44:50 -0400 Subject: [PATCH] Support "file://" prefixed flow registry base path Issue: SWF-1617 --- .../webflow/config/FlowDefinitionResourceFactory.java | 10 +++++++--- .../config/FlowDefinitionResourceFactoryTests.java | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowDefinitionResourceFactory.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowDefinitionResourceFactory.java index 3b7408e1..38eafe17 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowDefinitionResourceFactory.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowDefinitionResourceFactory.java @@ -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 { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/FlowDefinitionResourceFactoryTests.java b/spring-webflow/src/test/java/org/springframework/webflow/config/FlowDefinitionResourceFactoryTests.java index 2640bbd8..69cb3a94 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/config/FlowDefinitionResourceFactoryTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/FlowDefinitionResourceFactoryTests.java @@ -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");