KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > response > CheckedInResponse


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Robert Greig.
17  * Portions created by Robert Greig are Copyright (C) 2000.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Robert Greig.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.response;
23
24 import java.io.*;
25 import java.util.*;
26 import java.text.*;
27
28 import org.netbeans.lib.cvsclient.admin.*;
29 import org.netbeans.lib.cvsclient.util.*;
30
31 /**
32  * Indicates that a file has been successfully operated on, e.g. checked in,
33  * added etc.
34  * @author Robert Greig
35  */

36 class CheckedInResponse implements Response {
37
38     /**
39      * The date Formatter used to parse and format dates.
40      * Format is: "EEE MMM dd HH:mm:ss yyyy"
41      */

42     private DateFormat dateFormatter;
43     
44     /**
45      * Process the data for the response.
46      * @param dis the data inputstream allowing the client to read the server's
47      * response. Note that the actual response name has already been read
48      * and the input stream is positioned just before the first argument, if
49      * any.
50      */

51     public void process(LoggedDataInputStream dis, ResponseServices services)
52             throws ResponseException {
53         try {
54             String JavaDoc localPath = dis.readLine();
55             //System.err.println("Pathname is: " + localPath);
56
String JavaDoc repositoryPath = dis.readLine();
57             //System.err.println("Repository path is: " + repositoryPath);
58
String JavaDoc entriesLine = dis.readLine();
59             //System.err.println("New entries line is: " + entriesLine);
60
// we set the date the file was last modified in the Entry line
61
// so that we can easily determine whether the file has been
62
// untouched
63
final File theFile = new File(services.convertPathname(localPath,
64                                                                    repositoryPath));
65             final Date date = new Date(theFile.lastModified());
66             final Entry entry = new Entry(entriesLine);
67             entry.setConflict(getDateFormatter().format(date));
68
69             // for added and removed entries set the conflict to Dummy timestamp.
70
if (entry.isNewUserFile() ||
71                     entry.isUserFileToBeRemoved()) {
72                 entry.setConflict(Entry.DUMMY_TIMESTAMP);
73             }
74
75             services.setEntry(theFile, entry);
76         }
77         catch (IOException e) {
78             throw new ResponseException((Exception JavaDoc)e.fillInStackTrace(), e.getLocalizedMessage());
79         }
80     }
81
82     /**
83      * Is this a terminal response, i.e. should reading of responses stop
84      * after this response. This is true for responses such as OK or
85      * an error response
86      */

87     public boolean isTerminalResponse() {
88         return false;
89     }
90     
91     /**
92      * Returns the DateFormatter instance that parses and formats date Strings.
93      * The exact format matches the one in Entry.getLastModifiedDateFormatter() method.
94      *
95      */

96     protected DateFormat getDateFormatter() {
97         if (dateFormatter == null) {
98             dateFormatter = new SimpleDateFormat(Entry.getLastModifiedDateFormatter().toPattern(), Locale.US);
99             dateFormatter.setTimeZone(Entry.getTimeZone());
100         }
101         return dateFormatter;
102     }
103     
104 }
105
Popular Tags