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:biz.dfch.j.graylog2.plugin.filter.dfchBizExecScript.java

public dfchBizExecScript() throws IOException, URISyntaxException {
    try {/* ww  w  .  ja  va 2 s . co m*/
        LOG.debug(String.format("*** [%d] %s: Initialising plugin ...\r\n", Thread.currentThread().getId(),
                DF_PLUGIN_NAME));

        // get config file
        CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
        URI uri = codeSource.getLocation().toURI();

        // String path = uri.getSchemeSpecificPart();
        // path would contain absolute path including jar file name with extension
        // String path = FilenameUtils.getPath(uri.getPath());
        // path would contain relative path (no leadig '/' and no jar file name

        String path = FilenameUtils.getPath(uri.getPath());
        if (!path.startsWith("/")) {
            path = String.format("/%s", path);
        }
        String baseName = FilenameUtils.getBaseName(uri.getSchemeSpecificPart());
        if (null == baseName || baseName.isEmpty()) {
            baseName = this.getClass().getPackage().getName();
        }

        // get config values
        configurationFileName = FilenameUtils.concat(path, baseName + ".conf");
        JSONParser jsonParser = new JSONParser();
        Object object = jsonParser.parse(new FileReader(configurationFileName));

        JSONObject jsonObject = (JSONObject) object;
        String scriptEngine = (String) jsonObject.get(DF_SCRIPT_ENGINE);
        String scriptPathAndName = (String) jsonObject.get(DF_SCRIPT_PATH_AND_NAME);
        if (null == scriptPathAndName || scriptPathAndName.isEmpty()) {
            scriptPathAndName = FilenameUtils.concat(path, (String) jsonObject.get(DF_SCRIPT_NAME));
        }
        Boolean scriptCacheContents = (Boolean) jsonObject.get(DF_SCRIPT_CACHE_CONTENTS);
        Boolean scriptDisplayOutput = (Boolean) jsonObject.get(DF_SCRIPT_DISPLAY_OUTPUT);
        String pluginPriority = (String) jsonObject.get(DF_PLUGIN_PRIORITY);
        Boolean pluginDropMessage = (Boolean) jsonObject.get(DF_PLUGIN_DROP_MESSAGE);
        Boolean pluginDisabled = (Boolean) jsonObject.get(DF_PLUGIN_DISABLED);

        // set configuration
        Map<String, Object> map = new HashMap<>();
        map.put(DF_SCRIPT_ENGINE, scriptEngine);
        map.put(DF_SCRIPT_PATH_AND_NAME, scriptPathAndName);
        map.put(DF_SCRIPT_DISPLAY_OUTPUT, scriptDisplayOutput);
        map.put(DF_SCRIPT_CACHE_CONTENTS, scriptCacheContents);
        map.put(DF_PLUGIN_PRIORITY, pluginPriority);
        map.put(DF_PLUGIN_DROP_MESSAGE, pluginDropMessage);
        map.put(DF_PLUGIN_DISABLED, pluginDisabled);

        initialize(new Configuration(map));
    } catch (IOException ex) {
        LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n%s\r\n",
                Thread.currentThread().getId(), DF_PLUGIN_NAME, ex.getMessage()));
        LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - IOException - Filter will be disabled.");
        ex.printStackTrace();
    } catch (Exception ex) {
        LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n",
                Thread.currentThread().getId(), DF_PLUGIN_NAME));
        LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - Exception - Filter will be disabled.");
        ex.printStackTrace();
    }
}

From source file:de.mpg.imeji.presentation.servlet.FileServlet.java

@Override
public void init() {
    try {//from   www  .  j  av a  2s . c  o m
        storageController = new StorageController();
        logger.info("ImageServlet initialized");
        authorization = new Authorization();
        navivation = new Navigation();
        domain = StringHelper.normalizeURI(navivation.getDomain());
        domain = domain.substring(0, domain.length() - 1);
        digilibUrl = PropertyReader.getProperty("digilib.imeji.instance.url");
        if (digilibUrl != null && !digilibUrl.isEmpty())
            digilibUrl = StringHelper.normalizeURI(digilibUrl);
        InternalStorageManager ism = new InternalStorageManager();
        internalStorageRoot = FilenameUtils
                .getBaseName(FilenameUtils.normalizeNoEndSeparator(ism.getStoragePath()));
    } catch (Exception e) {
        throw new RuntimeException("Image servlet not initialized! " + e);
    }
}

From source file:it.geosolutions.geobatch.destination.action.datamigration.MigrationAction.java

/**
 *
 *///w  ww . j a  v a 2 s . c  om
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException {

    listenerForwarder.setTask("Check config");
    checkInit();
    final LinkedList<EventObject> ret = new LinkedList<EventObject>();
    try {
        listenerForwarder.started();
        while (!events.isEmpty()) {
            EventObject event = events.poll();
            if (event instanceof FileSystemEvent) {
                FileSystemEvent fse = (FileSystemEvent) event;
                File file = fse.getSource();
                doProcess(configuration, FilenameUtils.getBaseName(file.getName()));
            }

            // pass the feature config to the next action
            ret.add(new FileSystemEvent(((FileSystemEvent) event).getSource(), FileSystemEventType.FILE_ADDED));
        }
        listenerForwarder.completed();
        return ret;
    } catch (Exception t) {
        listenerForwarder.failed(t);
        throw new ActionException(this, t.getMessage(), t);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java

public static void testOneWay(Class<? extends CollectionReader> aReader,
        Class<? extends AnalysisComponent> aWriter, String aExpectedFile, String aFile, Object... aExtraParams)
        throws Exception {
    Class<?> dkproReaderBase = Class.forName(RESOURCE_COLLECTION_READER_BASE);
    if (!dkproReaderBase.isAssignableFrom(aReader)) {
        throw new IllegalArgumentException(
                "Reader must be a subclass of [" + RESOURCE_COLLECTION_READER_BASE + "]");
    }//  w  w w .j av a 2 s  . com

    Class<?> dkproWriterBase = Class.forName(JCAS_FILE_WRITER_IMPL_BASE);
    if (!dkproWriterBase.isAssignableFrom(aWriter)) {
        throw new IllegalArgumentException("writer must be a subclass of [" + JCAS_FILE_WRITER_IMPL_BASE + "]");
    }

    // We assume that the writer is creating a file with the same extension as is provided as
    // the expected file
    String extension = FilenameUtils.getExtension(aExpectedFile);
    String name = FilenameUtils.getBaseName(aFile);

    testOneWay2(aReader, aWriter, aExpectedFile, name + "." + extension, aFile, aExtraParams);
}

From source file:modmanager.swing.ImageListRenderer.java

@Override
public Component getListCellRendererComponent(JList<? extends String> jlist, String e, int i,
        boolean isSelected, boolean isFocused) {
    if (isSelected) {
        this.setBackground(UIManager.getColor("List.selectionBackground"));
    } else {//  w w  w  .j  av a 2s  .c o  m
        this.setBackground(UIManager.getColor("List.background"));
    }

    imagePanel.setImage(images.get(e));
    fileNameLabel.setText(FilenameUtils.getBaseName(e));

    return this;
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtilsTest.java

@Test
public void testWithSpace() throws Exception {
    File dir = workspace.newFolder("this is a test");
    File file = new File(dir, "this is a file name.extension with spaces");

    System.out.println("Original: " + file);
    System.out.println("Original (URL): " + file.toURI().toURL());
    File asFile = ResourceUtils.getUrlAsFile(file.toURI().toURL(), false);
    System.out.println("As file: " + asFile.getPath());
    assertEquals("this is a file name", FilenameUtils.getBaseName(asFile.getPath()));
    assertEquals("extension with spaces", FilenameUtils.getExtension(asFile.getPath()));
}

From source file:com.bt.download.android.gui.UniversalScanner.java

private void scanDocument(String filePath) {
    File file = new File(filePath);

    if (documentExists(filePath, file.length())) {
        return;/* ww w. j a va2 s .co m*/
    }

    String displayName = FilenameUtils.getBaseName(file.getName());

    ContentResolver cr = context.getContentResolver();

    ContentValues values = new ContentValues();

    values.put(DocumentsColumns.DATA, filePath);
    values.put(DocumentsColumns.SIZE, file.length());
    values.put(DocumentsColumns.DISPLAY_NAME, displayName);
    values.put(DocumentsColumns.TITLE, displayName);
    values.put(DocumentsColumns.DATE_ADDED, System.currentTimeMillis());
    values.put(DocumentsColumns.DATE_MODIFIED, file.lastModified());
    values.put(DocumentsColumns.MIME_TYPE, UIUtils.getMimeType(filePath));

    Uri uri = cr.insert(Documents.Media.CONTENT_URI, values);

    FileDescriptor fd = new FileDescriptor();
    fd.fileType = Constants.FILE_TYPE_DOCUMENTS;
    fd.id = Integer.valueOf(uri.getLastPathSegment());

    shareFinishedDownload(fd);
}

From source file:com.frostwire.android.gui.adapters.menu.RenameFileMenuAction.java

private void renameFile(String newFileName) {
    Context context = getContext();
    if (context == null) {
        return;/*  ww  w . j a  va 2s . c o  m*/
    }
    if (isValidFileName(newFileName)) {
        fd.filePath = Librarian.instance().renameFile(context, fd, newFileName);
        fd.title = FilenameUtils.getBaseName(newFileName);
        if (adapter != null) {
            adapter.notifyDataSetChanged();
        }
    } else {
        UIUtils.showLongMessage(context, R.string.invalid_filename);
    }
}

From source file:fr.inria.soctrace.tools.importer.otf2.Otf2Importer.java

private String getNewTraceDBName(String traceFile) {
    String basename = FilenameUtils.getBaseName(traceFile);
    String extension = FilenameUtils.getExtension(traceFile);
    if (extension.equals(Otf2Constants.TRACE_EXT)) {
        basename = basename.replace(Otf2Constants.TRACE_EXT, "");
    }/*from  w  ww. ja  v a  2 s . co  m*/
    return FramesocManager.getInstance().getTraceDBName(basename);
}

From source file:com.splunk.shuttl.archiver.archive.PathResolver.java

/**
 * Resolves index from a {@link URI} to a bucket.<br/>
 * <br/>/*from www .  j a v  a  2s  .c o  m*/
 * 
 * @param bucketURI
 *          , {@link URI} needs to have the index in a structure decided by a
 *          {@link PathResolver}.
 */
public String resolveIndexFromUriToBucket(URI bucketURI) {
    String bucketPath = UtilsURI.getPathByTrimmingEndingFileSeparator(bucketURI);
    String parentWhichIsIndex = getParent(bucketPath);
    return FilenameUtils.getBaseName(parentWhichIsIndex);
}