コード例 #1
0
 /**
  * Returns all file extensions that could be loaded.
  *
  * @return the file extensions
  */
 public Set<String> getAllFileExtensions() {
   Set<String> fileExtensions = new LinkedHashSet<String>();
   for (PropertySourceLoader loader : this.loaders) {
     fileExtensions.addAll(Arrays.asList(loader.getFileExtensions()));
   }
   return fileExtensions;
 }
コード例 #2
0
 /**
  * Load the profile-specific properties from the specified resource (if any), give the name
  * provided and add it to a group of property sources identified by the group name. Property
  * sources are added to the end of a group, but new groups are added as the first in the chain
  * being assembled. This means the normal sequence of calls is to first create the group for the
  * default (null) profile, and then add specific groups afterwards (with the highest priority
  * last). Property resolution from the resulting sources will consider all keys for a given group
  * first and then move to the next group.
  *
  * @param resource the source resource (may be {@code null}).
  * @param group an identifier for the group that this source belongs to
  * @param name the root property name (may be {@code null}).
  * @param profile a specific profile to load or {@code null} to load the default.
  * @return the loaded property source or {@code null}
  * @throws IOException if the source cannot be loaded
  */
 public PropertySource<?> load(Resource resource, String group, String name, String profile)
     throws IOException {
   if (isFile(resource)) {
     String sourceName = generatePropertySourceName(name, profile);
     for (PropertySourceLoader loader : this.loaders) {
       if (canLoadFileExtension(loader, resource)) {
         PropertySource<?> specific = loader.load(sourceName, resource, profile);
         addPropertySource(group, specific, profile);
         return specific;
       }
     }
   }
   return null;
 }
コード例 #3
0
 private boolean canLoadFileExtension(PropertySourceLoader loader, Resource resource) {
   String filename = resource.getFilename().toLowerCase();
   for (String extension : loader.getFileExtensions()) {
     if (filename.endsWith("." + extension.toLowerCase())) {
       return true;
     }
   }
   return false;
 }