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

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

Introduction

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

Prototype

public static String getName(String filename) 

Source Link

Document

Gets the name minus the path from a full filename.

Usage

From source file:com.orange.ocara.model.export.docx.CommentPresenter.java

public String getAttachmentName() {

    switch (getType()) {
    case AUDIO: {
        String baseName = FilenameUtils.getBaseName(value.getAttachment());
        return notNull(String.format("%s.bin", baseName));
    }//from  w w  w  .  j av a2s .  c o m

    default:
        return notNull(FilenameUtils.getName(value.getAttachment()));
    }

}

From source file:ccw.editors.clojure.LoadFileAction.java

/**
 * @param editor the clojure editor//  w w w  .ja va  2s.  co  m
 * @param mode the "run" or "debug" launch mode
 */
public static void run(final ClojureEditor editor, final String mode, boolean forceLeinLaunchWhenPossible) {
    final IFile editorFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);

    final String filePath = computeFilePath(editor, editorFile);
    final String fileName = FilenameUtils.getName(filePath);

    if (filePath == null) {
        editor.setStatusLineErrorMessage("Unable to create a Clojure Application for this editor's content");
        return;
    }

    final String sourcePath = computeSourcePath(editor, editorFile, filePath);

    final REPLView repl = REPLView.activeREPL.get();
    if (repl != null && !repl.isDisposed()) {
        try {
            evaluateFileText(repl, editor.getDocument().get(), filePath, sourcePath, fileName);
        } catch (Exception e) {
            CCWPlugin.logError("Could not start a REPL for loading file " + filePath, e);
        }
    } else if (editorFile != null) {
        CCWPlugin.getTracer().trace(TraceOptions.LAUNCHER, "No active REPL found (",
                (repl == null) ? "active repl is null" : "active repl is disposed",
                "), so launching a new one");
        final IProject project = editorFile.getProject();
        new ClojureLaunchShortcut().launchProject(project, mode, forceLeinLaunchWhenPossible,
                new IWithREPLView() {
                    @Override
                    public void run(final REPLView repl) {
                        if (repl != null && !repl.isDisposed()) {
                            try {
                                evaluateFileText(repl, editor.getDocument().get(), filePath, sourcePath,
                                        fileName);
                            } catch (Exception e) {
                                CCWPlugin.logError("Could not start a REPL for loading file " + filePath, e);
                            }
                            SwitchNamespaceAction.run(repl, editor, false);
                        } else {
                            CCWPlugin.logError("Could not start a REPL for loading file " + filePath);
                        }
                    }
                });
    } else {
        editor.setStatusLineErrorMessage("Cannot start a REPL for loading " + fileName);
    }
}

From source file:com.centeractive.ws.common.ResourceUtils.java

private static Path parsePath(String resourcePath) {
    checkNotNull(resourcePath, "resourcePath cannot be null");
    Path path = new Path();
    path.packagePath = getFullPath(resourcePath);
    path.resourcePath = FilenameUtils.getName(resourcePath);
    return path;// w  w w  .ja v  a  2 s.co m
}

From source file:jodtemplate.pptx.io.PPTXImageReader.java

public void read(final Resources resources, final Presentation presentation) throws IOException {
    final String imagesPath = Utils.removePrefixSeparator(presentation.getFullPath() + "media/");
    for (Resource resource : resources.getResources()) {
        if (resource.getName().startsWith(imagesPath)) {
            final String fileName = FilenameUtils.getName(resource.getName());
            if (fileName.matches("^imageJodT.+?$")) {
                try (final InputStream imageStream = resource.getInputStream()) {
                    final String md5 = DigestUtils.md5Hex(imageStream);
                    final Image image = new Image();
                    image.setFullPath("/" + resource.getName());
                    image.setMd5(md5);//from   ww  w . ja  va2s . c  o m
                    presentation.addImage(image);
                }
            }
        }
    }
}

From source file:com.atlassian.theplugin.util.CodeNavigationUtil.java

/**
 * Note: must be run from event dispatch thread or inside read-action only!
 *//*from ww w. j a va 2  s  .  co m*/
@Nullable
public static PsiFile guessMatchingFile(String pathname, PsiFile[] psifiles, VirtualFile baseDir) {
    // PL-822 fix
    // for making it work if pathname comes from different OS than the file itself
    // e.g. Bamboo works on Windows, send pathname and the user has a project opened in IDEA on Linux
    pathname = pathname.replace('\\', '/');

    PsiFile bestMatch = null;

    int difference = 0;

    if (psifiles != null) {

        for (PsiFile psiFile : psifiles) {
            // we use hard-coded '/' as separator in order to make string comparison platform independent
            String absolutePath = psiFile.getVirtualFile().getUrl();
            if (absolutePath == null) {
                continue;
            }

            int diff = StringUtils.indexOfDifference(StringUtils.reverse(pathname),
                    StringUtils.reverse(absolutePath));
            if (diff >= FilenameUtils.getName(absolutePath).length()
                    && (diff > difference || absolutePath.equals(pathname))) {
                difference = diff;
                bestMatch = psiFile;
                if (absolutePath.equals(pathname)) {
                    break;
                }
            }
        }
    }
    return bestMatch;
}

From source file:com.atlassian.theplugin.commons.VersionedVirtualFile.java

public String getName() {
    return FilenameUtils.getName(getUrl());
}

From source file:mesclasses.util.EleveFileUtil.java

public static String moveFileForEleve(Eleve eleve, File file, String type) throws IOException {
    File eleveDir = getEleveDirWithType(eleve, type);
    eleveDir.mkdirs();//  w w  w.  j a v  a2  s.c  o  m
    String fileName = FilenameUtils.getName(file.getPath());
    File newFile = new File(eleveDir.getPath() + File.separator + fileName);
    if (newFile.exists()) {
        throw new IOException(
                "Le fichier " + fileName + " de type " + type + " existe dj pour " + eleve.getFirstName());
    }
    FileUtils.moveFile(file, newFile);
    return newFile.getPath();
}

From source file:com.tao_harmony.fx2extend.journal.JournalUtil.java

/**
 * ?????./*from  w w w .jav a2 s  .  com*/
 *
 * @param journals
 *            
 * @param fileName
 *            ?
 * @throws NoListException
 *             ?Null??????
 * @throws FileNameEmptyException
 *             ???Null??????
 * @throws IOException
 *             ???????
 */
public static void saveJournals(List<Journal> journals, String fileName)
        throws NoListException, FileNameEmptyException, IOException {
    // Null?
    if (journals == null) {
        throw new NoListException();
    }
    // ??
    if (journals.isEmpty()) {
        throw new NoListException();
    }
    // ????
    if (StringUtils.isBlank(fileName) || StringUtils.isBlank(FilenameUtils.getName(fileName))) {
        throw new FileNameEmptyException();
    }
    // ?.slp???
    String name = FilenameUtils.getFullPath(fileName) + FilenameUtils.getBaseName(fileName) + ".slp";
    // ?
    CsvManager csvManager = new CsvEntityManager();
    //CsvManager csvManager = CsvManagerFactory.newCsvManager();
    csvManager.save(journals, Journal.class).to(new File(name));

}

From source file:fr.paris.lutece.portal.service.fileupload.FileUploadService.java

/**
 * Return the file name, without its whole path, from the file item.
 * This should be used has FileItem.getName can return the whole path.
 * @param fileItem the fileItem to process
 * @return the name of the file associated
 *//*from   w  w  w  . j a va2  s.  c  o  m*/
public static String getFileNameOnly(FileItem fileItem) {
    String strFileName;

    if (fileItem != null) {
        strFileName = fileItem.getName();

        if (strFileName != null) {
            strFileName = FilenameUtils.getName(strFileName);
        }
    } else {
        strFileName = null;
    }

    return strFileName;
}

From source file:de.thischwa.pmcms.tool.file.FileComparator.java

@Override
public int compare(final File f1, final File f2) {
    if (f1.getAbsolutePath().equals(f2.getAbsolutePath()))
        return 0;

    String path1 = FilenameUtils.getFullPath(f1.getAbsolutePath());
    String path2 = FilenameUtils.getFullPath(f2.getAbsolutePath());
    String name1 = FilenameUtils.getName(f1.getAbsolutePath());
    String name2 = FilenameUtils.getName(f2.getAbsolutePath());
    if (path1.equals(path2) || (StringUtils.isBlank(path1) && StringUtils.isBlank(path2)))
        return name1.compareTo(name2);
    String[] pathParts1 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path1), File.separatorChar);
    String[] pathParts2 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path2), File.separatorChar);

    if (pathParts1.length < pathParts2.length)
        return -1;
    if (pathParts1.length > pathParts2.length)
        return +1;

    int i = 0;//  ww w.  ja  va 2 s. c  om
    while (i < pathParts1.length && i < pathParts2.length) {
        if (!pathParts1[i].equals(pathParts2[i]))
            return pathParts1[i].compareTo(pathParts2[i]);
        i++;
    }
    return 0;
}