1 19 20 package org.netbeans.modules.subversion.client; 21 22 import java.io.*; 23 import java.util.*; 24 import org.netbeans.modules.subversion.Subversion; 25 import org.netbeans.modules.subversion.client.parser.ParserSvnInfo; 26 import org.netbeans.modules.subversion.config.KVFile; 27 import org.tigris.subversion.svnclientadapter.ISVNInfo; 28 import org.tigris.subversion.svnclientadapter.SVNClientException; 29 30 54 public final class PropertiesClient { 55 56 private final File file; 57 58 59 public PropertiesClient(File file) { 60 assert file != null; 61 this.file = file; 62 } 63 64 68 public Map<String , byte[]> getBaseProperties() throws IOException { 69 File store; 70 try { 71 store = getPropertyFile(true); 72 } catch (SVNClientException ex) { 73 throw new IOException(ex.getMessage()); 74 } 75 if (store != null && store.isFile()) { 76 KVFile kv = new KVFile(store); 77 return normalize(kv.getMap()); 78 } else { 79 return new HashMap<String , byte[]>(); 80 } 81 } 82 83 87 public Map<String , byte[]> getProperties() throws IOException { 88 File store; 89 try { 90 store = getPropertyFile(false); 91 } catch (SVNClientException ex) { 92 throw new IOException(ex.getMessage()); 93 } 94 if (store != null && store.isFile()) { 95 KVFile kv = new KVFile(store); 96 return normalize(kv.getMap()); 97 } else { 98 return new HashMap<String , byte[]>(); 99 } 100 } 101 102 private File getPropertyFile(boolean base) throws SVNClientException { 103 SvnClient client = Subversion.getInstance().getClient(false); 105 ISVNInfo info = null; 106 try { 107 info = client.getInfoFromWorkingCopy(file); 108 } catch (SVNClientException ex) { 109 throw ex; 110 } 111 if(info instanceof ParserSvnInfo) { 112 if(base) { 113 return ((ParserSvnInfo) info).getBasePropertyFile(); 114 } else { 115 return ((ParserSvnInfo) info).getPropertyFile(); 116 } 117 } else { 118 throw new SVNClientException("Unexpected value:" + info + " should be from type " + ParserSvnInfo.class); 119 } 120 } 121 122 private Map<String , byte[]> normalize(Map map) { 123 Map<String , byte[]> ret = new HashMap<String , byte[]>(map.size()); 124 Iterator<Map.Entry> it = map.entrySet().iterator(); 125 while (it.hasNext()) { 126 Map.Entry next = it.next(); 127 ret.put(next.getKey().toString(), (byte[]) next.getValue()); 129 } 130 return ret; 131 } 132 133 134 public Map getProperties(int revision) throws IOException { 135 throw new UnsupportedOperationException (); 136 } 137 } 138 | Popular Tags |