User:Tierlieb

From Open-Xchange
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

User Information

TODOs

  • Refractor Open Xchange Installation to use headings instead of bold text for titles to allow for editing of sub sections instead of whole text.
  • Wiki-Howto/Styleguide

How to import/export

Using it to import or export data

Importing and exporting is done by the servlet ImportExport.java in the package com.openexchange.ajax. The path to this servlet is stored in servletmapping.properties, usually it is [serveraddress]/ajax/importexport.

Whether you do an import or an export is decided quite simply: If you send a PUT request, you're importing (because you are sending data), if you send a GET request, you're exporting (because you are requesting data). So no parameter is needed to indicate that. This has the additional advantage that you can use the same kind of URL to import and export (which also means: I only have to describe this only once ;-)). So, let's construct an URL:

  StringBuilder bob = new StringBuilder();
  bob.append("http://");
  bob.append(getHostName()); 

you probably know your hostname better than I do. ;-)

  bob.append("/ajax/importexport?session=");
  bob.append(getSessionId());  

how you get the session depends on whether use write another servlet or work from the GUI.

  addParam(bob, ImportExport.PARAMETER_FOLDERID, folderId ) ; 

folderID = the ID of the folder you want to export from or import into.

  addParam(bob, ImportExport.AJAX_TYPE, type);

type = the type of folder (Contact, Task, Appointment or whatever), as defines in com.openexchange.groupware.Types. Now, if you are stuck with another number (yeah, the OX design is a bit incongruent there...), you might want to take a look at com.openexchange.groupware.importexport.ModuleTypeTranslator, which was written to solve this problem.

  addParam(bob, ImportExport.PARAMETER_CONTENT_TYPE, format.getMimeType());

format is usually of type com.openexchange.groupware.importexport.Format - you can use a selfmade MIME-type if you're sure you have a converter for that.

  addParam(bob, ImportExport.PARAMETER_COLUMNS, ContactField.GIVEN_NAME.getNumber());
  addParam(bob, ImportExport.PARAMETER_COLUMNS, ContactField.EMAIL1.getNumber());

This one is additional and currently only used for CSV: If you have a format that allows for a variable number of data fields to be exported or imported, this is the way to pass them to the servlet. This is an array (so you can use this parameter more than one). For Contacts, the way to identify a field is to use the enum ContactField of the package com.openexchange.groupware.contact.ContactException.