1 19 20 21 package org.netbeans.modules.masterfs; 22 23 import org.openide.filesystems.LocalFileSystem; 24 import org.openide.filesystems.AbstractFileSystem; 25 import org.openide.filesystems.DefaultAttributes; 26 import org.netbeans.modules.masterfs.providers.Attributes; 27 28 import java.io.IOException ; 29 import java.io.File ; 30 import java.util.Enumeration ; 31 import java.beans.PropertyVetoException ; 32 33 public class ExLocalFileSystem extends LocalFileSystem { 34 public static ExLocalFileSystem getInstance (File root) throws PropertyVetoException , IOException { 35 ExLocalFileSystem retVal = new ExLocalFileSystem (); 36 if (root.equals(Attributes.getRootForAttributes())) { 37 retVal.attr = new OneFileAttributeAttachedToRoot(retVal.info, retVal.change, retVal.list); 38 } else { 39 retVal.attr = new Attributes(root, retVal.info, retVal.change, retVal.list); 40 } 41 retVal.setRootDirectory(root); 42 43 return retVal; 44 } 45 46 public DefaultAttributes getAttributes () { 47 return (DefaultAttributes)attr; 48 } 49 50 private static class OneFileAttributeAttachedToRoot extends DefaultAttributes { 51 52 public OneFileAttributeAttachedToRoot( 53 AbstractFileSystem.Info info, 54 AbstractFileSystem.Change change, 55 AbstractFileSystem.List list 56 ) { 57 58 super(info, change, list, Attributes.ATTRNAME); } 60 61 62 public String [] children(String f) { 63 return super.children(f); 64 } 65 66 71 public Object readAttribute(String name, String attrName) { 72 return super.readAttribute(transformName (name), attrName); 73 } 74 75 81 public void writeAttribute(String name, String attrName, Object value) 82 throws IOException { 83 super.writeAttribute(transformName (name), attrName, value); 84 } 85 86 90 public synchronized Enumeration attributes(String name) { 91 return super.attributes(transformName (name)); 92 } 93 94 99 public synchronized void renameAttributes(String oldName, String newName) { 100 super.renameAttributes(transformName (oldName), transformName (newName)); 101 } 102 103 107 public synchronized void deleteAttributes(String name) { 108 super.deleteAttributes(transformName (name)); 109 } 110 111 private String transformName (String name) { 112 char replaceChar = '|'; if (name.indexOf(replaceChar) != -1 ) { 114 StringBuffer transformed = new StringBuffer (name.length() + 50); 115 for (int i = 0; i < name.length(); i++) { 116 transformed.append(name.charAt(i)); 117 if (name.charAt(i) == replaceChar) 118 transformed.append(replaceChar); 119 } 120 name = transformed.toString(); 121 } 122 return name.replace('/',replaceChar); } 124 } 125 } 126 | Popular Tags |