示例#1
0
 /**
  * Tests the {@link FormatTable#getEntry} and {@link FormatTable#getEntries} methods.
  *
  * @throws SQLException If the test can't connect to the database.
  */
 @Test
 public void testSelectAndList() throws SQLException {
   final FormatTable table = getDatabase().getTable(FormatTable.class);
   final FormatEntry entry = table.getEntry(TEMPERATURE);
   assertEquals("Unexpected format read from the database.", TEMPERATURE, entry.identifier);
   assertSame("Expected the cached instance.", entry, table.getEntry(TEMPERATURE));
   assertEquals("Wrong image format.", "PNG", entry.imageFormat);
   assertEquals("Wrong color palette.", "rainbow", entry.paletteName);
   /*
    * Check the sample dimensions.
    */
   final List<GridSampleDimension> bands = entry.sampleDimensions;
   SampleDimensionTableTest.checkTemperatureDimension(bands.toArray(new GridSampleDimension[0]));
   /*
    * Ask for every format, and ensure that our instance is in the list.
    */
   table.setImageFormats(entry.getImageFormats());
   final Set<FormatEntry> entries = table.getEntries();
   assertFalse(entries.isEmpty());
   assertTrue(entries.contains(entry));
   table.release();
 }
示例#2
0
 /**
  * Tests a for an entry having two bands
  *
  * @throws SQLException If the test can't connect to the database.
  */
 @Test
 public void testTwoBands() throws SQLException {
   final FormatTable table = getDatabase().getTable(FormatTable.class);
   final FormatEntry entry = table.getEntry(CURRENT);
   assertEquals("Unexpected format read from the database.", CURRENT, entry.identifier);
   assertSame("Expected the cached instance.", entry, table.getEntry(CURRENT));
   assertEquals("Wrong image format.", "NetCDF", entry.imageFormat);
   assertEquals("Wrong color palette.", "white-cyan-red", entry.paletteName);
   /*
    * Check the sample dimensions.
    */
   final List<GridSampleDimension> bands = entry.sampleDimensions;
   assertEquals(2, bands.size());
   assertFalse(bands.get(0).equals(bands.get(1)));
   /*
    * Ask for every format, and ensure that our instance is in the list.
    */
   table.setImageFormats(entry.getImageFormats());
   final Set<FormatEntry> entries = table.getEntries();
   assertFalse(entries.isEmpty());
   assertTrue(entries.contains(entry));
   table.release();
 }
示例#3
0
  /**
   * Tests the {@lik FormatTable#find} method.
   *
   * @throws SQLException If the test can't connect to the database.
   */
  @Test
  public void testFind() throws SQLException {
    final Category[] categories = {
      new Category("No data", null, 0), new Category("Temperature", null, 1, 256, 0.15, -3)
    };
    final FormatTable table = getDatabase().getTable(FormatTable.class);
    /*
     * Following entry should be found for the PNG format only.
     */
    GridSampleDimension search = new GridSampleDimension("Temperature", categories, Units.CELSIUS);
    FormatEntry found = table.find("NetCDF", Arrays.asList(search));
    assertNull("Should be defined for the PNG format, not NetCDF.", found);
    found = table.find("PNG", Arrays.asList(search));
    assertNotNull("Should be defined for the PNG format.", found);
    assertEquals(TEMPERATURE, found.getIdentifier());
    /*
     * Replace the category by a different one.
     * The entry should not be found anymore.
     */
    categories[1] = new Category("Temperature", null, 1, 256, 0.15, -4);
    search = new GridSampleDimension("Temperature", categories, Units.CELSIUS);
    found = table.find("PNG", Arrays.asList(search));
    assertNull("Should not found because the transfer function is different.", found);

    categories[1] = new Category("Temperature", null, 1, 255, 0.15, -3);
    search = new GridSampleDimension("Temperature", categories, Units.CELSIUS);
    found = table.find("PNG", Arrays.asList(search));
    assertNull("Should not found because the range is different.", found);

    categories[1] = new Category("Temperature", null, 1, 256, 0.15, -3);
    search = new GridSampleDimension("Temperature", categories, Units.CELSIUS);
    found = table.find("PNG", Arrays.asList(search));
    assertNotNull("Should found since the category has been restored.", found);
    assertEquals(TEMPERATURE, found.getIdentifier());
    table.release();
  }
  public String format(String field) {
    StringBuilder sb = new StringBuilder();

    // Build the table model containing the links:
    FileListTableModel tableModel = new FileListTableModel();
    if (field == null) return "";
    tableModel.setContent(field);

    int piv = 1; // counter for relevant iterations
    for (int i = 0; i < tableModel.getRowCount(); i++) {
      FileListEntry flEntry = tableModel.getEntry(i);
      // Use this entry if we don't discriminate on types, or if the type fits:
      if ((fileType == null) || flEntry.getType().getName().toLowerCase().equals(fileType)) {

        for (FormatEntry entry : format) {
          switch (entry.getType()) {
            case STRING:
              sb.append(entry.getString());
              break;
            case ITERATION_COUNT:
              sb.append(String.valueOf(piv));
              break;
            case FILE_PATH:
              if (flEntry.getLink() == null) break;

              String dir;
              // We need to resolve the file directory from the database's metadata,
              // but that is not available from a formatter. Therefore, as an
              // ugly hack, the export routine has set a global variable before
              // starting the export, which contains the database's file directory:
              if (Globals.prefs.fileDirForDatabase != null) dir = Globals.prefs.fileDirForDatabase;
              else dir = Globals.prefs.get(GUIGlobals.FILE_FIELD + "Directory");

              File f = Util.expandFilename(flEntry.getLink(), new String[] {dir});
              /*
               * Stumbled over this while investigating
               *
               * https://sourceforge.net/tracker/index.php?func=detail&aid=1469903&group_id=92314&atid=600306
               */
              if (f != null) {
                try {
                  sb.append(replaceStrings(f.getCanonicalPath())); // f.toURI().toString();
                } catch (IOException ex) {
                  ex.printStackTrace();
                  sb.append(replaceStrings(f.getPath()));
                }
              } else {
                sb.append(replaceStrings(flEntry.getLink()));
              }

              break;
            case RELATIVE_FILE_PATH:
              if (flEntry.getLink() == null) break;

              /*
               * Stumbled over this while investigating
               *
               * https://sourceforge.net/tracker/index.php?func=detail&aid=1469903&group_id=92314&atid=600306
               */
              sb.append(replaceStrings(flEntry.getLink())); // f.toURI().toString();

              break;
            case FILE_EXTENSION:
              if (flEntry.getLink() == null) break;
              int index = flEntry.getLink().lastIndexOf('.');
              if ((index >= 0) && (index < flEntry.getLink().length() - 1))
                sb.append(replaceStrings(flEntry.getLink().substring(index + 1)));
              break;
            case FILE_TYPE:
              sb.append(replaceStrings(flEntry.getType().getName()));
              break;
            case FILE_DESCRIPTION:
              sb.append(replaceStrings(flEntry.getDescription()));
              break;
          }
        }

        piv++; // update counter
      }
    }

    return sb.toString();
  }