List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:com.orange.wro.taglib.config.GroupLoader.java
@Override public Map<ResourceType, String> getMinimizedResources() { Map<ResourceType, String> res = new HashMap<ResourceType, String>(); String groupName = group.getName(); Set<String> resourcePaths = wroTagLibConfig.getResourcePaths(); if (resourcePaths != null) { for (String path : resourcePaths) { String fileName = FilenameUtils.getName(path); String group = wroTagLibConfig.getGroupForFile(fileName); if (group != null) { if (groupName.equals(FilenameUtils.getBaseName(group))) { String type = FilenameUtils.getExtension(group); res.put(ResourceType.get(type), path); }/* w w w . jav a 2 s . com*/ } else { if (FilenameUtils.getBaseName(path).startsWith(groupName)) { String type = FilenameUtils.getExtension(path); res.put(ResourceType.get(type), path); } } } } return res; }
From source file:com.intuit.tank.project.ExternalScript.java
public ScriptEngine getEngine() { return new ScriptEngineManager().getEngineByExtension(FilenameUtils.getExtension(name)); }
From source file:gui.menubar.SaveCommand.java
/** * Passes the file to the LevelSaver, first ensuring it has the correct * file type suffix./*w w w .j a v a 2 s .c o m*/ */ @Override public void execute() { fileChooser.setCurrentDirectory(new File(SAVE_FILE_LOCATION)); fileChooser.setFileFilter(new XmlFileFilter()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); if (selectedFile != null) { if (FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase("xml")) { levelSaver.save(level, selectedFile); } else { selectedFile = new File(selectedFile.getParentFile(), FilenameUtils.getBaseName(selectedFile.getName()) + ".xml"); levelSaver.save(level, selectedFile); } } } }
From source file:ch.cyberduck.core.transfer.download.RenameFilter.java
@Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if (status.isExists()) { final String filename = file.getName(); int no = 0; do {//from ww w .ja v a 2 s . c o m String proposal = String.format("%s-%d", FilenameUtils.getBaseName(filename), ++no); if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) { proposal += String.format(".%s", FilenameUtils.getExtension(filename)); } if (parent.getRename().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(LocalFactory.get(local.getParent(), proposal)); } } while (status.getRename().local.exists()); if (log.isInfoEnabled()) { log.info(String.format("Changed download target from %s to %s", local, status.getRename().local)); } if (log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", local)); } status.setExists(false); } else { if (parent.getRename().local != null) { status.rename(LocalFactory.get(parent.getRename().local, file.getName())); } if (log.isInfoEnabled()) { log.info(String.format("Changed download target from %s to %s", local, status.getRename().local)); } } return status; }
From source file:cloudlens.parser.FileReader.java
public static ArrayList<String> fullPaths(String[] filePaths) { final ArrayList<String> res = new ArrayList<>(); if (filePaths != null) { for (final String filePath : filePaths) { final File file = new File(filePath); if (!file.exists()) { throw new CLException(filePath + ": no such file."); }/*from w w w . j av a 2 s . co m*/ final String filename = file.getName(); if (!FilenameUtils.getExtension(filename).equals("js")) { throw new CLException(filePath + " is not a JS file."); } final String abspath = file.getAbsolutePath(); res.add(abspath); } } return res; }
From source file:com.intuit.tank.tools.debugger.ConfiguredLanguage.java
/** * //from w ww . j a va2 s .c o m * @param scriptName * @return */ public static ConfiguredLanguage getLanguagebyExtension(String scriptName) { ConfiguredLanguage ret = null; String extension = FilenameUtils.getExtension(scriptName); ScriptEngine engineByExtension = manager.getEngineByExtension(extension); for (ConfiguredLanguage lang : configuredLanguages) { if (lang.name == engineByExtension.getFactory().getLanguageName()) { ret = lang; break; } } return ret; }
From source file:com.jaspersoft.studio.server.dnd.RepositoryFileResourceDropTargetListener.java
@Override public void drop(DropTargetEvent event) { // Drop only the allowed items String[] items = (String[]) event.data; for (String item : items) { String fileExt = Misc.nvl(FilenameUtils.getExtension(item).toLowerCase()); if (RepositoryDNDHelper.isDropOperationAllowed(fileExt) && event.item != null && event.item.getData() instanceof MResource && event.data instanceof String[]) { MResource targetParentResource = (MResource) event.item.getData(); RepositoryDNDHelper.performDropOperation(targetParentResource, item); }//from w w w. jav a 2 s.c om } }
From source file:com.silverpeas.sandbox.converter.ODTConverter.java
public File convert(final File document) { String fileName = document.getName(); String suffix = FilenameUtils.getExtension(fileName); if (suffix != null && !suffix.trim().isEmpty()) { fileName = FilenameUtils.getBaseName(fileName); }//from w ww . j a v a 2 s .co m fileName += "." + format.name(); File output = new File(DESTINATION_PATH + fileName); OpenOfficeConnection connection = new SocketOpenOfficeConnection(OPENOFFICE_SERVER_PORT); try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(document, output); } catch (Exception e) { throw new DocumentConvertionException(e.getMessage(), e); } finally { if (connection.isConnected()) { connection.disconnect(); } } return output; }
From source file:com.github.bfour.fpliteraturecollector.service.FileStorageService.java
public Link persist(File localFile, Literature lit) throws IOException { String fileName = getFileNameForLiterature(lit); fileName += "." + FilenameUtils.getExtension(localFile.getAbsolutePath()); File file = new File(rootDirectory.getAbsolutePath() + "/" + lit.getID() + "/" + fileName); FileUtils.copyFile(localFile, file); return new Link(fileName, file.toURI()); }
From source file:com.bibisco.manager.ImageManager.java
private static String writeFile(FileItem pFileItem) { String lStrFileName = null;//from w w w . j a va 2 s . c o m mLog.debug("Start writeFile(FileItem, String)"); String lStrFileItemFileName = pFileItem.getName(); if (lStrFileItemFileName == null) { mLog.error("File name is null"); throw new BibiscoException(BibiscoException.IO_EXCEPTION); } // build file name StringBuilder lStringBuilderFileName = new StringBuilder(); lStringBuilderFileName.append(UUID.randomUUID().toString()); lStringBuilderFileName.append("."); lStringBuilderFileName.append(FilenameUtils.getExtension(lStrFileItemFileName)); lStrFileName = lStringBuilderFileName.toString(); // get file path String lStrFilePath = getFilePath(lStrFileName); // write file to disk File lFile = new File(lStrFilePath); try { pFileItem.write(lFile); } catch (Throwable t) { mLog.error(t, "insert() Error writing file: lFile=" + lFile); throw new BibiscoException(BibiscoException.IO_EXCEPTION); } mLog.debug("End writeFile(FileItem): return ", lStrFileName); return lStrFileName; }