View Javadoc
1   /*
2    * dpkg - Debian Package library and the Debian Package Maven plugin
3    * (c) Copyright 2016 Gerrit Hohl
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package net.sourceforge.javadpkg.impl;
20  
21  import net.sourceforge.javadpkg.DebianPackageConstants;
22  import net.sourceforge.javadpkg.DocumentPaths;
23  import net.sourceforge.javadpkg.control.PackageName;
24  
25  
26  /**
27   * <p>
28   * A {@link DocumentPaths} implementation.
29   * </p>
30   *
31   * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
32   * @version <b>1.0</b>, 06.05.2016 by Gerrit Hohl
33   */
34  public class DocumentPathsImpl implements DocumentPaths, DebianPackageConstants {
35  	
36  	
37  	/** The base path of the document folder. */
38  	private String	documentBasePath;
39  	/** The path of the document folder of the Debian package. */
40  	private String	documentPath;
41  	/** The path of the copyright file. */
42  	private String	copyrightPath;
43  	/** The path of the change log file. */
44  	private String	changeLogPath;
45  	/** The path of the Debian change log file. */
46  	private String	changeLogDebianPath;
47  	/** The path of the GZIP compressed change log file. */
48  	private String	changeLogGzipPath;
49  	/** The path of the HTML formatted change log file. */
50  	private String	changeLogHtmlPath;
51  	/** The path of the GZIP compressed HTML formatted change log file. */
52  	private String	changeLogHtmlGzipPath;
53  
54  
55  	/**
56  	 * <p>
57  	 * Creates the paths.
58  	 * </p>
59  	 *
60  	 * @param name
61  	 *            The name of the package.
62  	 * @throws IllegalArgumentException
63  	 *             If the name is <code>null</code>.
64  	 */
65  	public DocumentPathsImpl(PackageName name) {
66  		super();
67  		
68  		if (name == null)
69  			throw new IllegalArgumentException("Argument name is null.");
70  		
71  		this.initialize(DOC_BASE_PATH, name);
72  	}
73  
74  
75  	/**
76  	 * <p>
77  	 * Initializes the paths.
78  	 * </p>
79  	 *
80  	 * @param docBasePath
81  	 *            The base of the documentation path.
82  	 * @param name
83  	 *            The name of the package.
84  	 */
85  	private void initialize(String docBasePath, PackageName name) {
86  		this.documentBasePath = docBasePath;
87  		this.documentPath = docBasePath + name.getName() + "/";
88  		this.copyrightPath = this.documentPath + "copyright";
89  		this.changeLogPath = this.documentPath + "changelog";
90  		this.changeLogDebianPath = this.changeLogPath + ".Debian";
91  		this.changeLogGzipPath = this.changeLogPath + ".gz";
92  		this.changeLogHtmlPath = this.changeLogPath + ".html";
93  		this.changeLogHtmlGzipPath = this.changeLogHtmlPath + ".gz";
94  	}
95  
96  
97  	@Override
98  	public String getDocumentBasePath() {
99  		return this.documentBasePath;
100 	}
101 
102 
103 	@Override
104 	public String getDocumentPath() {
105 		return this.documentPath;
106 	}
107 	
108 	
109 	@Override
110 	public boolean isCopyrightPath(String path) {
111 		if (path == null)
112 			throw new IllegalArgumentException("Argument path is null.");
113 		
114 		return this.copyrightPath.equals(path);
115 	}
116 
117 
118 	@Override
119 	public String getCopyrightPath() {
120 		return this.copyrightPath;
121 	}
122 
123 
124 	@Override
125 	public boolean isChangeLogPath(String path) {
126 		if (path == null)
127 			throw new IllegalArgumentException("Argument path is null.");
128 		
129 		return (path.equals(this.changeLogPath) || path.startsWith(this.changeLogPath + "."));
130 	}
131 
132 
133 	@Override
134 	public boolean isChangeLogDebianPath(String path) {
135 		if (path == null)
136 			throw new IllegalArgumentException("Argument path is null.");
137 		
138 		return (path.equals(this.changeLogDebianPath) || path.startsWith(this.changeLogDebianPath + "."));
139 	}
140 
141 
142 	@Override
143 	public boolean isChangeLogGzipPath(String path) {
144 		if (path == null)
145 			throw new IllegalArgumentException("Argument path is null.");
146 		
147 		if (!this.isChangeLogPath(path))
148 			return false;
149 		return path.endsWith(".gz");
150 	}
151 
152 
153 	@Override
154 	public boolean isChangeLogHtmlPath(String path) {
155 		int index;
156 		String name, extension;
157 		
158 		
159 		if (path == null)
160 			throw new IllegalArgumentException("Argument path is null.");
161 		
162 		if (!this.isChangeLogPath(path))
163 			return false;
164 		index = path.lastIndexOf('/');
165 		name = path.substring(index + 1);
166 		if (name.isEmpty())
167 			return false;
168 		index = name.indexOf('.');
169 		if (index == -1)
170 			return false;
171 		extension = name.substring(index + 1);
172 		if (extension.isEmpty())
173 			return false;
174 		
175 		return ("html".equals(extension) || extension.startsWith("html."));
176 	}
177 
178 
179 	@Override
180 	public String getChangeLogPath() {
181 		return this.changeLogPath;
182 	}
183 
184 
185 	@Override
186 	public String getChangeLogGzipPath() {
187 		return this.changeLogGzipPath;
188 	}
189 
190 
191 	@Override
192 	public String getChangeLogHtmlPath() {
193 		return this.changeLogHtmlPath;
194 	}
195 
196 
197 	@Override
198 	public String getChangeLogHtmlGzipPath() {
199 		return this.changeLogHtmlGzipPath;
200 	}
201 
202 
203 }