001/* 002 * Copyright 2013 Box, Inc. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.box.api.marshalling.dao; 017 018import org.nuxeo.box.api.marshalling.interfaces.IBoxType; 019 020import java.util.HashMap; 021import java.util.Locale; 022import java.util.Map; 023 024/** 025 * Type of resources that can be requested by API's. 026 */ 027public enum BoxResourceType implements IBoxType { 028 /** 029 * An item, which could be a file, a folder, a weblink... 030 */ 031 ITEM, 032 /** 033 * A plural format of {@link #ITEM}. 034 */ 035 ITEMS, 036 /** 037 * A box file. 038 */ 039 FILE, 040 /** 041 * A plural format of {@link #FILE}. 042 */ 043 FILES, 044 /** 045 * A box weblink. 046 */ 047 WEB_LINK, 048 /** 049 * A plural format of {@link #WEB_LINK}. 050 */ 051 WEB_LINKS, 052 /** 053 * Preview of a file. 054 */ 055 PREVIEW, 056 /** 057 * A box folder. 058 */ 059 FOLDER, 060 /** 061 * A box user. 062 */ 063 USER, 064 /** 065 * A plural format of {@link #USER}. 066 */ 067 USERS, 068 /** 069 * A group of {@link #GROUP}. 070 */ 071 GROUP, 072 /** 073 * A comment. 074 */ 075 COMMENT, 076 /** 077 * A plural format of {@link #COMMENT}. 078 */ 079 COMMENTS, 080 /** 081 * A version of a file. 082 */ 083 FILE_VERSION, 084 /** 085 * A plural format of {@link #FILE_VERSION}. 086 */ 087 FILE_VERSIONS, 088 /** 089 * Box's equivalent of access control lists. They can be used to set and apply permissions for users to folders. 090 */ 091 COLLABORATION, 092 /** 093 * A plural format of {@link org.nuxeo.box.api.marshalling.dao .BoxResourceType .COLLABORATIONS}. 094 */ 095 COLLABORATIONS, 096 /** 097 * An email alias. 098 */ 099 EMAIL_ALIAS, 100 /** 101 * A plural format of {@link #EMAIL_ALIAS}. 102 */ 103 EMAIL_ALIASES, 104 /** 105 * OAuth data. 106 */ 107 OAUTH_DATA, 108 /** 109 * Error. 110 */ 111 ERROR, 112 /** 113 * Event. 114 */ 115 EVENT, 116 /** 117 * A plural format of {@link #EVENT}. 118 */ 119 EVENTS, 120 /** 121 * Updates 122 */ 123 UPDATES, 124 /** 125 * Realtime server. 126 */ 127 REALTIME_SERVER, 128 /** 129 * File lock (shows up in event stream). 130 */ 131 LOCK, 132 /** 133 * Service action is a subtype of file lock. 134 */ 135 SERVICE_ACTION, 136 /** 137 * Administrator settings 138 */ 139 ADMIN_SETTINGS, 140 /** 141 * Login token 142 */ 143 LOGIN_TOKEN; 144 145 // As a performance optimization, set up string values for all types. 146 private static final Map<BoxResourceType, String> typeToLowercaseString = new HashMap<BoxResourceType, String>(); 147 148 static { 149 for (BoxResourceType type : values()) { 150 String str = type.name().toLowerCase(Locale.US); 151 typeToLowercaseString.put(type, str); 152 } 153 } 154 155 /** 156 * Get the BoxResourceType from a lower case string value. For example "file" would return BoxResourceType.FILE 157 * Deprecated, use getTypeFromLowercaseString method in IBoxResourceHub instead. 158 * 159 * @param string 160 * @return 161 */ 162 @Deprecated 163 public static BoxResourceType getTypeFromLowercaseString(final String string) { 164 return Enum.valueOf(BoxResourceType.class, string.toUpperCase(Locale.US)); 165 } 166 167 @Override 168 public String toString() { 169 return typeToLowercaseString.get(this); 170 } 171 172 /** 173 * Get the String representing plural format of a resource. 174 * 175 * @return the String representing plural format of a resource 176 */ 177 public String toPluralString() { 178 return toString() + "s"; 179 } 180}