@Override public URL locate(FileSystem fileSystem, FileLocator locator) { locatedUrl = baseStrategy.locate(fileSystem, locator); if (locatedUrl != null) { return locatedUrl; } locatedUrl = fallbackBasePath != null ? FileLocatorUtils.DEFAULT_LOCATION_STRATEGY.locate(fileSystem, FileLocatorUtils.fileLocator(locator).basePath(fallbackBasePath).create()) : null; return locatedUrl; }
@Override public URL locate(FileSystem fileSystem, FileLocator locator) { try { FileObject file = VFSUtils.resolveFile(_fileName); String base = VFSUtils.isLocal(file) ? new File(_fileName).getParent() : file.getParent().getURL().toString(); return VFSUtils.resolveFile(base, locator.getFileName()).getURL(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
private void init() { this.setListDelimiterHandler(new DefaultListDelimiterHandler(',')); FileLocationStrategy strategy = new MyFileLocationStrategy(); String basePath = _fileName == null ? "." : new File(_fileName).getParent(); FileLocator locator = FileLocatorUtils.fileLocator() .locationStrategy(strategy) .basePath(basePath) .create(); this.initFileLocator(locator); }
/** * The file {@link URL} can be absolute or relative to the working folder. The configuration file is located using a {@link FileLocatorUtils#DEFAULT_LOCATION_STRATEGY strategy} that uses a number of techniques to determine the file location. * <p> * If no file is found, the {@link #FILENAME resource file} is used. * * @return the configuration file {@link URL}. */ public URL getFileName() { if (this.propertiesFile == null) { final List<FileLocationStrategy> subs = Arrays.asList( new ProvidedURLLocationStrategy(), new FileSystemLocationStrategy(), new ClasspathLocationStrategy()); final FileLocationStrategy strategy = new CombinedLocationStrategy(subs); FileLocator fileLocator = FileLocatorUtils.fileLocator() .basePath(this.getDefaultFile().getParent()) .fileName(this.getDefaultFile().getName()) .create(); if (!new File(FileLocatorUtils.locate(fileLocator).getFile()).exists()) { fileLocator = FileLocatorUtils.fileLocator() .fileName(this.getDefaultFile().getName()) .locationStrategy(strategy) .create(); } this.propertiesFile = FileLocatorUtils.locate(fileLocator); // Ensure that the ConfigurationBuilder is now initialised as that may force a re-initialisation of this FileLocator. this.getConfigurationBuilder(); } return this.propertiesFile; }
/** * Sets the file locator to use for the next invocation of {@link #read(InputStream)} or {@link #write(Writer)}. * * @param locator The file locator to use; or <code>null</code>. */ @Override public void initFileLocator(@Nullable final FileLocator locator) { this.locator = locator; }