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.utils; 18 19 import org.apache.commons.io.FileUtils; 20 21 import java.io.File; 22 import java.io.IOException; 23 import java.net.URL; 24 25 /** 26 * Copy SyntaxHighlighter files under the specified directories. 27 */ 28 public final class SyntaxHighlighterCopier { 29 30 /** 31 * SyntaxHighlighter CSS files. 32 */ 33 private final String[] shCssResources = { 34 "/css/shCore.css", 35 "/css/shCoreEclipse.css", 36 "/css/shThemeEclipse.css" 37 }; 38 39 /** 40 * SyntaxHighlighter JavaScript files. 41 */ 42 private final String[] shJavaScriptResources = { 43 "/js/shCore.js", 44 "/js/shBrushAci.js", 45 "/js/shBrushBash.js", 46 "/js/shBrushCsv.js", 47 "/js/shBrushHttp.js", 48 "/js/shBrushJava.js", 49 "/js/shBrushJScript.js", 50 "/js/shBrushLDIF.js", 51 "/js/shBrushPlain.js", 52 "/js/shBrushProperties.js", 53 "/js/shBrushXml.js", 54 "/js/shAll.js" 55 }; 56 57 /** 58 * Directories where SyntaxHighlighter scripts and CSS are to be added. 59 */ 60 private String[] outputDirectories; 61 62 /** 63 * Construct a SyntaxHighlighterCopier, specifying output directories. 64 * 65 * @param outputDirectories Full path to directories under which to copy files. 66 */ 67 public SyntaxHighlighterCopier(final String[] outputDirectories) { 68 this.outputDirectories = outputDirectories; 69 } 70 71 /** 72 * For each outputDirectory, copy SyntaxHighlighter files under outputDirectory/sh. 73 * 74 * @throws IOException Failed to copy files. 75 */ 76 public void copy() throws IOException { 77 addShCss(); 78 addShScripts(); 79 } 80 81 /** 82 * Add SyntaxHighlighter CSS files in each output directory. 83 * 84 * @throws IOException Failed to add CSS. 85 */ 86 private void addShCss() throws IOException { 87 addShResources(shCssResources); 88 } 89 90 /** 91 * Add SyntaxHighlighter JavaScript files in each output directory. 92 * 93 * @throws IOException Failed to add scripts. 94 */ 95 private void addShScripts() throws IOException { 96 addShResources(shJavaScriptResources); 97 } 98 99 /** 100 * Add SyntaxHighlighter resource files in each output directory. 101 * 102 * @param resources List of resource files to copy. 103 * @throws IOException Failed to files. 104 */ 105 private void addShResources(final String[] resources) throws IOException { 106 107 for (String resource : resources) { 108 URL resourceUrl = getClass().getResource(resource); 109 110 // The html.stylesheet parameter should probably take URLs. 111 // When local files are referenced, 112 // the DocBook XSL stylesheets do not copy the files. 113 // Instead the files must be copied to the output directories. 114 115 for (final String outputDirectory : outputDirectories) { 116 final File styleSheetFile = FileUtils.getFile(outputDirectory, "sh", resource); 117 FileUtils.copyURLToFile(resourceUrl, styleSheetFile); 118 } 119 } 120 } 121 }