- Add Mimetype application/x-freemind for .mm
- Add transformer from appplication/x-freemind to text/plain
Extract the text
An example shows how Freemind stores this sample map in a XML file:
<map version="0.7.1">
<node text="Alfresco Hack No 2">
<node text="Explore how Freemind XML looks like" position="right">
</node>
</node>
</map>
Quite simple XML without namespaces. The text of the map nodes is stored in a the value of the attribute text.
To extract the text I will use a quick-and-dirty XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:call-template name="t1"/>
</xsl:template>
<xsl:template name="t1">
<xsl:for-each select="//node">
<xsl:value-of select="@TEXT"/>
<xsl:value-of select="' '"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Throwing this XSLT on the Freemind XML results in the extracted text:
Alfresco Hack No 2 Explore how Freemind XML looks like
Add transformer to Alfresco
To keep things simple, I will use the Alfrescos feature to do content transformations with external tools or programs. This is done by configuring a RuntimeExecutableContentTransformer bean. But first, the command line of the external tool has to be figured out. I will use the xmlstarlet command line tool from http://xmlstar.sourceforge.net/. Depending on your linux distribution the executable will be called just xml or xmlstarlet. There is also a Windows version available from the download page. Transforming the above XSLT to xmlstarlets commandline results in:
xmlstarlet sel -t -m //node -v @TEXT -o ' ' Alfresco\ Hack\ No\ 2.mmSadly, the output always go to stdout and no output file can be specified. But this is required for the RuntimeExecutableContentTransformer, so a simple script wrapper can be used. I put the following to a file /home/lothar/bin/freemind2text.sh (made executable with chmod 775) which will be configured to the transformer bean:
#!/bin/bash # save arguments to variables SOURCE=$1 TARGET=$2 # to see what gets extracted append arguments to logfile echo "from $SOURCE to $TARGET" >>/tmp/freemindtransform.log # call xmlstarlet tool and redirect output to $TARGET xmlstarlet sel --text --encoding UTF-8 -t -m //node -v @TEXT -o ' ' "$SOURCE" > "$TARGET"Now we are ready to configure the RuntimeExecutableContentTransformer bean:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="transformer.freemindToText" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformer" parent="baseContentTransformer">
<property name="transformCommand">
<bean name="transformer.freemind.Command" class="org.alfresco.util.exec.RuntimeExec">
<property name="commandMap">
<map>
<entry key="Linux.*">
<value>/home/lothar/bin/freemind2text.sh ${source} ${target}</value>
</entry>
<entry key="Windows.*">
<value>...whatever windows needs here....</value>
</entry>
</map>
</property>
<property name="defaultProperties">
<props>
<prop key="options"/>
</props>
</property>
</bean>
</property>
<property name="explicitTransformations">
<list>
<bean class="org.alfresco.repo.content.transform.ContentTransformerRegistry$TransformationKey">
<constructor-arg>
<value>application/x-freemind</value>
</constructor-arg>
<constructor-arg>
<value>text/plain</value>
</constructor-arg>
</bean>
</list>
</property>
</bean>
</beans>
Finished!
Now indexing of Freemind mindmaps will take place. On the plus side: No Java coding, just configuration of the standard Alfresco features. On the down side: ...is there anything? Anybody who could contribute the Windows batch file wrapper for the xmlstarlet call?