1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.tentacles;
20
21 import java.io.IOException;
22 import java.util.Map;
23 import java.util.concurrent.ConcurrentHashMap;
24
25 public enum LicenseType {
26
27 ASL_2_0("asl-2.0"), CPL_1_0("cpl-1.0"), CDDL_1_0("cddl-1.0");
28
29 public static Licenses loadLicensesFrom(final Platform platform)
30 throws IOException {
31 final Map<String, String> licenses =
32 new ConcurrentHashMap<String, String>();
33 for (final LicenseType type : LicenseType.values()) {
34 type.putTextInto(licenses, platform.getTentaclesResources());
35 }
36 return new Licenses(licenses, platform);
37 }
38
39 private final String resourceName;
40 private final String resourcePath;
41
42 private LicenseType(final String resourceName) {
43 this.resourceName = resourceName;
44 this.resourcePath = "licenses/" + getResourceName() + ".txt";
45 }
46
47 public String getResourceName() {
48 return this.resourceName;
49 }
50
51 public String getResourcePath() {
52 return this.resourcePath;
53 }
54
55 public String readText(final TentaclesResources tentaclesResources)
56 throws IOException {
57 return tentaclesResources.readText(getResourcePath()).trim();
58 }
59
60 public void putTextInto(final Map<String, String> licenseTextByName,
61 final TentaclesResources tentaclesResources) throws IOException {
62 licenseTextByName.put(getResourceName(), readText(tentaclesResources));
63 }
64 }