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:org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractorTest.java

@Test
public void testExtractFromValidZipFileAllAtOnce()
        throws GeoEntryExtractionException, GeoNamesRemoteDownloadException {
    testFileExtractionAllAtOnce(VALID_ZIP_FILE_PATH, null);
    // Delete the extracted text file.
    FileUtils.deleteQuietly(new File(FilenameUtils.removeExtension(VALID_ZIP_FILE_PATH) + ".txt"));
}

From source file:org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractorTest.java

@Test
public void testExtractFromValidZipFileStreaming()
        throws GeoEntryExtractionException, GeoNamesRemoteDownloadException, GeoEntryIndexingException {
    testFileExtractionStreaming(VALID_ZIP_FILE_PATH);
    // Delete the extracted text file.
    FileUtils.deleteQuietly(new File(FilenameUtils.removeExtension(VALID_ZIP_FILE_PATH) + ".txt"));
}

From source file:org.commonjava.indy.autoprox.ftest.catalog.ReparsePicksUpNewRuleFileTest.java

@Test
public void writeRuleFileThenReparseCatalogAndVerifyRulePresence() throws Exception {
    final CatalogDTO catalog = module.getCatalog();

    assertThat(catalog.isEnabled(), equalTo(true));

    assertThat(catalog.getRules().isEmpty(), equalTo(true));

    final RuleDTO rule = getRule("0001-simple-rule.groovy", "rules/simple-rule.groovy");

    final File script = new File(fixture.getBootOptions().getIndyHome(),
            "var/lib/indy/data/autoprox/0001-simple-rule.groovy");
    FileUtils.write(script, rule.getSpec());

    module.reparseCatalog();// w  w  w  .  ja  v a  2 s.com

    final CatalogDTO resultCatalog = module.getCatalog();

    final List<RuleDTO> rules = resultCatalog.getRules();
    assertThat(rules.size(), equalTo(1));

    final RuleDTO dto = rules.get(0);
    assertThat(dto.getName(), equalTo(FilenameUtils.removeExtension(rule.getName())));
    assertThat(dto.getSpec(), equalTo(rule.getSpec()));
}

From source file:org.commonjava.indy.autoprox.util.ScriptRuleParser.java

public RuleMapping parseRule(final String spec, final String scriptName) throws AutoProxRuleException {
    if (spec == null) {
        return null;
    }/*from w ww  .  j a v a 2  s .  c o  m*/

    AutoProxRule rule;
    try {

        rule = scriptEngine.parseScriptInstance(spec, AutoProxRule.class);
    } catch (final IndyGroovyException e) {
        throw new AutoProxRuleException(
                "[AUTOPROX] Cannot load autoprox factory from: {} as an instance of: {}. Reason: {}", e,
                scriptName, AutoProxRule.class.getSimpleName(), e.getMessage());
    }

    if (rule != null) {
        return new RuleMapping(FilenameUtils.removeExtension(scriptName), spec, rule);
    }

    logger.warn("Rule named: {} parsed to null AutoProxRule instance. Spec was:\n\n{}\n\n", scriptName, spec);
    return null;
}

From source file:org.craftercms.core.store.impl.AbstractFileBasedContentStoreAdapter.java

@Override
protected Item doFindItem(Context context, CachingOptions cachingOptions, String path, boolean withDescriptor)
        throws InvalidContextException, PathNotFoundException, XmlFileParseException, StoreException {
    path = normalizePath(path);/*from  ww  w  .j  a v  a 2s  . c o  m*/

    File file = findFile(context, path);

    if (file == null) {
        return null;
    }

    Item item = new Item();
    item.setName(file.getName());
    item.setUrl(path);
    item.setFolder(file.isDirectory());

    if (withDescriptor) {
        File descriptorFile;

        // If it's a file and it's a descriptor, set the descriptor url to the item's path and load the file as
        // a DOM.
        if (file.isFile() && item.getName().endsWith(descriptorFileExtension)) {
            item.setDescriptorUrl(path);

            descriptorFile = file;
            // If it's not a file (a dir) or is not a descriptor (a static asset, like an image), locate the file's
            // descriptor by appending a metadata file extension to the file name. If the file exists, load it as
            // a DOM.
        } else {
            String descriptorPath = FilenameUtils.removeExtension(path) + metadataFileExtension;

            item.setDescriptorUrl(descriptorPath);

            descriptorFile = findFile(context, descriptorPath);
            if (descriptorFile != null && !descriptorFile.isFile()) {
                throw new StoreException("Descriptor file at " + descriptorFile + " is not really a file");
            }
        }

        if (descriptorFile != null) {
            try {
                InputStream fileInputStream = new BufferedInputStream(descriptorFile.getInputStream());
                Reader fileReader = new InputStreamReader(fileInputStream, charset);

                try {
                    item.setDescriptorDom(createXmlReader().read(fileReader));
                } finally {
                    IOUtils.closeQuietly(fileReader);
                }
            } catch (IOException e) {
                throw new StoreException("Unable to open input stream for descriptor file at " + descriptorFile,
                        e);
            } catch (DocumentException e) {
                throw new XmlFileParseException("Error while parsing xml document at " + descriptorFile, e);
            }
        }
    }

    return item;
}

From source file:org.craftercms.engine.controller.PageRenderController.java

protected String getScriptUrl(SiteContext siteContext, ScriptFactory scriptFactory, HttpServletRequest request,
        String pageUrl) {/*from ww  w .j a  v  a 2 s.c om*/
    String method = request.getMethod().toLowerCase();
    String pageUrlNoExt = FilenameUtils.removeExtension(pageUrl);
    String controllerScriptsPath = siteContext.getControllerScriptsPath();

    String baseUrl = UrlUtils.concat(controllerScriptsPath, pageUrlNoExt);

    return String.format(SCRIPT_URL_FORMAT, baseUrl, method, scriptFactory.getScriptFileExtension());
}

From source file:org.craftercms.engine.controller.rest.RestScriptsController.java

protected String getScriptUrl(ScriptFactory scriptFactory, SiteContext siteContext, HttpServletRequest request,
        String serviceUrl) {//from   w  ww . j  ava  2s .co m
    String baseUrl = UrlUtils.concat(siteContext.getRestScriptsPath(),
            FilenameUtils.removeExtension(serviceUrl));

    return String.format(SCRIPT_URL_FORMAT, baseUrl, request.getMethod().toLowerCase(),
            scriptFactory.getScriptFileExtension());
}

From source file:org.craftercms.engine.navigation.impl.DefaultItemConverter.java

protected String getNavigationLabel(SiteItem siteItem) {
    String navLabel = siteItem.getItem().queryDescriptorValue(navLabelXPath);
    if (StringUtils.isEmpty(navLabel)) {
        navLabel = siteItem.getItem().queryDescriptorValue(internalNameXPath);
        if (StringUtils.isEmpty(navLabel)) {
            navLabel = FilenameUtils.removeExtension(siteItem.getStoreName());
            navLabel = StringUtils.replace(navLabel, "-", " ");
            navLabel = StringUtils.capitalize(navLabel);
        }//  ww  w.  j  a  va  2  s  .  com
    }

    return navLabel;
}

From source file:org.craftercms.engine.targeting.impl.TargetedUrlByFileStrategy.java

@Override
protected String doToTargetedUrl(String url, String currentTargetId) {
    String ext = FilenameUtils.getExtension(url);
    if (StringUtils.isNotEmpty(ext)) {
        String urlWithoutExt = FilenameUtils.removeExtension(url);

        return buildTargetedUrl(urlWithoutExt, currentTargetId, ext);
    } else {/*from www .  j  ava 2  s.  c o  m*/
        return url;
    }
}

From source file:org.craftercms.profile.services.impl.ProfileServiceImpl.java

@Override
public ProfileAttachment addProfileAttachment(final String profileId, final String attachmentName,
        final InputStream file) throws ProfileException {
    String storeName = "/" + profileId + "/" + FilenameUtils.removeExtension(attachmentName);

    try {/*from  w  ww .  ja  v  a2  s.c o  m*/
        ObjectId currentId = checkIfAttachmentExist(storeName);
        String mimeType = getAttachmentContentType(attachmentName);
        FileInfo fileInfo;

        if (currentId != null) { // Update !!!
            fileInfo = profileRepository.updateFile(currentId, file, storeName, mimeType, true);
        } else {
            fileInfo = profileRepository.saveFile(file, storeName, mimeType);
        }

        return fileInfoToProfileAttachment(fileInfo);
    } catch (MongoDataException | FileExistsException | FileNotFoundException e) {
        throw new ProfileException("Unable to attach file to profile '" + profileId + "'", e);
    }
}