All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swiftboot.sheet.SwiftBootSheetFactory Maven / Gradle / Ivy

There is a newer version: 2.4.7
Show newest version
package org.swiftboot.sheet;

import org.swiftboot.sheet.exp.CsvExporter;
import org.swiftboot.sheet.exp.ExcelExporter;
import org.swiftboot.sheet.exp.Exporter;
import org.swiftboot.sheet.imp.CsvImporter;
import org.swiftboot.sheet.imp.ExcelImporter;
import org.swiftboot.sheet.imp.Importer;

import static org.swiftboot.sheet.constant.SheetFileType.*;

/**
 * @author swiftech
 */
public class SwiftBootSheetFactory {

    /**
     * Create a importer by file suffix.
     *
     * @param suffix
     * @return
     * @see org.swiftboot.sheet.constant.SheetFileType
     */
    public Importer createImporter(String suffix) {
        Importer importer;
        if (TYPE_XLSX.equals(suffix) || TYPE_XLS.equals(suffix)) {
            importer = new ExcelImporter(suffix);
        }
        else if (TYPE_CSV.equals(suffix)) {
            importer = new CsvImporter(TYPE_CSV);
        }
        else {
            throw new RuntimeException("Not supported file type: " + suffix);
        }
        return importer;
    }

    /**
     * Create a exporter by file suffix.
     *
     * @param suffix
     * @return
     * @see org.swiftboot.sheet.constant.SheetFileType
     */
    public Exporter createExporter(String suffix) {
        Exporter exporter = null;
        if (TYPE_XLSX.equals(suffix) || TYPE_XLS.equals(suffix)) {
            exporter = new ExcelExporter(suffix);
        }
        else if (TYPE_CSV.equals(suffix)) {
            exporter = new CsvExporter(TYPE_CSV);
        }
        else {
            throw new RuntimeException("Not supported file type: " + suffix);
        }
        return exporter;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy