/** * Creates a new {@code FileLocator} object with the properties defined in * the given map. The map must be conform to the structure generated by the * {@link #put(FileLocator, Map)} method; unexpected data can cause * {@code ClassCastException} exceptions. The map can be <b>null</b>, then * an uninitialized {@code FileLocator} is returned. * * @param map the map * @return the new {@code FileLocator} * @throws ClassCastException if the map contains invalid data */ public static FileLocator fromMap(final Map<String, ?> map) { final FileLocator.FileLocatorBuilder builder = fileLocator(); if (map != null) { builder.basePath((String) map.get(PROP_BASE_PATH)) .encoding((String) map.get(PROP_ENCODING)) .fileName((String) map.get(PROP_FILE_NAME)) .fileSystem((FileSystem) map.get(PROP_FILE_SYSTEM)) .locationStrategy( (FileLocationStrategy) map.get(PROP_STRATEGY)) .sourceURL((URL) map.get(PROP_SOURCE_URL)); } return builder.create(); }
private static URL locateFile(String fileName) { FileLocationStrategy strategy = new CombinedLocationStrategy(Arrays.asList(new FileSystemLocationStrategy(), new ClasspathLocationStrategy())); FileSystem fileSystem = new DefaultFileSystem(); FileLocator locator = FileLocatorUtils.fileLocator().locationStrategy(strategy).fileName(fileName).create(); return strategy.locate(fileSystem, locator); }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.locationStrategy(strategy); }