Changeset 1193 for trunk/src/org/expeditee/items
- Timestamp:
- 11/05/18 16:32:46 (6 years ago)
- Location:
- trunk/src/org/expeditee/items
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Permission.java
r919 r1193 1 1 /** 2 * Permission.java3 * Copyright (C) 2010 New Zealand Digital Library,http://expeditee.org2 * Permission.java Copyright (C) 2010 New Zealand Digital Library, 3 * http://expeditee.org 4 4 * 5 * This program is free software: you can redistribute it and/or modify6 * it under the terms of the GNU General Public License as published by7 * the Free Software Foundation, either version 3 of the License, or8 * (at your option) any laterversion.5 * This program is free software: you can redistribute it and/or modify it under 6 * the terms of the GNU General Public License as published by the Free Software 7 * Foundation, either version 3 of the License, or (at your option) any later 8 * version. 9 9 * 10 * This program is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for moredetails.10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 * details. 14 14 * 15 * You should have received a copy of the GNU General Public License16 * along with this program.If not, see <http://www.gnu.org/licenses/>.15 * You should have received a copy of the GNU General Public License along with 16 * this program. If not, see <http://www.gnu.org/licenses/>. 17 17 */ 18 18 19 19 package org.expeditee.items; 20 21 // public enum Permission { 22 // bedrock(-1), none(0), followLinks(1), copy(2), createFrames(3), full(4); 23 // 24 // private final int val; 25 // 26 // private Permission(final int val) { 27 // this.val = val; 28 // } 29 // 30 // public static Permission convertString(final String permissionCode) { 31 // return getPermission(permissionCode, Permission.full); 32 // } 33 // 34 // public static Permission getPermission(String permissionCode, final 35 // Permission defaultPermission) { 36 // if (permissionCode == null) { 37 // return defaultPermission; 38 // } 39 // 40 // permissionCode = permissionCode.trim().toLowerCase(); 41 // if (permissionCode.length() == 0) { 42 // return defaultPermission; 43 // } 44 // 45 // try { 46 // return resolve(Integer.parseInt(permissionCode), defaultPermission); 47 // } catch (final NumberFormatException e) { 48 // try { 49 // return valueOf(permissionCode); 50 // } catch (final Exception ex) { 51 // return defaultPermission; 52 // } 53 // } 54 // } 55 // 56 // public int getCode() { 57 // return val; 58 // } 59 // 60 // public String toString() { 61 // return this.name(); 62 // } 63 // 64 // public static Permission min(Permission p1, Permission p2) { 65 // return p1.val < p2.val ? p1 : p2; 66 // } 67 // 68 // public static Permission max(Permission p1, Permission p2) { 69 // return p1.val > p2.val ? p1 : p2; 70 // } 71 // 72 // private static Permission resolve(final int val, final Permission 73 // defaultPermission) { 74 // for (Permission p : Permission.values()) { 75 // if (p.val == val) { 76 // return p; 77 // } 78 // } 79 // return defaultPermission; 80 // } 81 // } 20 82 21 83 public enum Permission { … … 23 85 24 86 /** 25 * Converts the given Expeditee permission code into a int corresponding to 26 * theconstants defined in Item.27 * 87 * Converts the given Expeditee permission code into a int corresponding to the 88 * constants defined in Item. 89 * 28 90 * @param permissionCode 29 91 * The Expeditee permission code to convert 30 * @return The resulting int corresponding to one of the constants defined 31 * inItem92 * @return The resulting int corresponding to one of the constants defined in 93 * Item 32 94 */ 33 95 public static Permission convertString(String permissionCode) { … … 35 97 } 36 98 37 public static Permission getPermission(String permissionCode, 38 Permission defaultPermission) { 99 public static Permission getPermission(String permissionCode, Permission defaultPermission) { 39 100 if (permissionCode == null) 40 101 return defaultPermission; -
trunk/src/org/expeditee/items/PermissionPair.java
r1190 r1193 39 39 permissionCode += permissionCode; 40 40 } 41 42 ownerPermission = UserAppliedPermission.getPermission(permissionCode.substring(0, 1), 43 defaultPermission); 44 notOwnerPermission = UserAppliedPermission.getPermission(permissionCode.substring(1, 2), 45 defaultPermission); 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); 46 56 } 47 57 } … … 62 72 } 63 73 64 public UserAppliedPermission getPermission(String username) {74 public UserAppliedPermission getPermission(String ownerOfItem) { 65 75 66 if (UserSettings.UserName.get().equals( username)) {76 if (UserSettings.UserName.get().equals(ownerOfItem)) { 67 77 return ownerPermission; 68 78 } else { -
trunk/src/org/expeditee/items/UserAppliedPermission.java
r919 r1193 16 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 17 */ 18 19 18 package org.expeditee.items; 20 19 20 public enum UserAppliedPermission { 21 denied(-1), none(0), followLinks(1), copy(2), createFrames(3), full(4); 21 22 22 public enum UserAppliedPermission { 23 none, followLinks, copy, createFrames, full; 24 25 26 public static UserAppliedPermission getPermission(String permissionCode,27 UserAppliedPermission defaultPermission) 28 {29 if (permissionCode == null) 23 private final int val; 24 25 private UserAppliedPermission(final int val) { 26 this.val = val; 27 } 28 29 public static UserAppliedPermission getPermission(String permissionCode, final UserAppliedPermission defaultPermission) { 30 if (permissionCode == null) { 30 31 return defaultPermission; 32 } 31 33 32 34 permissionCode = permissionCode.trim().toLowerCase(); 33 if (permissionCode.length() == 0) 35 if (permissionCode.length() == 0) { 34 36 return defaultPermission; 37 } 35 38 36 // if it is a single char just match the first character37 39 try { 38 return values()[Integer.parseInt(permissionCode)]; 39 // Otherwise match the whole string 40 } catch (Exception ex) { 40 return resolve(Integer.parseInt(permissionCode), defaultPermission); 41 } catch (final NumberFormatException e) { 41 42 try { 42 43 return valueOf(permissionCode); 43 } 44 catch (Exception e) {44 } catch (final Exception ex) { 45 return defaultPermission; 45 46 } 46 47 } 47 48 // default permission49 return defaultPermission;50 48 } 51 49 52 50 public int getCode() { 53 return ordinal();51 return val; 54 52 } 55 53 … … 59 57 60 58 public static UserAppliedPermission min(UserAppliedPermission p1, UserAppliedPermission p2) { 61 return p1. ordinal() < p2.ordinal()? p1 : p2;59 return p1.val < p2.val ? p1 : p2; 62 60 } 63 61 64 62 public static UserAppliedPermission max(UserAppliedPermission p1, UserAppliedPermission p2) { 65 return p1.ordinal() > p2.ordinal() ? p1 : p2; 63 return p1.val > p2.val ? p1 : p2; 64 } 65 66 private static UserAppliedPermission resolve(final int val, final UserAppliedPermission defaultPermission) { 67 for (UserAppliedPermission p : UserAppliedPermission.values()) { 68 if (p.val == val) { 69 return p; 70 } 71 } 72 return defaultPermission; 66 73 } 67 74 } 75 //public enum UserAppliedPermission { 76 // none, followLinks, copy, createFrames, full; 77 // 78 // 79 // public static UserAppliedPermission getPermission(String permissionCode, 80 // UserAppliedPermission defaultPermission) 81 // { 82 // if (permissionCode == null) 83 // return defaultPermission; 84 // 85 // permissionCode = permissionCode.trim().toLowerCase(); 86 // if (permissionCode.length() == 0) 87 // return defaultPermission; 88 // 89 // // if it is a single char just match the first character 90 // try { 91 // return values()[Integer.parseInt(permissionCode)]; 92 // // Otherwise match the whole string 93 // } catch (Exception ex) { 94 // try { 95 // return valueOf(permissionCode); 96 // } 97 // catch (Exception e) { 98 // } 99 // } 100 // 101 // // default permission 102 // return defaultPermission; 103 // } 104 // 105 // public int getCode() { 106 // return ordinal(); 107 // } 108 // 109 // public String toString() { 110 // return this.name(); 111 // } 112 // 113 // public static UserAppliedPermission min(UserAppliedPermission p1, UserAppliedPermission p2) { 114 // return p1.ordinal() < p2.ordinal() ? p1 : p2; 115 // } 116 // 117 // public static UserAppliedPermission max(UserAppliedPermission p1, UserAppliedPermission p2) { 118 // return p1.ordinal() > p2.ordinal() ? p1 : p2; 119 // } 120 //}
Note:
See TracChangeset
for help on using the changeset viewer.