Ignore:
Timestamp:
11/05/18 16:32:46 (6 years ago)
Author:
bln4
Message:

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.

Location:
trunk/src/org/expeditee/items
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Permission.java

    r919 r1193  
    11/**
    2  *    Permission.java
    3  *    Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
     2 * Permission.java Copyright (C) 2010 New Zealand Digital Library,
     3 * http://expeditee.org
    44 *
    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.
     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.
    99 *
    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.
     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.
    1414 *
    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/>.
     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/>.
    1717 */
    1818
    1919package 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// }
    2082
    2183public enum Permission {
     
    2385
    2486        /**
    25          * Converts the given Expeditee permission code into a int corresponding to
    26          * the constants defined in Item.
    27          * 
     87         * Converts the given Expeditee permission code into a int corresponding to the
     88         * constants defined in Item.
     89         *
    2890         * @param permissionCode
    2991         *            The Expeditee permission code to convert
    30          * @return The resulting int corresponding to one of the constants defined
    31          *         in Item
     92         * @return The resulting int corresponding to one of the constants defined in
     93         *         Item
    3294         */
    3395        public static Permission convertString(String permissionCode) {
     
    3597        }
    3698
    37         public static Permission getPermission(String permissionCode,
    38                         Permission defaultPermission) {
     99        public static Permission getPermission(String permissionCode, Permission defaultPermission) {
    39100                if (permissionCode == null)
    40101                        return defaultPermission;
  • trunk/src/org/expeditee/items/PermissionPair.java

    r1190 r1193  
    3939                                        permissionCode += permissionCode;
    4040                                }
    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);
    4656                        }
    4757                }
     
    6272        }
    6373
    64         public UserAppliedPermission getPermission(String username) {
     74        public UserAppliedPermission getPermission(String ownerOfItem) {
    6575
    66                 if (UserSettings.UserName.get().equals(username)) {
     76                if (UserSettings.UserName.get().equals(ownerOfItem)) {
    6777                        return ownerPermission;
    6878                } else {
  • trunk/src/org/expeditee/items/UserAppliedPermission.java

    r919 r1193  
    1616 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 
    1918package org.expeditee.items;
    2019
     20public enum UserAppliedPermission {
     21        denied(-1), none(0), followLinks(1), copy(2), createFrames(3), full(4);
    2122
    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) {
    3031                        return defaultPermission;
     32                }
    3133
    3234                permissionCode = permissionCode.trim().toLowerCase();
    33                 if (permissionCode.length() == 0)
     35                if (permissionCode.length() == 0) {
    3436                        return defaultPermission;
     37                }
    3538
    36                 // if it is a single char just match the first character
    3739                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) {
    4142                        try {
    4243                                return valueOf(permissionCode);
    43                         }
    44                         catch (Exception e) {
     44                        } catch (final Exception ex) {
     45                                return defaultPermission;
    4546                        }
    4647                }
    47 
    48                 // default permission
    49                 return defaultPermission;
    5048        }
    5149
    5250        public int getCode() {
    53                 return ordinal();
     51                return val;
    5452        }
    5553
     
    5957
    6058        public static UserAppliedPermission min(UserAppliedPermission p1, UserAppliedPermission p2) {
    61                 return p1.ordinal() < p2.ordinal() ? p1 : p2;
     59                return p1.val < p2.val ? p1 : p2;
    6260        }
    6361
    6462        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;
    6673        }
    6774}
     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.