Skip to end of metadata
Go to start of metadata

Creating a custom detector involves the following steps:

  • Create a Maven 3 project for your detector;
  • Implement the MimeTypeDetector interface with your own implementation, and create unit tests to verify the functionality and expected behavior;
  • Add a MimeTypeDetectorConfig to the MimeType class in your application as described earlier; and
  • Deploy the JAR file with your implementation (as well as any dependencies), and make them available to ModeShape in your application.
    It's that simple.

The first step is to create the Maven 3 project that you can use to compile your code and build the JARs. Maven 3 automates a lot of the work, and since you're already set up to use Maven, using Maven for your project will save you a lot of time and effort. Of course, you don't have to use Maven 3, but then you'll have to get the required libraries and manage the compiling and building process yourself.

ModeShape may provide in the future a Maven archetype for creating detector projects. If you'd find this useful and would like to help create it, please join the community.
The modeshape-mimetype-detector-aperture project is a small, self-contained detector implementation that that you can use to help you get going. Starting with this project's source and modifying it to suit your needs may be the easiest way to get started. See the Git repository:

You can create your Maven project any way you'd like. For examples, see the Maven 3 documentation. Once you've done that, just add the dependencies in your project's pom.xml dependencies section:

These are minimum dependencies required for compiling a detector. Of course, you'll have to add other dependencies that your sequencer needs.

As for testing, you probably will want to add more dependencies, such as those listed here:

After you've created the project, simply implement the MimeTypeDetector interface. And testing should be quite straightforward, as MIME type detectors don't require any other components. In your tests, simply instantiate your MimeTypeDetector implementation, supply various combinations of names and/or InputStreams, and verify the output is what you expect.

To use in your application, create a MimeTypeDetectorConfig object with the name, description, and class information for your detector, and add to the MimeType class using the addDetector(MimeTypeDetectorConfig config) method. Then, just use the MimeType class.2.8

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.