示例#1
0
 /**
  * Use the fully qualified name of a MimeDetector and try to instantiate it if it's not already
  * registered. If it's already registered then log a warning and return the already registered
  * MimeDetector
  *
  * @param mimeDetector
  * @return MimeDetector registered under this name. Returns null if an exception occurs
  */
 MimeDetector registerMimeDetector(final String mimeDetector) {
   if (mimeDetectors.containsKey(mimeDetector)) {
     log.warn(
         "MimeDetector ["
             + mimeDetector
             + "] will not be registered as a MimeDetector with this name is already registered.");
     return (MimeDetector) mimeDetectors.get(mimeDetector);
   }
   // Create the mime detector if we can
   try {
     MimeDetector md = (MimeDetector) Class.forName(mimeDetector).newInstance();
     md.init();
     if (log.isDebugEnabled()) {
       log.debug(
           "Registering MimeDetector with name ["
               + md.getName()
               + "] and description ["
               + md.getDescription()
               + "]");
     }
     mimeDetectors.put(mimeDetector, md);
     return md;
   } catch (Exception e) {
     log.error("Exception while registering MimeDetector [" + mimeDetector + "].", e);
   }
   // Failed to create an instance
   return null;
 }
示例#2
0
 /**
  * unregister the MimeDetector from the list.
  *
  * @param mimeDetector the MimeDetector to unregister
  * @return MimeDetector unregistered or null if it was not registered
  */
 MimeDetector unregisterMimeDetector(final MimeDetector mimeDetector) {
   if (mimeDetector == null) {
     return null;
   }
   return unregisterMimeDetector(mimeDetector.getName());
 }