source: trunk/src/org/expeditee/items/PermissionPair.java@ 1193

Last change on this file since 1193 was 1193, checked in by bln4, 6 years ago

org.expeditee.gui.Frame ->
org.expeditee.gui.FrameUtils ->
org.expeditee.items.Permission ->
org.expeditee.items.PermissionPair ->
org.expeditee.items.UserAppliedPermission ->
The beginnings of the new denied level of permissions. A frame with a denied level of permission cannot be navigated too. Denied level permission for items coming soon.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1/**
2 * PermissionPair.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21import org.expeditee.settings.UserSettings;
22
23public class PermissionPair {
24
25 private UserAppliedPermission ownerPermission;
26 private UserAppliedPermission notOwnerPermission;
27
28 public PermissionPair(String permissionCode, UserAppliedPermission defaultPermission) {
29 ownerPermission = defaultPermission;
30 notOwnerPermission = defaultPermission;
31
32 if (permissionCode != null) {
33
34 permissionCode = permissionCode.trim().toLowerCase();
35 if (permissionCode.length() != 0) {
36
37 if (permissionCode.length() == 1) {
38 // replicate it to cover ifOwner/ifNotOwner
39 permissionCode += permissionCode;
40 }
41
42 final int ownerPermissionIndexStart = 0;
43 final int ownerPermissionIndexEnd = permissionCode.charAt(ownerPermissionIndexStart) == '-' ?
44 ownerPermissionIndexStart + 2 : ownerPermissionIndexStart + 1;
45 final int notOwnerPermissionIndexStart = ownerPermissionIndexEnd;
46 final int notOwnerPermissionIndexEnd = permissionCode.charAt(notOwnerPermissionIndexStart) == '-' ?
47 notOwnerPermissionIndexStart + 2 : notOwnerPermissionIndexStart + 1;
48 final String ownerPermissionCode = permissionCode.substring(ownerPermissionIndexStart, ownerPermissionIndexEnd);
49 final String notOwnerPermissionCode = permissionCode.substring(notOwnerPermissionIndexStart, notOwnerPermissionIndexEnd);
50 ownerPermission = UserAppliedPermission.getPermission(ownerPermissionCode, defaultPermission);
51 notOwnerPermission = UserAppliedPermission.getPermission(notOwnerPermissionCode, defaultPermission);
52 //ownerPermission = UserAppliedPermission.getPermission(permissionCode.substring(0, 1),
53 // defaultPermission);
54 //notOwnerPermission = UserAppliedPermission.getPermission(permissionCode.substring(1, 2),
55 // defaultPermission);
56 }
57 }
58 }
59
60 public PermissionPair(UserAppliedPermission ownerPermission, UserAppliedPermission notOwnerPermission) {
61 this.ownerPermission = ownerPermission;
62 this.notOwnerPermission = notOwnerPermission;
63 }
64
65 public PermissionPair(UserAppliedPermission ownerPermissionForBoth) {
66 this(ownerPermissionForBoth, ownerPermissionForBoth);
67 }
68
69 public PermissionPair(PermissionPair pp) {
70 ownerPermission = pp.ownerPermission;
71 notOwnerPermission = pp.notOwnerPermission;
72 }
73
74 public UserAppliedPermission getPermission(String ownerOfItem) {
75
76 if (UserSettings.UserName.get().equals(ownerOfItem)) {
77 return ownerPermission;
78 } else {
79 return notOwnerPermission;
80 }
81 }
82
83 /**
84 * Converts the given Expeditee permission code into a PermissionPair
85 * corresponding to the constants defined in Item.
86 *
87 * @param permissionCode
88 * The Expeditee permission code to convert
89 * @return The resulting PermissionPair corresponding to a pair of constants as
90 * defined in Item
91 */
92 public static PermissionPair convertString(String permissionCode) {
93 PermissionPair pp = new PermissionPair(permissionCode, UserAppliedPermission.full);
94
95 return pp;
96 }
97
98 public String getCode() {
99 return Integer.toString(ownerPermission.getCode()) + Integer.toString(notOwnerPermission.getCode());
100 }
101
102 @Override
103 public String toString() {
104 return ownerPermission.toString() + ":" + notOwnerPermission.toString();
105 }
106}
Note: See TracBrowser for help on using the repository browser.