Exemplo n.º 1
0
  /**
   * This is used when called from within a program. If args is null or args.length is 0, this
   * loops; otherwise it returns when done.
   *
   * @param args if args has values, they are used to answer the questions.
   * @returns the contents of outFileName (will be "" if trouble)
   */
  public String doIt(String args[], boolean loop) throws Throwable {
    File2.safeRename(logFileName, logFileName + ".previous");
    if (File2.isFile(outFileName)) {
      try {
        File2.rename(outFileName, outFileName + ".previous");
      } catch (Throwable t) {
        File2.delete(outFileName);
      }
    }
    String2.setupLog(
        true,
        false, // toSystemOut, toSystemErr
        logFileName,
        false, // logToStringBuffer
        true,
        20000000); // append
    String2.log(
        "*** Starting DasDds "
            + Calendar2.getCurrentISODateTimeStringLocal()
            + "\n"
            + "logFile="
            + String2.logFileName()
            + "\n"
            + String2.standardHelpAboutMessage());
    outFile = new FileWriter(outFileName); // default charset

    // delete the old log files (pre 1.48 names)
    File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt");
    File2.delete(EDStatic.fullLogsDirectory + "DasDdsLog.txt.previous");

    String datasetID = "";
    if (args == null) args = new String[0];

    // look for -verbose (and remove it)
    boolean verbose = false; // actually controls reallyVerbose
    int vi = String2.indexOf(args, "-verbose");
    if (vi >= 0) {
      String2.log("verbose=true");
      verbose = true;
      StringArray sa = new StringArray(args);
      sa.remove(vi);
      args = sa.toArray();
    }

    do {
      // get the EDD type
      // EDD.reallyVerbose = false;  //sometimes while testing
      datasetID =
          get(
              args,
              0,
              "\n*** DasDds ***\n"
                  + "This generates the DAS and DDS for a dataset and puts it in\n"
                  + outFileName
                  + "\n"
                  + "Press ^D or ^C to exit at any time.\n\n"
                  + "Which datasetID",
              datasetID);
      if (datasetID == null) {
        String2.flushLog();
        outFile.flush();
        outFile.close();
        return String2.readFromFile(outFileName)[1];
      }

      // delete the datasetInfo files for this datasetID (in case incorrect info)
      try {
        String dir = EDD.datasetDir(datasetID);
        String2.log(
            "dataset dir="
                + dir
                + "\n"
                + "dataset n files not deleted = "
                + RegexFilenameFilter.regexDelete(dir, ".*", false));

      } catch (Throwable t) {
        String2.log(
            "\n*** An error occurred while deleting the old info for "
                + datasetID
                + ":\n"
                + MustBe.throwableToString(t));
      }

      try {
        printToBoth(EDD.testDasDds(datasetID, verbose));
      } catch (Throwable t) {
        String2.log(
            "\n*** An error occurred while trying to load "
                + datasetID
                + ":\n"
                + MustBe.throwableToString(t));
      }
      String2.flushLog();

    } while (loop && args.length == 0);

    outFile.flush();
    outFile.close();
    String ret = String2.readFromFile(outFileName)[1];
    String2.returnLoggingToSystemOut();
    return ret;
  }
Exemplo n.º 2
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();
  }