[Q&A Friday] How to Create a Nuxeo Studio Defined Document on File Drag and Drop


Fri 22 November 2013 By Laurent Doguin


How to Create Nuxeo Studio Defined Document on File Drag and Drop How to Create Nuxeo Studio Defined Document on File Drag and Drop

Today we have a question from carlosrg and vjoussot who ask how to use a document type defined in Studio when a file is dragged and dropped in Nuxeo. A classic approach would be to override the classic Document Type like File, Picture, Audio or Video. But what happens when you want to keep the original document type? Well, you have to modify the way files are imported on drag and drop.

And the cool thing about this answer is that it comes from brian, another active community member. Here's what he has to say:

Say you have document types SampleCustomPicture, CustomVideo, and CustomAudio -- under "Projects>Advanced Settings>XML Extensions" do "+New" and create an extension with this content:
<require>org.nuxeo.ecm.platform.picture.filemanager.contrib</require>
<require>org.nuxeo.ecm.platform.video.filemanager.contrib</require>
<require>org.nuxeo.ecm.platform.audio.filemanager.contrib</require>

<extension target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService" point="plugins">
    <plugin name="Imageplugin" merge="true" docType="SampleCustomPicture" />
</extension>

<extension target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService" point="plugins">
    <plugin name="VideoImporter" merge="true" docType="CustomVideo" />
</extension>

<extension target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService" point="plugins">
    <plugin name="AudioImporter" merge="true" docType="CustomAudio" />
</extension>

https://gist.github.com/tingletech/7574407

Kudos to Brian for providing the answer. Now how does it work? Well, when you drag and drop a file in Nuxeo, the plugins extension point is used. It lets you define a Java class to handle the import logic. Each plugin has an associated document type, some mime types and an order. The plugin with the lowest order and matching mime type is used. The plugin can either return a document or nothing. If it's a document, the import is done. If it's nothing, the next in order plugin is called.

Here all you have to do is modify the docType attribute to make sure your document types are used. Don't forget the require tag to make sure your contribution will be deployed after the one you want to override.

If you want to go further, I recommend reading this blog post explaining how to create your own plugin implementation. This can help a lot especially for custom metadata you might have defined with Nuxeo Studio.


Category: Product & Development
Tagged: Nuxeo Studio, Q&A