001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.commons.httppart; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021/** 022 * Valid values for the <c>format</c> field. 023 * 024 * <h5 class='section'>See Also:</h5><ul> 025 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a> 026 * </ul> 027 */ 028public enum HttpPartFormat { 029 030 /** 031 * Signed 32 bits. 032 */ 033 INT32, 034 035 /** 036 * Signed 64 bits. 037 */ 038 INT64, 039 040 /** 041 * 32-bit floating point number. 042 */ 043 FLOAT, 044 045 /** 046 * 64-bit floating point number. 047 */ 048 DOUBLE, 049 050 /** 051 * BASE-64 encoded characters. 052 */ 053 BYTE, 054 055 /** 056 * Hexadecimal encoded octets (e.g. <js>"00FF"</js>). 057 */ 058 BINARY, 059 060 /** 061 * Spaced-separated hexadecimal encoded octets (e.g. <js>"00 FF"</js>). 062 */ 063 BINARY_SPACED, 064 065 /** 066 * An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 full-date</a>. 067 */ 068 DATE, 069 070 /** 071 * An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 date-time</a>. 072 */ 073 DATE_TIME, 074 075 /** 076 * Used to hint UIs the input needs to be obscured. 077 */ 078 PASSWORD, 079 080 /** 081 * UON notation (e.g. <js>"(foo=bar,baz=@(qux,123))"</js>). 082 */ 083 UON, 084 085 /** 086 * Email address (RFC 5321). 087 * 088 * @since 9.2.0 089 */ 090 EMAIL, 091 092 /** 093 * Internationalized email address (RFC 6531). 094 * 095 * @since 9.2.0 096 */ 097 IDN_EMAIL, 098 099 /** 100 * Internet host name (RFC 1123). 101 * 102 * @since 9.2.0 103 */ 104 HOSTNAME, 105 106 /** 107 * Internationalized host name (RFC 5890). 108 * 109 * @since 9.2.0 110 */ 111 IDN_HOSTNAME, 112 113 /** 114 * IPv4 address (RFC 2673). 115 * 116 * @since 9.2.0 117 */ 118 IPV4, 119 120 /** 121 * IPv6 address (RFC 4291). 122 * 123 * @since 9.2.0 124 */ 125 IPV6, 126 127 /** 128 * Universal Resource Identifier (RFC 3986). 129 * 130 * @since 9.2.0 131 */ 132 URI, 133 134 /** 135 * URI Reference (RFC 3986). 136 * 137 * @since 9.2.0 138 */ 139 URI_REFERENCE, 140 141 /** 142 * Internationalized Resource Identifier (RFC 3987). 143 * 144 * @since 9.2.0 145 */ 146 IRI, 147 148 /** 149 * IRI Reference (RFC 3987). 150 * 151 * @since 9.2.0 152 */ 153 IRI_REFERENCE, 154 155 /** 156 * Universally Unique Identifier (RFC 4122). 157 * 158 * @since 9.2.0 159 */ 160 UUID, 161 162 /** 163 * URI Template (RFC 6570). 164 * 165 * @since 9.2.0 166 */ 167 URI_TEMPLATE, 168 169 /** 170 * JSON Pointer (RFC 6901). 171 * 172 * @since 9.2.0 173 */ 174 JSON_POINTER, 175 176 /** 177 * Relative JSON Pointer. 178 * 179 * @since 9.2.0 180 */ 181 RELATIVE_JSON_POINTER, 182 183 /** 184 * Regular expression (ECMA-262). 185 * 186 * @since 9.2.0 187 */ 188 REGEX, 189 190 /** 191 * Duration (RFC 3339 Appendix A). 192 * 193 * @since 9.2.0 194 */ 195 DURATION, 196 197 /** 198 * Time (RFC 3339). 199 * 200 * @since 9.2.0 201 */ 202 TIME, 203 204 /** 205 * Date and time with time zone (RFC 3339). 206 * 207 * @since 9.2.0 208 */ 209 DATE_TIME_ZONE, 210 211 /** 212 * Not specified. 213 */ 214 NO_FORMAT; 215 216 /** 217 * Create from lowercase dashed name. 218 * 219 * @param value The enum name. Must not be <jk>null</jk>. 220 * @return The enum. 221 */ 222 @SuppressWarnings({ 223 "javabugs:S2259" // The value must not be null, per the Javadoc contract; ucr() returns null only for a null input. 224 }) 225 public static HttpPartFormat fromString(String value) { 226 value = ucr(value).replace('-', '_'); 227 return valueOf(value); 228 } 229 230 /** 231 * Returns <jk>true</jk> if this format is in the provided list. 232 * 233 * @param list The list of formats to check against. 234 * @return <jk>true</jk> if this format is in the provided list. 235 */ 236 public boolean isOneOf(HttpPartFormat...list) { 237 for (var ff : list) 238 if (this == ff) 239 return true; 240 return false; 241 } 242 243 @Override /* Overridden from Object */ 244 public String toString() { 245 return lcr(name()).replace('_', '-'); 246 } 247}