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

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

Introduction

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

Prototype

public static String getFullPathNoEndSeparator(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.

Usage

From source file:it.drwolf.ridire.index.cwb.scripts.VRTFilesBuilder.java

private String getHeaderFromFile(int i, File f) {
    String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
    header += "<text id=\"" + FilenameUtils.getBaseName(FilenameUtils.getBaseName(f.getAbsolutePath()))
            + "\" functional=\"";
    if (i % 5 == 0) {
        header += "Informazione\"";
    } else if (i % 4 == 0) {
        header += "Amministrazione_e_Legislazione\"";
    } else {/*from w ww . jav a2 s  . c om*/
        header += "Economia_e_Affari\"";
    }
    header += " semantic=\"";
    if (i % 5 == 0) {
        header += "Cinema\"";
    } else if (i % 4 == 0) {
        header += "Moda\"";
    } else {
        header += "Religione\"";
    }
    String jobname = FilenameUtils.getFullPathNoEndSeparator(f.getAbsolutePath())
            .substring(FilenameUtils.getFullPathNoEndSeparator(f.getAbsolutePath())
                    .lastIndexOf(System.getProperty("file.separator")) + 1);
    header += " jobname=\"" + jobname.replaceAll("\\s", "_") + "\">";
    return header;
}

From source file:com.uwsoft.editor.proxy.ProjectManager.java

public File importExternalAnimationIntoProject(FileHandle animationFileSource) {
    try {//w  ww. j a  v  a  2 s  .co  m
        String fileName = animationFileSource.name();
        if (!Overlap2DUtils.JSON_FILTER.accept(null, fileName)
                && !Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            //showError("Spine animation should be a .json file with atlas in same folder \n Spriter animation should be a .scml file with images in same folder");
            return null;
        }

        String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
        String sourcePath;
        String animationDataPath;
        String targetPath;
        if (Overlap2DUtils.JSON_FILTER.accept(null, fileName)) {
            sourcePath = animationFileSource.path();

            animationDataPath = FilenameUtils.getFullPathNoEndSeparator(sourcePath);
            targetPath = currentProjectPath + "/assets/orig/spine-animations" + File.separator
                    + fileNameWithOutExt;
            FileHandle atlasFileSource = new FileHandle(
                    animationDataPath + File.separator + fileNameWithOutExt + ".atlas");
            if (!atlasFileSource.exists()) {
                //showError("the atlas file needs to have same name and location as the json file");
                return null;
            }

            FileUtils.forceMkdir(new File(targetPath));
            File jsonFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".json");
            File atlasFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".atlas");
            Array<File> imageFiles = getAtlasPages(atlasFileSource);

            FileUtils.copyFile(animationFileSource.file(), jsonFileTarget);
            FileUtils.copyFile(atlasFileSource.file(), atlasFileTarget);

            for (File imageFile : imageFiles) {
                FileHandle imgFileTarget = new FileHandle(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget.file());
            }

            return atlasFileTarget;

        } else if (Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            targetPath = currentProjectPath + "/assets/orig/spriter-animations" + File.separator
                    + fileNameWithOutExt;
            File scmlFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".scml");
            ArrayList<File> imageFiles = getScmlFileImagesList(animationFileSource);

            FileUtils.copyFile(animationFileSource.file(), scmlFileTarget);
            for (File imageFile : imageFiles) {
                File imgFileTarget = new File(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget);
            }
            return scmlFileTarget;

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

From source file:edu.ku.brc.specify.datamodel.SpAppResource.java

/**
 * Gets the contents with a possible existing session.
 * @param sessionArg the current session or null.
 * @return the contents as a string/*from ww w  . j av a  2 s .  co m*/
 */
@Transient
public String getDataAsString(final DataProviderSessionIFace sessionArg) {
    SpAppResourceData appResData = null;
    DataProviderSessionIFace session = null;
    try {
        if (spAppResourceId != null) {
            session = sessionArg != null ? sessionArg : DataProviderFactory.getInstance().createSession();
            session.attach(this);
        }

        if (spAppResourceDatas.size() > 0) {
            appResData = spAppResourceDatas.iterator().next();
            if (appResData != null) {
                return new String(appResData.getData());
            }
        }

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpAppResource.class, ex);
        log.error(ex);
        ex.printStackTrace();

    } finally {
        if (sessionArg == null && session != null) {
            session.close();
        }
    }

    String fileNameToOpen = fileName;
    boolean doesFileExist = false;
    if (StringUtils.isNotEmpty(fileNameToOpen)) {
        File file = new File(fileNameToOpen);
        if (!file.exists()) {
            String fName = FilenameUtils.getName(fileNameToOpen);
            String path = FilenameUtils.getFullPathNoEndSeparator(fileNameToOpen);
            path = path.substring(0, FilenameUtils.indexOfLastSeparator(path));

            fileNameToOpen = path + File.separator + fName;

            doesFileExist = (new File(fileNameToOpen)).exists();
        } else {
            doesFileExist = true;
        }
    }

    String str = null;
    if (doesFileExist) {
        File file = new File(fileNameToOpen);
        str = XMLHelper.getContents(file);
        timestampCreated = new Timestamp(file.lastModified());
        //timestampModified = timestampCreated;
    } else {
        UIRegistry.showError("The file in the app_resources.xml [" + fileName + "] is missing.");
    }

    if (str != null && str.length() > 0) {
        return StringEscapeUtils.unescapeXml(str);
    }

    return null;
}

From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java

public File importExternalAnimationIntoProject(FileHandle animationFileSource) {
    try {/*from ww  w .  j  a  va  2  s. c  o m*/
        String fileName = animationFileSource.name();
        if (!Overlap2DUtils.JSON_FILTER.accept(null, fileName)
                && !Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            //showError("Spine animation should be a .json file with atlas in same folder \n Spriter animation should be a .scml file with images in same folder");
            return null;
        }

        String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
        String sourcePath;
        String animationDataPath;
        String targetPath;
        if (Overlap2DUtils.JSON_FILTER.accept(null, fileName)) {
            sourcePath = animationFileSource.path();

            animationDataPath = FilenameUtils.getFullPathNoEndSeparator(sourcePath);
            targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/spine-animations" + File.separator + fileNameWithOutExt;
            FileHandle atlasFileSource = new FileHandle(
                    animationDataPath + File.separator + fileNameWithOutExt + ".atlas");
            if (!atlasFileSource.exists()) {
                //showError("the atlas file needs to have same name and location as the json file");
                return null;
            }

            FileUtils.forceMkdir(new File(targetPath));
            File jsonFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".json");
            File atlasFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".atlas");
            Array<File> imageFiles = getAtlasPages(atlasFileSource);

            FileUtils.copyFile(animationFileSource.file(), jsonFileTarget);
            FileUtils.copyFile(atlasFileSource.file(), atlasFileTarget);

            for (File imageFile : imageFiles) {
                FileHandle imgFileTarget = new FileHandle(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget.file());
            }

            return atlasFileTarget;

        } else if (Overlap2DUtils.SCML_FILTER.accept(null, fileName)) {
            targetPath = currentWorkingPath + "/" + currentProjectVO.projectName
                    + "/assets/orig/spriter-animations" + File.separator + fileNameWithOutExt;
            File scmlFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".scml");
            ArrayList<File> imageFiles = getScmlFileImagesList(animationFileSource);

            FileUtils.copyFile(animationFileSource.file(), scmlFileTarget);
            for (File imageFile : imageFiles) {
                File imgFileTarget = new File(targetPath + File.separator + imageFile.getName());
                FileUtils.copyFile(imageFile, imgFileTarget);
            }
            return scmlFileTarget;

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

From source file:com.izforge.izpack.util.os.Unix_Shortcut.java

/**
 * Write the given ShortDefinition in a File $ShortcutName-$timestamp.desktop in the given
 * TargetPath. If the given replaceSpaces was true ALSO all WhiteSpaces in the ShortCutName will
 * be replaced with "-"// w  w  w  .  jav a 2 s  .c o m
 *
 * @param targetPath   The Path in which the files should be written.
 * @param shortcutName The Name for the File
 * @param shortcutDef  The Shortcut FileContent
 * @return The written File
 */
private File writeAppShortcutWithSimpleSpacehandling(String targetPath, String shortcutName, String shortcutDef,
        boolean replaceSpacesWithMinus) {
    File shortcutFile = new File(FilenameUtils.getFullPathNoEndSeparator(targetPath) + '/'
            + (replaceSpacesWithMinus ? StringTool.replaceSpacesWithMinus(shortcutName) : shortcutName)
            + DESKTOP_EXT);

    try {
        FileUtils.writeStringToFile(shortcutFile, shortcutDef);
    } catch (IOException e) {
        logger.warning("Application shortcut could not be created (" + e.getMessage() + ")");
    }

    return shortcutFile;
}

From source file:org.abstracthorizon.proximity.impl.AbstractProximity.java

public void copyItem(ProximityRequest source, ProximityRequest target) throws ItemNotFoundException,
        AccessDeniedException, NoSuchRepositoryException, RepositoryNotAvailableException {
    logger.debug("Got copyItem with {} -> {}", source, target);
    Item item = retrieveItem(source);//from  w  w  w.j a  v a  2s  .  c  o m
    ItemProperties itemProps = item.getProperties();
    itemProps.setDirectoryPath(
            FilenameUtils.separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(target.getPath())));
    itemProps.setName(FilenameUtils.getName(target.getPath()));
    itemProps.setRepositoryId(target.getTargetedReposId());
    itemProps.setRepositoryGroupId(target.getTargetedReposGroupId());
    storeItem(target, item);
}

From source file:org.abstracthorizon.proximity.impl.AbstractProximity.java

public void storeItem(ProximityRequest request, Item item)
        throws AccessDeniedException, NoSuchRepositoryException, RepositoryNotAvailableException {
    logger.debug("Got storeItem for {}", request);

    String targetRepoId = request.getTargetedReposId();
    List pathList = ProximityUtils.explodePathToList(request.getPath());

    if (targetRepoId == null) {

        // first repo if not targeted and store
        if (isEmergeRepositoryGroups()) {
            if (pathList.size() == 0) {
                // cannot store on root if emergeGroups, error
                throw new AccessDeniedException(request,
                        "Cannot store item on the root when emergeRepositoryGroups are enabled!");
            }//from   w  ww  . ja  v  a  2 s.co  m
            // get group, get first repo of the group and store
            String groupId = (String) pathList.get(0);
            if (repositoryGroups.containsKey(groupId)) {
                List repositoryGroupOrder = (List) repositoryGroups.get(groupId);
                targetRepoId = (String) repositoryGroupOrder.get(0);
            } else {
                throw new NoSuchRepositoryException("group " + request.getTargetedReposGroupId());
            }
        } else {
            // get first repo and store
            targetRepoId = (String) repositoryOrder.get(0);
        }
    }

    if (repositories.containsKey(targetRepoId)) {
        Repository repo = (Repository) repositories.get(targetRepoId);
        ProximityRequest mangledRequest = mangleItemRequest(request);
        ItemProperties itemProperties = item.getProperties();
        // set the mangled path for store
        itemProperties.setDirectoryPath(FilenameUtils
                .separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(mangledRequest.getPath())));
        repo.storeItem(mangledRequest, item);
    } else {
        throw new NoSuchRepositoryException(targetRepoId);
    }
}

From source file:org.abstracthorizon.proximity.metadata.AbstractProxiedItemPropertiesFactory.java

/**
 * Expand default item properties.//from  ww w. j  av  a2 s.c o  m
 * 
 * @param path the path
 * @param ip the ip
 * @param file the file
 */
protected final void expandDefaultItemProperties(String path, ItemProperties ip, File file) {
    ip.setDirectoryPath(FilenameUtils.separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(path)));
    if ("".equals(ip.getDirectoryPath())) {
        ip.setDirectoryPath(ItemProperties.PATH_ROOT);
    }
    ip.setName(FilenameUtils.getName(path));
    ip.setDirectory(file.isDirectory());
    ip.setFile(file.isFile());
    ip.setLastModified(new Date(file.lastModified()));
    if (file.isFile()) {
        String ext = FilenameUtils.getExtension(path);
        if (ext != null) {
            ip.setExtension(ext);
        }
        ip.setSize(file.length());
    } else {
        ip.setSize(0);
    }
    ip.setLastScanned(new Date());
}

From source file:org.abstracthorizon.proximity.webapp.webdav.ProximityWebdavStorageAdapter.java

public void setResourceContent(String resourceUri, InputStream content, String contentType,
        String characterEncoding) throws WebdavException {
    logger.debug("setResourceContent");
    try {/*  w  w  w.ja va  2s .  c o m*/
        createdButNotStoredResources.remove(resourceUri);
        ProximityRequest request = createRequest(resourceUri, false);
        Item item = new Item();
        ItemProperties itemProperties = new HashMapItemPropertiesImpl();
        itemProperties.setDirectoryPath(
                FilenameUtils.separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(resourceUri)));
        itemProperties.setName(FilenameUtils.getName(resourceUri));
        itemProperties.setLastModified(new Date());
        itemProperties.setDirectory(false);
        itemProperties.setFile(true);
        item.setProperties(itemProperties);
        item.setStream(content);
        proximity.storeItem(request, item);
    } catch (ProximityException ex) {
        logger.error("Proximity throw exception.", ex);
        throw new WebdavException("Proximity throw " + ex.getMessage());
    }
}

From source file:org.alfresco.bm.cm.FolderData.java

/**
 * @param id                the unique ID of the folder.  The value must be unique but is dependent on the format used by the system in test
 * @param context           an arbitrary context in which the folder path is valid.  The format is determined by the target test system.
 * @param path              the folder path with the given context.  The <tt>context</tt> and <tt>path</tt> combination must be unique
 * @param folderCount       the number of subfolders in the folder
 * @param fileCount         the number of files in the folder
 * /*w w  w.jav a 2s .c o  m*/
 * @throws IllegalArgumentException if the values are <tt>null</tt>
 */
public FolderData(String id, String context, String path, long folderCount, long fileCount) {
    if (id == null || context == null || path == null) {
        throw new IllegalArgumentException();
    }
    if (!path.isEmpty() && (!path.startsWith("/") || path.endsWith("/"))) {
        throw new IllegalArgumentException("Path must start with '/' and not end with '/'.");
    }

    this.id = id;
    this.context = context;
    this.path = path;
    this.fileCount = fileCount;
    this.folderCount = folderCount;

    // Derived data
    this.level = StringUtils.countMatches(path, "/");
    this.name = FilenameUtils.getName(path);
    this.parentPath = FilenameUtils.getFullPathNoEndSeparator(path);
}