/************************************************************************ * * BatchConverterBase.java * * Copyright: 2002-2014 by Henrik Just * * This file is part of Writer2LaTeX. * * Writer2LaTeX is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Writer2LaTeX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Writer2LaTeX. If not, see . * * Version 1.4 (2014-08-27) * */ package writer2latex.base; import java.io.File; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import writer2latex.api.BatchConverter; import writer2latex.api.BatchHandler; import writer2latex.api.Converter; import writer2latex.api.ConverterResult; import writer2latex.api.IndexPageEntry; import writer2latex.api.OutputFile; import writer2latex.util.Misc; /** * Abstract base implementation of writer2latex.api.BatchConverter. * The base implementation handles the traversal of directories and files, and * leaves the handling of indexpages to the subclass. */ public abstract class BatchConverterBase implements BatchConverter { private Converter converter; public BatchConverterBase() { converter = null; } // Partial implementation of the interface public void setConverter(Converter converter) { this.converter = converter; } public void convert(File source, File target, boolean bRecurse, BatchHandler handler) { handler.startConversion(); convertDirectory(source, target, bRecurse, source.getName(), handler); handler.endConversion(); } protected abstract String getIndexFileName(); // Convert files and directories in the directory indir // (return false if conversion has been cancelled by the BatchHandler) private boolean convertDirectory(File indir, File outdir, boolean bRecurse, String sHeading, BatchHandler handler) { handler.startDirectory(indir.getPath()); // Step 1: Get the directory File[] contents = indir.listFiles(); int nLen = contents.length; IndexPageEntry[] entries = new IndexPageEntry[nLen]; // Step 2: Traverse subdirectories, if allowed if (bRecurse) { String sUplink = getConfig().getOption("uplink"); for (int i=0; i