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

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

Introduction

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

Prototype

public static String getBaseName(String filename) 

Source Link

Document

Gets the base name, minus the full path and extension, from a full filename.

Usage

From source file:de.thischwa.pmcms.livecycle.C5MessageResolverImpl.java

@Override
public void setServletContext(ServletContext servletContext) throws RuntimeException {
    Path fileSystemPath = new Path(PropertiesLoader.getFilemanagerPath());
    fileSystemPath.addFolder(langPath);/*from   w  w w  .  j a  v a  2s.  c  o  m*/
    File msgFolder = new File(Constants.APPLICATION_DIR, fileSystemPath.toString());
    if (!msgFolder.exists())
        throw new RuntimeException(
                String.format("C5 scripts folder couldn't be found: %s", msgFolder.getAbsolutePath()));
    logger.debug(String.format("try to resolve lang-data from dir: %s", msgFolder.getAbsolutePath()));
    ObjectMapper mapper = new ObjectMapper();
    try {
        for (File file : msgFolder.listFiles(jsFilter)) {
            String lang = FilenameUtils.getBaseName(file.getName());
            logger.debug(String.format("  - found: %s", file.getAbsoluteFile()));
            @SuppressWarnings("unchecked")
            Map<String, String> langData = mapper.readValue(file, Map.class);
            collectLangData(lang, langData);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:eu.esdihumboldt.hale.io.groovy.ui.snippets.SnippetConfigurationPage.java

@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);

    if (firstShow) {
        // determine default for identifier from file name

        URI loc = null;//  w  w w. j  a v a2s.co m
        try {
            loc = getWizard().getProvider().getSource().getLocation();
        } catch (NullPointerException e) {
            // ignore
        }
        if (loc != null) {
            String baseName = FilenameUtils.getBaseName(loc.getPath());
            if (baseName != null && !baseName.isEmpty()) {
                baseName = baseName.replaceAll("[^\\w]", "_");
                identifierText.setText(baseName);
                updateState();
            }
        }
    }
}

From source file:com.nuvolect.securesuite.webserver.connector.CmdExtract.java

@Override
public InputStream go(@NonNull Map<String, String> params) {
    String url = params.get("url");
    OmniFile zipFile = new OmniFile(params.get("target"));
    String volumeId = zipFile.getVolumeId();
    OmniFile destinationFolder = zipFile.getParentFile();
    JsonArray added = new JsonArray();

    /**//from   ww w  . j  a  v a  2  s .  c om
     * Get the parent directory and inside it create a new directory
     */
    if (params.containsKey("makedir") && params.get("makedir").contentEquals("1")) {

        String dirName = FilenameUtils.getBaseName(zipFile.getName());
        if (dirName == null || dirName.isEmpty()) {
            dirName = "Archive";
        }

        /**
         * Create a new directory.
         * Avoid collision by adding ~ to make directory name unique.
         */
        String path = destinationFolder.getPath() + "/" + dirName;
        destinationFolder = new OmniFile(volumeId, path);
        destinationFolder = OmniUtil.makeUniqueName(destinationFolder);
        destinationFolder.mkdir();

        // Record addition of the new directory
        added.add(destinationFolder.getFileObject(url));
    }

    /**
     * Unzip files and directories and record additions to 'added'
     */
    OmniZip.unzipFile(zipFile, destinationFolder, added, url);

    JsonObject wrapper = new JsonObject();
    wrapper.add("added", added);

    if (DEBUG) {
        LogUtil.log(LogUtil.LogType.CMD_EXTRACT, "json result: " + wrapper.toString());
    }

    return getInputStream(wrapper);
}

From source file:com.igormaznitsa.zxpspritecorrector.files.FileNameDialog.java

public static String[] makeFileNames(final String baseName) {
    final String[] result = new String[4];
    for (int i = 0; i < 4; i++) {
        result[i] = FilenameUtils.getBaseName(baseName) + '_' + i + '.' + FilenameUtils.getExtension(baseName);
    }/*from ww w  .  java  2  s  .  c o m*/
    return result;
}

From source file:com.consol.citrus.admin.util.FileHelperImpl.java

/**
 * {@inheritDoc}/*from  w ww.  jav  a 2s  . c o m*/
 */
public String[] getFiles(File directory, final String fileExtension) {
    List<String> fileNames = new ArrayList<String>();

    if (!directory.exists()) {
        return new String[] {};
    }

    File[] found = directory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(fileExtension);
        }
    });

    for (File file : found) {
        fileNames.add(FilenameUtils.getBaseName(file.getName()));
    }

    return fileNames.toArray(new String[fileNames.size()]);
}

From source file:de.dfki.resc28.ole.bootstrap.listener.AssetListener.java

public AssetListener(String fileName, IGraphStore graphStore) {
    super();//from w w w .j av  a  2 s .c  o  m

    this.fileName = fileName;
    this.basename = FilenameUtils.getBaseName(fileName);
    this.graphStore = graphStore;
}

From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java

public void readAndParseDVER() throws WrongConfigurationException, IOException {
    if (scanDir == null && archiveDir == null && maxFiles == null && xmlDir == null) {
        log.info("Wrong configuration used");
        throw new WrongConfigurationException("Some configuration is missing in job");
    }//from  w w w . j  ava  2s . c  om

    // Fetching the files up to 50
    DirectoryScanner scanner = new HeadDirectoryScanner(Integer.parseInt(maxFiles.trim()));
    File dverScanDirectory = new File(scanDir);
    if (dverScanDirectory.isDirectory()) {
        List<File> files = scanner.listFiles(dverScanDirectory);
        // Sorting the list as per created time.
        Collections.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
        // Iterate the files list
        for (File file : files) {
            if (file.isFile()) {
                PDFTextStripperByArea textStripper = readDVER(file);
                generateDverXML(FilenameUtils.getBaseName(file.getName()), textStripper);
            }
        }
    } else {
        throw new WrongConfigurationException("The Path to look for DVER is not a directory");
    }
}

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);
    }// w  w w  . j a va 2 s.c om
    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.doplgangr.secrecy.FileSystem.File.java

public File(java.io.File file, String secret) {
    if (file.exists()) {
        name = FilenameUtils.getBaseName(file.getName());
        try {/*  w  w  w.  j a  v a  2  s  .  c  om*/
            name = Base64Coder.decodeString(name); //if name is invalid, return original name
        } catch (IllegalArgumentException ignored) {

        }
        FileType = FilenameUtils.getExtension(file.getName());
        this.file = file;
        this.key = secret;
        String path = file.getParent();
        this.size = humanReadableByteCount(file.length());
        thumbnailRealFile = new java.io.File(path + "/_thumb" + file.getName());
        Timestamp = new Date(file.lastModified());
    } else {
        invalidFile = true;
    }
}

From source file:ch.cyberduck.ui.cocoa.DuplicateFileController.java

@Override
protected void beginSheet(final NSWindow window) {
    final Path selected = this.getSelected();
    alert.setIcon(IconCacheFactory.<NSImage>get().fileIcon(selected, 64));
    String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("browser.duplicate.format"),
            FilenameUtils.getBaseName(selected.getName()),
            UserDateFormatterFactory.get().getShortFormat(System.currentTimeMillis(), false)
                    .replace(Path.DELIMITER, ':'),
            StringUtils.isNotEmpty(selected.getExtension()) ? "." + selected.getExtension()
                    : StringUtils.EMPTY);
    inputField.setStringValue(proposal);
    super.beginSheet(window);
}