public boolean isVisible(Hashtable overallRoles) {

    if (roles.size() == 0) {
      return false;
    }

    Enumeration keys = roles.keys();

    while (keys.hasMoreElements()) {
      String nextKey = (String) keys.nextElement();

      Boolean thisElement = (Boolean) roles.get(nextKey);
      if (!overallRoles.containsKey(nextKey)) {
        Global.getPref().log("Lookup role " + nextKey + " not possible", null);
        return false;
      }

      Role overallElement = (Role) overallRoles.get(nextKey);
      if (thisElement.booleanValue() != overallElement.getState()) {
        return false;
      }
    }

    return true;
  }
  private Vector addAnchorString(Vector list, String field, double diff) {
    Vector topIndex = new Vector();
    Hashtable topIndexParms, currEntry;
    double lastValue, currValue;

    if (list.size() == 0) return null;

    currEntry = (Hashtable) list.get(0);
    lastValue = Common.parseDouble((String) currEntry.get(field)) + diff;

    for (int i = 1; i < list.size(); i++) {
      currEntry = (Hashtable) list.get(i);
      currValue = Common.parseDouble((String) currEntry.get(field));
      if (currValue >= lastValue) {
        // Values for navigation line
        topIndexParms = new Hashtable();
        topIndexParms.put("HREF", Convert.toString(i));
        topIndexParms.put("TEXT", Convert.toString(lastValue));
        topIndex.add(topIndexParms);
        // add anchor entry to list
        currEntry.put("ANCHORNAME", Convert.toString(i));
        currEntry.put("ANCHORTEXT", Convert.toString(lastValue));
        lastValue = currValue + diff;
      } else {
        // clear value from previous run
        currEntry.put("ANCHORNAME", "");
        currEntry.put("ANCHORTEXT", "");
      }
      list.set(i, currEntry);
    }
    return topIndex;
  }
  public void setVisibilityRole(String visibility) {
    String[] parts = mString.split(visibility, '+');

    for (int i = 0; i < parts.length; i++) {
      String part = parts[i];
      if (part.startsWith("!")) {
        roles.put(part.substring(1), Boolean.FALSE);
      } else {
        roles.put(part, Boolean.TRUE);
      }
    }
  }
  /**
   * return the X9ECParameters object for the named curve represented by the passed in object
   * identifier. Null if the curve isn't present.
   *
   * @param oid an object identifier representing a named curve, if present.
   */
  public static X9ECParameters getByOID(DERObjectIdentifier oid) {
    X9ECParametersHolder holder = (X9ECParametersHolder) curves.get(oid);

    if (holder != null) {
      return holder.getParameters();
    }

    return null;
  }
  public static X9ECParameters getByName(String name) {
    DERObjectIdentifier oid = (DERObjectIdentifier) objIds.get(Strings.toLowerCase(name));

    if (oid != null) {
      return getByOID(oid);
    }

    return null;
  }
 protected static String char2simpleChar(char c) {
   if (c < 127) {
     // leave alone as equivalent string.
     return null;
   } else {
     String s = (String) iso2simpleMappings.get(new Integer(c));
     if (s == null) // not in table, replace with empty string just to be sure
     return "";
     else return s;
   }
 } // end charToEntity
    public int compare(Object o1, Object o2) {
      Hashtable hash1 = (Hashtable) o1;
      Hashtable hash2 = (Hashtable) o2;
      String str1, str2;
      double dbl1, dbl2;

      str1 = hash1.get(compareWhat).toString().toLowerCase();
      str2 = hash2.get(compareWhat).toString().toLowerCase();

      if (this.compareWhat.equals("WAYPOINT")) {
        str1 = hash1.get(compareWhat).toString().substring(2).toLowerCase();
        str2 = hash2.get(compareWhat).toString().substring(2).toLowerCase();
      }

      if (this.compareWhat.equals("DISTANCE")) {
        dbl1 = Common.parseDouble(str1.substring(0, str1.length() - 3));
        dbl2 = Common.parseDouble(str2.substring(0, str2.length() - 3));
        if (dbl1 > dbl2) return 1;
        if (dbl1 < dbl2) return -1;
        else return 0;
      } else {
        return str1.compareTo(str2);
      }
    }
 static {
   String[] mappingArray =
       new String[] {
         "34", "'",
         "160", " ",
         "161", "i",
         "162", "c",
         "163", "$",
         "164", "o",
         "165", "$",
         "166", "!",
         "167", "$",
         "168", " ",
         "169", " ",
         "170", " ",
         "171", "<",
         "172", " ",
         "173", "-",
         "174", " ",
         "175", "-",
         "176", " ",
         "177", "+/-",
         "178", "2",
         "179", "3",
         "180", "'",
         "181", " ",
         "182", " ",
         "183", " ",
         "184", ",",
         "185", "1",
         "186", " ",
         "187", ">",
         "188", "1/4",
         "189", "1/2",
         "190", "3/4",
         "191", "?",
         "192", "A",
         "193", "A",
         "194", "A",
         "195", "A",
         "196", "Ae",
         "197", "A",
         "198", "AE",
         "199", "C",
         "200", "E",
         "201", "E",
         "202", "E",
         "203", "E",
         "204", "I",
         "205", "I",
         "206", "I",
         "207", "I",
         "208", "D",
         "209", "N",
         "210", "O",
         "211", "O",
         "212", "O",
         "213", "O",
         "214", "Oe",
         "215", "x",
         "216", "O",
         "217", "U",
         "218", "U",
         "219", "U",
         "220", "Ue",
         "221", "Y",
         "222", " ",
         "223", "ss",
         "224", "a",
         "225", "a",
         "226", "a",
         "227", "a",
         "228", "ae",
         "229", "a",
         "230", "ae",
         "231", "c",
         "232", "e",
         "233", "e",
         "234", "e",
         "235", "e",
         "236", "i",
         "237", "i",
         "238", "i",
         "239", "i",
         "240", "o",
         "241", "n",
         "242", "o",
         "243", "o",
         "244", "o",
         "245", "o",
         "246", "oe",
         "247", "/",
         "248", "o",
         "249", "u",
         "250", "u",
         "251", "u",
         "252", "ue",
         "253", "y",
         "254", "p",
         "255", "y"
       };
   for (int i = 0; i < mappingArray.length; i = i + 2) {
     iso2simpleMappings.put(Integer.valueOf(mappingArray[i]), mappingArray[i + 1]);
   }
 }
  public void doIt() {
    CacheHolderDetail det;
    CacheHolder ch;
    ProgressBarForm pbf = new ProgressBarForm();
    Handle h = new Handle();
    int exportErrors = 0;

    new String();
    FileChooser fc = new FileChooser(FileChooserBase.DIRECTORY_SELECT, pref.getExportPath(expName));
    fc.setTitle("Select target directory:");
    String targetDir;
    if (fc.execute() != FormBase.IDCANCEL) {
      targetDir = fc.getChosen() + "/";
      pref.setExportPath(expName, targetDir);
      Vector cache_index = new Vector();
      Vector cacheImg = new Vector();
      Vector logImg = new Vector();
      Vector mapImg = new Vector();
      Vector usrImg = new Vector();
      Vector logIcons = new Vector(15);
      String icon;

      Hashtable varParams;
      Hashtable imgParams;
      Hashtable logImgParams;
      Hashtable usrImgParams;
      Hashtable mapImgParams;

      // Generate index page
      int counter = cacheDB.countVisible();

      pbf.showMainTask = false;
      pbf.setTask(h, "Exporting ...");
      pbf.exec();

      for (int i = 0; i < counter; i++) {
        h.progress = (float) (i + 1) / (float) counter;
        h.changed();

        ch = cacheDB.get(i);
        if (ch.isVisible()) {
          if (ch.is_incomplete()) {
            exportErrors++;
            Global.getPref()
                .log("HTMLExport: skipping export of incomplete waypoint " + ch.getWayPoint());
            continue;
          }
          det = ch.getCacheDetails(false, false);
          varParams = new Hashtable();
          varParams.put("TYPE", CacheType.cw2ExportString(ch.getType()));
          varParams.put("WAYPOINT", ch.getWayPoint());
          varParams.put("NAME", ch.getCacheName());
          varParams.put("OWNER", ch.getCacheOwner());
          if (ch.isAddiWpt() || CacheType.CW_TYPE_CUSTOM == ch.getType()) {
            varParams.put("SIZE", "");
            varParams.put("DIFFICULTY", "");
            varParams.put("TERRAIN", "");
          } else {
            varParams.put(
                "SIZE",
                CacheSize.isValidSize(ch.getCacheSize())
                    ? CacheSize.cw2ExportString(ch.getCacheSize())
                    : "");
            varParams.put(
                "DIFFICULTY",
                CacheTerrDiff.isValidTD(ch.getHard()) ? CacheTerrDiff.longDT(ch.getHard()) : "");
            varParams.put(
                "TERRAIN",
                CacheTerrDiff.isValidTD(ch.getTerrain())
                    ? CacheTerrDiff.longDT(ch.getTerrain())
                    : "");
          }
          varParams.put("DISTANCE", ch.getDistance());
          varParams.put("BEARING", ch.bearing);
          varParams.put("LATLON", ch.LatLon);
          varParams.put("STATUS", ch.getCacheStatus());
          varParams.put("DATE", ch.getDateHidden());
          cache_index.add(varParams);
          // We can generate the individual page here!
          try {
            Template page_tpl = new Template(template_init_page);
            page_tpl.setParam("TYPE", varParams.get("TYPE").toString());
            page_tpl.setParam("SIZE", varParams.get("SIZE").toString());
            page_tpl.setParam("WAYPOINT", ch.getWayPoint());
            page_tpl.setParam("NAME", ch.getCacheName());
            page_tpl.setParam("OWNER", ch.getCacheOwner());
            page_tpl.setParam("DIFFICULTY", varParams.get("DIFFICULTY").toString());
            page_tpl.setParam("TERRAIN", varParams.get("TERRAIN").toString());
            page_tpl.setParam("DISTANCE", ch.getDistance());
            page_tpl.setParam("BEARING", ch.bearing);
            page_tpl.setParam("LATLON", ch.LatLon);
            page_tpl.setParam("STATUS", ch.getCacheStatus());
            page_tpl.setParam("DATE", ch.getDateHidden());
            if (det != null) {
              if (ch.is_HTML()) {
                page_tpl.setParam("DESCRIPTION", modifyLongDesc(det, targetDir));
              } else {
                page_tpl.setParam(
                    "DESCRIPTION", STRreplace.replace(det.LongDescription, "\n", "<br>"));
              }
              page_tpl.setParam("HINTS", det.Hints);
              page_tpl.setParam("DECRYPTEDHINTS", Common.rot13(det.Hints));

              StringBuffer sb = new StringBuffer(2000);
              for (int j = 0; j < det.CacheLogs.size(); j++) {
                sb.append(
                    STRreplace.replace(
                        det.CacheLogs.getLog(j).toHtml(),
                        "http://www.geocaching.com/images/icons/",
                        null));
                sb.append("<br>");
                icon = det.CacheLogs.getLog(j).getIcon();
                if (logIcons.find(icon) < 0)
                  logIcons.add(icon); // Add the icon to list of icons to copy to dest directory
              }

              page_tpl.setParam("LOGS", sb.toString());
              page_tpl.setParam("NOTES", STRreplace.replace(det.getCacheNotes(), "\n", "<br>"));

              cacheImg.clear();
              for (int j = 0; j < det.images.size(); j++) {
                imgParams = new Hashtable();
                String imgFile = new String(det.images.get(j).getFilename());
                imgParams.put("FILE", imgFile);
                imgParams.put("TEXT", det.images.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + imgFile, targetDir + imgFile))
                  cacheImg.add(imgParams);
                else exportErrors++;
              }
              page_tpl.setParam("cacheImg", cacheImg);

              // Log images
              logImg.clear();
              for (int j = 0; j < det.logImages.size(); j++) {
                logImgParams = new Hashtable();
                String logImgFile = det.logImages.get(j).getFilename();
                logImgParams.put("FILE", logImgFile);
                logImgParams.put("TEXT", det.logImages.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + logImgFile, targetDir + logImgFile))
                  logImg.add(logImgParams);
                else exportErrors++;
              }
              page_tpl.setParam("logImg", logImg);

              // User images
              usrImg.clear();
              for (int j = 0; j < det.userImages.size(); j++) {
                usrImgParams = new Hashtable();
                String usrImgFile = new String(det.userImages.get(j).getFilename());
                usrImgParams.put("FILE", usrImgFile);
                usrImgParams.put("TEXT", det.userImages.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + usrImgFile, targetDir + usrImgFile))
                  usrImg.add(usrImgParams);
                else exportErrors++;
              }
              page_tpl.setParam("userImg", usrImg);

              // Map images
              mapImg.clear();
              mapImgParams = new Hashtable();

              String mapImgFile = new String(ch.getWayPoint() + "_map.gif");
              // check if map file exists
              File test = new File(profile.dataDir + mapImgFile);

              if (test.exists()) {
                mapImgParams.put("FILE", mapImgFile);
                mapImgParams.put("TEXT", mapImgFile);
                if (DataMover.copy(profile.dataDir + mapImgFile, targetDir + mapImgFile))
                  mapImg.add(mapImgParams);
                else exportErrors++;

                mapImgParams = new Hashtable();
                mapImgFile = ch.getWayPoint() + "_map_2.gif";
                mapImgParams.put("FILE", mapImgFile);
                mapImgParams.put("TEXT", mapImgFile);
                if (DataMover.copy(profile.dataDir + mapImgFile, targetDir + mapImgFile))
                  mapImg.add(mapImgParams);
                else exportErrors++;

                page_tpl.setParam("mapImg", mapImg);
              }
            } else {
              page_tpl.setParam("DESCRIPTION", "");
              page_tpl.setParam("HINTS", "");
              page_tpl.setParam("DECRYPTEDHINTS", "");
              page_tpl.setParam("LOGS", "");
              page_tpl.setParam("NOTES", "");
              page_tpl.setParam("cacheImg", cacheImg);
              page_tpl.setParam("logImg", ""); // ???
              page_tpl.setParam("userImg", ""); // ???
              page_tpl.setParam("mapImg", ""); // ???
              exportErrors++;
            }

            PrintWriter pagefile =
                new PrintWriter(
                    new BufferedWriter(new FileWriter(targetDir + ch.getWayPoint() + ".html")));
            pagefile.print(page_tpl.output());
            pagefile.close();
          } catch (IllegalArgumentException e) {
            exportErrors++;
            ch.setIncomplete(true);
            Global.getPref()
                .log(
                    "HTMLExport: " + ch.getWayPoint() + " is incomplete reason: ",
                    e,
                    Global.getPref().debug);
          } catch (Exception e) {
            exportErrors++;
            Global.getPref()
                .log(
                    "HTMLExport: error wehen exporting " + ch.getWayPoint() + " reason: ",
                    e,
                    Global.getPref().debug);
          }
        } // if is black, filtered
      }

      // Copy the log-icons to the destination directory
      for (int j = 0; j < logIcons.size(); j++) {
        icon = (String) logIcons.elementAt(j);
        if (!DataMover.copy(FileBase.getProgramDirectory() + "/" + icon, targetDir + icon))
          exportErrors++;
      }
      if (!DataMover.copy(
          FileBase.getProgramDirectory() + "/recommendedlog.gif", targetDir + "recommendedlog.gif"))
        exportErrors++;

      try {
        Template tpl = new Template(template_init_index);
        tpl.setParam("cache_index", cache_index);
        PrintWriter detfile;
        detfile = new PrintWriter(new BufferedWriter(new FileWriter(targetDir + "/index.html")));
        detfile.print(tpl.output());
        detfile.close();
        // sort by waypoint
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_wp.html", "WAYPOINT");
        // sort by name
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_alpha.html", "NAME", false);
        // sort by type
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_type.html", "TYPE", true);
        // sort by size
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_size.html", "SIZE", true);
        // sort by distance
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_dist.html", "DISTANCE", 10.0);
      } catch (Exception e) {
        Vm.debug("Problem writing HTML files\n");
        e.printStackTrace();
      } // try
    } // if
    pbf.exit(0);

    if (exportErrors > 0) {
      new MessageBox(
              "Export Error",
              exportErrors + " errors during export. See log for details.",
              FormBase.OKB)
          .execute();
    }
  }
  private Vector addAnchorString(Vector list, String field, boolean fullCompare) {
    Vector topIndex = new Vector();
    Hashtable topIndexParms, currEntry;
    String lastValue, currValue;

    if (list.size() == 0) return null;

    currEntry = (Hashtable) list.get(0);
    lastValue = (String) currEntry.get(field);
    if (lastValue == null || lastValue.length() == 0) lastValue = "  ";
    lastValue = lastValue.toUpperCase();

    for (int i = 1; i < list.size(); i++) {
      currEntry = (Hashtable) list.get(i);
      currValue = (String) currEntry.get(field);
      currValue = currValue.toUpperCase();
      if (currValue == null || currValue == "") continue;
      try {
        if (fullCompare) {
          if (lastValue.compareTo(currValue) != 0) {
            // Values for navigation line
            topIndexParms = new Hashtable();
            topIndexParms.put("HREF", Convert.toString(i));
            topIndexParms.put("TEXT", currValue);
            topIndex.add(topIndexParms);
            // add anchor entry to list
            currEntry.put("ANCHORNAME", Convert.toString(i));
            currEntry.put("ANCHORTEXT", currValue);
          } else {
            // clear value from previous run
            currEntry.put("ANCHORNAME", "");
            currEntry.put("ANCHORTEXT", "");
          }
        } else {
          if (lastValue.charAt(0) != currValue.charAt(0)) {
            // Values for navigation line
            topIndexParms = new Hashtable();
            topIndexParms.put("HREF", Convert.toString(i));
            topIndexParms.put("TEXT", currValue.charAt(0) + " ");
            topIndex.add(topIndexParms);
            // add anchor entry to list
            currEntry.put("ANCHORNAME", Convert.toString(i));
            currEntry.put("ANCHORTEXT", currValue.charAt(0) + " ");
          } else {
            // clear value from previous run
            currEntry.put("ANCHORNAME", "");
            currEntry.put("ANCHORTEXT", "");
          }
        }
        list.set(i, currEntry);
        lastValue = currValue;
      } catch (Exception e) {
        continue;
      }
    }
    return topIndex;
  }
 /** returns an enumeration containing the name strings for curves contained in this structure. */
 public static Enumeration getNames() {
   return objIds.keys();
 }
 /** return the named curve name represented by the given object identifier. */
 public static String getName(DERObjectIdentifier oid) {
   return (String) names.get(oid);
 }
 /**
  * return the object identifier signified by the passed in name. Null if there is no object
  * identifier associated with name.
  *
  * @return the object identifier associated with name, if present.
  */
 public static DERObjectIdentifier getOID(String name) {
   return (DERObjectIdentifier) objIds.get(Strings.toLowerCase(name));
 }
 static void defineCurve(String name, DERObjectIdentifier oid, X9ECParametersHolder holder) {
   objIds.put(name, oid);
   names.put(oid, name);
   curves.put(oid, holder);
 }