001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2012-2014 ForgeRock AS
015 */
016
017package org.forgerock.doc.maven.release;
018
019import org.apache.maven.plugin.MojoExecutionException;
020import org.forgerock.doc.maven.AbstractDocbkxMojo;
021import org.forgerock.doc.maven.utils.HtmlUtils;
022
023import java.io.IOException;
024import java.util.HashMap;
025
026/**
027 * Fix favicon links in release HTML.
028 */
029public class Favicon {
030
031    /**
032     * The Mojo that holds configuration and related methods.
033     */
034    private AbstractDocbkxMojo m;
035
036    /**
037     * Constructor setting the Mojo that holds the configuration.
038     *
039     * @param mojo The Mojo that holds the configuration.
040     */
041    public Favicon(final AbstractDocbkxMojo mojo) {
042        m = mojo;
043    }
044
045    /**
046     * Fix favicon links in release HTML.
047     *
048     * @throws MojoExecutionException Failed to fix links.
049     */
050    public void execute() throws MojoExecutionException {
051
052        HashMap<String, String> replacements = new HashMap<String, String>();
053        final String oldFaviconLink = m.getFaviconLink();
054        final String newFaviconLink = m.getReleaseFaviconLink();
055
056        if (!oldFaviconLink.equalsIgnoreCase(newFaviconLink)) {
057            replacements.put(oldFaviconLink, newFaviconLink);
058            try {
059                HtmlUtils.updateHtml(m.getReleaseVersionPath(), replacements);
060            } catch (IOException e) {
061                throw new MojoExecutionException(e.getMessage(), e);
062            }
063        }
064    }
065}