The IDfFormatRecognizer Class

When doing imports — especially mass imports — one of the trickiest and most annoying steps is determining the format of the imported content. You could make the determination by examining the file extension of each file and mapping the extension to a Documentum format type. Or, you could just use the IDfFormatRecognizer class, like this:

// this is just notional code to make the rest of the exmaple make sense
DfClientX CX = new DfClientX();
String path = "c:/Temp/test.pdf";
IDfSysObject sObj = (IDfSysObject) session.newObject("dm_document");
IDfSession session = sObj.getSession();

// get file format using the format recognizer class. the class needs the
// session and the file must be on the file system.

String format = "";
try {
    IDfFormatRecognizer oFormatRec = CX.getFormatRecognizer(session,path,null);
    format = oFormatRec.getDefaultSuggestedFileFormat();
} catch (DfException e) {
    format = "unknown";
}

// set type and attach file
sObj.setObjectName("test");
sObj.setContentType(format);
sObj.setFile(path);
sObj.save();

Pretty cool, huh?

Advertisements

About Scott
I have been implementing Documentum solutions since 1997. In 2005, I published a book about developing Documentum solutions for the Documentum Desktop Client (ISBN 0595339689). In 2010, I began this blog as a record of interesting and (hopefully) helpful bits of information related to Documentum, and as a creative outlet.

2 Responses to The IDfFormatRecognizer Class

  1. Matt says:

    Hi Scott – Nice article, but I believe that the IDfImportOperation does this for you automatically. Is there an instance when you would not use the IDfImportOperation?

    Like

    • Scott says:

      Matt,
      This little snippet of code came from a custom migration program I developed to migrate content and metadata out of a homegrown CM system to Documentum. I was moving one document and its metadata at a time, creating types and folder structures in the Docbase as necessary, and updating an external database. I guess I didn’t really consider the IDfImportOperation class because it seemed awkward and heavy for what I was doing.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: