001package com.hfg.util.mime;
002
003
004import java.util.Map;
005import java.util.HashMap;
006
007//------------------------------------------------------------------------------
008/**
009 Standard mime types.
010
011 @author J. Alex Taylor, hairyfatguy.com
012 */
013//------------------------------------------------------------------------------
014// com.hfg XML/HTML Coding Library
015//
016// This library is free software; you can redistribute it and/or
017// modify it under the terms of the GNU Lesser General Public
018// License as published by the Free Software Foundation; either
019// version 2.1 of the License, or (at your option) any later version.
020//
021// This library is distributed in the hope that it will be useful,
022// but WITHOUT ANY WARRANTY; without even the implied warranty of
023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
024// Lesser General Public License for more details.
025//
026// You should have received a copy of the GNU Lesser General Public
027// License along with this library; if not, write to the Free Software
028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
029//
030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
031// jataylor@hairyfatguy.com
032//------------------------------------------------------------------------------
033
034public class MimeType
035{
036   private static Map<String, MimeType> sUniqueMap = new HashMap<>();
037
038
039   public static final MimeType APPLICATION_JSON                 = new MimeType("application/json");
040   public static final MimeType APPLICATION_MSWORD               = new MimeType("application/msword");
041   public static final MimeType APPLICATION_VND_MS_EXCEL         = new MimeType("application/vnd.ms-excel");
042   public static final MimeType APPLICATION_EXCEL                = new MimeType("application/x-excel");
043   public static final MimeType APPLICATION_OCTET_STREAM         = new MimeType("application/octet-stream");
044   public static final MimeType APPLICATION_PDF                  = new MimeType("application/pdf");
045   public static final MimeType APPLICATION_WWW_FORM_URLENCODED  = new MimeType("application/x-www-form-urlencoded");
046   public static final MimeType APPLICATION_XHTML                = new MimeType("application/xhtml+xml");
047   public static final MimeType APPLICATION_XML                  = new MimeType("application/xml");
048   public static final MimeType APPLICATION_X_GZIP               = new MimeType("application/x-gzip");
049   public static final MimeType APPLICATION_X_ZIP_COMPRESSED     = new MimeType("application/x-zip-compressed");
050   public static final MimeType APPLICATION_ZIP                  = new MimeType("application/zip");
051
052   public static final MimeType IMAGE_PNG          = new MimeType("image/png");
053   public static final MimeType IMAGE_GIF          = new MimeType("image/gif");
054   public static final MimeType IMAGE_JPG          = new MimeType("image/jpeg");
055   public static final MimeType IMAGE_TIFF         = new MimeType("image/tiff");
056   public static final MimeType IMAGE_ICO          = new MimeType("image/vnd.microsoft.icon");
057   public static final MimeType IMAGE_SVG_XML      = new MimeType("image/svg+xml");
058
059   public static final MimeType AUDIO_MPEG         = new MimeType("audio/mpeg");
060   public static final MimeType AUDIO_OGG          = new MimeType("audio/ogg");
061   public static final MimeType AUDIO_WAV          = new MimeType("audio/wav");
062   public static final MimeType AUDIO_WEBM         = new MimeType("audio/webm");
063
064   public static final MimeType VIDEO_MPEG         = new MimeType("video/mpeg");
065   public static final MimeType VIDEO_OGG          = new MimeType("video/ogg");
066   public static final MimeType VIDEO_WEBM         = new MimeType("video/webm");
067
068   public static final MimeType TEXT_CSS           = new MimeType("text/css");
069   public static final MimeType TEXT_CSV           = new MimeType("text/csv");
070   public static final MimeType TEXT_EVENT_STREAM  = new MimeType("text/event-stream");
071   public static final MimeType TEXT_HTML          = new MimeType("text/html");
072   public static final MimeType TEXT_JAVASCRIPT    = new MimeType("text/javascript");
073   public static final MimeType TEXT_PLAIN         = new MimeType("text/plain");
074   public static final MimeType TEXT_VBSCRIPT      = new MimeType("text/VBScript");
075   public static final MimeType TEXT_XML           = new MimeType("text/xml");
076
077   public static final MimeType MULTIPART_FORM_DATA              = new MimeType("multipart/form-data");
078   public static final MimeType MULTIPART_MIXED                  = new MimeType("multipart/mixed");
079
080
081   private String mValue;
082
083
084   //###########################################################################
085   // CONSTRUCTORS
086   //###########################################################################
087
088   //--------------------------------------------------------------------------
089   protected MimeType(String inValue)
090   {
091      if (! sUniqueMap.containsKey(inValue))
092      {
093         mValue = inValue;
094         sUniqueMap.put(inValue, this);
095      }
096   }
097
098
099   //###########################################################################
100   // PUBLIC METHODS
101   //###########################################################################
102
103   //--------------------------------------------------------------------------
104   public static MimeType valueOf(String inString)
105   {
106      return sUniqueMap.get(inString);
107   }
108
109   //--------------------------------------------------------------------------
110   @Override
111   public String toString()
112   {
113      return mValue;
114   }
115
116}