View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }