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.httppart;
018
019/**
020 * Valid values for the <c>format</c> field.
021 *
022 * <h5 class='section'>See Also:</h5><ul>
023 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HttpPartSerializersParsers">HTTP Part Serializers and Parsers</a>
024 * </ul>
025 */
026public enum HttpPartFormat {
027
028   /**
029    * Signed 32 bits.
030    */
031   INT32,
032
033   /**
034    * Signed 64 bits.
035    */
036   INT64,
037
038   /**
039    * 32-bit floating point number.
040    */
041   FLOAT,
042
043   /**
044    * 64-bit floating point number.
045    */
046   DOUBLE,
047
048   /**
049    * BASE-64 encoded characters.
050    */
051   BYTE,
052
053   /**
054    * Hexadecimal encoded octets (e.g. <js>"00FF"</js>).
055    */
056   BINARY,
057
058   /**
059    * Spaced-separated hexadecimal encoded octets (e.g. <js>"00 FF"</js>).
060    */
061   BINARY_SPACED,
062
063   /**
064    * An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 full-date</a>.
065    */
066   DATE,
067
068   /**
069    *  An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 date-time</a>.
070    */
071   DATE_TIME,
072
073   /**
074    * Used to hint UIs the input needs to be obscured.
075    */
076   PASSWORD,
077
078   /**
079    * UON notation (e.g. <js>"(foo=bar,baz=@(qux,123))"</js>).
080    */
081   UON,
082
083   /**
084    * Not specified.
085    */
086   NO_FORMAT;
087
088   /**
089    * Create from lowercase dashed name.
090    *
091    * @param value The enum name.
092    * @return The enum.
093    */
094   public static HttpPartFormat fromString(String value) {
095      value = value.toUpperCase().replace('-','_');
096      return valueOf(value);
097   }
098
099   /**
100    * Returns <jk>true</jk> if this format is in the provided list.
101    *
102    * @param list The list of formats to check against.
103    * @return <jk>true</jk> if this format is in the provided list.
104    */
105   public boolean isOneOf(HttpPartFormat...list) {
106      for (HttpPartFormat ff : list)
107         if (this == ff)
108            return true;
109      return false;
110   }
111
112   @Override /* Object */
113   public String toString() {
114      String s = name().toLowerCase().replace('_','-');
115      return s;
116   }
117}