/** * Sets the file format. The given name should be a short name like "GeoTIFF". * The long name will be inferred from the given short name, if possible. * Storage location is: * * <ul> * <li>{@code metadata/identificationInfo/resourceFormat/formatSpecificationCitation/alternateTitle}</li> * </ul> * * @param abbreviation the format short name or abbreviation, or {@code null} for no-operation. * @throws MetadataStoreException if this method can not connect to the {@code jdbc/SpatialMetadata} database. * Callers should generally handle this exception as a recoverable one (i.e. log a warning and continue). * * @see #addCompression(CharSequence) */ public final void setFormat(final String abbreviation) throws MetadataStoreException { if (abbreviation != null && abbreviation.length() != 0) { if (format == null) { format = MetadataSource.getProvided().lookup(Format.class, abbreviation); /* * Additional step for converting deprecated "name" and "specification" into non-deprecated properties. * This step is not required on SIS branches that depend on development branches of GeoAPI 3.1 or 4.0. */ format = DefaultFormat.castOrCopy(format); } } }
/** * Tests {@link MetadataSource#lookup(Class, String)} be fetching some {@link Format} instances from * the given source. The first call to the {@code lookup(…)} method will trig the database installation. * * @param source the instance to test. * @throws MetadataStoreException if an error occurred while querying the database. */ @TestStep public static void verifyFormats(final MetadataSource source) throws MetadataStoreException { verify(source.lookup(Format.class, "PNG"), "PNG", "PNG (Portable Network Graphics) Specification"); verify(source.lookup(Format.class, "NetCDF"), "NetCDF", "NetCDF Classic and 64-bit Offset Format"); verify(source.lookup(Format.class, "GeoTIFF"), "GeoTIFF", "GeoTIFF Coverage Encoding Profile"); verify(source.lookup(Format.class, "CSV"), "CSV", "Common Format and MIME Type for Comma-Separated Values (CSV) Files"); verify(source.lookup(Format.class, "CSV-MF"), "CSV", "OGC Moving Features Encoding Extension: Simple Comma-Separated Values (CSV)"); }
if (abbreviation != null && abbreviation.length() != 0) { if (format == null) { format = MetadataSource.getProvided().lookup(Format.class, abbreviation);
if (c == null) { try { c = MetadataSource.getProvided().lookup(Citation.class, title); } catch (MetadataStoreException e) {
return MetadataSource.getProvided().lookup(Format.class, name); } catch (MetadataStoreException e) { if (listeners != null) {
/** * Compares {@link MetadataFallback} content with database content using the given source. * This method is invoked by {@link MetadataSourceTest} for opportunistically reusing the * available database. */ static void compare(final MetadataSource source) throws MetadataStoreException { for (final Citation c : Citations.values()) { final String name = ((CitationConstant) c).title; final boolean exclude = EXCLUDES.contains(name); final Citation fromFB = MetadataFallback.createCitation(name); assertEquals(name, exclude, fromFB == null); // Verify that missing fallbacks are known ones. if (!exclude) { compare(name, source.lookup(Citation.class, name), fromFB); } } compare("IOGP", source.lookup(Citation.class, "IOGP"), MetadataFallback.createCitation("IOGP")); }
return MetadataSource.getProvided().lookup(Format.class, name); } catch (MetadataStoreException e) { if (listeners != null) {
/** * Verifies that instances created by {@link MetadataSource} are read-only. * In particular, it should not be possible to add elements in the collection. * * @param source the instance to test. * @throws MetadataStoreException if an error occurred while querying the database. */ @TestStep public static void ensureReadOnly(final MetadataSource source) throws MetadataStoreException { final Citation c = source.lookup(Citation.class, "SIS"); @SuppressWarnings("unchecked") // Cheat or the purpose of this test. final Collection<InternationalString> titles = (Collection<InternationalString>) c.getAlternateTitles(); final InternationalString more = new SimpleInternationalString("An open source project."); try { titles.add(more); fail("Pre-defined metadata should be unmodifiable."); } catch (UnsupportedOperationException e) { // This is the expected exception. } } }