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:de.uzk.hki.da.metadata.XmpCollector.java

/**
 * Collect.//from   w  w  w  .jav  a 2 s . c om
 *
 * @param xmpFiles list of xmp files to collect
 * @param targetFile the target file
 * @throws IOException 
 */
public static void collect(WorkArea wa, List<DAFile> xmpFiles, File targetFile) throws IOException {

    Model model = ModelFactory.createDefaultModel();

    for (DAFile dafile : xmpFiles) {

        File file = wa.toFile(dafile);

        logger.debug("collecting XMP file {}", file.getAbsolutePath());

        StringWriter xmpWriter = new StringWriter();

        try {
            // preprocess xmp in order to make it RDF/XML compatible   
            BufferedReader reader = new BufferedReader(new FileReader(file));
            BufferedWriter writer = new BufferedWriter(xmpWriter);

            logger.debug("Read the xmp file...");
            String currentLine;
            while ((currentLine = reader.readLine()) != null) {
                String trimmedLine = currentLine.trim();
                if (trimmedLine.startsWith("<?xpacket"))
                    continue;
                if (trimmedLine.contains("x:xmpmeta"))
                    continue;
                writer.write(currentLine);
            }
            reader.close();
            writer.close();

        } catch (Exception e) {
            throw new RuntimeException("Unable to preprocess XMP file: " + file.getAbsolutePath(), e);
        }

        final String baseName = FilenameUtils.removeExtension(file.getName());
        String[] list = file.getParentFile().list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                String baseName2 = FilenameUtils.removeExtension(name);
                if (baseName.equals(baseName2) && !name.toLowerCase().endsWith(".xmp"))
                    return true;
                else
                    return false;
            }
        });
        if (list.length > 1) {
            logger.warn("More than one matching file for sidecar file {}. Skipping ...", file.getName());
            continue;
        } else if (list.length < 1) {
            logger.warn("No matching file for sidecar file {}. Skipping ...", file.getName());
            continue;
        }

        logger.debug("found matching file {}", list[0]);
        // read XMP with matching file as base name
        // use "http://www.danrw.de/temp/" as a pseudo base URI in order to allow relative resource URIs
        model.read(new StringReader(xmpWriter.toString().trim().replaceFirst("^([\\W]+)<", "<")),
                "http://www.danrw.de/temp/" + list[0]);
    }
    FileOutputStream targetStream = null;
    try {
        targetStream = new FileOutputStream(targetFile);
        model.write(targetStream, "RDF/XML-ABBREV", "http://www.danrw.de/temp/");
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Could not write XMP collection file: " + targetFile.getAbsolutePath());
    } finally {
        if (targetStream != null) {
            targetStream.close();
        }
    }

}

From source file:jease.cms.web.content.editor.FileEditor.java

protected void uploadPerformed() {
    if (getObject().isValidContentType(media.getContentType())) {
        String filename = media.getName();
        if (StringUtils.isEmpty(id.getValue())) {
            id.setText(filename);//ww  w  .ja va2s.co m
        }
        if (StringUtils.isEmpty(title.getValue())) {
            title.setText(FilenameUtils.removeExtension(filename));
        }
    } else {
        Modal.error(I18N.get("Content_is_not_valid"));
        media.setMedia(null);
        refresh();
    }
}

From source file:asciidoc.maven.plugin.AbstractAsciiDocMojo.java

/**
 * No-arg constructor.//from w  w w .  jav a  2s .c o  m
 */
public AbstractAsciiDocMojo() {
    try {
        File jarFile = new File(AbstractAsciiDocMojo.class.getProtectionDomain().getCodeSource().getLocation()
                .toURI().getPath());
        if (getLog().isDebugEnabled())
            getLog().debug("sourceJarFile: " + jarFile.getAbsolutePath());
        if (asciiDocHome == null) {
            ZipEntry zipEntry = null;
            String zipEntryName = null;
            ZipFile jarZipFile = new ZipFile(jarFile);
            Enumeration<? extends ZipEntry> e = jarZipFile.entries();
            while (e.hasMoreElements()) {
                zipEntry = (ZipEntry) e.nextElement();
                zipEntryName = zipEntry.getName();
                if (zipEntryName.startsWith("asciidoc") && zipEntryName.endsWith(".zip")) {
                    if (getLog().isInfoEnabled())
                        getLog().info("Found AsciiDoc in " + zipEntryName);
                    asciiDocHome = new File(jarFile.getParent(), FilenameUtils.removeExtension(zipEntryName));
                    break;
                }
            }
            if (asciiDocHome != null && !asciiDocHome.exists()) {
                unzipEntry(jarZipFile, zipEntry, jarFile.getParentFile());
                File asciiDocArchive = new File(jarFile.getParent(), zipEntryName);
                unzipArchive(asciiDocArchive, jarFile.getParentFile());
                asciiDocArchive.deleteOnExit();
            }
            if (getLog().isInfoEnabled())
                getLog().info("asciiDocHome: " + asciiDocHome);
        }
    } catch (URISyntaxException use) {
        getLog().error(use.getMessage(), use);
        // don't throw use;
    } catch (ZipException ze) {
        getLog().error(ze.getMessage(), ze);
        // don't throw ze;
    } catch (IOException ioe) {
        getLog().error(ioe.getMessage(), ioe);
        // don't throw ioe;
    }
}

From source file:hu.bme.mit.sette.common.util.JavaFileUtils.java

/**
 * Converts a filename to a Java class name by transliterating the file
 * separator characters to the package separator character.
 *
 * @param filename/* w  w w.j  a va 2s .  c om*/
 *            The filename (e.g. hu/bme/mit/sette/MyClass.java)
 * @return The class name (e.g. hu.bme.mit.sette.MyClass)
 */
public static String filenameToClassName(final String filename) {
    return StringUtils.replaceChars(FilenameUtils.removeExtension(filename), File.separatorChar,
            JavaFileUtils.PACKAGE_SEPARATOR);
}

From source file:avantssar.aslanpp.testing.LibraryTestTask.java

public LibraryTestTask(ISpecProvider specProvider, File modelsDir) throws IOException {
    this.specProvider = specProvider;
    ASLanPPSpecification spec = specProvider.getASLanPPSpecification();
    StringBuffer sb = new StringBuffer();
    sb.append(spec.getSpecificationName());
    if (specProvider instanceof IChannelModelFlexibleSpecProvider) {
        IChannelModelFlexibleSpecProvider cmFlex = (IChannelModelFlexibleSpecProvider) specProvider;
        sb.append("_");
        sb.append(cmFlex.getChannelModel().toString());
        if (specProvider instanceof IChannelTypeFlexibleSpecProvider) {
            IChannelTypeFlexibleSpecProvider ctFlex = (IChannelTypeFlexibleSpecProvider) specProvider;
            sb.append("_");
            sb.append(ctFlex.getChannelType().type.toString());
        }//ww  w  . j  a v a2  s. co  m
    }
    String baseFileName = sb.toString();
    sb.append(".aslan++");
    spec.setSpecificationName(baseFileName);
    aslanPP = new File(FilenameUtils.concat(modelsDir.getAbsolutePath(), sb.toString()));
    aslan = new File(FilenameUtils.removeExtension(aslanPP.getAbsolutePath()) + ".aslan");
    FileUtils.writeStringToFile(aslanPP, spec.toString());
    TranslatorOptions options = new TranslatorOptions();
    IASLanSpec aslanSpec = specProvider.getExpectedASLanTranslation(options);
    aslanSpec.getHornClauses();
    if (aslanSpec != null) {
        FileUtils.writeStringToFile(aslan, aslanSpec.getStrippedRepresentation());
    }
}

From source file:com.jadarstudios.rankcapes.forge.cape.CapePack.java

/**
 * Parses the Zip file in memory./*ww  w . j  av a 2  s.  c  o m*/
 *
 * @param input the bytes of a valid zip file
 */
private void parsePack(byte[] input) {
    try {
        ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(input));

        String metadata = "";

        ZipEntry entry;
        while ((entry = zipInput.getNextEntry()) != null) {
            String name = entry.getName();

            if (name.endsWith(".png")) {
                // remove file extension from the name.
                name = FilenameUtils.removeExtension(name);

                StaticCape cape = this.loadCape(name, zipInput);
                this.unprocessedCapes.put(name, cape);
            } else if (name.endsWith(".mcmeta")) {
                // parses the pack metadata.
                InputStreamReader streamReader = new InputStreamReader(zipInput);
                while (streamReader.ready()) {
                    metadata += (char) streamReader.read();
                }
            }
        }
        if (!Strings.isNullOrEmpty(metadata)) {
            this.parsePackMetadata(StringUtils.remove(metadata, (char) 65535));
        } else {
            RankCapesForge.log.warn("Cape Pack metadata is missing!");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.viddu.handlebars.HandlebarsMojo.java

/**
 * Compiles Handlebar template file./*from w w w. j  ava  2 s  .c  o  m*/
 * 
 * @param inputFile : The uncompiled Handlebars template file
 * @return A compiled Handlebar template file
 * @throws IOException
 */
protected String compile(Scriptable globalScope, File inputFile) throws IOException {
    getLog().info("Compiling file:" + inputFile.toString());
    String sInputFile = HandlebarsFileUtil.getFileContents(inputFile);
    String fileNameWithoutExt = FilenameUtils.removeExtension(inputFile.getName());
    Context compileContext = Context.enter();
    Scriptable compileScope = compileContext.newObject(globalScope);
    compileScope.setParentScope(globalScope);
    compileScope.put("template", compileScope, sInputFile);
    Object result = compileContext.evaluateString(compileScope, "Handlebars.precompile(template);",
            "PreCompile", 0, null);
    String compiledTemplate = Context.toString(result);
    StringBuilder strb = new StringBuilder("(function(){"
            + "\n  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n"
            + "templates[\'").append(fileNameWithoutExt).append("\'] = template(").append(compiledTemplate)
                    .append(");\n}());");
    return strb.toString();
}

From source file:de.uzk.hki.da.model.Document.java

/**
 * Instantiates a new document.//from w  w w  .j  a va 2 s .c o m
 *
 * @param name the name
 * @param first the first DAFile
 */
public Document(DAFile dafile) {
    this.docname = FilenameUtils.removeExtension(dafile.getRelative_path());
    this.lastDAFile = dafile;
    this.getLasttDAFile().setPreviousDAFile(null);
    logger.debug("Create new document " + getLasttDAFile());
}

From source file:com.viddu.handlebars.HandlebarsMojoTest.java

protected void render(File compiledTemplate, Object model) throws IOException {
    Scriptable globalScope = loadHandlebarsLibrary();

    for (File file : HandlebarsFileUtil.loadHandlebarTemplates(compiledTemplate)) {
        String sInputFile = HandlebarsFileUtil.getFileContents(file);
        String fileNameWithoutExt = FilenameUtils.removeExtension(file.getName());
        Context renderContext = Context.enter();
        Scriptable renderScope = renderContext.newObject(globalScope);
        renderScope.setParentScope(globalScope);
        renderContext.evaluateString(renderScope, sInputFile, "Loading template", 0, null);
        StringBuilder strb = new StringBuilder("var template = Handlebars.templates['")
                .append(fileNameWithoutExt).append("']; template(context);");
        renderScope.put("context", renderScope, model);
        Object result = renderContext.evaluateString(renderScope, strb.toString(), "Render", 0, null);
        System.out.println(result);
    }//  w w w . j a v a 2  s.c o m
}

From source file:eu.udig.style.advanced.common.StyleManager.java

/**
 * Reload the style folder content in the {@link TableViewer viewer}.
 *//*from   w  ww .  j a v  a  2 s .  c om*/
public void reloadStyleFolder() {
    File[] sldFilesArray = styleFolderFile.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(SLD_EXTENTION);
        }
    });

    List<StyleWrapper> newStylesList = new ArrayList<StyleWrapper>();
    for (File file : sldFilesArray) {
        try {
            StyledLayerDescriptor sld = readStyle(file);
            Style style = SLDs.getDefaultStyle(sld);
            String name = FilenameUtils.removeExtension(file.getName());
            style.setName(name);

            StyleWrapper styleWrapper = new StyleWrapper(style);
            newStylesList.add(styleWrapper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    stylesViewer.setInput(newStylesList);
}