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.whisker.out.velocity; 20 21 import java.io.IOException; 22 import java.io.Writer; 23 24 import org.apache.creadur.whisker.app.Result; 25 import org.apache.creadur.whisker.app.ResultWriterFactory; 26 27 /** 28 * Products generated by velocity templates. 29 */ 30 public enum Product { 31 32 /** 33 * Produces a NOTICE report. 34 */ 35 NOTICE("NOTICE", Result.NOTICE), 36 /** 37 * Produces a LICENSE report. 38 */ 39 LICENSE("LICENSE", Result.LICENSE), 40 /** 41 * Produces a directories report. 42 */ 43 DIRECTORIES_REPORT_TEMPLATE("DIRECTORIES", Result.DIRECTORIES_REPORT), 44 /** 45 * Produces a missing license report. 46 */ 47 MISSING_LICENSE_REPORT_TEMPLATE( 48 "MISSING-LICENSE", Result.MISSING_LICENSE_REPORT), 49 /** 50 * Produces an xml template. 51 */ 52 XML_TEMPLATE("XML-TEMPLATE", Result.XML_TEMPLATE); 53 54 /** Not null. */ 55 private final String template; 56 /** Not null. */ 57 private final Result result; 58 59 /** 60 * Constructs a product. 61 * @param template not null 62 * @param result not null 63 */ 64 private Product(final String template, final Result result) { 65 this.template = template; 66 this.result = result; 67 } 68 69 /** 70 * Gets the template name that generates this product. 71 * @return not null 72 */ 73 public String getTemplate() { 74 return template; 75 } 76 77 /** 78 * Gets result implemented by this product. 79 * @return not null 80 */ 81 public Result getResult() { 82 return result; 83 } 84 85 /** 86 * Builds writer for this product. 87 * @param writerFactory not null 88 * @return not null 89 * @throws IOException when write fails 90 */ 91 public Writer writerFrom( 92 final ResultWriterFactory writerFactory) throws IOException { 93 return writerFactory.writerFor(getResult()); 94 } 95 }