←Select platform

DocumentMimeTypeSource Enumeration

Summary

Source of a MIME type callback invocation.

Syntax
C#
C++/CLI
Python
[SerializableAttribute()] 
[DataContractAttribute()] 
public enum DocumentMimeTypeSource 
public: 
   [SerializableAttribute,  
   DataContractAttribute] 
   enum class DocumentMimeTypeSource sealed 
class DocumentMimeTypeSource(Enum): 
   User = 0 
   Cache = 1 
   Url = 2 
   Data = 3 
Members
ValueMemberDescription
0UserThe mime type is passed by the user. For instance, in LoadDocumentOptions.MimeType.
1CacheThe mime type is stored in the cache, for example, from BeginUploadDocumentOptions.MimeType.
2UrlThe mime type was obtained from the HTTP headers of a URL as set by the server containing the document.
3DataThe mime type is read by LEADTOOLS RasterCodecs from the actual image data.
Remarks

Refer to DocumentMimeTypes for more information.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public void MimeTypesWhitelistExample() 
{ 
   // Documents to try and load 
   string[] urls = 
   { 
      "https://demo.leadtools.com/images/pdf/leadtools.pdf", 
      "https://demo.leadtools.com/images/tiff/ocr.tif", 
      "https://demo.leadtools.com/images/png/pngimage.png" 
    }; 
 
   // Setup a callback for logging 
   // DocumentMimeTypes & DocumentMimeTypes.UserGetDocumentStatusHandler reference 
   DocumentMimeTypes.UserGetDocumentStatusHandler userGetDocumentStatus = (Uri uri, LoadDocumentOptions options, DocumentMimeTypeSource source, string mimeType) => 
   { 
      // Use default operation 
      DocumentMimeTypeStatus status = DocumentFactory.MimeTypes.GetDocumentStatus(uri, options, source, mimeType); 
      string mimeTypeValue = mimeType != null ? mimeType : "[null]"; 
      DocumentFactory.MimeTypes.GetStatus(mimeTypeValue); 
      Console.WriteLine(string.Format("  ** Whitelist url:{0} source:{1} mimeType:{2} status:{3}", uri.ToString(), source, mimeTypeValue, status)); 
 
      return status; 
   }; 
 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = userGetDocumentStatus; 
 
   // Load the documents, by default we should load all of them 
   Console.WriteLine("Everything should load OK"); 
   LoadDocuments(urls); 
 
   // Now, disable loading everything except PDF and TIFF and try again 
   Console.WriteLine("Disabling everything except PDF and TIFF"); 
   DocumentFactory.MimeTypes.DefaultStatus = DocumentMimeTypeStatus.Denied; 
   DocumentFactory.MimeTypes.Entries.Add("application/pdf", DocumentMimeTypeStatus.Allowed); 
   DocumentFactory.MimeTypes.Entries.Add("image/tiff", DocumentMimeTypeStatus.Allowed); 
   Console.WriteLine("Only PDF and TIFF should be loaeded"); 
   LoadDocuments(urls); 
 
   // Reset 
   DocumentFactory.MimeTypes.UserGetDocumentStatus = null; 
} 
 
private static void LoadDocuments(string[] urls) 
{ 
   var loadDocumentOptions = new LoadDocumentOptions(); 
 
   foreach (var url in urls) 
   { 
      Console.WriteLine(" Loading " + url); 
      using (var document = DocumentFactory.LoadFromUri(new Uri(url), loadDocumentOptions)) 
      { 
         if (document != null) 
            Console.WriteLine("  is Loaded"); 
         else 
            Console.WriteLine("  cannot be loaded"); 
      } 
   } 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentMimeTypesExample() throws URISyntaxException { 
   // Documents to try and load 
   String[] urls = { 
         "https://demo.leadtools.com/images/pdf/leadtools.pdf", 
         "https://demo.leadtools.com/images/tiff/ocr.tif", 
         "https://demo.leadtools.com/images/png/pngimage.png" 
   }; 
 
   // Setup a callback for logging 
   // DocumentMimeTypes & DocumentMimeTypes.UserGetDocumentStatusHandler reference 
   UserGetDocumentStatusHandler userGetDocumentStatus = new UserGetDocumentStatusHandler() { 
 
      @Override 
      public DocumentMimeTypeStatus userGetDocumentStatus(URI uri, LoadDocumentOptions options, 
            DocumentMimeTypeSource source, String mimeType) { 
         // Use default operation 
         DocumentMimeTypeStatus status = DocumentFactory.getMimeTypes().getDocumentStatus(uri, options, source, 
               mimeType); 
         String mimeTypeValue = mimeType != null ? mimeType : "[null]"; 
         DocumentFactory.getMimeTypes().getStatus(mimeTypeValue); 
         System.out.println(String.format("  ** Whitelist url:%s source:%s mimeType:%s status:%s%n", uri.toString(), 
               source, mimeTypeValue, status)); 
 
         return status; 
      } 
 
   }; 
 
   DocumentFactory.getMimeTypes().setUserGetDocumentStatus(userGetDocumentStatus); 
 
   // Load the documents, by default we should load all of them 
   System.out.println("Everything should load OK"); 
   loadDocuments(urls); 
 
   // Now, disable loading everything except PDF and TIFF and try again 
   System.out.println("Disabling everything except PDF and TIFF"); 
   DocumentFactory.getMimeTypes().setDefaultStatus(DocumentMimeTypeStatus.DENIED); 
   DocumentFactory.getMimeTypes().getEntries().put("application/pdf", DocumentMimeTypeStatus.ALLOWED); 
   DocumentFactory.getMimeTypes().getEntries().put("image/tiff", DocumentMimeTypeStatus.ALLOWED); 
   System.out.println("Only PDF and TIFF should be loaded"); 
   loadDocuments(urls); 
 
   // Reset 
   DocumentFactory.getMimeTypes().setUserGetDocumentStatus(null); 
 
} 
 
private void loadDocuments(String[] urls) throws URISyntaxException { 
   LoadDocumentOptions loadDocumentOptions = new LoadDocumentOptions(); 
   for (String url : urls) { 
      System.out.println(" Loading " + url); 
      LEADDocument document = DocumentFactory.loadFromUri(new URI(url), loadDocumentOptions); 
      if (document != null) 
         System.out.println("  is Loaded"); 
      else 
         System.out.println("  cannot be loaded"); 
   } 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Document Namespace

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.