2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre LEDRU
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 package org.scilab.modules.helptools;
14 import com.sun.java.help.search.Indexer; /* jhall (Java Help) */
17 import java.io.FileOutputStream;
18 import java.io.FilenameFilter;
19 import java.io.FileInputStream;
20 import java.util.zip.ZipEntry;
21 import java.util.jar.JarOutputStream;
25 * This class manages the build of the Java Help
27 public class BuildJavaHelp {
30 * Private method which is trying to build the jar
32 * @param outputDirectory Where to build the jar file
33 * @param language In which language (for the file name)
34 * @return The result of the operation
36 private static boolean buildJar(String outputDirectory, String language) {
37 String baseName = "scilab_" + language + "_help";
38 JarOutputStream jarFile = null;
39 FileOutputStream fileOutputStream = null;
40 final int compressionLevel = 5;
41 String fileName = outputDirectory + "/../../../jar/" + baseName + ".jar";
45 fileOutputStream = new FileOutputStream(fileName);
46 jarFile = new JarOutputStream(fileOutputStream);
48 } catch (java.io.FileNotFoundException e) {
49 System.err.println("buildDoc: Could not find/access to " + fileName + " ( " + e.getLocalizedMessage() + " )");
50 } catch (java.io.IOException e) {
51 System.err.println("buildDoc: Could not find/access to " + fileName + " ( " + e.getLocalizedMessage() + " )");
54 jarFile.setLevel(compressionLevel);
56 /* Defines the filter to know what we want to ship in the jar */
57 FilenameFilter filter = new FilenameFilter() {
58 public boolean accept(File dir, String name) {
59 return name.endsWith(".html") || name.endsWith(".xml") || name.endsWith(".jhm") || name.endsWith(".hs");
63 File currentDir = new File(outputDirectory);
64 File []allFiles = currentDir.listFiles(filter);
65 for (int i = 0; i < allFiles.length; i++) {
67 FileInputStream fileInputStream = new FileInputStream(allFiles[i]);
69 int length = (int) allFiles[i].length();
70 byte[] buffer = new byte[length];
73 fileInputStream.read(buffer, 0, length);
74 } catch (java.io.IOException e) {
75 System.err.println("buildDoc: Could not find/access to " + allFiles[i] + " ( " + e.getLocalizedMessage() + " )");
78 ZipEntry zipEntry = new ZipEntry(baseName + "/" + allFiles[i].getName());
79 jarFile.putNextEntry(zipEntry);
81 jarFile.write(buffer, 0, length);
83 fileInputStream.close();
84 } catch (java.io.IOException e) {
85 System.err.println("buildDoc: An error occurs while building the JavaHelp ( " + e.getLocalizedMessage() + " )");
91 } catch (java.io.IOException e) {
92 System.err.println("buildDoc: An error occurs while closing the JavaHelp ( " + e.getLocalizedMessage() + " )");
98 * After the saxon process, create the Jar
100 * @param outputDirectory Where the files are available and
101 * @param language In which language (for the file name)
102 * @return The result of the process
104 public static boolean buildJavaHelp(String outputDirectory, String language) {
105 Indexer indexer = new Indexer();
108 String[] args = new String[] {
111 indexer.compile(args);
112 } catch (Exception e) {
113 System.err.println("buildDoc: Error building search index: " + e.getLocalizedMessage());
117 BuildJavaHelp.buildJar(outputDirectory, language);