示例#1
0
  /**
   * Call reset() if needed.
   *
   * @return true if reset was called
   */
  public boolean resetIfNeeded() {
    // getDataFromReset if available
    getDataFromReset();

    // should runCWDataBrowserReset() be called?
    long sinceLastReset = System.currentTimeMillis() - timeOfLastReset;
    if (sinceLastReset > resetEveryNMillis) {
      runCWDataBrowserReset();
      return true;
    } else return false;
  }
示例#2
0
  /** Run CWDataBrowserReset */
  void runCWDataBrowserReset() {
    // is there already a reset thread?
    if (resetThread != null) {
      String2.log(String2.ERROR + " in runCWDataBrowserReset: resetThread!=null");
      return;
    }

    // create a lower priority thread and run cwDataBrowserReset
    timeOfLastReset = System.currentTimeMillis();
    cwDataBrowserReset = new CWDataBrowserReset();
    resetThread = new Thread(cwDataBrowserReset);
    resetThread.setPriority(Thread.currentThread().getPriority() - 2);
    // -2 because some adjacent priorities map to the same OS priority
    resetThread.start();
  }
示例#3
0
  /**
   * This creates the POST HTML form with the EmaAttributes.
   *
   * @param request is a request from a user
   * @param displayErrorMessage if false (for example, the first time the user sees the page), error
   *     messages aren't displayed
   * @return the HTML code for the form. The line separator is the newline character.
   */
  public String getHTMLForm(HttpServletRequest request, boolean displayErrorMessages) {
    long startTime = System.currentTimeMillis();
    HttpSession session = request.getSession();
    if (verbose)
      String2.log("\ngetHTMLForm session isNew=" + session.isNew() + " id=" + session.getId());
    nRequestsInitiated++;
    int rowNumber = 0;
    StringBuilder sb = new StringBuilder();

    sb.append(getStartOfHTMLForm());
    displayErrorMessages = false; // always

    // create the rows of the table with the attributes

    // title
    sb.append(
        "    <tr>\n"
            + "      <td colspan=\"2\">"
            + title
            + "</td>\n"
            + "      <td rowspan=\"6\"><img border=\"0\" src=\""
            + regionsImage
            + "\"\n"
            + "        width=\"228\" height=\"208\"\n"
            + "        alt=\""
            + regionsImageAlt
            + "\" title=\""
            + regionsImageTitle
            + "\"\n"
            + "        usemap=#regionCoordinates>\n"
            + "        <br><center><small>"
            + regionsImageTitle
            + "</small></center></td>\n"
            + "    </tr>\n");

    // dataset
    String dataSetValue = dataSet.getValue(session);
    int whichDataSet = String2.indexOf(activeDataSetOptions, dataSetValue);
    if (whichDataSet < 0) {
      whichDataSet = 0;
      dataSetValue = activeDataSetOptions[0];
      dataSet.setValue(session, dataSetValue);
    }
    dataSetRequests[String2.indexOf(dataSetOptions, dataSetValue)]++;
    if (verbose) String2.log("dataSetValue = " + dataSetValue);
    setBeginRow(beginRowArray[Math2.odd(rowNumber++) ? 1 : 0]);
    sb.append(dataSet.getTableEntry(dataSetValue, displayErrorMessages));

    // timePeriod
    Object[] object = (Object[]) activeDataSetContents.get(whichDataSet);
    String[] activeTimePeriodOptions = (String[]) object[0];
    String[] activeTimePeriodTitles = (String[]) object[1];
    Vector activeTimePeriodContents = (Vector) object[2];
    String dataSetDirectory = (String) object[3];
    if (verbose) String2.log("dataSetDirectory = " + dataSetDirectory);
    timePeriod.setOptions(activeTimePeriodOptions);
    timePeriod.setTitles(activeTimePeriodTitles);
    String timePeriodValue = timePeriod.getValue(session);
    int whichTimePeriod = String2.indexOf(activeTimePeriodOptions, timePeriodValue);
    if (whichTimePeriod < 0) {
      whichTimePeriod = 0;
      timePeriodValue = activeTimePeriodOptions[0];
      timePeriod.setValue(session, timePeriodValue);
    }
    timePeriodRequests[String2.indexOf(timePeriodOptions, timePeriodValue)]++;
    if (verbose) String2.log("timePeriodValue = " + timePeriodValue);
    setBeginRow(beginRowArray[Math2.odd(rowNumber++) ? 1 : 0]);
    sb.append(timePeriod.getTableEntry(timePeriodValue, displayErrorMessages));

    // region
    object = (Object[]) activeTimePeriodContents.get(whichTimePeriod);
    String[] activeRegionOptions = (String[]) object[0];
    String[] activeRegionTitles = (String[]) object[1];
    String[] activeRegionCoordinates = (String[]) object[2];
    Vector activeRegionContents = (Vector) object[3];
    String timePeriodDirectory = (String) object[4];
    region.setOptions(activeRegionOptions);
    region.setTitles(activeRegionTitles);
    String regionValue = region.getValue(session);
    int whichRegion = String2.indexOf(activeRegionOptions, regionValue);
    if (whichRegion < 0) {
      whichRegion = 0;
      regionValue = activeRegionOptions[0];
      region.setValue(session, regionValue);
    }
    regionRequests[String2.indexOf(regionOptions, regionValue)]++;
    if (verbose) String2.log("regionValue = " + regionValue);
    setBeginRow(beginRowArray[Math2.odd(rowNumber++) ? 1 : 0]);
    sb.append(region.getTableEntry(regionValue, displayErrorMessages));

    // define regionCoordinates for regionImage after activeRegionCoordinates known
    // do in reverse order, so small regions detected before large regions
    // (first match found is used)
    sb.append("    <map name=\"regionCoordinates\">\n");
    for (int i = activeRegionCoordinates.length - 1; i >= 0; i--)
      //        for (int i = 0; i < activeRegionCoordinates.length; i++)
      sb.append(
          "      <area shape=\"rect\" coords=\""
              + activeRegionCoordinates[i]
              + "\"\n"
              + "        title=\""
              + activeRegionTitles[i + 1]
              + "\"\n"
              + // +1 since 0 is main title
              "        href=\"#\" "
              + // was href=\"javascript:
              "onClick=\""
              + "document.forms[0].region["
              + i
              + "].checked=true; document.forms[0].submit();\">\n");
    sb.append("    </map>\n");

    // formSubmitted
    sb.append(formSubmitted.getControl("true"));

    // date
    object = (Object[]) activeRegionContents.get(whichRegion);
    String[] gifs = (String[]) object[0];
    String[] activeTimeOptions = (String[]) object[1];
    int[] getBits = (int[]) object[2];
    // if (verbose)
    //    String2.log("activeTimeOptions = " + String2.toCSSVString(activeTimeOptions));
    date.setOptions(activeTimeOptions);
    String timeValue = date.getValue(session);
    // find exact date match or one past (activeTimeOptions are sorted)
    // date will be off first time, and if user changes above settings and same date not available
    int whichDate = activeTimeOptions.length - 1; // last one
    if (timeValue != null) {
      for (int i = 0; i < activeTimeOptions.length; i++) {
        if (timeValue.compareTo(activeTimeOptions[i]) <= 0) {
          whichDate = i;
          break;
        }
      }
    }
    timeValue = activeTimeOptions[whichDate];
    date.setValue(session, timeValue);
    if (verbose) String2.log("timeValue = " + timeValue);
    setBeginRow(beginRowArray[Math2.odd(rowNumber++) ? 1 : 0]);
    sb.append(date.getTableEntry(timeValue, displayErrorMessages));

    // submitForm
    // may or may not be visible; so always a unique color (light red)
    setBeginRow("<tr bgcolor=\"#FFCCCC\">");
    sb.append(
        "    <noscript>\n"
            + submitForm.getTableEntry(submitForm.getValue(session), displayErrorMessages));
    sb.append("    </noscript>\n");

    // get
    String gifName = gifs[whichDate];
    int bits = getBits[whichDate];
    String currentFileDir =
        dataServer
            + dataSetDirectory
            + "/"
            + // for example, "QS"
            timePeriodDirectory
            + "/"; // for example, "1day"
    setBeginRow(beginRowArray[Math2.odd(rowNumber++) ? 1 : 0]);
    sb.append(
        "    "
            + getBeginRow()
            + "\n"
            + "      <td>"
            + classRB2.getString("get.label", "")
            + "&nbsp;</td>\n"
            + "      <td>");
    int nGetOptions = getOptions.length;
    for (int getI = 0; getI < nGetOptions; getI++)
      if ((bits & Math2.Two[getI]) != 0)
        sb.append(
            "<a href=\""
                + currentFileDir
                + getDirectories[getI]
                + "/"
                + gifName
                + getExtensions[getI]
                + "\"\n        title=\""
                + getTitles[getI + 1]
                + "\">"
                + // +1: title 0 is main title
                getOptions[getI]
                + "</a>\n        ");
    sb.append(
        //                     "<br><small>" + hereIs + "</small>\n" +
        "      </td>\n" + "    </tr>\n");

    // image
    String currentGifName = currentFileDir + getDirectories[0] + "/" + gifName + getExtensions[0];
    // "QN2005001_2005001_curl_westus.gif";
    sb.append(
        //            "    <tr><td>&nbsp;</td></tr>\n" +  //row 6
        //            "    <tr><td colspan=\"2\">" + hereIs + "</td></tr>\n" + //row 7
        "    <tr>\n"
            + // standard
            "      <td colspan=\"3\"><img border=\"0\" src=\""
            + currentGifName
            + "\"\n"
            + // row 8
            "        width=\"650\" height=\"502\"\n"
            + "        title=\""
            + hereIs
            + " "
            + currentGifName
            + "\"\n"
            + "        alt=\""
            + hereIsAlt
            + " "
            + currentGifName
            + "\">\n"
            + "      </td>\n"
            + "    </tr>\n");

    // update requestedFilesMap
    Integer I = (Integer) requestedFilesMap.get(gifName);
    requestedFilesMap.put(gifName, new Integer(I == null ? 1 : I.intValue() + 1));

    // end of table, end of form
    sb.append(getEndOfHTMLForm(startTime, ""));
    nRequestsCompleted++;

    sb.append(
        "<p>DISCLAIMER OF ENDORSEMENT\n"
            + "<br>Any reference obtained from this server to a specific commercial product,\n"
            + "process, or service does not constitute or imply an endorsement by CoastWatch,\n"
            + "NOAA, or the United States Government of the product, process, or service, or \n"
            + "its producer or provider. The views and opinions expressed in any referenced \n"
            + "document do not necessarily state or reflect those of CoastWatch,\n"
            + "NOAA, or the United States Government.\n"
            + "\n"
            + "<p>DISCLAIMER FOR EXTERNAL LINKS\n"
            + "<br>The appearance of external links on this World Wide Web site does not\n"
            + "constitute endorsement by the\n"
            + "<a href=\"http://www.doc.gov\">Department of Commerce</a>/<a href=\"http://www.noaa.gov\">National\n"
            + "Oceanic and Atmospheric Administration</a> of external Web sites or the information,\n"
            + "products or services contained\n"
            + "therein. For other than authorized activities the Department of Commerce/NOAA does not\n"
            + "exercise any editorial control over the information you may find at these locations. These\n"
            + "links are provided consistent with the stated purpose of this Department of Commerce/NOAA\n"
            + "Web site.\n"
            + "\n"
            + "<p>DISCLAIMER OF LIABILITY\n"
            + "<br>Neither the data Contributors, CoastWatch, NOAA, nor the United States Government, \n"
            + "nor any of their employees or contractors, makes any warranty, express or implied, \n"
            + "including warranties of merchantability and fitness for a particular purpose, \n"
            + "or assumes any legal liability for the accuracy, completeness, or usefulness,\n"
            + "of any information at this site.\n"
            + "\n"
            + "<p><font size=\"-1\">Please email questions, comments, or\n"
            + "suggestions regarding this web page to\n"
            + "<A HREF=\"mailto:[email protected]\">[email protected]</A>.</font>");

    return sb.toString();
  }