org.geoserver.security.iride.util.io.Filename.java Source code

Java tutorial

Introduction

Here is the source code for org.geoserver.security.iride.util.io.Filename.java

Source

/*
 *  GeoServer Security Provider plugin used for doing authentication and authorization operations using CSI-Piemonte IRIDE Service.
 *  Copyright (C) 2016  Regione Piemonte (www.regione.piemonte.it)
 *
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.geoserver.security.iride.util.io;

import org.apache.commons.io.FilenameUtils;

/**
 * <code>IRIDE</code> <code>Digital Identity</code> filename utilities.
 *
 * @author "Simone Cornacchia - seancrow76@gmail.com, simone.cornacchia@consulenti.csi.it (CSI:71740)"
 */
public final class Filename {

    /**
     * Constructor.
     */
    private Filename() {
        /* NOP */
    }

    /**
     * Checks whether the extension of the filename is that specified, appending it if not.
     * Returns the filename, with the specified extension if it was not found.
     *
     * @param filename the filename to check
     * @param extension the extension to check for, {@code null} or empty checks for no extension
     * @return the filename, with the specified extension if it was not found
     */
    public static String ensureFileWithExtension(String filename, String extension) {
        if (!FilenameUtils.isExtension(filename, extension)) {
            return filename + "." + extension;
        }

        return filename;
    }

}