Skip to main content
summaryrefslogtreecommitdiffstats
blob: e55ead110389a4ec26e32b38b3bd0f63985dedb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.core.client;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.util.SyncFileWriter;

/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class TemplateHandler extends ResponseHandler {

	/**
	 * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#getResponseID()
	 */
	public String getResponseID() {
		return "Template"; //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#handle(org.eclipse.team.internal.ccvs.core.client.Session, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException {
		String remoteDir = session.readLine();
		ICVSFolder localFolder = getExistingFolder(session, localDir);
		IContainer container = (IContainer)localFolder.getIResource();
		ICVSStorage templateFile;
		if (container == null) {
			// Create a dummy storage handle to recieve the contents from the server
			templateFile = new ICVSStorage() {
				public String getName() {
					return "Template"; //$NON-NLS-1$
				}
				public void setContents(
					InputStream stream,
					int responseType,
					boolean keepLocalHistory,
					IProgressMonitor monitor)
					throws CVSException {

					try {
						// Transfer the contents
						OutputStream out = new ByteArrayOutputStream();
						try {
							byte[] buffer = new byte[1024];
							int read;
							while ((read = stream.read(buffer)) >= 0) {
								Policy.checkCanceled(monitor);
								out.write(buffer, 0, read);
							}
						} finally {
							out.close();
						}
					} catch (IOException e) {
						throw CVSException.wrapException(e); //$NON-NLS-1$
					} finally {
						try {
							stream.close();
						} catch (IOException e1) {
							// Ignore close errors
						}
					}
				}
				public long getSize() {
					return 0;
				}
				public InputStream getContents() throws CVSException {
					return new ByteArrayInputStream(new byte[0]);
				}
			};
		} else {
			templateFile = CVSWorkspaceRoot.getCVSFileFor(SyncFileWriter.getTemplateFile(container));
		}
		session.receiveFile(templateFile, false, UpdatedHandler.HANDLE_UPDATED, monitor);
	}

}

Back to the top