1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.daemon.vfs;
27
28
29 /**
30 *
31 *
32 * @author $author$
33 * @version $Revision: 1.12 $
34 */
35 public class VFSPermission {
36 private boolean canRead;
37 private boolean canWrite;
38 private boolean canExecute;
39 private String name;
40
41 /**
42 * Creates a new VFSPermission object.
43 *
44 * @param name
45 * @param permissions
46 */
47 public VFSPermission(String name, String permissions) {
48 this.name = name;
49 setPermissions(permissions);
50 }
51
52 /**
53 * Creates a new VFSPermission object.
54 *
55 * @param name
56 */
57 public VFSPermission(String name) {
58 this.name = name;
59 setPermissions("rwx");
60 }
61
62 /**
63 *
64 *
65 * @return
66 */
67 public String getName() {
68 return name;
69 }
70
71 /**
72 *
73 *
74 * @param permissions
75 */
76 public void setPermissions(String permissions) {
77 canRead = false;
78 canWrite = false;
79 canExecute = false;
80
81 for (int i = 0; i < permissions.length(); i++) {
82 switch (permissions.charAt(i)) {
83 case 'r': {
84 canRead = true;
85
86 break;
87 }
88
89 case 'w': {
90 canWrite = true;
91
92 break;
93 }
94
95 case 'x': {
96 canExecute = true;
97
98 break;
99 }
100 }
101 }
102 }
103
104 /**
105 *
106 *
107 * @return
108 */
109 public String getPermissions() {
110 return (canRead ? "r" : "") + (canWrite ? "w" : "") +
111 (canExecute ? "x" : "");
112 }
113
114 /**
115 *
116 *
117 * @param permissions
118 *
119 * @return
120 */
121 public boolean verifyPermissions(String permissions) {
122 String tmp = getPermissions();
123 String ch;
124
125 for (int i = 0; i < permissions.length(); i++) {
126 ch = permissions.substring(i, 1);
127
128 if (tmp.indexOf(ch) == -1) {
129 return false;
130 }
131 }
132
133 return true;
134 }
135
136 /**
137 *
138 *
139 * @return
140 */
141 public boolean canRead() {
142 return canRead;
143 }
144
145 /**
146 *
147 *
148 * @return
149 */
150 public boolean canWrite() {
151 return canWrite;
152 }
153
154 /**
155 *
156 *
157 * @return
158 */
159 public boolean canExecute() {
160 return canExecute;
161 }
162 }