/** * Returns an uninitialized {@code FileLocatorBuilder} which can be used * for the creation of a {@code FileLocator} object. This method provides * a convenient way to create file locators using a fluent API as in the * following example: * <pre> * FileLocator locator = FileLocatorUtils.fileLocator() * .basePath(myBasePath) * .fileName("test.xml") * .create(); * </pre> * @return a builder object for defining a {@code FileLocator} */ public static FileLocator.FileLocatorBuilder fileLocator() { return fileLocator(null); }
/** * Creates an uninitialized file locator. * * @return the locator */ private static FileLocator emptyFileLocator() { return FileLocatorUtils.fileLocator().create(); }
/** * Performs an update of the enclosing file handler's * {@code FileLocator} object. */ public void update() { boolean done; do { final FileLocator oldLocator = fileLocator.get(); final FileLocatorBuilder builder = FileLocatorUtils.fileLocator(oldLocator); updateBuilder(builder); done = fileLocator.compareAndSet(oldLocator, builder.create()); } while (!done); fireLocationChangedEvent(); }
/** * 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(); }
/** * 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(); }
/** * 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); }
/** * Helper method for locating a given file. This implementation delegates to * the corresponding method in {@link FileLocatorUtils}. * * @param fs the {@code FileSystem} * @param basePath the base path * @param name the file name * @return the URL pointing to the file */ private static URL locate(final FileSystem fs, final String basePath, final String name) { final FileLocator locator = FileLocatorUtils.fileLocator().fileSystem(fs) .basePath(basePath).fileName(name).create(); return FileLocatorUtils.locate(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 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(); }
@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; if (locatedUrl == null) { notFound = true; } return locatedUrl; }
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); }
/** * Creates application composite configuration. * * @return Application composite configuration. */ private CompositeConfiguration createApplicationConfiguration() { CompositeConfiguration cc = new CompositeConfiguration(); SystemConfiguration systemConfiguration = new SystemConfiguration(); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setThrowExceptionOnMissing(true); propertiesConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(';')); propertiesConfiguration.setIncludesAllowed(false); FileLocator locator = FileLocatorUtils.fileLocator() .fileName("testlinkjavaapi.propertiesxml") .create(); propertiesConfiguration.initFileLocator(locator); cc.addConfiguration(systemConfiguration); cc.addConfiguration(propertiesConfiguration); return cc; }