1 /**
2 * Copyright 2010-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.mojo.license.header;
17
18 /**
19 * Contract of a file header.
20 * <p/>
21 * A header has three sections like in this example :
22 * <p/>
23 * <pre>
24 * Description
25 * %--
26 * Copyright (C) firstYear[ - lastYear] holder
27 * %--
28 * License
29 * </pre>
30 *
31 * @author tchemit <chemit@codelutin.com>
32 * @since 1.0
33 */
34 public class FileHeader
35 {
36
37 /**
38 * Copyright to string format
39 */
40 protected static final String COPYRIGHT_TO_STRING_FORMAT = "Copyright (C) %1$s %2$s";
41
42 /**
43 * Description of the project or module to add in header
44 */
45 protected String description;
46
47 /**
48 * Copyright holder
49 */
50 protected String copyrightHolder;
51
52 /**
53 * Copyright first year of application
54 */
55 protected Integer copyrightFirstYear;
56
57 /**
58 * Copyright last year of application (can be nullif copyright is
59 * only on one year).
60 */
61 protected Integer copyrightLastYear;
62
63 /**
64 * License used in the header.
65 */
66 protected String license;
67
68 /**
69 * @return the project name, or nay other common informations for all
70 * files of a project (or module)
71 */
72 public String getDescription()
73 {
74 return description;
75 }
76
77 /**
78 * @return the copyright holder
79 */
80 public String getCopyrightHolder()
81 {
82 return copyrightHolder;
83 }
84
85 /**
86 * @return the first year of the copyright
87 */
88 public Integer getCopyrightFirstYear()
89 {
90 return copyrightFirstYear;
91 }
92
93 /**
94 * @return the last year of the copyright (if copyright affects only one
95 * year, can be equals to the {@link #getCopyrightFirstYear()}).
96 */
97 public Integer getCopyrightLastYear()
98 {
99 return copyrightLastYear;
100 }
101
102 /**
103 * Produces a string representation of the copyright.
104 * <p/>
105 * If copyright acts on one year :
106 * <pre>
107 * Copyright (C) 2010 Holder
108 * </pre>
109 * <p/>
110 * If copyright acts on more than one year :
111 * <pre>
112 * Copyright (C) 2010 - 2012 Holder
113 * </pre>
114 *
115 * @return the String representation of the copyright
116 */
117 public String getCopyright()
118 {
119 String copyright;
120 if ( getCopyrightLastYear() == null )
121 {
122
123 // copyright on one year
124 copyright = String.format( COPYRIGHT_TO_STRING_FORMAT, getCopyrightFirstYear(), getCopyrightHolder() );
125 }
126 else
127 {
128
129 // copyright on more than one year
130 copyright =
131 String.format( COPYRIGHT_TO_STRING_FORMAT, getCopyrightFirstYear() + " - " + getCopyrightLastYear(),
132 getCopyrightHolder() );
133 }
134 return copyright;
135 }
136
137 /**
138 * @return the license content (this is not the fully license content,
139 * but just a per file license resume)
140 */
141 public String getLicense()
142 {
143 return license;
144 }
145
146 public void setDescription( String description )
147 {
148 this.description = description;
149 }
150
151 public void setCopyrightHolder( String copyrightHolder )
152 {
153 this.copyrightHolder = copyrightHolder;
154 }
155
156 public void setCopyrightFirstYear( Integer copyrightFirstYear )
157 {
158 this.copyrightFirstYear = copyrightFirstYear;
159 }
160
161 public void setCopyrightLastYear( Integer copyrightLastYear )
162 {
163 this.copyrightLastYear = copyrightLastYear;
164 }
165
166 public void setLicense( String license )
167 {
168 this.license = license;
169 }
170 }