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 2013-2015 ForgeRock AS.
015 */
016
017package org.forgerock.doc.maven.pre;
018
019import org.apache.maven.plugin.MojoExecutionException;
020import org.forgerock.doc.maven.AbstractDocbkxMojo;
021import org.forgerock.doc.maven.utils.ImageDataTransformer;
022
023import java.io.IOException;
024
025/**
026 * Edit {@code <imagedata>} elements in DocBook XML sources.
027 */
028public class ImageData {
029
030    /**
031     * The Mojo that holds configuration and related methods.
032     */
033    private AbstractDocbkxMojo m;
034
035    /**
036     * Constructor setting the Mojo that holds the configuration.
037     *
038     * @param mojo The Mojo that holds the configuration.
039     */
040    public ImageData(final AbstractDocbkxMojo mojo) {
041        m = mojo;
042    }
043
044    /**
045     * Edit {@code <imagedata>} elements in the copy of DocBook XML sources.
046     *
047     * @throws MojoExecutionException Failed to update an XML file.
048     */
049    public void execute() throws MojoExecutionException {
050        ImageDataTransformer idt = new ImageDataTransformer();
051        try {
052            idt.update(m.getDocbkxModifiableSourcesDirectory());
053        } catch (IOException e) {
054            throw new MojoExecutionException(e.getMessage(), e);
055        }
056    }
057}