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

Last change on this file since 570 was 570, checked in by jts21, 11 years ago

Add settings package which uses reflection to allow changing settings without hard coding the code to change every setting.

  • Currently only works for String/Int/Boolean/Double values
  • Supports default values by looking for fields with the prefix 'default', and will reset unset values to their default if a default exists.
  • For more complex settings (e.g. proxy settings), there is a "onParsed()" callback which can be used to run additional code, and (in the case of the password widget) parse abnormal items.
  • Some of the settings code in FrameUtils.ParseProfile has already been commented out since it's handled by default with the new Settings package. The rest could be moved over to UserSettings.onParsed(). Given the number of settings that remain to be moved, it may be a good idea to add the possibility for setting-specific onParsed() callbacks (could be done quite easily, similarly to how default values are handled).
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1package org.expeditee.items;
2
3import org.expeditee.items.UserAppliedPermission;
4import org.expeditee.settings.UserSettings;
5
6public 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}
Note: See TracBrowser for help on using the repository browser.