Performs the default action for a MIME type.
public DocumentMimeTypeStatus GetDocumentStatus(
Uri uri,
LoadDocumentOptions options,
DocumentMimeTypeSource source,
string mimeType
)
public:
DocumentMimeTypeStatus^ GetDocumentStatus(
Uri^ uri,
LoadDocumentOptions^ options,
DocumentMimeTypeSource^ source,
String^ mimeType
)
uri
The URI to the document being loaded.
options
The object passed by the user.
source
The source of this invocation.
mimeType
The MIME type being checked.
Status of the MIME type.
By default, Entries does not contain any entries and the value of DefaultStatus is Unspecified. Therefore, DocumentFactory is able to load any data containing an image or document format supported by LEADTOOLS.
Refer to DocumentMimeTypes to customize this behavior.
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");
}
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document