Building an exporter
You want to export a format the current exporters do not offer? Build a new one!
There are three steps to complete to write an exporter.
- Defining a new format in
- Write an exporter by implementing the
- Plug the exporter into the file
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 the Exporter interface
For the most current information, have a look the JavaDoc for the Importer Interface. Here are just two notes on the main methods:
This method is called by the class which selects an appropriate exporter. 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 export from meant for this kind of data (example: You can only make vCards from Contacts)? This usually means asking the type of the FolderObject and comparing it to the constants (like FolderObject.CONTACT).
- Is this user allowed to read from this folder?
These methods do the export itself - one exports only one entry, one all of a folder. I'd recommend that they internally call canExport to be sure the preconditions are met. The main job consists of reading data from the folder and wrapping these objects up nicely in the appropriate format-
- The readers for the database usually hide in
com.openexchange.api2and are named *SQLInterface for some strange reason.
- The objects resulting from reading the database are found in
com.openexchange.groupware.containerand end with *Object.
Plugging the new Exporter 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
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="exporters"> <list> <ref bean="iCalExporter" /> <ref bean="vCardExporter" /> <ref bean="csvContactExporter" /> <!-- add reference to your class here --> </list> </property> </bean> <bean id="iCalExporter" class="com.openexchange.groupware.importexport.exporters.ICalExporter" /> <bean id="vCardExporter" class="com.openexchange.groupware.importexport.exporters.VCardExporter" /> <bean id="csvContactExporter" class="com.openexchange.groupware.importexport.exporters.CSVContactExporter" /> <!-- add your class here --> </beans>
Yep, this is Spring . Now you know what you need those
spring-beans.jar thingies for.