Hacking Alfresco

There are many wiki pages at Alfresco dev sites, but no working simple excercises at all. At these days i'm playing with this CMS/DMS, so i'll try to collect some remarks about actions i'm doing, maybe it'll be helpful for someone. So, i'm experimenting with Content Metadata Extracters with intention to create some kind of Video Extracter (to save bitrate, resolution, codec… to metadata with that object).

There is a simple wiki page describing that problem, so if you want to know some background, you have to start there. If you dont (or if you prefer very simple way), let's continue. So, what Content Metadata Extracters (CME) are? Imagine following simple situation: you have repository with some multimedia document, let's say mp3 files. Every mp3 file has a header with some informations (id3), for example artist, album, music style, etc. And you want to your document system to create all needed metadata automaticaly, when user uploads his mp3 file. This is work of CME. In my following example I'm not going to extract data from anywhere to keep things simple, but there is also a source of MP3 Metadata Extracter and many more, all inside of the Alfresco SDK.

I'm going to try to "how this stuff works part by part", so i'm going to create an "empty extractor" which just creates some metadata. So, first thing to do is to add my own bean to content-services-context.xml. In Wiki there is a way through editing a custom-metadata-extrators-context.xml controller, but this way doesn't work for me, so i added my definition right into content-services-context.xml:

<bean id="extracter.ASD" class="cz.shmoula.ASDMetadataExtracter" parent="baseMetadataExtracter" />

So, id is identificator of created bean and class is my class in my package extending AbstractMappingMetadataExtracter. I chose name of ASDMetadataExtracter due to retaining of name convention of *MetadataExtrater and ASD due to my personaly liked phrase "asdfghj…" :-). And parent will automaticaly register this bean with metadataExtracterRegistry to handle mimetypes declared in my "Extractor".

Then i have to create some properties file with defined namespace prefixes and mappings on them. Alfresco for content model uses a namespace http://www.alfresco.org/model/content/1.0 and for lucidity there is a prefix cm binded with that. So my own ASDMetadataExtracter.properties file looks like this:





And last thing to do is to create a class, which fills in those metadata. I uploaded whole code to pastebin, so you can browse it online, its really simple, it has just 45 lines of code!!! But some snipets:

private static final String KEY_POKUS = "pokus"; // definitions of metadata names, binded with properties

… MimetypeMap.MIMETYPE_TEXT_PLAIN … // i'm using this "transformer" for text/plain mime

putRawValue(KEY_POKUS, Long.toString(size), rawProperties); // assigning of value to metadata

// TempFileProvider routines are provided just for testing purposes 😉

// Files uploaded (opened) with these routines are temporary saved in <tomcat>tempAlfresco*

So, that's all, folks :-). And what does it do? After upload of document of type text/plain it fills metadata binded. Now i'm going to solve how to view them, modify them and make a sorts based on them.

Image Hosted by ImageShack.us

Content type needs to correspond with predefined values in Extractor


Image Hosted by ImageShack.us

In column "popis" there is value defined through "putRawValue(KEY_DESCRIPTION,…"



Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *