001package com.hfg.xml.msofficexml; 002 003 004import java.util.HashMap; 005import java.util.Map; 006 007import com.hfg.util.mime.MimeType; 008 009//------------------------------------------------------------------------------ 010/** 011 Office Open XML mime types. 012 013 @author J. Alex Taylor, hairyfatguy.com 014 */ 015//------------------------------------------------------------------------------ 016// com.hfg XML/HTML Coding Library 017// 018// This library is free software; you can redistribute it and/or 019// modify it under the terms of the GNU Lesser General Public 020// License as published by the Free Software Foundation; either 021// version 2.1 of the License, or (at your option) any later version. 022// 023// This library is distributed in the hope that it will be useful, 024// but WITHOUT ANY WARRANTY; without even the implied warranty of 025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 026// Lesser General Public License for more details. 027// 028// You should have received a copy of the GNU Lesser General Public 029// License along with this library; if not, write to the Free Software 030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 031// 032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 033// jataylor@hairyfatguy.com 034//------------------------------------------------------------------------------ 035 036public class OfficeOpenXmlMimeType extends MimeType 037{ 038 private static Map<String, OfficeOpenXmlMimeType> sUniqueMap = new HashMap<String, OfficeOpenXmlMimeType>(); 039 private static Map<String, OfficeOpenXmlMimeType> sExtensionMap = new HashMap<String, OfficeOpenXmlMimeType>(); 040 041 public static final MimeType DOCX = new OfficeOpenXmlMimeType("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 042 public static final MimeType DOTX = new OfficeOpenXmlMimeType("dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"); 043 public static final MimeType XLSX = new OfficeOpenXmlMimeType("xlsx", "application/vnd.openxmlformats-officedocument.xlsx.sheet"); 044 public static final MimeType XLTX = new OfficeOpenXmlMimeType("xltx", "application/vnd.openxmlformats-officedocument.xlsx.template"); 045 public static final MimeType PPTX = new OfficeOpenXmlMimeType("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); 046 public static final MimeType POTX = new OfficeOpenXmlMimeType("potx", "application/vnd.openxmlformats-officedocument.presentationml.template"); 047 public static final MimeType PPSX = new OfficeOpenXmlMimeType("ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"); 048 049 private String mExtension; 050 051 //########################################################################### 052 // CONSTRUCTORS 053 //########################################################################### 054 055 //-------------------------------------------------------------------------- 056 private OfficeOpenXmlMimeType(String inExtension, String inValue) 057 { 058 super(inValue); 059 if (! sUniqueMap.containsKey(inValue)) 060 { 061 mExtension = inExtension; 062 sUniqueMap.put(inValue, this); 063 sExtensionMap.put(inExtension, this); 064 } 065 } 066 067 068 //########################################################################### 069 // PUBLIC METHODS 070 //########################################################################### 071 072 //-------------------------------------------------------------------------- 073 public String getExtension() 074 { 075 return mExtension; 076 } 077 078 //-------------------------------------------------------------------------- 079 /** 080 Look up a OfficeOpenXML mime type by String value or by extension. 081 */ 082 public static OfficeOpenXmlMimeType valueOf(String inString) 083 { 084 OfficeOpenXmlMimeType mimeType = null; 085 if (inString != null) 086 { 087 String lcString = inString.toLowerCase(); 088 if (lcString.startsWith(".")) 089 { 090 // If they passed an extension value that starts with a '.' remove it. 091 lcString = lcString.substring(1); 092 } 093 094 mimeType = sUniqueMap.get(lcString); 095 if (null == mimeType) 096 { 097 mimeType = sExtensionMap.get(lcString); 098 } 099 } 100 101 return mimeType; 102 } 103 104}