Coverage Report - org.webslinger.commons.vfs.flat.FlatFileSystem
 
Classes in this File Line Coverage Branch Coverage Complexity
FlatFileSystem
95%
21/22
100%
7/7
0
 
 1  
 package org.webslinger.commons.vfs.flat;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Collection;
 5  
 import java.util.HashMap;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.apache.commons.vfs.Capability;
 9  
 import org.apache.commons.vfs.FileName;
 10  
 import org.apache.commons.vfs.FileObject;
 11  
 import org.apache.commons.vfs.FileType;
 12  
 import org.apache.commons.vfs.FileSystemException;
 13  
 import org.apache.commons.vfs.FileSystemManager;
 14  
 import org.apache.commons.vfs.FileSystemOptions;
 15  
 
 16  
 import org.webslinger.commons.vfs.FileSet;
 17  
 import org.webslinger.commons.vfs.FilteringFileSystem;
 18  
 import org.webslinger.commons.vfs.handlers.ExclusionHandler;
 19  
 import org.webslinger.commons.vfs.handlers.HandlerFactory;
 20  
 import org.webslinger.commons.vfs.handlers.attributes.AttributeMapperHandler;
 21  
 import org.webslinger.commons.vfs.handlers.attributes.DefaultAttributeMapperHandler;
 22  
 
 23  9711
 public class FlatFileSystem extends FilteringFileSystem<FileName, FlatFileObject, FlatFileSystem> implements ExclusionHandler {
 24  
     // deleted token:
 25  
     //     path/to/file/$parent/.meta/deleted/file
 26  
     //     path/to/dir/.meta/self/deleted
 27  
     // operations(supports dirs and files), does the Flat magic:
 28  
     //     path/to/file/$parent/.meta/operations/file
 29  
     //     path/to/dir/.meta/self/operations
 30  
     // .meta/deleted and .meta/operations are local, not managed with Flat symantics
 31  
     // Should files be converted to dirs when a child is added: yes
 32  
     // path/to/dir/.meta/link
 33  
     // path/to/dir/.meta/self/content
 34  
     // attributes:
 35  
     //     path/to/file/$parent/.meta/attributes/file/$attrName
 36  
     //     path/to/dir/.meta/self/attributes/$attrName
 37  
     // How to handle removing content in Flat, but not the children?  Using
 38  
     // the deleted token on the item won't work, as that may cause
 39  
     // recursion to not work.
 40  
 
 41  
     private final FileObject root;
 42  
     private AttributeMapperHandler attributeHandler;
 43  
     private ExclusionHandler exclusionHandler;
 44  
 
 45  
     public FlatFileSystem(FileName name, FileObject root, FileSystemOptions options) throws FileSystemException {
 46  33
         super(name, root, options);
 47  33
         this.root = root;
 48  33
     }
 49  
 
 50  
     public FlatFileObject createFile(FileName name) throws FileSystemException {
 51  
 //log("createFile(" + name.getClass() + "->" + name + ")");
 52  7125
         return new FlatFileObject(name, this, root.resolveFile(name.getPath().substring(1)));
 53  
     }
 54  
     // operations(supports dirs and files), filees the Flat magic:
 55  
     //     path/to/file/$parent/.meta/operations/file
 56  
     //     path/to/dir/.meta/self/operations
 57  
     // .meta/deleted and .meta/operations are local, not managed with Flat symantics
 58  
     // Should files be converted to dirs when a child is added: yes
 59  
     // content:
 60  
     //     path/to/file
 61  
     //     path/to/dir/.meta/self/content
 62  
     // attributes:
 63  
     //     path/to/file/$parent/.meta/attributes/file/$attrName
 64  
     //     path/to/dir/.meta/self/attributes/$attrName
 65  
 
 66  
     // FlatFileObject interface
 67  
 
 68  
     protected AttributeMapperHandler getAttributeHandler() throws FileSystemException {
 69  4226
         if (attributeHandler != null) return attributeHandler;
 70  32
         HandlerFactory<AttributeMapperHandler, FlatFileSystem> factory = FlatConfigBuilder.getInstance().getAttributeMapperHandlerFactory(getFileSystemOptions());
 71  32
         if (factory != null) attributeHandler = factory.getHandler(this, AttributeMapperHandler.class);
 72  32
         if (attributeHandler == null) attributeHandler = new StandardFlatAttributeMapperHandler(this);
 73  32
         return attributeHandler;
 74  
     }
 75  
 
 76  
     protected ExclusionHandler getExclusionHandler() throws FileSystemException {
 77  2631
         if (exclusionHandler != null) return exclusionHandler;
 78  27
         HandlerFactory<ExclusionHandler, FlatFileSystem> factory = FlatConfigBuilder.getInstance().getExclusionHandlerFactory(getFileSystemOptions());
 79  27
         if (factory != null) exclusionHandler = factory.getHandler(this, ExclusionHandler.class);
 80  27
         if (exclusionHandler == null) exclusionHandler = new ExclusionHandler.NullHandler();
 81  27
         return exclusionHandler;
 82  
     }
 83  
 
 84  
     protected FileSet getRealFiles(FlatFileObject file) throws FileSystemException {
 85  0
         return createFileSet(new FileObject[] {file.getRealFile()}, new FileObject[0]);
 86  
     }
 87  
 
 88  
     protected FlatFileObject[] newArray(int length) {
 89  2586
         return new FlatFileObject[length];
 90  
     }
 91  
 
 92  
     public void excludeNames(Collection<String> names) throws FileSystemException {
 93  2631
         getAttributeHandler().excludeNames(names);
 94  2631
         ExclusionHandler exclusionHandler = getExclusionHandler();
 95  2631
         if (exclusionHandler == null) return;
 96  2631
         exclusionHandler.excludeNames(names);
 97  2631
     }
 98  
 }
 99