1 /* 2 * Copyright 2006-2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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 de.smartics.maven.util.report.link; 17 18 import java.io.File; 19 20 import org.apache.commons.lang.StringUtils; 21 22 /** 23 * Configuration information for a {@link LinkConstructorStrategy}. 24 */ 25 public final class LinkConstructorStrategyConfig // NOPMD 26 { 27 // ********************************* Fields ********************************* 28 29 // --- constants ------------------------------------------------------------ 30 31 // --- members -------------------------------------------------------------- 32 33 /** 34 * The location of the report to link to. 35 */ 36 private final File reportLocation; 37 38 /** 39 * The extension to the file name to reference to. Usually this is 40 * <code>html</code>. 41 */ 42 private final String extension; 43 44 /** 45 * The hint to request to construct a strategy specific link part to reference 46 * a member. 47 */ 48 private final boolean referenceMember; 49 50 /** 51 * The key to the label to use as a label for the rendered link. 52 */ 53 private final String labelKey; 54 55 // ****************************** Initializer ******************************* 56 57 // ****************************** Constructors ****************************** 58 59 /** 60 * Builder pattern. 61 * 62 * @param builder to information to set. 63 */ 64 private LinkConstructorStrategyConfig(final Builder builder) 65 { 66 this.reportLocation = builder.reportLocation; 67 this.extension = builder.extension; 68 this.referenceMember = builder.referenceMember; 69 this.labelKey = builder.labelKey; 70 } 71 72 // ****************************** Inner Classes ***************************** 73 74 /** 75 * Builds instances of {@link LinkConstructorStrategyConfig}. 76 */ 77 public static final class Builder 78 { 79 // ******************************** Fields ******************************** 80 81 // --- constants ---------------------------------------------------------- 82 83 // --- members ------------------------------------------------------------ 84 85 /** 86 * The location of the report to link to. 87 */ 88 private File reportLocation; 89 90 /** 91 * The extension to the file name to reference to. Usually this is 92 * <code>html</code>. 93 */ 94 private String extension = "html"; 95 96 /** 97 * The hint to request to construct a strategy specific link part to 98 * reference a member. 99 */ 100 private boolean referenceMember; 101 102 /** 103 * The key to the label to use as a label for the rendered link. 104 */ 105 private String labelKey; 106 107 // ***************************** Initializer ****************************** 108 109 // ***************************** Constructors ***************************** 110 111 // ***************************** Inner Classes **************************** 112 113 // ******************************** Methods ******************************* 114 115 // --- init --------------------------------------------------------------- 116 117 // --- get&set ------------------------------------------------------------ 118 119 /** 120 * Sets the location of the report to link to. 121 * 122 * @param reportLocation the location of the report to link to. 123 */ 124 public void setReportLocation(final File reportLocation) 125 { 126 final String path = reportLocation.getPath(); 127 if (path.contains("..")) // Fix for BUG 622: Referencing Aggregate Reports 128 { 129 final String parentPath = path.replace("..", "../../../target/site"); 130 this.reportLocation = new File(parentPath); 131 } 132 else 133 { 134 this.reportLocation = reportLocation; 135 } 136 } 137 138 /** 139 * Sets the extension to the file name to reference to. Usually this is 140 * <code>html</code>. 141 * 142 * @param extension the extension to the file name to reference to. 143 */ 144 public void setExtension(final String extension) 145 throws IllegalArgumentException 146 { 147 if (StringUtils.isBlank(extension)) 148 { 149 throw new IllegalArgumentException("The extentsion must not be blank."); 150 } 151 this.extension = extension; 152 } 153 154 /** 155 * Sets the hint to request to construct a strategy specific link part to 156 * reference a member. 157 * 158 * @param referenceMember the hint to request to construct a strategy 159 * specific link part to reference a member. 160 */ 161 public void setReferenceMember(final boolean referenceMember) 162 { 163 this.referenceMember = referenceMember; 164 } 165 166 /** 167 * Sets the key to the label to use as a label for the rendered link. 168 * 169 * @param labelKey the key to the label to use as a label for the rendered 170 * link. 171 */ 172 public void setLabelKey(final String labelKey) 173 { 174 if (StringUtils.isBlank(labelKey)) 175 { 176 throw new IllegalArgumentException( 177 "The label for the link must not be blank."); 178 } 179 this.labelKey = labelKey; 180 } 181 182 // --- business ----------------------------------------------------------- 183 184 /** 185 * Creates the congfiguration instance. 186 * 187 * @return the congfiguration instance. 188 */ 189 public LinkConstructorStrategyConfig build() 190 { 191 if (reportLocation == null) 192 { 193 throw new IllegalArgumentException( 194 "The report location must not be 'null'"); 195 } 196 if (StringUtils.isBlank(labelKey)) 197 { 198 throw new IllegalArgumentException( 199 "The label for the link must not be blank."); 200 } 201 202 return new LinkConstructorStrategyConfig(this); 203 } 204 205 // --- object basics ------------------------------------------------------ 206 } 207 208 // ********************************* Methods ******************************** 209 210 // --- init ----------------------------------------------------------------- 211 212 // --- get&set -------------------------------------------------------------- 213 214 /** 215 * Returns the location of the report to link to. 216 * 217 * @return the location of the report to link to. 218 */ 219 public File getReportLocation() 220 { 221 return reportLocation; 222 } 223 224 /** 225 * Returns the extension to the file name to reference to. Usually this is 226 * <code>html</code>. 227 * 228 * @return the extension to the file name to reference to. 229 */ 230 public String getExtension() 231 { 232 return extension; 233 } 234 235 /** 236 * Returns the hint to request to construct a strategy specific link part to 237 * reference a member. 238 * 239 * @return the hint to request to construct a strategy specific link part to 240 * reference a member. 241 */ 242 public boolean isReferenceMember() 243 { 244 return referenceMember; 245 } 246 247 /** 248 * Returns the key to the label to use as a label for the rendered link. 249 * 250 * @return the key to the label to use as a label for the rendered link. 251 */ 252 public String getLabelKey() 253 { 254 return labelKey; 255 } 256 257 // --- business ------------------------------------------------------------- 258 259 // --- object basics -------------------------------------------------------- 260 261 }