KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import org.netbeans.lib.cvsclient.util.*;
27
28 /**
29  * This Template response allows the server to send a template file that is
30  * used when committing changes. The client tools can read the Template file
31  * which is stored in CVS/Template and display it to the user to be used as a
32  * prompt for commit comments.
33  * @author Robert Greig
34  */

35 class TemplateResponse
36         implements Response {
37     /**
38      * A reference to an uncompressed file handler
39      */

40 /*
41     // TODO: Should this be taken from ResponseServices???
42     protected static FileHandler uncompressedFileHandler;
43 */

44
45     /**
46      * The local path of the new file
47      */

48     protected String JavaDoc localPath;
49
50     /**
51      * The full repository path of the file
52      */

53     protected String JavaDoc repositoryPath;
54
55     /**
56      * Creates new TemplateResponse
57      */

58     public TemplateResponse() {
59     }
60
61 /*
62     // TODO: replace this with a call to ResponseSerivices::getUncompr....ler?
63     protected static FileHandler getUncompressedFileHandler()
64     {
65         if (uncompressedFileHandler == null) {
66             uncompressedFileHandler = new DefaultFileHandler();
67         }
68         return uncompressedFileHandler;
69     }
70 */

71
72     /**
73      * Process the data for the response.
74      * @param dis the data inputstream allowing the client to read the server's
75      * response. Note that the actual response name has already been read
76      * and the input stream is positioned just before the first argument, if
77      * any.
78      */

79     public void process(LoggedDataInputStream dis, ResponseServices services)
80             throws ResponseException {
81         try {
82             localPath = dis.readLine();
83             repositoryPath = dis.readLine();
84
85             int length = Integer.parseInt(dis.readLine());
86
87             // now read in the file
88
final String JavaDoc filePath = services.convertPathname(localPath,
89                                                              repositoryPath) +
90                     "CVS/Template"; //NOI18N
91

92             // #69639 write metadata directly
93
// XXX possibly add a method to AdminHandler
94
OutputStream out = null;
95             File file = new File(filePath);
96             file.getParentFile().mkdirs();
97             try {
98                 out = new FileOutputStream(file);
99                 out = new BufferedOutputStream(out);
100                 byte[] lineSeparator = System.getProperty("line.separator").getBytes(); // NOI18N
101
byte[] data = dis.readBytes(length);
102                 for (int i = 0; i<data.length; i++) {
103                     byte ch = data[i];
104                     if (ch == '\n') {
105                         out.write(lineSeparator);
106                     } else {
107                         out.write(ch);
108                     }
109                 }
110             } catch (EOFException eof) {
111             } finally {
112                 if (out != null) {
113                     try {
114                         out.close();
115                     } catch (IOException alreadyClosed) {
116                     }
117                 }
118             }
119         }
120         catch (EOFException ex) {
121             String JavaDoc localMessage =
122                     ResponseException.getLocalMessage("CommandException.EndOfFile"); //NOI18N
123
throw new ResponseException(ex, localMessage);
124         }
125         catch (IOException ex) {
126             throw new ResponseException(ex);
127         }
128     }
129
130     /**
131      * Is this a terminal response, i.e. should reading of responses stop
132      * after this response. This is true for responses such as OK or
133      * an error response
134      */

135     public boolean isTerminalResponse() {
136         return false;
137     }
138 }
139
Popular Tags