/** * 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(); }
/** * Creates a fully initialized {@code FileLocator} based on the specified * URL. * * @param src the source {@code FileLocator} * @param url the URL * @return the fully initialized {@code FileLocator} */ private static FileLocator createFullyInitializedLocatorFromURL(final FileLocator src, final URL url) { final FileLocator.FileLocatorBuilder fileLocatorBuilder = fileLocator(src); if (src.getSourceURL() == null) { fileLocatorBuilder.sourceURL(url); } if (StringUtils.isBlank(src.getFileName())) { fileLocatorBuilder.fileName(getFileName(url)); } if (StringUtils.isBlank(src.getBasePath())) { fileLocatorBuilder.basePath(getBasePath(url)); } return fileLocatorBuilder.create(); }
/** * Injects a {@code FileLocator} pointing to the specified URL if the * current {@code FileBased} object implements the {@code FileLocatorAware} * interface. * * @param url the URL for the locator */ private void injectFileLocator(final URL url) { if (url == null) { injectNullFileLocator(); } else { if (getContent() instanceof FileLocatorAware) { final FileLocator locator = prepareNullLocatorBuilder().sourceURL(url).create(); ((FileLocatorAware) getContent()).initFileLocator(locator); } } }
/** * Tries to obtain the URL of an include file using the specified (optional) * base path and file name. * * @param basePath the base path * @param fileName the file name * @return the URL of the include file or <b>null</b> if it cannot be * resolved */ private URL locateIncludeFile(final String basePath, final String fileName) { final FileLocator includeLocator = FileLocatorUtils.fileLocator(locator).sourceURL(null) .basePath(basePath).fileName(fileName).create(); return FileLocatorUtils.locate(includeLocator); } }
/** * Creates a {@code FileLocator} which is a copy of the passed in one, but * has the given file name set to reference the target file. * * @param fileName the file name * @param locator the {@code FileLocator} to copy * @return the manipulated {@code FileLocator} with the file name */ private FileLocator createLocatorWithFileName(final String fileName, final FileLocator locator) { return FileLocatorUtils.fileLocator(locator).sourceURL(null) .fileName(fileName).create(); }
/** * Prepares a builder for a {@code FileLocator} which does not have a * defined file location. Other properties (e.g. encoding or file system) * are initialized from the {@code FileLocator} associated with this object. * * @return the initialized builder for a {@code FileLocator} */ private FileLocatorBuilder prepareNullLocatorBuilder() { return FileLocatorUtils.fileLocator(getFileLocator()).sourceURL(null) .basePath(null).fileName(null); }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.basePath(path); builder.sourceURL(null); } }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.basePath(null).fileName(null).sourceURL(null); } }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.sourceURL(url); builder.basePath(null).fileName(null); } }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.fileName(name); builder.sourceURL(null); } }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.fileName(fileName).basePath(basePath).sourceURL(null); } }