- m = reAccountName.matcher(line);
- if (m.find()) {
- String acct_encoded = m.group(1);
- String acct_name = URLDecoder.decode(acct_encoded, "UTF-8");
- acct_name = acct_name.replace("\"", "");
- L(String.format("found account: %s", acct_name));
-
- prevAccount = lastAccount;
- lastAccount = profile.tryLoadAccount(db, acct_name);
- if (lastAccount == null)
- lastAccount = new LedgerAccount(acct_name);
- else
- lastAccount.removeAmounts();
- profile.storeAccount(db, lastAccount);
-
- if (prevAccount != null)
- prevAccount.setHasSubAccounts(
- prevAccount.isParentOf(lastAccount));
- // make sure the parent account(s) are present,
- // synthesising them if necessary
- // this happens when the (missing-in-HTML) parent account has
- // only one child so we create a synthetic parent account record,
- // copying the amounts when child's amounts are parsed
- String parentName = lastAccount.getParentName();
- if (parentName != null) {
- Stack<String> toAppend = new Stack<>();
- while (parentName != null) {
- if (accountNames.containsKey(parentName))
- break;
- toAppend.push(parentName);
- parentName = new LedgerAccount(parentName).getParentName();
- }
- syntheticAccounts.clear();
- while (!toAppend.isEmpty()) {
- String aName = toAppend.pop();
- LedgerAccount acc = profile.tryLoadAccount(db, aName);
- if (acc == null) {
- acc = new LedgerAccount(aName);
- acc.setExpanded(!lastAccount.hasSubAccounts() ||
- lastAccount.isExpanded());
- }
- acc.setHasSubAccounts(true);
- acc.removeAmounts(); // filled below when amounts are
- // parsed
- if (acc.isVisible(accountList))
- accountList.add(acc);
- L(String.format("gap-filling with %s", aName));
- accountNames.put(aName, null);
- profile.storeAccount(db, acc);
- syntheticAccounts.put(aName, acc);
- }
- }