Chances are you are already familiar with Nuxeo Marketplace. It’s the Nuxeo ECM application store which offers plugins and packages that will enable you to easily add features to your Nuxeo application. One of the recent plugins we added in here is the customizable File System Exporter. This plugin enables you to export one chosen root structure of documents in the Nuxeo Platform to a specified File System repository on the server, and it can be customized too.

The Nuxeo File System Exporter


The Nuxeo File System Exporter can be installed following the instructions in the documentation.

In an earlier blog, we talked about the “File System Exporter” and you might be wondering what has changed since then that I am writing a new blog :) Well, we recently released the plugin as an official Marketplace plugin called the “Nuxeo FS Exporter”. In the previous blog, we discussed different examples of customizing the export by changing the default query and by using an extension point. Today, I will show you another example of customization by defining a new plugin.

In this new example, we want to be able to export only the main blob of a document (stored in the file:content field). Let’s get started!

How to Implement the Customized Export


Step 1: Install the Nuxeo FS Exporter plugin on your server. In Nuxeo Studio, add the JSON definition of the File System Exporter as explained in the documentation. You can now create an Automation Chain that uses this operation and is triggered by a User Action for instance.

Step 2: Create a new plugin.

Step 3: Manage dependencies. In the pom, you have to add a dependency to the fsexporter.

For example, for the version 7.10-SNAPSHOT this is what you need:

<dependency>
<groupId>org.nuxeo.io</groupId>
<artifactId>nuxeo-fsexporter</artifactId>
<version>7.10-SNAPSHOT</version>
</dependency>

Step 4: Write the Java class which will override the DefaultExporterPlugin.

Here's an example of exporting only the main blob of a document:

package org.nuxeo.sample;

import java.io.File;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuxeo.ecm.core.api.Blob;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.io.fsexporter.DefaultExporterPlugin;

/**

  • Exports only file:content and overrides existing files, if any. Depends on nuxeo-fsexporter
    *
  • @since 7.10
    */
    public class ExportOnlyMainBlob extends DefaultExporterPlugin {

public static final String DEFAULT_BLOB_XPATH = "file:content";
@Override
public File serialize(CoreSession session, DocumentModel docfrom, String fsPath) throws IOException {
File folder = null;
File newFolder = null;
folder = new File(fsPath);

// if target directory doesn't exist, create it
if (!folder.exists()) {
folder.mkdir();
}

if (docfrom.hasFacet("Folderish")) {
newFolder = new File(fsPath + "/" + docfrom.getName());
newFolder.mkdir();
}

Blob blob = null;
try {
blob = (Blob) docfrom.getPropertyValue(DEFAULT_BLOB_XPATH);
} catch (Exception e) {
// Ignore, we just have no blob here. Maybe we are handling a Folder with no "file" schema, it is not an
// error
blob = null;
}

if (blob != null) {
String fileName = blob.getFilename();
File target = new File(folder, fileName);
if (target.exists()) {
target.delete();
}
blob.transferTo(target);
}

if (newFolder != null) {
folder = newFolder;
}
return folder;
}
}


Step 5: You must now contribute this class in the OGSI/myNewExport.xml

<component name="org.nuxeo.sample.custom.fsexporter.onlymainblob">
<require>org.nuxeo.io.fsexporter.FSExporter</require>
<extension target="org.nuxeo.io.fsexporter.FSExporter" point="exportLogic">
<exportLogic class="org.nuxeo.sample.ExportOnlyMainBlob" />
</extension>
</component>

That's it!

Here’s an example of this export:


Customizable Nuxeo FS Exporter Customizable Nuxeo FS Exporter

Now you can create as many customized exports as you need!