Search in sources :

Example 6 with IPhonebookEntry

use of de.janrufmonitor.fritzbox.IPhonebookEntry in project janrufmonitor by tbrandt77.

the class TR064FritzBoxFirmware method getCallerList.

public List getCallerList(int addressbookId, String addressbookName) throws GetCallerListException, IOException {
    if (!this.isInitialized())
        throw new GetCallerListException("Could not get phone book from FritzBox: FritzBox firmware not initialized.");
    int size = 0;
    try {
        size = FritzBoxTR064Manager.getInstance().getPhonebookSize(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"), Integer.toString(addressbookId));
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Pre-calculated list size from FritzBox: " + size);
    } catch (IOException e) {
        throw new GetCallerListException(e.getMessage());
    }
    List result = new ArrayList();
    for (int i = 0; i < size; i++) {
        String xml = null;
        try {
            xml = FritzBoxTR064Manager.getInstance().getPhonebookEntry(this.m_user, this.m_password, this.m_server, (this.m_useHttp ? FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064Port() : FritzBoxTR064Manager.getInstance().getDefaultFritzBoxTR064SecurePort(this.m_server)), (this.m_useHttp ? "http" : "https"), Integer.toString(addressbookId), Integer.toString(i));
        } catch (IOException e) {
            xml = null;
        }
        if (xml == null) {
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("No more data found in list. Break at list position: " + i);
            break;
        }
        List<IPhonebookEntry> oneResult = FritzBoxMappingManager.getInstance().parseXmltoFritzBoxCallerList(new StringBuffer(xml), addressbookName);
        if (oneResult.size() == 1) {
            oneResult.get(0).setEntryID(Integer.toString(i));
        }
        result.addAll(oneResult);
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Phonebook from FritzBox succuessfully fetched. List size: " + result.size());
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Final result list elements {IPhonebookEntry}: " + result.toString());
    return result;
}
Also used : GetCallerListException(de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IPhonebookEntry(de.janrufmonitor.fritzbox.IPhonebookEntry)

Aggregations

IPhonebookEntry (de.janrufmonitor.fritzbox.IPhonebookEntry)6 ICallerList (de.janrufmonitor.framework.ICallerList)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ICaller (de.janrufmonitor.framework.ICaller)2 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)2 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)2 SQLException (java.sql.SQLException)2 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 DeleteCallerException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallerException)1 GetCallerListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException)1 SetCallerException (de.janrufmonitor.fritzbox.firmware.exception.SetCallerException)1