KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.*;
25 import java.util.*;
26 import org.netbeans.lib.cvsclient.admin.*;
27
28 import org.netbeans.lib.cvsclient.util.*;
29
30 /**
31  * Sets the modification time of the next file sent to a specified time.
32  * @author Robert Greig
33  */

34 class ModTimeResponse implements Response {
35
36     /**
37      * The formatter responsible for converting server dates to our own dates
38      */

39     protected static final SimpleDateFormat dateFormatter;
40
41     /**
42      * The way the server formats dates
43      */

44     protected static final String JavaDoc SERVER_DATE_FORMAT = "dd MMM yyyy HH:mm:ss"; //NOI18N
45

46     static {
47         dateFormatter = new SimpleDateFormat(SERVER_DATE_FORMAT, Locale.US);
48         dateFormatter.setTimeZone(Entry.getTimeZone());
49     }
50
51     /**
52      * Process the data for the response.
53      * @param dis the data inputstream allowing the client to read the server's
54      * response. Note that the actual response name has already been read
55      * and the input stream is positioned just before the first argument, if
56      * any.
57      */

58     public void process(LoggedDataInputStream dis, ResponseServices services)
59             throws ResponseException {
60         try {
61             String JavaDoc dateString = dis.readLine();
62
63             // we assume the date is in GMT, this appears to be the case
64
// We remove the ending because SimpleDateFormat does not parse
65
// +xxxx, only GMT+xxxx and this avoid us having to do String
66
// concat
67
Date date = dateFormatter.parse(
68                                    dateString.substring(0, dateString.length() - 6));
69             if (date.getTime() < 0) {
70                 // now we're in trouble - see #18232 issue.
71
// we need to adjust the modified time..
72
// so that the resulting date.getTime() is not negative.
73
// The problem occurs when the sent year has only 2 digits.
74
// this happens with old versions of cvs.
75
if (date.getYear() < 100 && date.getYear() >= 70) {
76                     date.setYear(date.getYear() + 1900);
77                 }
78                 else if (date.getYear() >= 0 && date.getYear() < 70) {
79                     date.setYear(date.getYear() + 2000);
80                 }
81                 else {
82                     date.setYear(2000 + date.getYear());
83                     // for values less than zero let's assume
84
// that we need to substract the value from 2000
85
/* throw new ResponseException(
86                        "Cannot adjust negative time value (" + dateString + ")", //NOI18N
87                        ResponseException.getLocalMessage("ModTimeResponse.badDate", //NOI18N
88                                            new Object[] {dateString}));
89  */

90                 }
91             }
92             services.setNextFileDate(date);
93         }
94         catch (Exception JavaDoc e) {
95             throw new ResponseException(e);
96         }
97     }
98
99     /**
100      * Is this a terminal response, i.e. should reading of responses stop
101      * after this response. This is true for responses such as OK or
102      * an error response
103      */

104     public boolean isTerminalResponse() {
105         return false;
106     }
107 }
108
Popular Tags