View Javadoc
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 2014 ForgeRock AS
15   */
16  
17  package org.forgerock.doc.maven.post;
18  
19  import org.apache.commons.io.FileUtils;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.forgerock.doc.maven.AbstractDocbkxMojo;
22  import org.forgerock.doc.maven.utils.SyntaxHighlighterCopier;
23  
24  import java.io.IOException;
25  
26  /**
27   * XHTML post-processor.
28   */
29  public class Xhtml {
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 Xhtml(final AbstractDocbkxMojo mojo) {
42          m = mojo;
43      }
44  
45      /**
46       * Add SyntaxHighlighter files for each XHTML document.
47       *
48       * @throws MojoExecutionException Failed to post-process XHTML.
49       */
50      public void execute() throws MojoExecutionException {
51  
52          String[] outputDirectories = new String[m.getDocNames().size()];
53  
54          int i = 0;
55          for (final String docName : m.getDocNames()) {
56  
57              // Example: ${project.build.directory}/docbkx/xhtml/my-book
58              outputDirectories[i] = FileUtils.getFile(
59                      m.getDocbkxOutputDirectory(), "xhtml", docName).getPath();
60              ++i;
61          }
62  
63          SyntaxHighlighterCopier copier =
64                  new SyntaxHighlighterCopier(outputDirectories);
65          try {
66              copier.copy();
67          } catch (IOException e) {
68              throw new MojoExecutionException(
69                      "Failed to copy files: " + e.getMessage(), e);
70          }
71      }
72  }