Package com.helger.xml.util.mime
Class MimeTypeInfoManager
- java.lang.Object
-
- com.helger.xml.util.mime.MimeTypeInfoManager
-
@ThreadSafe @Singleton public class MimeTypeInfoManager extends Object
This is the central manager for allMimeTypeInfoobjects.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringMIME_TYPE_INFO_XML
-
Constructor Summary
Constructors Constructor Description MimeTypeInfoManager()Create a new empty (!!)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExtension(MimeTypeInfo aInfo, MimeTypeInfo.ExtensionWithSource aExt)voidaddMimeType(MimeTypeInfo aInfo, MimeTypeInfo.MimeTypeWithSource aMimeType)com.helger.commons.state.EChangeclearCache()Remove all registered mime typesbooleancontainsMimeTypeForExtension(String sExtension)Check if any mime type is associated with the passed extensionbooleancontainsMimeTypeForFilename(String sFilename)Check if any mime type is registered for the extension of the specified filename.com.helger.commons.collection.impl.ICommonsOrderedSet<String>getAllExtensionsOfMimeType(com.helger.commons.mime.IMimeType aMimeType)Get all extensions associated to the specified mime typecom.helger.commons.collection.impl.ICommonsOrderedSet<String>getAllGlobsOfMimeType(com.helger.commons.mime.IMimeType aMimeType)Get all globs (=filename patterns) associated to the specified mime typecom.helger.commons.collection.impl.ICommonsList<MimeTypeInfo>getAllInfosOfExtension(String sExtension)Get all infos associated with the specified filename extension.com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo>getAllInfosOfFilename(File aFile)com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo>getAllInfosOfFilename(String sFilename)com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo>getAllInfosOfMimeType(com.helger.commons.mime.IMimeType aMimeType)Get all infos associated with the passed mime type.com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo>getAllMimeTypeInfos()com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType>getAllMimeTypes()com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType>getAllMimeTypesForExtension(String sExtension)Get all mime types that are associated to the specified filename extension.com.helger.commons.collection.impl.ICommonsSet<com.helger.commons.mime.IMimeType>getAllMimeTypesForFilename(String sFilename)Get all mime types that are associated to the extension of the specified filename.com.helger.commons.collection.impl.ICommonsOrderedSet<String>getAllMimeTypeStrings()com.helger.commons.collection.impl.ICommonsOrderedSet<String>getAllMimeTypeStringsForExtension(String sExtension)Get all mime types that are associated to the specified filename extension.com.helger.commons.collection.impl.ICommonsSet<String>getAllMimeTypeStringsForFilename(String sFilename)Get all mime types that are associated to the extension of the specified filename.IMicroDocumentgetAsDocument()static MimeTypeInfoManagergetDefaultInstance()StringgetPrimaryExtensionOfMimeType(com.helger.commons.mime.IMimeType aMimeType)Get the primary (=first) extension for the specified mime type.com.helger.commons.mime.IMimeTypegetPrimaryMimeTypeForExtension(String sExtension)Get the primary (=first) mime type that is associated to the specified filename extension.com.helger.commons.mime.IMimeTypegetPrimaryMimeTypeForFilename(String sFilename)Get the primary (=first) mime type associated with the specified filename.StringgetPrimaryMimeTypeStringForExtension(String sExtension)Get the primary (=first) mime type that is associated to the specified filename extension.StringgetPrimaryMimeTypeStringForFilename(String sFilename)Get the primary (=first) mime type associated with the specified filename.static booleanisDefaultInstantiated()MimeTypeInfoManagerread(com.helger.commons.io.resource.IReadableResource aRes)Read the information from the specified resource.MimeTypeInfoManagerreadDefault()Read the default resource.voidregisterMimeType(MimeTypeInfo aInfo)voidreinitializeToDefault()
-
-
-
Field Detail
-
MIME_TYPE_INFO_XML
public static final String MIME_TYPE_INFO_XML
- See Also:
- Constant Field Values
-
-
Method Detail
-
isDefaultInstantiated
public static boolean isDefaultInstantiated()
-
getDefaultInstance
@Nonnull public static MimeTypeInfoManager getDefaultInstance()
- Returns:
- The default instance that contains all predefined
MimeTypeInfos.
-
readDefault
@Nonnull public MimeTypeInfoManager readDefault()
Read the default resource.- Returns:
- this
- See Also:
MIME_TYPE_INFO_XML
-
read
@Nonnull public MimeTypeInfoManager read(@Nonnull com.helger.commons.io.resource.IReadableResource aRes)
Read the information from the specified resource.- Parameters:
aRes- The resource to read. May not benull.- Returns:
- this
-
clearCache
@Nonnull public com.helger.commons.state.EChange clearCache()
Remove all registered mime types- Returns:
EChange.
-
reinitializeToDefault
public void reinitializeToDefault()
-
getAsDocument
@Nonnull @ReturnsMutableCopy public IMicroDocument getAsDocument()
-
registerMimeType
public void registerMimeType(@Nonnull MimeTypeInfo aInfo)
-
addExtension
@VisibleForTesting public final void addExtension(@Nonnull MimeTypeInfo aInfo, @Nonnull MimeTypeInfo.ExtensionWithSource aExt)
-
addMimeType
@VisibleForTesting public final void addMimeType(@Nonnull MimeTypeInfo aInfo, @Nonnull MimeTypeInfo.MimeTypeWithSource aMimeType)
-
getAllInfosOfFilename
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfFilename(@Nullable File aFile)
-
getAllInfosOfFilename
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfFilename(@Nullable String sFilename)
-
getAllInfosOfExtension
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfExtension(@Nullable String sExtension)
Get all infos associated with the specified filename extension.- Parameters:
sExtension- The extension to search. May benullor empty.- Returns:
nullif the passed extension isnullor if no such extension is registered.
-
getAllInfosOfMimeType
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfMimeType(@Nullable com.helger.commons.mime.IMimeType aMimeType)
Get all infos associated with the passed mime type.- Parameters:
aMimeType- The mime type to search. May benull.- Returns:
nullif anullmime type was passed or the passed mime type is unknown.
-
getAllMimeTypeInfos
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllMimeTypeInfos()
- Returns:
- A non-
nullset with all mime types infos known to this instance.
-
getAllMimeTypes
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType> getAllMimeTypes()
- Returns:
- A non-
nullset with all mime types known to this instance.
-
getAllMimeTypeStrings
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllMimeTypeStrings()
- Returns:
- A non-
nullset with all mime types known to this instance.
-
containsMimeTypeForFilename
public boolean containsMimeTypeForFilename(@Nonnull @Nonempty String sFilename)
Check if any mime type is registered for the extension of the specified filename.- Parameters:
sFilename- The filename to search. May neither benullnor empty.- Returns:
trueif at least one mime type is associated with the extension of the passed filename,falseotherwise.
-
getAllMimeTypesForFilename
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsSet<com.helger.commons.mime.IMimeType> getAllMimeTypesForFilename(@Nonnull @Nonempty String sFilename)
Get all mime types that are associated to the extension of the specified filename.- Parameters:
sFilename- The filename to search. May neither benullnor empty.- Returns:
- Never
nullbut maybe empty set if no mime type is associated with the extension of the passed filename.
-
getAllMimeTypeStringsForFilename
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsSet<String> getAllMimeTypeStringsForFilename(@Nonnull @Nonempty String sFilename)
Get all mime types that are associated to the extension of the specified filename.- Parameters:
sFilename- The filename to search. May neither benullnor empty.- Returns:
- Never
nullbut maybe empty set if no mime type is associated with the extension of the passed filename.
-
getPrimaryMimeTypeForFilename
@Nullable public com.helger.commons.mime.IMimeType getPrimaryMimeTypeForFilename(@Nonnull @Nonempty String sFilename)
Get the primary (=first) mime type associated with the specified filename.- Parameters:
sFilename- The filename to retrieve the primary mime type from. May neither benullnor empty.- Returns:
nullif no mime type is associated with the extension of the passed filename
-
getPrimaryMimeTypeStringForFilename
@Nullable public String getPrimaryMimeTypeStringForFilename(@Nonnull @Nonempty String sFilename)
Get the primary (=first) mime type associated with the specified filename.- Parameters:
sFilename- The filename to retrieve the primary mime type from. May neither benullnor empty.- Returns:
nullif no mime type is associated with the extension of the passed filename
-
containsMimeTypeForExtension
public boolean containsMimeTypeForExtension(@Nonnull String sExtension)
Check if any mime type is associated with the passed extension- Parameters:
sExtension- The filename extension to search. May not benull.- Returns:
trueif at least one mime type is associated,falseif no mime type is associated with the extension
-
getAllMimeTypesForExtension
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType> getAllMimeTypesForExtension(@Nonnull String sExtension)
Get all mime types that are associated to the specified filename extension.- Parameters:
sExtension- The filename extension to search. May not benull.- Returns:
- Never
nullbut maybe empty set if no mime type is associated with the passed extension.
-
getAllMimeTypeStringsForExtension
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllMimeTypeStringsForExtension(@Nonnull String sExtension)
Get all mime types that are associated to the specified filename extension.- Parameters:
sExtension- The filename extension to search. May not benull.- Returns:
- Never
nullbut maybe empty set if no mime type is associated with the passed extension.
-
getPrimaryMimeTypeForExtension
@Nullable public com.helger.commons.mime.IMimeType getPrimaryMimeTypeForExtension(@Nonnull String sExtension)
Get the primary (=first) mime type that is associated to the specified filename extension.- Parameters:
sExtension- The filename extension to search. May not benull.- Returns:
nullif no mime type is associated with the passed extension.
-
getPrimaryMimeTypeStringForExtension
@Nullable public String getPrimaryMimeTypeStringForExtension(@Nonnull String sExtension)
Get the primary (=first) mime type that is associated to the specified filename extension.- Parameters:
sExtension- The filename extension to search. May not benull.- Returns:
nullif no mime type is associated with the passed extension.
-
getAllExtensionsOfMimeType
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllExtensionsOfMimeType(@Nullable com.helger.commons.mime.IMimeType aMimeType)
Get all extensions associated to the specified mime type- Parameters:
aMimeType- The mime type to search. May benull.- Returns:
- Never
nullbut empty set if no extensions are present.
-
getPrimaryExtensionOfMimeType
@Nullable public String getPrimaryExtensionOfMimeType(@Nullable com.helger.commons.mime.IMimeType aMimeType)
Get the primary (=first) extension for the specified mime type.- Parameters:
aMimeType- The mime type to be searched. May benull.- Returns:
nullif the mime type has no file extension assigned
-
getAllGlobsOfMimeType
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllGlobsOfMimeType(@Nullable com.helger.commons.mime.IMimeType aMimeType)
Get all globs (=filename patterns) associated to the specified mime type- Parameters:
aMimeType- The mime type to search. May benull.- Returns:
- Never
nullbut empty set if no globs are present.
-
-