View Javadoc

1   package org.kuali.common.util.properties;
2   
3   import java.util.ArrayList;
4   import java.util.Arrays;
5   import java.util.List;
6   
7   import org.kuali.common.util.project.ProjectService;
8   import org.kuali.common.util.project.ProjectUtils;
9   import org.kuali.common.util.project.model.FeatureIdentifier;
10  import org.kuali.common.util.project.model.Project;
11  import org.kuali.common.util.project.model.ProjectIdentifier;
12  
13  import com.google.common.collect.ImmutableList;
14  
15  public class DefaultPropertiesLocationService implements PropertiesLocationService {
16  
17  	public DefaultPropertiesLocationService(ProjectService projectService) {
18  		this(projectService, DEFAULT_CACHE_PROPERTIES_VALUE);
19  	}
20  
21  	public DefaultPropertiesLocationService(ProjectService projectService, boolean cache) {
22  		this.projectService = projectService;
23  		this.cache = cache;
24  	}
25  
26  	private static final boolean DEFAULT_CACHE_PROPERTIES_VALUE = true;
27  
28  	private final ProjectService projectService;
29  	private final boolean cache;
30  
31  	@Override
32  	public List<Location> getLocations(ProjectIdentifier identifier, List<String> filenames) {
33  		List<Location> locations = new ArrayList<Location>();
34  		for (String filename : filenames) {
35  			locations.add(getLocation(identifier, filename));
36  		}
37  		return locations;
38  	}
39  
40  	@Override
41  	public List<Location> getLocations(ProjectIdentifier identifier, String... filenames) {
42  		return getLocations(identifier, Arrays.asList(filenames));
43  	}
44  
45  	@Override
46  	public Location getLocation(ProjectIdentifier identifier, String filename) {
47  		Project project = projectService.getProject(identifier);
48  		String value = ProjectUtils.getClasspathPrefix(identifier) + "/" + filename;
49  		String encoding = ProjectUtils.getEncoding(project);
50  		return new Location(value, encoding, cache);
51  	}
52  
53  	@Override
54  	public List<Location> getLocations(FeatureIdentifier identifier, String... filenames) {
55  		return getLocations(identifier, ImmutableList.copyOf(filenames));
56  	}
57  
58  	@Override
59  	public List<Location> getLocations(FeatureIdentifier identifier, List<String> filenames) {
60  		List<Location> locations = new ArrayList<Location>();
61  		for (String filename : filenames) {
62  			locations.add(getLocation(identifier, filename));
63  		}
64  		return locations;
65  	}
66  
67  	@Override
68  	public Location getLocation(FeatureIdentifier identifier, String filename) {
69  		Project project = projectService.getProject(identifier.getProject());
70  		String value = ProjectUtils.getClasspathPrefix(identifier) + "/" + filename;
71  		String encoding = ProjectUtils.getEncoding(project);
72  		return new Location(value, encoding, cache);
73  	}
74  
75  }