Example usage for org.apache.commons.io FilenameUtils getExtension

List of usage examples for org.apache.commons.io FilenameUtils getExtension

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getExtension.

Prototype

public static String getExtension(String filename) 

Source Link

Document

Gets the extension of a filename.

Usage

From source file:com.daphne.es.maintain.staticresource.web.controller.utils.YuiCompressorUtils.java

public static String getNoneCompressFileName(String fileName) {
    if (!hasCompress(fileName)) {
        return fileName;
    }/*from ww  w  .j av a 2s  .c o  m*/
    String noneCompressFileName = null;
    final String extension = FilenameUtils.getExtension(fileName);
    if ("js".equalsIgnoreCase(extension)) {
        noneCompressFileName = fileName.substring(0, fileName.length() - 7) + ".js";
    } else if ("css".equals(extension)) {
        noneCompressFileName = fileName.substring(0, fileName.length() - 8) + ".css";
    }
    return noneCompressFileName;
}

From source file:de.thischwa.pmcms.view.renderer.resource.VirtualImage.java

@Override
public void consructFromTagFromView(String src) throws IllegalArgumentException {
    if (!InitializationManager.isImageExtention(FilenameUtils.getExtension(src)))
        throw new IllegalArgumentException("Image TYPE isn't supported! [" + src + "]");

    String cachePath = String.format("/%s/%s", Constants.LINK_IDENTICATOR_SITE_RESOURCE,
            pm.getProperty("pmcms.dir.site.imagecache"));
    if (src.startsWith(cachePath)) {
        String path = src.substring(cachePath.length() + 1);
        // adapt the path
        if (forLayout) {
            String layoutFolder = pm.getSiteProperty("pmcms.site.dir.resources.layout");
            if (!path.startsWith(layoutFolder))
                throw new IllegalArgumentException(String.format("[%s] isn't well-formed", path));
            path = path.substring(layoutFolder.length() + 1);
        } else {//from w ww . j a v  a 2s  .  c om
            String folder = forGallery ? pm.getSiteProperty("pmcms.site.dir.resources.gallery")
                    : pm.getSiteProperty("pmcms.site.dir.resources.other");
            if (!path.startsWith(folder))
                throw new IllegalArgumentException(String.format("[%s] isn't well-formed", path));
            path = path.substring(folder.length() + 1);
        }

        File cacheDir = PoPathInfo.getSiteImageCacheDirectory(site);
        File cacheFile = new File(cacheDir, path);
        analyse(cacheFile);
    } else {
        super.consructFromTagFromView(src);
    }
}

From source file:dcstore.web.ImagesWeb.java

public void add() {
    Long idImage = -1L;//  w  ww. j  a va 2 s . c o m

    try {
        if (!FilenameUtils.getExtension(file.getName()).equals("jpg")) {
            throw new Exception("Only jpg files are supported");
        }

        if (this.getIdProduct() == null) {
            throw new Exception("Could not read id product");
        }

        idImage = imageBean.add(this.getIdProduct());
        if (idImage <= 0) {
            throw new Exception("Getting new image id failed");
        }

        String imgPath = this.getImgPath(idProduct, idImage, "full");
        FileOutputStream out = new FileOutputStream(imgPath);
        IOUtils.copy(file.getInputStream(), out);
        out.close();

        this.resizeImage(imgPath, 300, 300, this.getImgPath(idProduct, idImage, "cover"));
        this.resizeImage(imgPath, 130, 130, this.getImgPath(idProduct, idImage, "category"));
        this.resizeImage(imgPath, 100, 100, this.getImgPath(idProduct, idImage, "mini"));
    } catch (Exception e) {
        try {
            if (idImage > 0) {
                imageBean.del(idImage);
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage("",
                    new FacesMessage("Rollbacking image from db failed"));
        }

        FacesContext.getCurrentInstance().addMessage("",
                new FacesMessage("File upload error: " + e.getMessage()));
    }
}

From source file:com.bbc.remarc.util.ResourceManager.java

private static void processUploadDir(File uploadFolder, String resourcesDir) {

    log.debug("processing resources within " + uploadFolder.getPath());

    List<File> directories = new ArrayList<File>();
    HashMap<String, List<File>> fileMap = new HashMap<String, List<File>>();
    HashMap<String, ResourceType> typeMap = new HashMap<String, ResourceType>();
    File properties = null;/*  w w w. jav a 2  s  .  c  o  m*/

    //iterate through all files in the upload folder
    File[] contents = uploadFolder.listFiles();
    for (File f : contents) {

        String filename = f.getName();

        //if the file is a directory, add it to the list, we'll process this later.
        if (f.isDirectory()) {
            log.debug("directory: " + filename);
            directories.add(f);
        } else {

            String extension = FilenameUtils.getExtension(filename);
            String nameId = FilenameUtils.getBaseName(filename);

            log.debug("file: " + nameId + "(" + extension + ")");

            //determine the type of resource for the FILE
            ResourceType resourceType = getTypeFromExtension(extension);

            if (resourceType == null) {

                log.debug("unrecognised extention (" + extension + "), skipping file");

            } else if (resourceType == ResourceType.PROPERTIES) {

                log.debug("found the properties file");
                properties = f;

            } else {

                //add the file to the fileMap, key'd on the nameId
                if (!fileMap.containsKey(nameId)) {
                    List<File> fileList = new ArrayList<File>();
                    fileList.add(f);
                    fileMap.put(nameId, new ArrayList<File>(fileList));
                } else {
                    fileMap.get(nameId).add(f);
                }

                //get the current type of resource for the DOCUMENT & update it: VIDEO > AUDIO > IMAGES
                ResourceType documentType = (typeMap.containsKey(nameId)) ? typeMap.get(nameId)
                        : ResourceType.IMAGE;
                documentType = (resourceType.getValue() > documentType.getValue()) ? resourceType
                        : documentType;

                //add the document type to the typeMap, key'd on the nameId
                typeMap.put(nameId, documentType);
            }

        }

    }

    createDocumentsFromFileMap(fileMap, typeMap, properties, resourcesDir);

    log.debug("upload finished for " + uploadFolder.getPath());

    //now call the same method for each directory
    for (File dir : directories) {
        processUploadDir(dir, resourcesDir);
    }

}

From source file:com.kamike.misc.FsNameUtils.java

public static String getName(String disk, String filename, String fid, String uid) {
    String name = FilenameUtils.getName(filename);
    String prefix = FilenameUtils.getPrefix(filename);
    Date date = new Date(System.currentTimeMillis());
    String extension = FilenameUtils.getExtension(filename);
    return getName(prefix, disk, getShortDate(date), name, fid, uid, extension);
}

From source file:FileUserAccess.java

@Override
public void deleteAllUsers() {
    File folder = new File(System.getProperty("user.dir"));
    File[] filesInFolder = folder.listFiles();
    for (File f : filesInFolder)
        if (FilenameUtils.getExtension(f.getName()).equals("userobj")) {
            f.delete();/*w ww . jav a2s .c  o m*/
        }
}

From source file:ch.cyberduck.core.DownloadTransfer.java

@Override
protected void normalize() {
    log.debug("normalize");
    final List<Path> normalized = new Collection<Path>();
    for (Path download : this.getRoots()) {
        if (!this.check()) {
            return;
        }//  ww w. j a va 2s. co  m
        this.getSession().message(
                MessageFormat.format(Locale.localizedString("Prepare {0}", "Status"), download.getName()));
        boolean duplicate = false;
        for (Iterator<Path> iter = normalized.iterator(); iter.hasNext();) {
            Path n = iter.next();
            if (download.isChild(n)) {
                // The selected file is a child of a directory already included
                duplicate = true;
                break;
            }
            if (n.isChild(download)) {
                iter.remove();
            }
            if (download.getLocal().equals(n.getLocal())) {
                // The selected file has the same name; if downloaded as a root element
                // it would overwrite the earlier
                final String parent = download.getLocal().getParent().getAbsolute();
                final String filename = download.getName();
                String proposal;
                int no = 0;
                do {
                    no++;
                    proposal = FilenameUtils.getBaseName(filename) + "-" + no;
                    if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) {
                        proposal += "." + FilenameUtils.getExtension(filename);
                    }
                    download.setLocal(LocalFactory.createLocal(parent, proposal));
                } while (download.getLocal().exists());
                if (log.isInfoEnabled()) {
                    log.info("Changed local name to:" + download.getName());
                }
            }
        }
        // Prunes the list of selected files. Files which are a child of an already included directory
        // are removed from the returned list.
        if (!duplicate) {
            normalized.add(download);
        }
    }
    this.setRoots(normalized);
}

From source file:com.ewcms.publication.freemarker.generator.ListGenerator.java

@Override
public String[] getPublishAdditionUris() throws PublishException {
    String[] additionUris = new String[0];
    if (createHome && pageNumber == 0) {
        logger.debug("Start create home uri");
        String uri = getPublishUri();
        logger.debug("List page first uri is {}", uri);
        String extension = FilenameUtils.getExtension(uri);
        if (StringUtils.isNotBlank(extension)) {
            extension = "." + extension;
        }//from   ww  w.  jav a  2  s  . c  om
        String homeUri = FilenameUtils.getFullPath(uri) + DEFAULT_HOME_NAME + extension;
        additionUris = new String[] { homeUri };
        logger.debug("Home page uri is {}", additionUris[0]);
    }
    return additionUris;
}

From source file:hudson.plugins.emailext.plugins.content.AbstractEvalContent.java

protected InputStream getFileInputStream(String fileName, String extension) throws FileNotFoundException {

    InputStream inputStream;//from  w  w  w .ja  v  a 2 s.  co m
    if (fileName.startsWith("managed:")) {
        String managedFileName = fileName.substring(8);
        try {
            inputStream = getManagedFile(managedFileName);
        } catch (NoClassDefFoundError e) {
            inputStream = null;
        }

        if (inputStream == null) {
            throw new FileNotFoundException(String.format("Managed file '%s' not found", managedFileName));
        }
        return inputStream;
    }

    String fileExt = FilenameUtils.getExtension(fileName);

    // add default extension if needed
    if (fileExt.equals("")) {
        fileName += extension;
    }

    inputStream = getClass().getClassLoader()
            .getResourceAsStream("hudson/plugins/emailext/templates/" + fileName);

    if (inputStream == null) {
        File templateFile = new File(scriptsFolder(), fileName);

        // the file may have an extension, but not the correct one
        if (!templateFile.exists()) {
            fileName += extension;
            templateFile = new File(scriptsFolder(), fileName);
        }
        inputStream = new FileInputStream(templateFile);
    }

    return inputStream;
}

From source file:com.antonjohansson.svncommit.core.domain.ModifiedItem.java

/**
 * Gets whether or not this item can be replicated.
 *
 * @return Returns {@code true} if this item can be replicated.
 *//*from  w  ww  . j a  v  a2  s . co  m*/
public boolean canReplicate() {
    String extension = FilenameUtils.getExtension(fileNameProperty.getValue());
    return StringUtils.equalsIgnoreCase(extension, "SQL");
}