001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.daemon.vfs;
027:
028: /**
029: *
030: *
031: * @author $author$
032: * @version $Revision: 1.12 $
033: */
034: public class VFSPermission {
035: private boolean canRead;
036: private boolean canWrite;
037: private boolean canExecute;
038: private String name;
039:
040: /**
041: * Creates a new VFSPermission object.
042: *
043: * @param name
044: * @param permissions
045: */
046: public VFSPermission(String name, String permissions) {
047: this .name = name;
048: setPermissions(permissions);
049: }
050:
051: /**
052: * Creates a new VFSPermission object.
053: *
054: * @param name
055: */
056: public VFSPermission(String name) {
057: this .name = name;
058: setPermissions("rwx");
059: }
060:
061: /**
062: *
063: *
064: * @return
065: */
066: public String getName() {
067: return name;
068: }
069:
070: /**
071: *
072: *
073: * @param permissions
074: */
075: public void setPermissions(String permissions) {
076: canRead = false;
077: canWrite = false;
078: canExecute = false;
079:
080: for (int i = 0; i < permissions.length(); i++) {
081: switch (permissions.charAt(i)) {
082: case 'r': {
083: canRead = true;
084:
085: break;
086: }
087:
088: case 'w': {
089: canWrite = true;
090:
091: break;
092: }
093:
094: case 'x': {
095: canExecute = true;
096:
097: break;
098: }
099: }
100: }
101: }
102:
103: /**
104: *
105: *
106: * @return
107: */
108: public String getPermissions() {
109: return (canRead ? "r" : "") + (canWrite ? "w" : "")
110: + (canExecute ? "x" : "");
111: }
112:
113: /**
114: *
115: *
116: * @param permissions
117: *
118: * @return
119: */
120: public boolean verifyPermissions(String permissions) {
121: String tmp = getPermissions();
122: String ch;
123:
124: for (int i = 0; i < permissions.length(); i++) {
125: ch = permissions.substring(i, 1);
126:
127: if (tmp.indexOf(ch) == -1) {
128: return false;
129: }
130: }
131:
132: return true;
133: }
134:
135: /**
136: *
137: *
138: * @return
139: */
140: public boolean canRead() {
141: return canRead;
142: }
143:
144: /**
145: *
146: *
147: * @return
148: */
149: public boolean canWrite() {
150: return canWrite;
151: }
152:
153: /**
154: *
155: *
156: * @return
157: */
158: public boolean canExecute() {
159: return canExecute;
160: }
161: }
|