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

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

Introduction

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

Prototype

public static String getFullPath(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path.

Usage

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Fourni un nouveau nom de fichier  partir de l'ancien
 *
 * @param filename L'ancien nom de fichier
 * @return Le nouveau nom de fichier//from   ww  w  .j a v a  2 s . co m
 */
private String getNewName(String filename) {
    return FilenameUtils.getFullPath(filename) + FilenameUtils.getBaseName(filename) + "_clean."
            + FilenameUtils.getExtension(filename);
}

From source file:org.onexus.resource.manager.internal.providers.AbstractProjectProvider.java

private List<String> getIncludes(Template resourceTemplate) {

    List<String> includes = new ArrayList<String>();
    TemplateElement root = resourceTemplate.getRootTreeNode();
    for (int i = 0; i < root.getChildCount(); i++) {
        TreeNode node = root.getChildAt(i);
        if (node instanceof TemplateElement) {
            String tag = ((TemplateElement) node).getCanonicalForm();
            if (tag != null && tag.startsWith("<#include")) {
                String include = tag.replace("<#include \"", "").replace("\"/>", "");
                String templatePath = FilenameUtils.getFullPath(resourceTemplate.getName());
                includes.add(templatePath + include);
                try {
                    Template includeTemplate = freemarkerConfig.getTemplate(templatePath + include);
                    includes.addAll(getIncludes(includeTemplate));
                } catch (IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }//from   ww  w .  ja  v a 2s  .c o m
            }
        }
    }

    return includes;
}

From source file:org.openflexo.foundation.fml.rm.AbstractVirtualModelResourceImpl.java

@Override
public Resource getDirectory() {
    if (getFlexoIODelegate() instanceof FileFlexoIODelegate) {
        String parentPath = getDirectoryPath();
        if (ResourceLocator.locateResource(parentPath) == null) {
            FileSystemResourceLocatorImpl.appendDirectoryToFileSystemResourceLocator(parentPath);
        }/*from ww  w.j  a  v  a2s . com*/
        return ResourceLocator.locateResource(parentPath);
    } else if (getFlexoIODelegate() instanceof InJarFlexoIODelegate) {
        InJarResourceImpl resource = ((InJarFlexoIODelegate) getFlexoIODelegate()).getInJarResource();
        String parentPath = FilenameUtils.getFullPath(resource.getRelativePath());
        BasicResourceImpl parent = (BasicResourceImpl) ((ClasspathResourceLocatorImpl) (resource.getLocator()))
                .getJarResourcesList().get(parentPath);
        return parent;
    }
    return null;
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

private void exploreVirtualModels(Resource parent) {
    XMLRootElementInfo result = null;//  w  w w  . j  a  va  2 s . com

    if (parent == null) {
        return;
    }

    for (Resource child : parent.getContents()) {
        if (child.isContainer()) {
            exploreVirtualModels(child);
        } else {
            try {
                if (child.getURI().endsWith(".xml")) {
                    result = reader.readRootElement(child);
                    // Serialization artefact is File
                    if (result.getName().equals("VirtualModel")
                            && getFlexoIODelegate() instanceof FileFlexoIODelegate) {
                        VirtualModelResource virtualModelResource = VirtualModelResourceImpl
                                .retrieveVirtualModelResource(
                                        new File(FilenameUtils.getFullPath(child.getRelativePath())),
                                        /*ResourceLocator.retrieveResourceAsFile(child),*/ this,
                                        getServiceManager());
                        addToContents(virtualModelResource);
                    }
                    // Serialization artefact is InJarResource
                    else if (result.getName().equals("VirtualModel")
                            && getFlexoIODelegate() instanceof InJarFlexoIODelegate) {
                        VirtualModelResource virtualModelResource = VirtualModelResourceImpl
                                .retrieveVirtualModelResource((InJarResourceImpl) child, parent, this,
                                        getServiceManager());
                        addToContents(virtualModelResource);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
    /*if (getDirectory().exists() && getDirectory().isDirectory()) {
       for (File f : getDirectory().listFiles()) {
    if (f.isDirectory()) {
       File virtualModelFile = new File(f, f.getName() + ".xml");
       if (virtualModelFile.exists()) {
            
          // This directory should be append to resources to be looked-up, because of images.
          FileSystemResourceLocatorImpl fsrl = (FileSystemResourceLocatorImpl) ResourceLocator
                .getInstanceForLocatorClass(FileSystemResourceLocatorImpl.class);
          if (fsrl != null && f.getPath() != null) {
             fsrl.appendToDirectories(f.getPath());
          }
            
          try {
            
             result = reader.readRootElement(virtualModelFile);
            
             if (result.getName().equals("VirtualModel")) {
                VirtualModelResource virtualModelResource = VirtualModelResourceImpl.retrieveVirtualModelResource(f,
                      virtualModelFile, this, getServiceManager());
                addToContents(virtualModelResource);
             } 
          } catch (IOException e) {
             e.printStackTrace();
          }
       }
    }
       }
    }*/
}

From source file:org.panbox.desktop.common.vfs.PanboxFSLinux.java

public synchronized void symlink(final String target, final String link) throws IOException {

    try {//from www . jav a2s. co  m
        // TODO: Here, we parse 3 times for the Share that manages the File
        VirtualFile vlink = getVirtualFileForFileName(link, true);
        String fullpath = FilenameUtils.getFullPath(link);
        String sharePath = FilenameUtils.normalize(fullpath.substring(0, fullpath.indexOf('/', 1) + 1));

        String shareloc = FilenameUtils.concat(fullpath, target);

        if (FilenameUtils.equals(sharePath, shareloc) || FilenameUtils.directoryContains(sharePath, shareloc)) {

            SecretKey sk = backingStorage.getObfuscationKeyForFile(shareloc);
            Obfuscator obfuscator = backingStorage.getObfuscator(shareloc);

            // create obfuscated symlink target
            String[] targetparts = target.split("/");
            StringBuffer res = new StringBuffer();

            if (target.startsWith(File.separator)) {
                res.append(File.separator);
            }

            for (int i = 0; i < targetparts.length; i++) {
                String cur = targetparts[i];
                if (cur.equals(".") || cur.equals("..")) {
                    res.append(cur);
                } else {
                    // append obfuscated part of path
                    res.append(obfuscator.obfuscate(cur, sk, true));
                }
                // append intermediary separators
                if (i < targetparts.length - 1) {
                    res.append(File.separator);
                }
            }

            if (target.endsWith(File.separator)) {
                res.append(File.separator);
            }

            String obfuscatedTarget = res.toString();
            Path ptarget = Paths.get(obfuscatedTarget);

            Path plink = Paths.get(vlink.getFileName());
            Files.createSymbolicLink(plink, ptarget);
            logger.debug("symlink, Target : " + obfuscatedTarget + ", Link: " + vlink.getFileName());
        } else {
            throw new IOException("Symlinks outside of shares are not supported.");
        }
    } catch (ObfuscationException e) {
        // logger.error("Could not obfuscate symlink target!", e);
        throw new IOException("Could not obfuscate symlink target!", e);
    }

}

From source file:org.panbox.desktop.common.vfs.PanboxFSLinux.java

public synchronized void readlink(final String path, final ByteBuffer buffer, final long size)
        throws IOException {

    try {//from w  w  w  . j  a  v a 2  s  . co  m
        // TODO: Here, we parse 3 times for the Share that manages the File
        String fullpath = FilenameUtils.getFullPath(path);
        String sharePath = FilenameUtils.normalize(fullpath.substring(0, fullpath.indexOf('/', 1) + 1));

        VirtualFile vpath = getVirtualFileForFileName(path);
        String target = Files.readSymbolicLink(vpath.getFile().toPath()).toString();

        String shareloc = FilenameUtils.concat(fullpath, target.toString());

        if (FilenameUtils.directoryContains(sharePath, shareloc) || FilenameUtils.equals(sharePath, shareloc)) {

            SecretKey sk = backingStorage.getObfuscationKeyForFile(shareloc);
            Obfuscator obfuscator = backingStorage.getObfuscator(shareloc);

            // create deobfuscated symlink target
            String[] targetparts = target.split("/");
            StringBuffer res = new StringBuffer();

            if (target.startsWith(File.separator)) {
                res.append(File.separator);
            }

            for (int i = 0; i < targetparts.length; i++) {
                String cur = targetparts[i];
                if (cur.equals(".") || cur.equals("..")) {
                    res.append(cur);
                } else {
                    // append obfuscated part of path
                    res.append(obfuscator.deObfuscate(cur, sk));
                }
                // append intermediary separators
                if (i < targetparts.length - 1) {
                    res.append(File.separator);
                }
            }

            if (target.endsWith(File.separator)) {
                res.append(File.separator);
            }

            byte[] ret = res.toString().getBytes();
            int realsize = Math.min(ret.length, (int) size);
            buffer.put(ret, 0, realsize);
            logger.debug("readline, Link : " + path + ", Target: " + res.toString());
        } else {
            throw new IOException("Symlinks outside of shares are not supported.");
        }
    } catch (ObfuscationException e) {
        throw new IOException("Error deobfuscating symlink contents!", e);
    }
}

From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java

/**
 * Gets the full path from a full filename, which is the prefix + path.
 * <p/>//from   ww w.  j  a va 2 s.  co  m
 * The method is entirely text based, and returns the text before and including the last forward or backslash.
 * 
 * <pre>
 * a.txt        --> ""
 * a/b/c        --> a/b/
 * a/b/c/       --> a/b/c/
 * /a.txt       --> /
 * /a/b/c       --> /a/b/
 * /a/b/c/      --> /a/b/c/
 * </pre>
 * <p/>
 * The output will be the same irrespective of the machine that the code is running on.
 * 
 * @param filename
 *          the filename to query, null returns null
 * @return the path of the file, an empty string if none exists, null if invalid
 */
public static String getFullPath(final String filename) {
    return FilenameUtils.getFullPath(filename);
}

From source file:org.perfclipse.core.scenario.ScenarioManager.java

public void runScenario(URL scenarioURL) throws ScenarioException {

    if (scenarioURL == null) {
        log.error("URL to scenario is null");
        throw new IllegalArgumentException("URL to scenario is null.");
    }/*w ww .  j a  va2s. c om*/

    try {
        String path = scenarioURL.getPath();
        String scenarioDir = FilenameUtils.getFullPath(path);
        String scenarioName = FilenameUtils.getName(FilenameUtils.removeExtension(path));

        //remove last slash in the path (PerfCake will append one slash)
        if (scenarioDir.lastIndexOf("/") == (scenarioDir.length() - 1))
            scenarioDir = scenarioDir.substring(0, scenarioDir.length() - 1);

        //Use system properties to specify folder with scenario
        System.setProperty(PerfCakeConst.SCENARIOS_DIR_PROPERTY, scenarioDir);
        scenario = new ScenarioLoader().load(scenarioName);
    } catch (PerfCakeException e) {
        log.error("Cannot load scenario", e);
        throw new ScenarioException("Cannot load scenario", e);
    } catch (Exception e) {
        log.error("Cannot build scenario.", e);
        throw new ScenarioException("Cannot build scenario.", e);
    }

    try {
        scenario.init();
        scenario.run();
    } catch (PerfCakeException e) {
        log.error("Error during scenario execution.", e);
        throw new ScenarioException("Error during scenario execution.", e);
    }

    try {
        scenario.close();
    } catch (PerfCakeException e) {
        log.error("Error during finishing scenario.", e);
        throw new ScenarioException("Error during finishing scenario.", e);
    }
}

From source file:org.pgptool.gui.ui.mainframe.DecryptedFilesModel.java

/**
 * If file was decrypted to temp dir or to the same dir as source file, don't
 * show the path//from  w  w w. ja va  2s . com
 * 
 * @param r
 * @return
 */
private Object getTargetFileName(DecryptedFile r) {
    if (r.getDecryptedFile().toLowerCase()
            .startsWith(decryptedTempFolder.getTempFolderBasePath().toLowerCase())) {
        return FilenameUtils.getName(r.getDecryptedFile());
    } else {
        String sourceBasePath = FilenameUtils.getFullPath(r.getEncryptedFile());
        String targetBasePath = FilenameUtils.getFullPath(r.getDecryptedFile());
        if (sourceBasePath.equalsIgnoreCase(targetBasePath)) {
            return FilenameUtils.getName(r.getDecryptedFile());
        }

        return r.getDecryptedFile();
    }
}

From source file:org.rhq.enterprise.remoting.cli.ScriptTestRunner.java

private String getTestName(Script script) {
    String pathExcludingFileName = FilenameUtils.getFullPath(script.srcFile.getAbsolutePath());
    String packagePath = StringUtils.difference(scriptDir.getAbsolutePath(), pathExcludingFileName);

    packagePath = StringUtils.replace(packagePath, File.separator, ".");
    packagePath = StringUtils.removeStart(packagePath, ".");

    return packagePath + FilenameUtils.getBaseName(script.srcFile.getName());
}