Building an importer
So, you're not happy with the present importers? You have got data in a format that is not covered by the current selection of importers? No problem, just build one yourself!
There are three steps to complete to write an importer.
- Defining a new format in
com.openexchange.groupware.importexport.Format
- Write an importer by implementing the
com.openexchange.groupware.importexport.Importer
interface. - Plug the importer into the file
/conf/groupware/importerExporter.xml
A new format
Now this should be easy: Open the file, write a new enum with a different identifier and you are done. In case you want to extend an existing format (CSV comes to mind) to import something different than Contacts (which currently is the only use for it), you do not need to define a new format.
Implementing Importer Interface
For the most current information, have a look the JavaDoc for the Importer Interface. Here are just two notes:
canImport
This method is called by the class which selects an appropriate importer. So make sure to use all your checking here, like
- Is this the format I am responsible for?
- Are the folders I am supposed to import into meant for this kind of data? This usually means asking the type of the FolderObject
- Is this user allowed to write to this folder?
importData
This methods does the import (you guessed that). I'd recommend that it internally calls canImport to be sure. The main job consists of writing the data into the folder. This usually is done by creating containing objects and writing them to the database. We got interfaces for that, of course:
- The objects are found in
com.openexchange.groupware.container
and end with *Object. - The writers for the database usually hide in
com.openexchange.api2
and are named *SQLInterface for some strange reason.
Plugging the new Importer in
As said, open the file importerExporter.xml
. After checking out the projects, this should be in the main project at /conf/groupware
, if installed, it ought to be somewhere like /opt/open-xchange/groupware
.
The file looks like this, just go to the two comment lines and do like people before you did:
<beans> <bean id="importerExporter" class="com.openexchange.groupware.importexport.ImporterExporter"> <property name="importers"> <list> <ref bean="iCalImporter" /> <ref bean="vCardImporter" /> <ref bean="csvContactImporter" /> <!-- add reference to your class here --> </list> </property> </bean> <bean id="iCalImporter" class="com.openexchange.groupware.importexport.importers.ICalImporter" /> <bean id="vCardImporter" class="com.openexchange.groupware.importexport.importers.VCardImporter" /> <bean id="csvContactImporter" class="com.openexchange.groupware.importexport.importers.CSVContactImporter" /> <!-- add your class here --> </beans>
Yep, this is Spring [1]. Now you know what you need those spring-core.jar
and spring-beans.jar
thingies for.