{
monitor.setStatusText(i18n.tr("Importiere Backup"));
Logger.info("importing backup " + file.getAbsolutePath());
final ClassLoader loader = Application.getPluginLoader().getManifest(HBCI.class).getClassLoader();
Reader reader = null;
try
{
InputStream is = new BufferedInputStream(new FileInputStream(file));
reader = new XmlReader(is,new ObjectFactory() {
public GenericObject create(String type, String id, Map values) throws Exception
{
AbstractDBObject object = (AbstractDBObject) Settings.getDBService().createObject(loader.loadClass(type),null);
object.setID(id);
Iterator i = values.keySet().iterator();
while (i.hasNext())
{
String name = (String) i.next();
object.setAttribute(name,values.get(name));
}
return object;
}
});
long count = 1;
GenericObject o = null;
while ((o = reader.read()) != null)
{
try
{
((AbstractDBObject)o).insert();
}
catch (Exception e)
{
if (o instanceof Protokoll)
{
// Bei den Protokollen kann das passieren. Denn beim Import der Datei werden vorher
// die Konten importiert. Und deren Anlage fuehrt auch bereits zur Erstellung von
// Protokollen, deren IDs dann im Konflikt zu diesen hier stehen.
Logger.write(Level.DEBUG,"unable to import " + o.getClass().getName() + ":" + o.getID() + ", skipping",e);
}
else
{
Logger.error("unable to import " + o.getClass().getName() + ":" + o.getID() + ", skipping",e);
monitor.log(" " + i18n.tr("{0} fehlerhaft ({1}), �berspringe",new String[]{BeanUtil.toString(o),e.getMessage()}));
}
}
if (count++ % 100 == 0)
monitor.addPercentComplete(1);
}
monitor.setStatus(ProgressMonitor.STATUS_DONE);
monitor.setStatusText("Backup importiert");
monitor.setPercentComplete(100);
}
catch (Exception e)
{
Logger.error("error while importing data",e);
throw new ApplicationException(e.getMessage());
}
finally
{
if (reader != null)
{
try
{
reader.close();
Logger.info("backup imported");
}
catch (Exception e) {/*useless*/}
}
}