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 2013-2014 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 * Set DPI on .png images in the modifiable copy of the sources.
31 *
32 * <p>
33 *
34 * This class transforms the .png images in place.
35 */
36 public class Dpi {
37
38 /**
39 * The Mojo that holds configuration and related methods.
40 */
41 private AbstractDocbkxMojo m;
42
43 /**
44 * Constructor setting the Mojo that holds the configuration.
45 *
46 * @param mojo The Mojo that holds the configuration.
47 */
48 public Dpi(final AbstractDocbkxMojo mojo) {
49 m = mojo;
50 }
51
52 /**
53 * Set DPI on .png images in the modifiable copy of the sources.
54 * Default: 160 DPI.
55 *
56 * @throws MojoExecutionException Failed to edit image file.
57 */
58 public void execute() throws MojoExecutionException {
59
60 try {
61
62 for (File image : FileUtils.listFiles(
63 m.getDocbkxModifiableSourcesDirectory(),
64 new WildcardFileFilter("*.png"),
65 TrueFileFilter.INSTANCE)) {
66 PngUtils.setSafeDpi(image, m.getMaxImageHeightInInches());
67 }
68
69 } catch (IOException e) {
70 throw new MojoExecutionException(e.getMessage(), e);
71 }
72 }
73 }