001 package org.kuali.common.util.properties; 002 003 import java.util.ArrayList; 004 import java.util.Arrays; 005 import java.util.List; 006 007 import org.kuali.common.util.project.ProjectService; 008 import org.kuali.common.util.project.ProjectUtils; 009 import org.kuali.common.util.project.model.Project; 010 import org.kuali.common.util.project.model.ProjectIdentifier; 011 import org.kuali.common.util.project.model.ProjectResource; 012 013 import com.google.common.base.Preconditions; 014 import com.google.common.collect.ImmutableList; 015 016 public class DefaultPropertiesLocationService implements PropertiesLocationService { 017 018 public DefaultPropertiesLocationService(ProjectService projectService) { 019 this(projectService, DEFAULT_CACHE_PROPERTIES_VALUE); 020 } 021 022 public DefaultPropertiesLocationService(ProjectService projectService, boolean cache) { 023 Preconditions.checkNotNull(projectService, "'projectService' cannot be null"); 024 this.projectService = projectService; 025 this.cache = cache; 026 } 027 028 private static final boolean DEFAULT_CACHE_PROPERTIES_VALUE = true; 029 030 private final ProjectService projectService; 031 private final boolean cache; 032 033 @Override 034 public List<Location> getLocations(ProjectIdentifier identifier, List<String> filenames) { 035 List<Location> locations = new ArrayList<Location>(); 036 for (String filename : filenames) { 037 locations.add(getLocation(identifier, filename)); 038 } 039 return locations; 040 } 041 042 @Override 043 public List<Location> getLocations(ProjectIdentifier identifier, String... filenames) { 044 return getLocations(identifier, Arrays.asList(filenames)); 045 } 046 047 @Override 048 public Location getLocation(ProjectIdentifier identifier, String filename) { 049 Project project = projectService.getProject(identifier); 050 String value = ProjectUtils.getClasspathPrefix(identifier) + "/" + filename; 051 String encoding = ProjectUtils.getEncoding(project); 052 return new Location(value, encoding, cache); 053 } 054 055 /** 056 * @deprecated 057 */ 058 @Deprecated 059 @Override 060 public List<Location> getLocations(org.kuali.common.util.project.model.FeatureIdentifier identifier, String... filenames) { 061 return getLocations(identifier, ImmutableList.copyOf(filenames)); 062 } 063 064 /** 065 * @deprecated 066 */ 067 @Deprecated 068 @Override 069 public List<Location> getLocations(org.kuali.common.util.project.model.FeatureIdentifier identifier, List<String> filenames) { 070 List<Location> locations = new ArrayList<Location>(); 071 for (String filename : filenames) { 072 locations.add(getLocation(identifier, filename)); 073 } 074 return locations; 075 } 076 077 /** 078 * @deprecated 079 */ 080 @Deprecated 081 @Override 082 public Location getLocation(org.kuali.common.util.project.model.FeatureIdentifier identifier, String filename) { 083 Project project = projectService.getProject(identifier.getProject()); 084 String value = ProjectUtils.getClasspathPrefix(identifier) + "/" + filename; 085 String encoding = ProjectUtils.getEncoding(project); 086 return new Location(value, encoding, cache); 087 } 088 089 @Override 090 public Location getLocation(ProjectResource resource) { 091 return getLocation(resource.getProject(), resource.getPath()); 092 } 093 }