Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileName


        // Locate the destination folder, and make sure it exists
        final FileObject destFolder = resolveFile(destDirUrl);
        destFolder.createFolder();

        // Locate the source files, and make sure they exist
        FileName srcDirName = null;
        if (srcDirUrl != null)
        {
            srcDirName = resolveFile(srcDirUrl).getName();
        }
        final ArrayList<FileObject> srcs = new ArrayList<FileObject>();
        for (int i = 0; i < srcFiles.size(); i++)
        {
            // Locate the source file, and make sure it exists
            final SourceInfo src = srcFiles.get(i);
            final FileObject srcFile = resolveFile(src.file);
            if (!srcFile.exists())
            {
                final String message =
                    Messages.getString("vfs.tasks/sync.src-file-no-exist.warn", srcFile);

                logOrDie(message, Project.MSG_WARN);
            }
            else
            {
                srcs.add(srcFile);
            }
        }

        // Scan the source files
        final Set<FileObject> destFiles = new HashSet<FileObject>();
        for (int i = 0; i < srcs.size(); i++)
        {
            final FileObject rootFile = srcs.get(i);
            final FileName rootName = rootFile.getName();

            if (rootFile.getType() == FileType.FILE)
            {
                // Build the destination file name
                String relName = null;
                if (srcDirName == null || !srcDirIsBase)
                {
                    relName = rootName.getBaseName();
                }
                else
                {
                    relName = srcDirName.getRelativeName(rootName);
                }
                final FileObject destFile = destFolder.resolveFile(relName, NameScope.DESCENDENT);

                // Do the copy
                handleFile(destFiles, rootFile, destFile);
            }
            else
            {
                // Find matching files
                // If srcDirIsBase is true, select also the sub-directories
                final FileObject[] files = rootFile.findFiles(srcDirIsBase
                    ? Selectors.SELECT_ALL : Selectors.SELECT_FILES);

                for (int j = 0; j < files.length; j++)
                {
                    final FileObject srcFile = files[j];

                    // Build the destination file name
                    String relName = null;
                    if (srcDirName == null || !srcDirIsBase)
                    {
                        relName = rootName.getRelativeName(srcFile.getName());
                    }
                    else
                    {
                        relName = srcDirName.getRelativeName(srcFile.getName());
                    }
View Full Code Here


     */
    public void removeFile(final FileObject file)
    {
        synchronized (this.monitorMap)
        {
            FileName fn = file.getName();
            if (this.monitorMap.get(fn) != null)
            {
                FileObject parent;
                try
                {
View Full Code Here

                fileNames = this.monitorMap.keySet().toArray();
            }
            for (int iterFileNames = 0; iterFileNames < fileNames.length;
                 iterFileNames++)
            {
                FileName fileName = (FileName) fileNames[iterFileNames];
                FileMonitorAgent agent;
                synchronized (this.monitorMap)
                {
                    agent = this.monitorMap.get(fileName);
                }
View Full Code Here

     * @throws FileSystemException if an error occurs.
     */
    public FileName resolveName(final FileName base, final String name,
            final NameScope scope) throws FileSystemException
    {
        final FileName realBase;
        if (base != null && VFS.isUriStyle() && base.getType() == FileType.FILE)
        {
            realBase = base.getParent();
        }
        else
        {
            realBase = base;
        }

        final StringBuilder buffer = new StringBuilder(name);

        // Adjust separators
        UriParser.fixSeparators(buffer);
        String scheme = UriParser.extractScheme(buffer.toString());

        // Determine whether to prepend the base path
        if (name.length() == 0 || (scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR))
        {
            // Supplied path is not absolute
            if (!VFS.isUriStyle())
            {
                // when using uris the parent already do have the trailing "/"
                buffer.insert(0, FileName.SEPARATOR_CHAR);
            }
            buffer.insert(0, realBase.getPath());
        }

        // // UriParser.canonicalizePath(buffer, 0, name.length());

        // Normalise the path
        FileType fileType = UriParser.normalisePath(buffer);

        // Check the name is ok
        final String resolvedPath = buffer.toString();
        if (!AbstractFileName
                .checkName(realBase.getPath(), resolvedPath, scope))
        {
            throw new FileSystemException(
                    "vfs.provider/invalid-descendent-name.error", name);
        }

        String fullPath;
        if (scheme != null)
        {
            fullPath = resolvedPath;
        }
        else
        {
            scheme = realBase.getScheme();
            fullPath = realBase.getRootURI() + resolvedPath;
        }
        final FileProvider provider = providers.get(scheme);
        if (provider != null)
        {
            // todo: extend the filename parser to be able to parse
View Full Code Here

        throws FileSystemException
    {
        StringBuilder uri = new StringBuilder(name.length() + 5);
        uri.append("file:");
        uri.append(name);
        FileName filename = parseUri(null, uri.toString());
        return findFile(filename, null);
    }
View Full Code Here

     * find the root of the filesystem.
     *
     * @return The root FileName.
     */
    public FileName getRoot() {
        FileName root = this;
        while (root.getParent() != null) {
            root = root.getParent();
        }

        return root;
    }
View Full Code Here

    @Test
    public void testLastModificationDateFileSystemEx()
            throws FileSystemException
    {
        final FileObject fo = EasyMock.createMock(FileObject.class);
        FileName name = EasyMock.createMock(FileName.class);
        EasyMock.expect(fo.exists()).andReturn(Boolean.TRUE);
        EasyMock.expect(fo.getContent()).andThrow(
                new FileSystemException("error"));
        EasyMock.expect(fo.getName()).andReturn(name);
        EasyMock.expect(name.getURI()).andReturn("someURI");
        EasyMock.replay(fo, name);
        VFSFileHandlerReloadingDetector strategy =
                new VFSFileHandlerReloadingDetector()
                {
                    @Override
View Full Code Here

        try
        {
            FileSystemManager fsManager = VFS.getManager();
            if (url != null)
            {
                FileName name = fsManager.resolveURI(url.toString());
                if (name != null)
                {
                    return name.toString();
                }
            }

            if (UriParser.extractScheme(fileName) != null)
            {
                return fileName;
            }
            else if (basePath != null)
            {
                FileName base = fsManager.resolveURI(basePath);
                return fsManager.resolveName(base, fileName).getURI();
            }
            else
            {
                FileName name = fsManager.resolveURI(fileName);
                FileName base = name.getParent();
                return fsManager.resolveName(base, name.getBaseName()).getURI();
            }
        }
        catch (FileSystemException fse)
        {
View Full Code Here

            return super.getBasePath(path);
        }
        try
        {
            FileSystemManager fsManager = VFS.getManager();
            FileName name = fsManager.resolveURI(path);
            return name.getParent().getURI();
        }
        catch (FileSystemException fse)
        {
            fse.printStackTrace();
            return null;
View Full Code Here

            return super.getFileName(path);
        }
        try
        {
            FileSystemManager fsManager = VFS.getManager();
            FileName name = fsManager.resolveURI(path);
            return name.getBaseName();
        }
        catch (FileSystemException fse)
        {
            fse.printStackTrace();
            return null;
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs2.FileName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.