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 2015 ForgeRock AS.
15 */
16
17 package org.forgerock.doc.maven.pre;
18
19 import org.apache.commons.io.FileUtils;
20 import org.apache.commons.io.filefilter.TrueFileFilter;
21 import org.apache.commons.io.filefilter.WildcardFileFilter;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.forgerock.doc.maven.AbstractDocbkxMojo;
24 import org.forgerock.doc.maven.utils.PngUtils;
25
26 import java.io.File;
27 import java.io.IOException;
28
29 /**
30 * Create thumbnails of .png images in the modifiable copy of the sources.
31 *
32 * <p>
33 *
34 * This class creates resized thumbnail files prefixed with 'thumb_' in the
35 * same directory as the original image.
36 */
37 public class CreateThumbs {
38
39 /**
40 * The Mojo that holds configuration and related methods.
41 */
42 private AbstractDocbkxMojo m;
43
44 /**
45 * Constructor setting the Mojo that holds the configuration.
46 *
47 * @param mojo The Mojo that holds the configuration.
48 */
49 public CreateThumbs(final AbstractDocbkxMojo mojo) {
50 m = mojo;
51 }
52
53 /**
54 * Create thumbnails of .png images in the modifiable copy of
55 * the sources.
56 *
57 * @throws org.apache.maven.plugin.MojoExecutionException Failed to edit image file.
58 */
59 public void execute() throws MojoExecutionException {
60
61 try {
62
63 for (File image : FileUtils.listFiles(
64 m.getDocbkxModifiableSourcesDirectory(),
65 new WildcardFileFilter("*.png"),
66 TrueFileFilter.INSTANCE)) {
67 PngUtils.resizePng(image);
68 }
69
70 } catch (IOException e) {
71 throw new MojoExecutionException(e.getMessage(), e);
72 }
73 }
74 }