1 | package org.expeditee.items;
|
---|
2 |
|
---|
3 | import org.expeditee.items.UserAppliedPermission;
|
---|
4 | import org.expeditee.settings.UserSettings;
|
---|
5 |
|
---|
6 | public class PermissionPair {
|
---|
7 |
|
---|
8 | private UserAppliedPermission ownerPermission;
|
---|
9 | private UserAppliedPermission notOwnerPermission;
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 | public PermissionPair(String permissionCode, UserAppliedPermission defaultPermission)
|
---|
15 | {
|
---|
16 | ownerPermission = defaultPermission;
|
---|
17 | notOwnerPermission = defaultPermission;
|
---|
18 |
|
---|
19 | if (permissionCode != null) {
|
---|
20 |
|
---|
21 | permissionCode = permissionCode.trim().toLowerCase();
|
---|
22 | if (permissionCode.length() != 0) {
|
---|
23 |
|
---|
24 | if (permissionCode.length()==1) {
|
---|
25 | // replicate it to cover ifOwner/ifNotOwner
|
---|
26 | permissionCode += permissionCode;
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | ownerPermission = UserAppliedPermission.getPermission(permissionCode.substring(0,1), defaultPermission);
|
---|
31 | notOwnerPermission = UserAppliedPermission.getPermission(permissionCode.substring(1,2), defaultPermission);
|
---|
32 |
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public PermissionPair(UserAppliedPermission ownerPermission, UserAppliedPermission notOwnerPermission)
|
---|
38 | {
|
---|
39 | ownerPermission = ownerPermission;;
|
---|
40 | notOwnerPermission = notOwnerPermission;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public PermissionPair(UserAppliedPermission ownerPermissionForBoth)
|
---|
44 | {
|
---|
45 | this(ownerPermissionForBoth,ownerPermissionForBoth);
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | public PermissionPair(PermissionPair pp)
|
---|
50 | {
|
---|
51 | ownerPermission = pp.ownerPermission;;
|
---|
52 | notOwnerPermission = pp.notOwnerPermission;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | public UserAppliedPermission getPermission(String username)
|
---|
57 | {
|
---|
58 |
|
---|
59 | if (UserSettings.UserName.equals(username)) {
|
---|
60 | return ownerPermission;
|
---|
61 | }
|
---|
62 | else {
|
---|
63 | return notOwnerPermission;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Converts the given Expeditee permission code into a PermissionPair corresponding to
|
---|
69 | * the constants defined in Item.
|
---|
70 | *
|
---|
71 | * @param permissionCode
|
---|
72 | * The Expeditee permission code to convert
|
---|
73 | * @return The resulting PermissionPair corresponding to a pair of constants as defined
|
---|
74 | * in Item
|
---|
75 | */
|
---|
76 | public static PermissionPair convertString(String permissionCode)
|
---|
77 | {
|
---|
78 | PermissionPair pp = new PermissionPair(permissionCode,UserAppliedPermission.full);
|
---|
79 |
|
---|
80 | return pp;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public String getCode() {
|
---|
84 | return Integer.toString(ownerPermission.getCode()) + Integer.toString(notOwnerPermission.getCode());
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | public String toString()
|
---|
90 | {
|
---|
91 | return ownerPermission.toString() + ":" + notOwnerPermission.toString();
|
---|
92 | }
|
---|
93 | }
|
---|