Search in sources :

Example 1 with MorkDocument

use of mork.MorkDocument in project janrufmonitor by tbrandt77.

the class ThunderbirdTransformer method getCallers.

public ICallerList getCallers() {
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    if (this.m_filename == null)
        return cl;
    File f = new File(this.m_filename);
    if (!f.exists() || !f.isFile()) {
        this.m_logger.warning("Mozilla Thunderbird file " + this.m_filename + " does not exists.");
        PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "nofile", new Exception("Sync Mozilla Thunderbird Adressbook...")));
        return cl;
    }
    if (this.m_sync)
        PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "sync", new Exception("Sync Mozilla Thunderbird Adressbook...")));
    try {
        List rawData = new ArrayList();
        FileInputStream fis = new FileInputStream(f);
        MorkDocument md = new MorkDocument(new InputStreamReader(fis));
        List l = md.getRows();
        Row r = null;
        for (int i = 0, j = l.size(); i < j; i++) {
            r = (Row) l.get(i);
            rawData.add(r.getAliases());
        }
        l = md.getTables();
        Table t = null;
        for (int i = 0, j = l.size(); i < j; i++) {
            t = (Table) l.get(i);
            for (int k = 0; k < t.getRows().size(); k++) {
                r = (Row) t.getRows().get(k);
                rawData.add(r.getAliases());
            }
        }
        fis.close();
        this.m_total = rawData.size();
        if (rawData.size() > 0) {
            this.m_logger.info("Found " + rawData.size() + " Mozilla Thunderbird contacts.");
            this.parseContacts(cl, rawData);
        }
    } catch (FileNotFoundException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    this.m_logger.info(cl.size() + " contacts from Mozilla Thunderbird available.");
    return cl;
}
Also used : Table(mork.Table) Message(de.janrufmonitor.exception.Message) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) MorkDocument(mork.MorkDocument) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) ICallerList(de.janrufmonitor.framework.ICallerList) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) Row(mork.Row) File(java.io.File)

Aggregations

Message (de.janrufmonitor.exception.Message)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MorkDocument (mork.MorkDocument)1 Row (mork.Row)1 Table (mork.Table)1