/** * Create a file-based based resource from the file path provided. * @param path the {@link FileSystemResource} path * @return the file-based flow definition resource */ public FlowDefinitionResource createFileResource(String path) { Resource resource = new FileSystemResource(new File(path)); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
/** * Create a classpath-based resource from the path provided. * @param path the {@link ClassPathResource} path * @param clazz to specify if the path should be relative to another class * @return the classpath-based flow definition resource */ public FlowDefinitionResource createClassPathResource(String path, Class<?> clazz) { Resource resource = new ClassPathResource(path, clazz); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
/** * Create an array of flow definition resources from the path pattern location provided. * @param pattern the encoded {@link Resource} path pattern. * @param attributes meta attributes to apply to each flow definition resource * @return the flow definition resources */ public FlowDefinitionResource[] createResources(String pattern, AttributeMap<Object> attributes) throws IOException { if (resourceLoader instanceof ResourcePatternResolver) { ResourcePatternResolver resolver = (ResourcePatternResolver) resourceLoader; Resource[] resources; if (basePath == null) { resources = resolver.getResources(pattern); } else { if (basePath.endsWith(SLASH) || pattern.startsWith(SLASH)) { resources = resolver.getResources(basePath + pattern); } else { resources = resolver.getResources(basePath + SLASH + pattern); } } FlowDefinitionResource[] flowResources = new FlowDefinitionResource[resources.length]; for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; flowResources[i] = new FlowDefinitionResource(getFlowId(resource), resource, attributes); } return flowResources; } else { throw new IllegalStateException( "Cannot create flow definition resources from patterns without a ResourceLoader configured that is a ResourcePatternResolver"); } }
/** * Create a flow definition resource from the path location provided. The returned resource will be configured with * the provided attributes and flow id. * @param path the encoded {@link Resource} path. * @param attributes the flow definition meta attributes to configure * @param flowId the flow definition id to configure * @return the flow definition resource */ public FlowDefinitionResource createResource(String path, AttributeMap<Object> attributes, String flowId) { Resource resource; if (basePath == null) { resource = resourceLoader.getResource(path); } else { try { String basePath = this.basePath; if (!basePath.endsWith(SLASH)) { // the basePath must end with a slash to create a relative resource basePath = basePath + SLASH; } resource = resourceLoader.getResource(basePath).createRelative(path); } catch (IOException e) { throw new IllegalStateException("The base path cannot be resolved from '" + basePath + "': " + e.getMessage()); } } if (flowId == null || flowId.length() == 0) { flowId = getFlowId(resource); } return new FlowDefinitionResource(flowId, resource, attributes); }
/** * Create a classpath-based resource from the path provided. * @param path the {@link ClassPathResource} path * @param clazz to specify if the path should be relative to another class * @return the classpath-based flow definition resource */ public FlowDefinitionResource createClassPathResource(String path, Class<?> clazz) { Resource resource = new ClassPathResource(path, clazz); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
/** * Create a file-based based resource from the file path provided. * @param path the {@link FileSystemResource} path * @return the file-based flow definition resource */ public FlowDefinitionResource createFileResource(String path) { Resource resource = new FileSystemResource(new File(path)); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
/** * Create a classpath-based resource from the path provided. * @param path the {@link ClassPathResource} path * @param clazz to specify if the path should be relative to another class * @return the classpath-based flow definition resource */ public FlowDefinitionResource createClassPathResource(String path, Class clazz) { Resource resource = new ClassPathResource(path, clazz); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
/** * Create a file-based based resource from the file path provided. * @param path the {@link FileSystemResource} path * @return the file-based flow definition resource */ public FlowDefinitionResource createFileResource(String path) { Resource resource = new FileSystemResource(new File(path)); return new FlowDefinitionResource(getFlowId(resource), resource, null); }
public void testGetFlowIdNoBasePath() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); assertEquals("booking-flow", factory.getFlowId(resource)); }
public void testGetFlowIdClassPathStarResource() { Resource resource = new ClassPathResource("org/springframework/webflow/sample/sample-flow.xml"); factory.setBasePath("classpath*:org/springframework/webflow/"); assertEquals("sample", factory.getFlowId(resource)); }
public void testGetFlowCustomBasePathTrailingSlash() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("WEB-INF/"); assertEquals("hotels/booking", factory.getFlowId(resource)); }
public void testGetFlowIdFlowPathIsBasePath() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("/WEB-INF/hotels/booking"); assertEquals("booking-flow", factory.getFlowId(resource)); }
public void testGetFlowIdClassPathResource() { Resource resource = new ClassPathResource("org/springframework/webflow/sample/sample-flow.xml"); factory.setBasePath("classpath:org/springframework/webflow/"); assertEquals("sample", factory.getFlowId(resource)); }
public void testGetFlowIdCustomBasePathLeadingSlash() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("/WEB-INF"); assertEquals("hotels/booking", factory.getFlowId(resource)); }
public void testGetFlowIdCustomBasePathLeadingAndTrailingSlash() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("/WEB-INF/"); assertEquals("hotels/booking", factory.getFlowId(resource)); }
public void testGetFlowIdBasePathMismatch() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("/foo/bar"); assertEquals("WEB-INF/hotels/booking", factory.getFlowId(resource)); }
public void testGetFlowIdFileSystemResource() { Resource resource = new FileSystemResource( "/the/path/on/the/file/system/org/springframework/webflow/sample/sample-flow.xml"); factory.setBasePath("classpath:org/springframework/webflow/"); assertEquals("sample", factory.getFlowId(resource)); }
public void testGetFlowIdCustomBasePath() { Resource resource = resourceLoader.getResource("/WEB-INF/hotels/booking/booking-flow.xml"); factory.setBasePath("WEB-INF"); assertEquals("hotels/booking", factory.getFlowId(resource)); }
public void testGetFlowIdUrlResourceNoBasePathMatch() throws MalformedURLException { Resource resource = new UrlResource("file:/the/path/on/the/file/system/sample-flow.xml"); factory.setBasePath("classpath:org/springframework/webflow/"); assertEquals("the/path/on/the/file/system", factory.getFlowId(resource)); }
public void testGetFlowIdUrlResource() throws MalformedURLException { Resource resource = new UrlResource( "file:/the/path/on/the/file/system/org/springframework/webflow/sample/sample-flow.xml"); factory.setBasePath("classpath:org/springframework/webflow/"); assertEquals("sample", factory.getFlowId(resource)); }