1 /* 2 * The contents of this file are subject to the terms of the Common Development and 3 * Distribution License (the License). You may not use this file except in compliance with the 4 * License. 5 * 6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 7 * specific language governing permission and limitations under the License. 8 * 9 * When distributing Covered Software, include this CDDL Header Notice in each file and include 10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 11 * Header, with the fields enclosed by brackets [] replaced by your own identifying 12 * information: "Portions copyright [year] [name of copyright owner]". 13 * 14 * Copyright 2012-2014 ForgeRock AS 15 */ 16 17 package org.forgerock.doc.maven.release; 18 19 import org.apache.maven.plugin.MojoExecutionException; 20 import org.forgerock.doc.maven.AbstractDocbkxMojo; 21 import org.forgerock.doc.maven.utils.HtmlUtils; 22 23 import java.io.IOException; 24 import java.util.HashMap; 25 26 /** 27 * Fix favicon links in release HTML. 28 */ 29 public class Favicon { 30 31 /** 32 * The Mojo that holds configuration and related methods. 33 */ 34 private AbstractDocbkxMojo m; 35 36 /** 37 * Constructor setting the Mojo that holds the configuration. 38 * 39 * @param mojo The Mojo that holds the configuration. 40 */ 41 public Favicon(final AbstractDocbkxMojo mojo) { 42 m = mojo; 43 } 44 45 /** 46 * Fix favicon links in release HTML. 47 * 48 * @throws MojoExecutionException Failed to fix links. 49 */ 50 public void execute() throws MojoExecutionException { 51 52 HashMap<String, String> replacements = new HashMap<String, String>(); 53 final String oldFaviconLink = m.getFaviconLink(); 54 final String newFaviconLink = m.getReleaseFaviconLink(); 55 56 if (!oldFaviconLink.equalsIgnoreCase(newFaviconLink)) { 57 replacements.put(oldFaviconLink, newFaviconLink); 58 try { 59 HtmlUtils.updateHtml(m.getReleaseVersionPath(), replacements); 60 } catch (IOException e) { 61 throw new MojoExecutionException(e.getMessage(), e); 62 } 63 } 64 } 65 }