[919] | 1 | /**
|
---|
| 2 | * UserAppliedPermission.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 |
|
---|
[449] | 19 | package org.expeditee.items;
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 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)
|
---|
| 30 | return defaultPermission;
|
---|
| 31 |
|
---|
| 32 | permissionCode = permissionCode.trim().toLowerCase();
|
---|
| 33 | if (permissionCode.length() == 0)
|
---|
| 34 | return defaultPermission;
|
---|
| 35 |
|
---|
| 36 | // if it is a single char just match the first character
|
---|
| 37 | try {
|
---|
| 38 | return values()[Integer.parseInt(permissionCode)];
|
---|
| 39 | // Otherwise match the whole string
|
---|
| 40 | } catch (Exception ex) {
|
---|
| 41 | try {
|
---|
| 42 | return valueOf(permissionCode);
|
---|
| 43 | }
|
---|
| 44 | catch (Exception e) {
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | // default permission
|
---|
| 49 | return defaultPermission;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public int getCode() {
|
---|
| 53 | return ordinal();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public String toString() {
|
---|
| 57 | return this.name();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public static UserAppliedPermission min(UserAppliedPermission p1, UserAppliedPermission p2) {
|
---|
| 61 | return p1.ordinal() < p2.ordinal() ? p1 : p2;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public static UserAppliedPermission max(UserAppliedPermission p1, UserAppliedPermission p2) {
|
---|
| 65 | return p1.ordinal() > p2.ordinal() ? p1 : p2;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|