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

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

Introduction

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

Prototype

public static String removeExtension(String filename) 

Source Link

Document

Removes the extension from a filename.

Usage

From source file:net.sourceforge.atunes.kernel.modules.tags.PropertiesFileTagAdapter.java

private String getFileNameForCover(final ILocalAudioObject file) {
    if (file == null) {
        return null;
    }/*  www . j  a  v a  2 s .  c  o  m*/

    return StringUtils.getString(FilenameUtils.removeExtension(file.getUrl()), ".", ImageUtils.FILES_EXTENSION);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.examples.io.ReutersCorpusReader.java

@Override
public Set<String> getTextClassificationOutcomes(JCas jcas) throws CollectionException {
    Set<String> outcomes = new HashSet<String>();

    DocumentMetaData dmd = DocumentMetaData.get(jcas);
    String titleWithoutExtension = FilenameUtils.removeExtension(dmd.getDocumentTitle());

    if (!goldLabelMap.containsKey(titleWithoutExtension)) {
        throw new CollectionException(new Throwable("No gold label for document: " + dmd.getDocumentTitle()));
    }//from www. j  av  a2  s .co  m

    for (String label : goldLabelMap.get(titleWithoutExtension)) {
        outcomes.add(label);
    }
    return outcomes;
}

From source file:eu.udig.style.jgrass.core.PredefinedColorRules.java

/**
 * Reads and returns the {@link HashMap map} holding all predefined color rules.
 * //from  w  w  w  .j  av  a 2 s.co m
 * <p>
 * The map has the name of the colortable as key and 
 * and array of Strings as value, representing the colors and values
 * of the colortable.<br>
 * The array can be of two types:<br>
 * <ul>
 *  <li>
 *      3 values per row (r, g, b): in that case the colortable
 *      will be interpolated over a supplied range and be kept 
 *      continuos between the values. On example is the elevation map.
 *  </li>
 *  <li>
 *      8 values per row (v1, r1, g1, b1, v2, r2, g2, b2): 
 *      in that case the values of every step is defined and the 
 *      color rules are used as they come. One example is the corine 
 *      landcover map, that has to be consistent with the given values
 *      and colors.
 *  </li>
 * </ul>
 * </p>
 *
 * @param doReset if true the folder of colortables is reread.
 * @return the map of colortables.
 */
public static HashMap<String, String[][]> getColorsFolder(boolean doReset) {
    int size = colorRules.size();
    if (!doReset && size > 0) {
        return colorRules;
    }

    /*
     * read the default colortables from the plugin folder
     */
    try {
        // create the rainbow colortable, which has to exist
        colorRules.put("rainbow", rainbow);

        File colorTablesFolder = null;
        Bundle bundle = Platform.getBundle(JGrassrasterStyleActivator.PLUGIN_ID);
        if (bundle != null) {
            URL queriesUrl = bundle.getResource("colortables");
            String colorTablesFolderPath = FileLocator.toFileURL(queriesUrl).getPath();
            colorTablesFolder = new File(colorTablesFolderPath);
        } else {
            File baseFolder = new File("..");
            File[] listFiles = baseFolder.listFiles();

            for (File folder : listFiles) {
                String name = folder.getName().toLowerCase();
                if (name.startsWith("eu.hydrologis.jgrass.libs") && !name.contains("external")
                        && !name.contains("scripting")) {
                    colorTablesFolder = new File(folder, "colortables");
                }
            }

        }
        if (colorTablesFolder != null && colorTablesFolder.exists()) {
            File[] files = colorTablesFolder.listFiles();
            for (File file : files) {
                String name = file.getName();
                if (name.toLowerCase().endsWith(".clr")) {
                    BufferedReader bR = new BufferedReader(new FileReader(file));
                    List<String[]> lines = new ArrayList<String[]>();
                    String line = null;
                    int cols = 0;
                    while ((line = bR.readLine()) != null) {
                        if (line.startsWith("#")) {
                            continue;
                        }
                        String[] lineSplit = line.trim().split("\\s+");
                        cols = lineSplit.length;
                        lines.add(lineSplit);
                    }
                    bR.close();
                    String[][] linesArray = (String[][]) lines.toArray(new String[lines.size()][cols]);
                    String ruleName = FilenameUtils.removeExtension(file.getName());
                    ruleName = ruleName.replaceAll("\\_", " ");
                    colorRules.put(ruleName, linesArray);
                }
            }

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return colorRules;
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.io.HOO2012Evaluator.java

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    DocumentMetaData dmd = DocumentMetaData.get(jcas);
    String baseName = FilenameUtils.removeExtension(dmd.getDocumentTitle());
    String outputFilename = baseName + teamId + runId;

    System.out.println("Evaluating " + dmd.getDocumentTitle());

    if (writeEdits) {
        try {/* w  w  w  .jav a  2s  . c om*/
            extractionPath.delete();
            extractionPath.mkdirs();
            File runExtractionPath = new File(extractionPath, runId);
            runExtractionPath.mkdir();

            writeEdits(jcas, runExtractionPath, outputFilename);

        } catch (Exception e) {
            throw new AnalysisEngineProcessException(e);
        }
    }
}

From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java

/**
 * Uploads the file into the destination folder
 * If the file does not exist, adds the file. If exists, updates the existing file
 * Adds tags and categories to documents
 *
 * @param file//from w  w  w . java2  s  . c o  m
 * @param fileDescription
 * @param fileName
 * @param changeLog
 * @param serviceContext
 * @return FileEntry
 * @throws PortalException
 */
public FileEntry uploadFile(File file, String fileDescription, String fileName, String changeLog,
        ServiceContext serviceContext) throws PortalException {

    if (_log.isDebugEnabled()) {
        _log.debug("Invoking uploadFile....");
    }

    long companyId = serviceContext.getCompanyId();
    long groupId = serviceContext.getScopeGroupId();
    long userId = serviceContext.getUserId();

    // see https://issues.liferay.com/browse/LPS-66607

    User user = userLocalService.getUser(userId);

    // Check permissions

    _fileUploadHelper.checkPermission(companyId, groupId, userId);

    String title = FilenameUtils.removeExtension(fileName);

    long folderId = GetterUtil.getLong(serviceContext.getAttribute(DESTINATION_FOLDER_ID));

    fileName = file.getName();

    String mimeType = MimeTypesUtil.getContentType(fileName);

    boolean majorVersion = true;

    DLFileEntry dlFileEntry = _dlFileEntryLocalService.fetchFileEntry(groupId, folderId, title);

    FileEntry fileEntry = null;

    if (Validator.isNull(dlFileEntry)) {
        fileEntry = addFileEntry(userId, groupId, folderId, fileName, mimeType, title, fileDescription,
                changeLog, file, serviceContext);
    } else {
        fileEntry = updateFileEntry(userId, dlFileEntry, fileName, mimeType, title, fileDescription, changeLog,
                majorVersion, file, serviceContext);
    }

    FileVersion fileVersion = fileEntry.getFileVersion();

    long[] assetCategoryIds = _fileUploadHelper.getAssetCategoryIds(groupId, title, serviceContext);

    String[] assetTagNames = serviceContext.getAssetTagNames();

    if (_log.isDebugEnabled()) {
        _log.debug(">>> Updating FileEntry with tags and categories");
    }

    _dlAppLocalService.updateAsset(userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, null);

    // Post processing uploaded file

    _fileUploadHelper.postProcessUpload(file, fileEntry.getFileEntryId(), serviceContext);

    return fileEntry;
}

From source file:com.ibm.wala.cast.js.nodejs.NodejsRequiredSourceModule.java

/**
 * Generate a className based on the file name and path of the module file.
 * The path should be encoded in the className since the file name is not unique.
 * //w ww.j  a  v  a2  s.  c  o  m
 * @param rootDir
 * @param file
 */
public static String convertFileToClassName(File rootDir, File file) {
    URI normalizedWorkingDirURI = rootDir.getAbsoluteFile().toURI().normalize();
    URI normalizedFileURI = file.getAbsoluteFile().toURI().normalize();
    String relativePath = normalizedWorkingDirURI.relativize(normalizedFileURI).getPath();

    return FilenameUtils.removeExtension(relativePath).replace("/", "_").replace("-", "__").replace(".", "__");
}

From source file:com.opendoorlogistics.studio.components.map.plugins.snapshot.ExportImagePanel.java

protected void validateFilename() {
    String filename = config.getFilename();
    if (filename.length() > 0 && config.getImageType() != null) {
        //   ImageType type = config.getImageType();
        if (config.getImageType() != null) {
            String ext = FilenameUtils.getExtension(filename);
            if (Strings.equalsStd(ext, config.getImageType().name()) == false) {
                filename = FilenameUtils.removeExtension(filename);
                filename += "." + config.getImageType().name().toLowerCase();
                fileBrowser.setFilename(filename);
                config.setFilename(filename);
            }//w ww .ja va2 s .  com
        }
    }

}

From source file:edu.cornell.med.icb.goby.modes.TallyBasesMode.java

/**
 * Configure./*from   w  ww  . ja v  a 2  s  . c o  m*/
 *
 * @param args command line arguments
 * @return this object for chaining
 * @throws IOException error parsing
 * @throws JSAPException error parsing
 */
@Override
public AbstractCommandLineMode configure(final String[] args) throws IOException, JSAPException {
    final JSAPResult jsapResult = parseJsapArguments(args);

    inputFilenames = jsapResult.getStringArray("input");
    basenames = AlignmentReaderImpl.getBasenames(inputFilenames);
    alternativeCountArhive = jsapResult.getString("alternative-count-archive");
    outputFilename = jsapResult.getString("output");
    genomeFilename = jsapResult.getString("genome");
    genomeCacheFilename = jsapResult.getString("genome-cache");
    offsetString = jsapResult.getString("offset");
    cutoff = jsapResult.getDouble("cutoff");
    sampleRate = jsapResult.getDouble("sample-rate", 100d) / 100d;
    if (sampleRate == 0d) {
        System.err.println("Sample rate must be larger than zero or no positions will be reported.");
        System.exit(1);
    }
    if ("auto".equals(genomeCacheFilename)) {
        String filename = FilenameUtils.getBaseName(genomeFilename);
        filename = FilenameUtils.removeExtension(filename);
        genomeCacheFilename = filename + "-cache";
    }

    final String includeReferenceNameCommas = jsapResult.getString("include-reference-names");
    if (includeReferenceNameCommas != null) {
        includeReferenceNames = new ObjectOpenHashSet<String>();
        includeReferenceNames.addAll(Arrays.asList(includeReferenceNameCommas.split("[,]")));
        System.out.println("Will tally bases for the following sequences:");
        for (final String name : includeReferenceNames) {
            System.out.println(name);
        }
    }
    return this;
}

From source file:edu.cornell.med.icb.goby.algorithmic.algorithm.dmr.RegionAveragingWriter.java

public RegionAveragingWriter(final OutputInfo outputInfo, RandomAccessSequenceInterface genome,
        MethylCountProvider provider) {//from  www  . j  a  v  a2 s.c  om
    super(new NullWriter());
    final String contextString = doc.getString("contexts");
    final String[] contextTokens = contextString.split(",");
    if (contextTokens.length != 0) {
        LOG.info("registering user defined contexts: " + ObjectArrayList.wrap(contextTokens));
        contexts = contextTokens;
    }
    estimateIntraGroupDifferences = doc.getBoolean("estimate-intra-group-differences");
    estimateIntraGroupP = doc.getBoolean("estimate-empirical-P");
    writeCounts = doc.getBoolean("write-counts");
    writeObservations = doc.getBoolean("write-observations");

    if (estimateIntraGroupDifferences || estimateIntraGroupP) {
        String basename = FilenameUtils.removeExtension(outputInfo.getFilename());
        if (basename == null) {
            basename = Long.toString(new Date().getTime());
        }
        if (writeObservations) {
            String filename = basename + "-" + (estimateIntraGroupDifferences ? "null" : "test")
                    + "-observations.tsv";
            try {
                obsWriter = new ObservationWriter(new FileWriter(filename));
                obsWriter.setHeaderIds(
                        new String[] { "context", "chromosome", "start", "end", "annotation-id" });
            } catch (IOException e) {
                LOG.error("Cannot open observation file for writing: " + filename);
            }

        }
    }

    this.provider = provider;
    this.outputInfo = outputInfo;
    if (!estimateIntraGroupDifferences) {
        //outputWriter = outputInfo.getPrintWriter();
    } else {
        //outputWriter = new NullWriter();
    }
    this.genome = genome;
    initialized = false;
    //processGroups = true;

}

From source file:com.opendoorlogistics.core.geometry.rog.builder.ROGBuilder.java

public ROGBuilder(File shapefile, boolean isNOLPL, double pixelTol, int nbThreads,
        ProcessingApi processingApi) {/*from  www. jav a 2s  . c  o m*/
    this(shapefile, new File(
            FilenameUtils.removeExtension(shapefile.getPath()) + "." + RogReaderUtils.RENDER_GEOMETRY_FILE_EXT),
            isNOLPL, pixelTol, nbThreads, processingApi);
}