Statistics
| Branch: | Revision:

root / java / jgsscli / src / jgsscli / cli / DefaultCmdPrinter.java @ 112:e33109eab665

History | View | Annotate | Download (3.8 kB)

1
/*
2

3
Copyright (c) 2009--2010, Panos Louridas, GRNET S.A.
4

5
All rights reserved.
6

7
Redistribution and use in source and binary forms, with or without modification,
8
are permitted provided that the following conditions are met:
9

10
 * Redistributions of source code must retain the above copyright notice, this 
11
   list of conditions and the following disclaimer.
12

13
 * Redistributions in binary form must reproduce the above copyright notice, 
14
   this list of conditions and the following disclaimer in the documentation 
15
   and/or other materials provided with the distribution.
16

17
 * Neither the name of GRNET S.A, nor the names of its contributors may be used 
18
   to endorse or promote products derived from this software without specific 
19
   prior written permission.
20

21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
22
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
23
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
24
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
25
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
26
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
27
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
28
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
29
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
30
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31

32
*/
33
package jgsscli.cli;
34

    
35
import jgsscli.commands.GSSCmd;
36
import jgsscli.commands.GSSUtils;
37
import jgsscli.event.EventHandler;
38
import jgsscli.httpmethods.StatusCode;
39

    
40
public class DefaultCmdPrinter implements EventHandler<GSSCmd> {
41

    
42
    private static Messages messages = Messages.getInstance();
43

    
44
    public void handle(GSSCmd cmd) {
45

    
46
        StatusCode statusCode = cmd.getStatusCode();
47
        String message = statusCode.code() + ": ";
48
        switch(cmd.getCommand()) {
49
            case PUT_FILE:
50
                message = GSSUtils.EOL + message;
51
                message += translatePutFileMsg(statusCode) + " "
52
                    + cmd.getRemotePath();
53
                break;
54

    
55
            case TRASH:
56
                message += translateTrashMsg(statusCode);
57
                break;
58

    
59
            default:
60
                message += messages.getString(statusCode.toString());
61
                break;
62
        }
63
        System.out.println(message);
64
    }
65

    
66
    private String translatePutFileMsg(StatusCode statusCode) {
67
        String message;
68
        switch(statusCode) {
69
            case METHOD_NOT_ALLOWED:
70
                message = messages.getString(Messages.Key.PERMISSION_DENIED);
71
                break;
72

    
73
            case CONFLICT:
74
                message = messages.getString(Messages.Key.FILE_EXISTS);
75
                break;
76

    
77
            case REQUEST_TOO_LONG:
78
                message = messages.getString(Messages.Key.QUOTA_EXCEEDED);
79
                break;
80

    
81
            case NO_CONTENT:
82
                message = messages.getString(Messages.Key.VERSION_UPDATED);
83
                break;
84

    
85
            case CREATED:
86
                message = messages.getString(Messages.Key.CREATED);
87
                break;
88

    
89
            case OK:
90
                message = messages.getString(Messages.Key.OK);
91
                break;
92

    
93
            default:
94
                message = messages.getString(Messages.Key.INTERNAL_ERROR);
95
        }
96
        return message;
97
    }
98

    
99
    private String translateTrashMsg(StatusCode statusCode) {
100
        String message;
101
        switch(statusCode) {
102
            case NO_CONTENT:
103
                message = messages.getString(Messages.Key.OK);
104
                break;
105

    
106
            default:
107
                message = messages.getString(Messages.Key.INTERNAL_ERROR);
108
        }
109
        return message;
110
    }
111

    
112
}