001: /*****************************************************************************
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is the CVS Client Library.
027: * The Initial Developer of the Original Software is Robert Greig.
028: * Portions created by Robert Greig are Copyright (C) 2000.
029: * All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041: *
042: * Contributor(s): Robert Greig.
043: *****************************************************************************/package org.netbeans.lib.cvsclient.response;
044:
045: import java.io.*;
046: import java.util.*;
047: import java.text.*;
048:
049: import org.netbeans.lib.cvsclient.admin.*;
050: import org.netbeans.lib.cvsclient.util.*;
051:
052: /**
053: * Indicates that a file has been successfully operated on, e.g. checked in,
054: * added etc.
055: * @author Robert Greig
056: */
057: class CheckedInResponse implements Response {
058:
059: /**
060: * The date Formatter used to parse and format dates.
061: * Format is: "EEE MMM dd HH:mm:ss yyyy"
062: */
063: private DateFormat dateFormatter;
064:
065: /**
066: * Process the data for the response.
067: * @param dis the data inputstream allowing the client to read the server's
068: * response. Note that the actual response name has already been read
069: * and the input stream is positioned just before the first argument, if
070: * any.
071: */
072: public void process(LoggedDataInputStream dis,
073: ResponseServices services) throws ResponseException {
074: try {
075: String localPath = dis.readLine();
076: //System.err.println("Pathname is: " + localPath);
077: String repositoryPath = dis.readLine();
078: //System.err.println("Repository path is: " + repositoryPath);
079: String entriesLine = dis.readLine();
080: //System.err.println("New entries line is: " + entriesLine);
081: // we set the date the file was last modified in the Entry line
082: // so that we can easily determine whether the file has been
083: // untouched
084: final File theFile = new File(services.convertPathname(
085: localPath, repositoryPath));
086: final Date date = new Date(theFile.lastModified());
087: final Entry entry = new Entry(entriesLine);
088: entry.setConflict(getDateFormatter().format(date));
089:
090: // for added and removed entries set the conflict to Dummy timestamp.
091: if (entry.isNewUserFile() || entry.isUserFileToBeRemoved()) {
092: entry.setConflict(Entry.DUMMY_TIMESTAMP);
093: }
094:
095: services.setEntry(theFile, entry);
096: } catch (IOException e) {
097: throw new ResponseException((Exception) e
098: .fillInStackTrace(), e.getLocalizedMessage());
099: }
100: }
101:
102: /**
103: * Is this a terminal response, i.e. should reading of responses stop
104: * after this response. This is true for responses such as OK or
105: * an error response
106: */
107: public boolean isTerminalResponse() {
108: return false;
109: }
110:
111: /**
112: * Returns the DateFormatter instance that parses and formats date Strings.
113: * The exact format matches the one in Entry.getLastModifiedDateFormatter() method.
114: *
115: */
116: protected DateFormat getDateFormatter() {
117: if (dateFormatter == null) {
118: dateFormatter = Entry.getLastModifiedDateFormatter();
119: }
120: return dateFormatter;
121: }
122:
123: }
|