I’ve had a requirement to get some document details out of Alfresco using perl.
CMIS seems to be the obvious answer and a little bit of googling gives us the WebService::Cmis package.
This seems to do the job nicely but the documentation isn’t great (hint: use the pod) so here is a trival example to recurse through a folder and print out the details of the contents.
#!/usr/bin/perl -w use Data::Dumper; use WebService::Cmis; use Cache::FileCache; print "Content-type:text/htmlrnrn"; my $client = WebService::Cmis::getClient( url => "https://myhost/alfresco/cmisatom", user => '', password => "", cache => new Cache::FileCache({ cache_root => "/tmp/cmis_client" } ) ); my $repo = $client->getRepository; # print Dumper($repo); my $projectFolder = "/Sites/mySite/documentLibrary/myFolder"; my $folder = $repo->getObjectByPath($projectFolder); # print Dumper($folder); showFolderContents($folder);
sub showFolderDetails { my $fold = shift; print "<h2>".$fold->getTitle()."</h2>n"; # my $props = $fold->getProperties; #print Dumper($props); } sub showDocumentDetails { my $doc = shift; # print Dumper($doc); my $props = $doc->getProperties; if ($props->{'cmis:isLatestVersion'}->getValue eq 1) { #Show mail messages if (defined $props->{'imap:messageFrom'}) { print $props->{'imap:messageFrom'}->getValue; print $props->{'imap:messageTo'}->getValue; print $props->{'imap:messageSubject'}->getValue; print $props->{'imap:flagAnswered'}->getValue; } else { print $doc->getTitle()."n"; } # print Dumper($props); } } sub showFolderContents { my $fold = shift; showFolderDetails($fold); my $projects = $fold->getChildren(); while (($entry = $projects->getNext())){ if ($entry->isa("WebService::Cmis::Folder")) { showFolderContents($entry); } else { showDocumentDetails($entry); } } }