public List<Village> getSelectedElements() {
   TreePath[] paths = jSelectionTree.getSelectionModel().getSelectionPaths();
   List<Village> result = new LinkedList<Village>();
   if (paths == null) {
     return result;
   }
   for (TreePath p : paths) {
     Object o = p.getLastPathComponent();
     if (o instanceof AllyNode) {
       Ally a = ((AllyNode) o).getUserObject();
       Village[] copy = treeData.toArray(new Village[] {});
       for (Village v : copy) {
         if (v.getTribe() == Barbarians.getSingleton() && a.equals(BarbarianAlly.getSingleton())) {
           // remove barbarian ally member
           if (!result.contains(v)) {
             result.add(v);
           }
         } else if (v.getTribe() != Barbarians.getSingleton()
             && v.getTribe().getAlly() == null
             && a.equals(NoAlly.getSingleton())) {
           // remove no-ally member
           if (!result.contains(v)) {
             result.add(v);
           }
         } else if (v.getTribe() != Barbarians.getSingleton()
             && v.getTribe().getAlly() != null
             && a.equals(v.getTribe().getAlly())) {
           // remove if ally is equal
           if (!result.contains(v)) {
             result.add(v);
           }
         }
       }
     } else if (o instanceof TribeNode) {
       Tribe t = ((TribeNode) o).getUserObject();
       Village[] copy = treeData.toArray(new Village[] {});
       for (Village v : copy) {
         if (v.getTribe() == Barbarians.getSingleton() && t.equals(Barbarians.getSingleton())) {
           // if village is barbarian village and selected tribe are barbs, remove village
           if (!result.contains(v)) {
             result.add(v);
           }
         } else if (v.getTribe() != null
             && !v.getTribe().equals(Barbarians.getSingleton())
             && t != null
             && v.getTribe().getId() == t.getId()) {
           // selected tribe are no barbs, so check tribes to be equal
           if (!result.contains(v)) {
             result.add(v);
           }
         }
       }
     } else if (o instanceof TagNode) {
       Tag t = ((TagNode) o).getUserObject();
       Village[] copy = treeData.toArray(new Village[] {});
       for (Village v : copy) {
         if (v != null && t != null && t.tagsVillage(v.getId())) {
           if (!result.contains(v)) {
             result.add(v);
           }
         }
       }
     } else if (o instanceof VillageNode) {
       Village v = ((VillageNode) o).getUserObject();
       if (!result.contains(v)) {
         result.add(v);
       }
     } else if (o != null && o.equals(mRoot)) {
       // remove all
       result = new LinkedList<Village>(treeData);
       // nothing more than everything can be removed
       return result;
     } else {
       // remove nothing
     }
   }
   return result;
 }
  public static void doExport(File pHtmlFile, String pPlanName, List<Attack> pAttacks) {
    if (TEMPLATE_ERROR) {
      logger.warn("Skip writing HTML file due to TEMPLATE_ERROR flag");
      return;
    }
    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    StringBuffer result = new StringBuffer();
    // append header
    result.append(replaceHeadFootVariables(HEADER, pPlanName, pAttacks));

    int cnt = 0;
    for (Attack a : pAttacks) {
      String b = BLOCK;
      // <editor-fold defaultstate="collapsed" desc="Replace DIV-IDs">
      if (cnt % 2 == 0) {
        b = b.replaceAll(DIV_CLASS, "odd_div");
      } else {
        b = b.replaceAll(DIV_CLASS, "even_div");
      }
      b = b.replaceAll(ID, Integer.toString(cnt));
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace Unit Icons">
      UnitHolder unit = a.getUnit();
      b =
          b.replaceAll(
              UNIT,
              "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/"
                  + unit.getPlainName()
                  + ".png\">");

      switch (a.getType()) {
        case Attack.CLEAN_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/att.png\">");
            break;
          }
        case Attack.SNOB_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/snob.png\">");
            break;
          }
        case Attack.FAKE_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/fake.png\">");
            break;
          }
        case Attack.FAKE_DEFF_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE,
                    "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/def_fake.png\">");
            break;
          }
        case Attack.SUPPORT_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/ally.png\">");
            break;
          }
        default:
          {
            b = b.replaceAll(TYPE, "-");
            break;
          }
      }
      // </editor-fold>

      String baseURL = ServerManager.getServerURL(GlobalOptions.getSelectedServer()) + "/";

      // <editor-fold defaultstate="collapsed" desc=" replace source tribe and ally">
      Tribe sourceTribe = a.getSource().getTribe();
      String sourceTribeName = "";
      String sourceTribeLink = "";
      String sourceAllyName = "";
      String sourceAllyTag = "";
      String sourceAllyLink = "";
      String sourceVillageName = "";
      String sourceVillageCoord = "";
      String sourceVillageLink = "";

      if (sourceTribe == null) {
        // tribe is null, so it is a barbarian village
        sourceTribeName = "Barbaren";
        sourceAllyName = "Barbaren";
      } else {
        sourceTribeLink = baseURL;
        sourceTribeLink += "guest.php?screen=info_player&id=" + sourceTribe.getId();
        sourceTribeName = sourceTribe.getName();

        // replace source tribe
        Ally sourceAlly = sourceTribe.getAlly();
        if (sourceAlly == null) {
          // tribe has no ally
          sourceAllyName = "Kein Stamm";
        } else {
          // ally valid
          sourceAllyName = sourceAlly.getName();
          sourceAllyTag = sourceAlly.getTag();
          sourceAllyLink = baseURL;
          sourceAllyLink += "guest.php?screen=info_ally&id=" + sourceAlly.getId();
        }
      }
      // replace source village
      sourceVillageLink = baseURL;
      sourceVillageLink += "guest.php?screen=info_village&id=" + a.getSource().getId();
      sourceVillageName = a.getSource().getFullName();
      sourceVillageCoord = a.getSource().getCoordAsString();

      // replace values
      b = b.replaceAll(SOURCE_PLAYER_NAME, Matcher.quoteReplacement(sourceTribeName));
      b = b.replaceAll(SOURCE_PLAYER_LINK, sourceTribeLink);
      b = b.replaceAll(SOURCE_ALLY_NAME, Matcher.quoteReplacement(sourceAllyName));
      b = b.replaceAll(SOURCE_ALLY_TAG, Matcher.quoteReplacement(sourceAllyTag));
      b = b.replaceAll(SOURCE_ALLY_LINK, sourceAllyLink);
      b = b.replaceAll(SOURCE_VILLAGE_NAME, Matcher.quoteReplacement(sourceVillageName));
      b = b.replaceAll(SOURCE_VILLAGE_COORD, sourceVillageCoord);
      b = b.replaceAll(SOURCE_VILLAGE_LINK, sourceVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" replace target tribe and ally">
      Tribe targetTribe = a.getTarget().getTribe();
      String targetTribeName = "";
      String targetTribeLink = "";
      String targetAllyName = "";
      String targetAllyTag = "";
      String targetAllyLink = "";
      String targetVillageName = "";
      String targetVillageCoord = "";
      String targetVillageLink = "";

      if (targetTribe == null) {
        // tribe is null, so it is a barbarian village
        targetTribeName = "Barbaren";
        targetAllyName = "Barbaren";
      } else {
        targetTribeLink = baseURL;
        targetTribeLink += "guest.php?screen=info_player&id=" + targetTribe.getId();
        targetTribeName = targetTribe.getName();

        // replace source tribe
        Ally targetAlly = targetTribe.getAlly();
        if (targetAlly == null) {
          // tribe has no ally
          targetAllyName = "Kein Stamm";
        } else {
          // ally valid
          targetAllyName = targetAlly.getName();
          targetAllyTag = targetAlly.getTag();
          targetAllyLink = baseURL;
          targetAllyLink += "guest.php?screen=info_ally&id=" + targetAlly.getId();
        }
      }
      // replace source village
      targetVillageLink = baseURL;
      targetVillageLink += "guest.php?screen=info_village&id=" + a.getTarget().getId();
      targetVillageName = a.getTarget().getFullName();
      targetVillageCoord = a.getTarget().getCoordAsString();

      // replace values
      b = b.replaceAll(TARGET_PLAYER_NAME, Matcher.quoteReplacement(targetTribeName));
      b = b.replaceAll(TARGET_PLAYER_LINK, targetTribeLink);
      b = b.replaceAll(TARGET_ALLY_NAME, Matcher.quoteReplacement(targetAllyName));
      b = b.replaceAll(TARGET_ALLY_TAG, Matcher.quoteReplacement(targetAllyTag));
      b = b.replaceAll(TARGET_ALLY_LINK, targetAllyLink);
      b = b.replaceAll(TARGET_VILLAGE_NAME, Matcher.quoteReplacement(targetVillageName));
      b = b.replaceAll(TARGET_VILLAGE_COORD, targetVillageCoord);
      b = b.replaceAll(TARGET_VILLAGE_LINK, targetVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace times and place URL">
      // replace arrive time
      String arrive = f.format(a.getArriveTime());
      b = b.replaceAll(ARRIVE_TIME, arrive);
      // replace send time
      long send =
          a.getArriveTime().getTime()
              - ((long)
                      DSCalculator.calculateMoveTimeInSeconds(
                          a.getSource(), a.getTarget(), a.getUnit().getSpeed())
                  * 1000);
      b = b.replaceAll(SEND_TIME, f.format(new Date(send)));
      // replace place link
      String placeURL = baseURL + "game.php?village=";
      int uvID = GlobalOptions.getSelectedProfile().getUVId();
      if (uvID >= 0) {
        placeURL = baseURL + "game.php?t=" + uvID + "&village=";
      }
      placeURL +=
          a.getSource().getId() + "&screen=place&mode=command&target=" + a.getTarget().getId();

      placeURL += "&type=0";

      StandardAttack stdAttack = StandardAttackManager.getSingleton().getElementByIcon(a.getType());
      for (UnitHolder u : DataHolder.getSingleton().getUnits()) {
        int amount = 0;
        if (stdAttack != null) {
          amount = stdAttack.getAmountForUnit(u, a.getSource());
        }
        placeURL += "&" + u.getPlainName() + "=" + amount;
      }

      b = b.replaceAll(PLACE, placeURL);
      // </editor-fold>

      result.append(b);
      cnt++;
    }

    // append footer
    result.append(replaceHeadFootVariables(FOOTER, pPlanName, pAttacks));
    try {
      FileWriter w = new FileWriter(pHtmlFile);
      w.write(result.toString());
      w.flush();
      w.close();
    } catch (Exception e) {
      logger.error("Failed writing HTML file", e);
    }
  }