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.rat.documentation.velocity;
20
21 import java.util.UUID;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.apache.rat.license.ILicense;
25
26 /**
27 * The License representation for documentation.
28 */
29 public final class License {
30 /** The RAT internal license we are wrapping */
31 private final ILicense license;
32
33 /** Constructor */
34 License(final ILicense license) {
35 this.license = license;
36 }
37
38 /**
39 * Gets the name of this license.
40 * @return the name of this license.
41 */
42 public String name() {
43 return license.getName();
44 }
45
46 /**
47 * Gets the family name of this license.
48 * @return the family name of this license.
49 */
50 public String family() {
51 return license.getFamilyName();
52 }
53
54 /**
55 * Gets the space normalized note for the license.
56 * @return the space normalized note for the license. May be {@code null}.
57 * @see StringUtils
58 */
59 public String note() {
60 return StringUtils.normalizeSpace(license.getNote());
61 }
62
63 /**
64 * Gets the id for this license if it is not a system generated one.
65 * @return the id for this license. May be {@code null}.
66 */
67 public String id() {
68 String result = license.getId();
69 try {
70 UUID.fromString(result);
71 return null;
72 } catch (IllegalArgumentException e) {
73 // do nothing.
74 }
75 return result;
76 }
77
78 /**
79 * Gets the matcher associated with this license.
80 * @return the matcher associated with this license.
81 */
82 public Matcher getMatcher() {
83 return new Matcher(license.getMatcher());
84 }
85
86 /**
87 * Gets the matcher tree associated with this license.
88 * @return the matcher tree associated with this license.
89 */
90 public MatcherTree getMatcherTree() {
91 return new MatcherTree(license.getMatcher());
92 }
93 }