1 11 12 package org.eclipse.team.internal.ccvs.ui; 13 14 import java.io.*; 15 16 import org.eclipse.swt.dnd.*; 17 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; 18 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 19 import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; 20 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; 21 22 23 27 public final class CVSResourceTransfer extends ByteArrayTransfer { 28 29 public static final String TYPE_NAME = "CVS-resource-transfer-format"; 31 public static int TYPE = registerType(TYPE_NAME); 32 33 private static CVSResourceTransfer instance = new CVSResourceTransfer(); 34 35 36 private CVSResourceTransfer() { 37 } 38 39 public static CVSResourceTransfer getInstance() { 40 return instance; 41 } 42 43 44 protected int[] getTypeIds() { 45 return new int[] { TYPE }; 46 } 47 48 protected String [] getTypeNames() { 49 return new String [] { TYPE_NAME }; 50 } 51 52 53 58 public void javaToNative(Object object, TransferData transferData) { 59 if (!isSupportedType(transferData)) { 60 DND.error(DND.ERROR_INVALID_DATA); 61 } 62 63 final byte[] bytes = toByteArray((ICVSRemoteFile) object); 64 if (bytes != null) { 65 super.javaToNative(bytes, transferData); 66 } 67 } 68 69 74 protected Object nativeToJava(TransferData transferData) { 75 byte[] bytes = (byte[]) super.nativeToJava(transferData); 76 return fromByteArray(bytes); 77 } 78 79 80 public Object fromByteArray(byte[] bytes) { 81 final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)); 82 83 try { 84 String location = in.readUTF(); 85 String filePath = in.readUTF(); 86 String fileRevision = in.readUTF(); 87 88 ICVSRepositoryLocation repositoryLocation = KnownRepositories.getInstance().getRepository(location); 89 RemoteFile file = RemoteFile.create( filePath, repositoryLocation); 90 file.setRevision(fileRevision); 91 file.setReadOnly(true); 92 return file; 93 } catch (Exception ex) { 94 return null; 95 } 96 } 97 98 public byte[] toByteArray(ICVSRemoteFile file) { 99 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 100 DataOutputStream dos = new DataOutputStream(bos); 101 try { 102 dos.writeUTF(file.getRepository().getLocation(false)); 103 dos.writeUTF(file.getRepositoryRelativePath()); 104 dos.writeUTF(file.getRevision()); 105 return bos.toByteArray(); 106 } catch (Exception ex) { 107 return null; 109 } 110 } 111 112 } 113 | Popular Tags |