KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > ImportStructureVisitor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13
14 import java.util.StringTokenizer JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.team.core.Team;
20 import org.eclipse.team.internal.ccvs.core.*;
21 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
22 import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher;
23
24 /**
25  * The ImportStructureVisitor sends the content of the folder it is
26  * used on to the server. It constructs the locations of the resources
27  * because the resources do not yet have a remote-location.<br>
28  * It can also ignore certain files and decides wether to send
29  * a file in binary or text mode due to a specification that is passed
30  * as a "wrapper" argument.
31  */

32 class ImportStructureVisitor implements ICVSResourceVisitor {
33     
34     private static final String JavaDoc KEYWORD_OPTION = "-k"; //$NON-NLS-1$
35
private static final String JavaDoc QUOTE = "'"; //$NON-NLS-1$
36

37     protected Session session;
38     protected IProgressMonitor monitor;
39     
40     private FileNameMatcher ignoreMatcher;
41     private FileNameMatcher wrapMatcher;
42     
43     /**
44      * Constructor for ImportStructureVisitor.
45      * @param requestSender
46      * @param mRoot
47      * @param monitor
48      */

49     public ImportStructureVisitor(Session session,
50         String JavaDoc[] wrappers, IProgressMonitor monitor) {
51
52         this.session = session;
53         this.monitor = Policy.infiniteSubMonitorFor(monitor, 512);
54         wrapMatcher = initWrapMatcher(wrappers);
55     }
56     
57
58     /**
59      * Inits the wrapMatcher, that is responsible to find out
60      * whether a file is to be send as a binary (on an import)
61      * or not.
62      *
63      * Takes wrappers of this format:
64      * *.class -k 'o'
65      *
66      * and inits the FileNameMatcher to give
67      * -ko back if you call it with match("somename.class")
68      *
69      * ignores all wrappers, that do not contain -k
70      */

71     private FileNameMatcher initWrapMatcher(String JavaDoc[] wrappers) {
72         
73         FileNameMatcher wrapMatcher;
74         
75         if (wrappers == null) {
76             return null;
77         }
78         
79         wrapMatcher = new FileNameMatcher();
80         
81         for (int i = 0; i < wrappers.length; i++) {
82             
83             if (wrappers[i].indexOf(KEYWORD_OPTION) == -1) {
84                 continue;
85             }
86             
87             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(wrappers[i]);
88             String JavaDoc pattern = st.nextToken();
89             String JavaDoc option = st.nextToken();
90             // get rid of the quotes
91
StringTokenizer JavaDoc quoteSt =
92                 new StringTokenizer JavaDoc(st.nextToken(),QUOTE);
93             option += quoteSt.nextToken();
94             
95             wrapMatcher.register(pattern,option);
96         }
97         
98         return wrapMatcher;
99     }
100     
101     /**
102      * @see ICVSResourceVisitor#visitFile(IManagedFile)
103      */

104     public void visitFile(ICVSFile mFile) throws CVSException {
105         if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) {
106             return;
107         }
108         
109         boolean binary = Team.getFileContentManager().getType((IFile)mFile.getIResource()) == Team.BINARY;
110         if (wrapMatcher != null) {
111             String JavaDoc mode = wrapMatcher.getMatch(mFile.getName());
112             if (mode != null) binary = KSubstOption.fromMode(mode).isBinary();
113         }
114         session.sendModified(mFile, binary, monitor);
115     }
116
117     /**
118      * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
119      */

120     public void visitFolder(ICVSFolder mFolder) throws CVSException {
121         
122         if (ignoreMatcher != null && ignoreMatcher.match(mFolder.getName())) {
123             return;
124         }
125         
126         String JavaDoc localPath = mFolder.getRelativePath(session.getLocalRoot());
127         monitor.subTask(NLS.bind(CVSMessages.AbstractStructureVisitor_sendingFolder, new String JavaDoc[] { localPath }));
128         
129         session.sendConstructedDirectory(localPath);
130         mFolder.acceptChildren(this);
131     }
132
133 }
134
Popular Tags