/************************************************************************ * * BatchConverterBase.java * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * Copyright: 2002-2008 by Henrik Just * * All Rights Reserved. * * Version 1.0 (2008-10-15) * */ 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