use of de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException in project janrufmonitor by tbrandt77.
the class FritzOSFirmware method getAddressbooks.
public Map getAddressbooks() throws GetAddressbooksException, IOException {
if (!this.isInitialized())
throw new GetAddressbooksException("Could not get address book list from FritzBox: FritzBox firmware not initialized.");
StringBuffer data = new StringBuffer();
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/fonbook_select.lua?sid=" + this.m_sid;
try {
data.append(this.executeURL(urlstr, null, true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetAddressbooksException("Could not get address book list from FritzBox: " + e.getMessage());
}
Map abs = new HashMap();
String[] s = data.toString().split("uiBookid");
Pattern p = Pattern.compile(PATTERN_DETECT_AB, Pattern.UNICODE_CASE);
for (int i = 0, j = s.length; i < j; i++) {
Matcher m = p.matcher(s[i]);
while (m.find() && m.groupCount() > 1) {
abs.put(Integer.parseInt(m.group(1)), m.group(2).trim());
}
}
return abs;
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method createFieldEditors.
protected void createFieldEditors() {
FirmwareManager fwm = FirmwareManager.getInstance();
String label = this.m_i18n.getString(this.getNamespace(), "enabled", "label", this.m_language);
if (label.length() < 150)
for (int i = 150; i > label.length(); i--) {
label += " ";
}
BooleanFieldEditor bfe = new BooleanFieldEditor(this.getConfigNamespace() + SEPARATOR + "enabled", label, this.getFieldEditorParent());
bfe.setEnabled((fwm.isInstance(UnitymediaFirmware.class) || fwm.isInstance(SessionIDFritzBoxFirmware.class) || fwm.isInstance(FritzOSFirmware.class) || fwm.isInstance(FritzOS559Firmware.class) || fwm.isInstance(TR064FritzBoxFirmware.class)), this.getFieldEditorParent());
addField(bfe);
if (fwm.isInstance(FritzOSFirmware.class) || fwm.isInstance(FritzOS559Firmware.class) || fwm.isInstance(TR064FritzBoxFirmware.class)) {
try {
if (!fwm.isLoggedIn())
fwm.login();
Map adb = fwm.getAddressbooks();
String[][] list = new String[adb.size()][2];
Iterator i = adb.keySet().iterator();
int c = 0;
while (i.hasNext()) {
list[c][1] = ((Integer) i.next()).toString();
list[c][0] = (String) adb.get(Integer.parseInt(list[c][1]));
c++;
}
ComboFieldEditor cfe = new ComboFieldEditor(getConfigNamespace() + SEPARATOR + "ab", this.m_i18n.getString(this.getNamespace(), "ab", "label", this.m_language), list, this.getFieldEditorParent());
addField(cfe);
} catch (GetAddressbooksException e) {
this.m_logger.severe(e.getMessage());
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
} catch (FritzBoxLoginException e) {
this.m_logger.severe(e.getMessage());
}
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException in project janrufmonitor by tbrandt77.
the class FritzBoxPhonebookManager method createCallerListFromFritzBoxPhonebook.
private void createCallerListFromFritzBoxPhonebook() {
Thread t = new Thread(new Runnable() {
Logger m_logger;
public void run() {
isSyncing = true;
this.m_logger = LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER);
if (this.m_logger.isLoggable(Level.FINE))
this.m_logger.fine("Starting JAM-FritzBoxPhonebookSync-Thread");
File mso_cache = new File(FBP_CACHE_PATH);
if (!mso_cache.exists())
mso_cache.mkdirs();
ICallerList cl = getRuntime().getCallerFactory().createCallerList();
FirmwareManager fwm = FirmwareManager.getInstance();
fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("FritzBox Firmware created.");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Login to FritzBox successfull.");
// check if phonebook is configured
String abId = getConfiguration().getProperty(CFG_ADDRESSBOOK, "0");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook ID: #" + abId);
int id = Integer.parseInt(abId);
String name = null;
try {
Map abs = fwm.getAddressbooks();
if (abs.containsKey(Integer.parseInt(abId))) {
name = (String) abs.get(Integer.parseInt(abId));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook name: " + name);
}
} catch (GetAddressbooksException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
}
List callers = null;
if (name != null) {
callers = fwm.getCallerList(id, name);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox phonebook callers: " + callers.size());
} else {
callers = fwm.getCallerList();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Getting FritzBox default phonebook callers: " + callers.size());
}
if (callers.size() == 0) {
try {
getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
isSyncing = false;
return;
}
cl.add(FritzBoxMappingManager.getInstance().toCallerList(callers));
} catch (FritzBoxLoginException e2) {
this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
} catch (GetCallerListException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (Throwable e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
try {
getDatabaseHandler().deleteCallerList(getRuntime().getCallerFactory().createCallerList());
getDatabaseHandler().insertOrUpdateCallerList(cl);
getDatabaseHandler().commit();
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
try {
getDatabaseHandler().rollback();
} catch (SQLException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
isSyncing = false;
if (this.m_logger.isLoggable(Level.FINE))
this.m_logger.fine("Stopping JAM-FritzBoxPhonebookSync-Thread");
}
});
t.setName("JAM-FritzBoxPhonebookSync-Thread-(non-deamon)");
t.start();
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException in project janrufmonitor by tbrandt77.
the class FritzOS559Firmware method getAddressbooks.
public Map getAddressbooks() throws GetAddressbooksException, IOException {
if (!this.isInitialized())
throw new GetAddressbooksException("Could not get address book list from FritzBox: FritzBox firmware not initialized.");
StringBuffer data = new StringBuffer();
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/fonbook_select.lua?sid=" + this.m_sid;
try {
data.append(this.executeURL(urlstr, null, true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetAddressbooksException("Could not get address book list from FritzBox: " + e.getMessage());
}
Map abs = new HashMap();
String[] s = data.toString().split("uiBookid");
Pattern p = Pattern.compile(PATTERN_DETECT_AB, Pattern.UNICODE_CASE);
for (int i = 0, j = s.length; i < j; i++) {
Matcher m = p.matcher(s[i]);
while (m.find() && m.groupCount() > 1) {
abs.put(Integer.parseInt(m.group(1)), m.group(2).trim());
}
}
return abs;
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetAddressbooksException in project janrufmonitor by tbrandt77.
the class UnitymediaFirmware method getAddressbooks.
public Map getAddressbooks() throws GetAddressbooksException, IOException {
if (!this.isInitialized())
throw new GetAddressbooksException("Could not get address book list from FritzBox: FritzBox firmware not initialized.");
StringBuffer data = new StringBuffer();
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/fon_num/fonbook_select.lua?sid=" + this.m_sid;
try {
data.append(this.executeURL(urlstr, null, true).trim());
} catch (UnsupportedEncodingException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetAddressbooksException("Could not get address book list from FritzBox: " + e.getMessage());
}
Map abs = new HashMap();
String[] s = data.toString().split("uiBookid");
Pattern p = Pattern.compile(PATTERN_DETECT_AB, Pattern.UNICODE_CASE);
for (int i = 0, j = s.length; i < j; i++) {
Matcher m = p.matcher(s[i]);
while (m.find() && m.groupCount() > 1) {
abs.put(Integer.parseInt(m.group(1)), m.group(2).trim());
}
}
return abs;
}
Aggregations