1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 import java.io.*; 14 15 import org.eclipse.core.resources.IContainer; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.team.internal.ccvs.core.*; 19 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 20 import org.eclipse.team.internal.ccvs.core.util.SyncFileWriter; 21 22 30 public class TemplateHandler extends ResponseHandler { 31 32 35 public String getResponseID() { 36 return "Template"; } 38 39 42 public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { 43 session.readLine(); 44 ICVSFolder localFolder = session.getLocalRoot().getFolder(localDir); 47 IContainer container = (IContainer)localFolder.getIResource(); 48 ICVSStorage templateFile = null; 49 if (container != null && container.exists()) { 50 try { 51 templateFile = CVSWorkspaceRoot.getCVSFileFor(SyncFileWriter.getTemplateFile(container)); 52 } catch (CVSException e) { 53 CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, "Could not write template file in " + container.getFullPath() + ": " + e.getMessage(), e, session.getLocalRoot())); } 56 } 57 if (container == null || templateFile == null) { 58 templateFile = new ICVSStorage() { 60 public String getName() { 61 return "Template"; } 63 public void setContents( 64 InputStream stream, 65 int responseType, 66 boolean keepLocalHistory, 67 IProgressMonitor monitor) 68 throws CVSException { 69 70 try { 71 OutputStream out = new ByteArrayOutputStream(); 73 try { 74 byte[] buffer = new byte[1024]; 75 int read; 76 while ((read = stream.read(buffer)) >= 0) { 77 Policy.checkCanceled(monitor); 78 out.write(buffer, 0, read); 79 } 80 } finally { 81 out.close(); 82 } 83 } catch (IOException e) { 84 throw CVSException.wrapException(e); 85 } finally { 86 try { 87 stream.close(); 88 } catch (IOException e1) { 89 } 91 } 92 } 93 public long getSize() { 94 return 0; 95 } 96 public InputStream getContents() throws CVSException { 97 return new ByteArrayInputStream(new byte[0]); 98 } 99 }; 100 } 101 try { 102 session.receiveFile(templateFile, false, UpdatedHandler.HANDLE_UPDATED, monitor); 103 } catch (CVSException e) { 104 if (!(templateFile instanceof ICVSFile && handleInvalidResourceName(session, (ICVSFile)templateFile, e))) { 105 throw e; 106 } 107 } 108 } 109 110 } 111 | Popular Tags |