Text Compare
Produced: 10/30/2012 3:49:28 PM
   
Mode:  All  
Left file: C:\workspace\jboss-vfs\src\main\java\org\jboss\vfs\spi\RootFileSystem.java  
Right file: C:\workspace\jbossas-jboss-vfs-3.1.0.Final-0-g922c3db\src\main\java\org\jboss\vfs\spi\RootFileSystem.java  
/* = /*
* JBoss, Home of Professional Open Source   * JBoss, Home of Professional Open Source
* Copyright 2009, JBoss Inc., and individual contributors as indicated   * Copyright 2009, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a   * by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.   * full listing of individual contributors.
*   *
* This is free software; you can redistribute it and/or modify it   * This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as   * under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of   * published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.   * the License, or (at your option) any later version.
*   *
* This software is distributed in the hope that it will be useful,   * This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.   * Lesser General Public License for more details.
*   *
* You should have received a copy of the GNU Lesser General Public   * You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free   * License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/   */
     
package org.jboss.vfs.spi;   package org.jboss.vfs.spi;
     
import java.net.URI;   import java.net.URI;
import java.net.URISyntaxException;   import java.net.URISyntaxException;
import org.jboss.vfs.VirtualFile;   import org.jboss.vfs.VirtualFile;
import org.jboss.logging.Logger;   import org.jboss.logging.Logger;
     
import java.io.File;   import java.io.File;
  -+ import java.io.FileFilter;
    import java.io.FilenameFilter;
import java.io.IOException; = import java.io.IOException;
import java.io.InputStream;   import java.io.InputStream;
import java.io.FileInputStream;   import java.io.FileInputStream;
import java.security.CodeSigner;   import java.security.CodeSigner;
import java.util.List;   import java.util.List;
import java.util.Arrays;   import java.util.Arrays;
import java.util.Collections;   import java.util.Collections;
  -+ import java.util.UUID;
  =  
/**   /**
* A special FileSystem which supports multiple roots.   * A special FileSystem which supports multiple roots.
*   *
* This is currently accomplished by requiring that VirtualFile.getPathName()   * This is currently accomplished by requiring that VirtualFile.getPathName()
* produce output that is consumable by java.io.File as a path.   * produce output that is consumable by java.io.File as a path.
*/   */
public final class RootFileSystem implements FileSystem {   public final class RootFileSystem implements FileSystem {
     
    private static final Logger log = Logger.getLogger("org.jboss.vfs.root");       private static final Logger log = Logger.getLogger("org.jboss.vfs.root");
         
    public static final RootFileSystem ROOT_INSTANCE = new RootFileSystem();       public static final RootFileSystem ROOT_INSTANCE = new RootFileSystem();
         
  <>     private boolean forceCaseSensative = false;
       
    private RootFileSystem(){}       private RootFileSystem() {
            forceCaseSensative = "true".equals(System.getProperty("jboss.vfs.forceCaseSensative"));
        }
  =  
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException {       public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException {
        return new FileInputStream(getFile(mountPoint, target));           return new FileInputStream(getFile(mountPoint, target));
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public boolean isReadOnly() {       public boolean isReadOnly() {
        return false;           return false;
    }       }
     
  -+     public class WindowsCaseSensativeFileFilter implements FilenameFilter {
            private String virtualFileName = "";
           
            public WindowsCaseSensativeFileFilter(String virtualFileName) {
                this.virtualFileName = virtualFileName;
                if (virtualFileName == null) {
                    virtualFileName = "";
                }
            }
           
            @Override
            public boolean accept(File dir, String name) {
                return virtualFileName.equals(name); // Now it won't find the file unless it actually matched the case.
            }       
        }
       
    /** =     /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public File getFile(VirtualFile mountPoint, VirtualFile target) {       public File getFile(VirtualFile mountPoint, VirtualFile target) {
        return new File(target.getPathName()); <>         File retFile = new File(target.getPathName());
            if (forceCaseSensative && retFile != null && retFile.isFile() && retFile.getAbsolutePath().contains("\\")) {
                File parentFile = retFile.getParentFile();
                if (parentFile != null) {
                    WindowsCaseSensativeFileFilter wc = new WindowsCaseSensativeFileFilter(target.getName());
                    if (parentFile.list(wc).length == 0) {
                        retFile = new File(target.getPathName() + UUID.randomUUID().toString());   
                    }               
                }           
            }
            return retFile;
    } =     }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public boolean delete(VirtualFile mountPoint, VirtualFile target) {       public boolean delete(VirtualFile mountPoint, VirtualFile target) {
        return getFile(mountPoint, target).delete();           return getFile(mountPoint, target).delete();
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public long getSize(VirtualFile mountPoint, VirtualFile target) {       public long getSize(VirtualFile mountPoint, VirtualFile target) {
        return getFile(mountPoint, target).length();           return getFile(mountPoint, target).length();
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public long getLastModified(VirtualFile mountPoint, VirtualFile target) {       public long getLastModified(VirtualFile mountPoint, VirtualFile target) {
        return getFile(mountPoint, target).lastModified();           return getFile(mountPoint, target).lastModified();
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public boolean exists(VirtualFile mountPoint, VirtualFile target) {       public boolean exists(VirtualFile mountPoint, VirtualFile target) {
        return getFile(mountPoint, target).exists();           return getFile(mountPoint, target).exists();
    }       }
     
    /** {@inheritDoc} */       /** {@inheritDoc} */
    public boolean isFile(final VirtualFile mountPoint, final VirtualFile target) {       public boolean isFile(final VirtualFile mountPoint, final VirtualFile target) {
        return getFile(mountPoint, target).isFile();           return getFile(mountPoint, target).isFile();
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public boolean isDirectory(VirtualFile mountPoint, VirtualFile target) {       public boolean isDirectory(VirtualFile mountPoint, VirtualFile target) {
        return getFile(mountPoint, target).isDirectory();           return getFile(mountPoint, target).isDirectory();
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {       public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
        final String[] names = getFile(mountPoint, target).list();           final String[] names = getFile(mountPoint, target).list();
        return names == null ? Collections.<String>emptyList() : Arrays.asList(names);           return names == null ? Collections.<String>emptyList() : Arrays.asList(names);
    }       }
         
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target) {       public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target) {
        return null;           return null;
    }       }
     
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public File getMountSource() {       public File getMountSource() {
        return null;           return null;
    }       }
     
    public URI getRootURI() throws URISyntaxException {       public URI getRootURI() throws URISyntaxException {
        return null;           return null;
    }       }
     
    /**       /**
     * {@inheritDoc}        * {@inheritDoc}
     */        */
    public void close() throws IOException {       public void close() throws IOException {
        // no operation - the root FS can't be closed           // no operation - the root FS can't be closed
    }       }
}   }