use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class MetadataReader method read.
/**
* Creates an ISO {@code Metadata} object from the information found in the netCDF file.
*
* @return the ISO metadata object.
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
*/
public Metadata read() throws IOException, DataStoreException {
addResourceScope(ScopeCode.DATASET, null);
Set<InternationalString> publisher = addCitation();
addIdentificationInfo(publisher);
for (final String service : SERVICES) {
final String name = stringValue(service);
if (name != null) {
addResourceScope(ScopeCode.SERVICE, name);
}
}
addAcquisitionInfo();
addContentInfo();
/*
* Add the dimension information, if any. This metadata node
* is built from the netCDF CoordinateSystem objects.
*/
for (final GridGeometry cs : decoder.getGridGeometries()) {
if (cs.getSourceDimensions() >= Variable.MIN_DIMENSION && cs.getTargetDimensions() >= Variable.MIN_DIMENSION) {
addSpatialRepresentationInfo(cs);
}
}
addFileIdentifier();
/*
* Add history in Metadata.dataQualityInfo.lineage.statement as specified by UnidataDD2MI.xsl.
* However Metadata.resourceLineage.statement could be a more appropriate place.
* See https://issues.apache.org/jira/browse/SIS-361
*/
final DefaultMetadata metadata = build(false);
for (final String path : searchPath) {
decoder.setSearchPath(path);
DefaultLineage lineage = null;
String value = stringValue(HISTORY);
if (value != null) {
lineage = new DefaultLineage();
lineage.setStatement(new SimpleInternationalString(value));
}
value = stringValue(SOURCE);
if (value != null) {
if (lineage == null)
lineage = new DefaultLineage();
addIfAbsent(lineage.getSources(), new DefaultSource(value));
}
if (lineage != null) {
final DefaultDataQuality quality = new DefaultDataQuality(ScopeCode.DATASET);
quality.setLineage(lineage);
addIfAbsent(metadata.getDataQualityInfo(), quality);
}
}
decoder.setSearchPath(searchPath);
metadata.setMetadataStandards(Citations.ISO_19115);
addCompleteMetadata(createURI(stringValue(METADATA_LINK)));
return metadata;
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class EPSGDataAccess method getAuthority.
/**
* Returns the authority for this EPSG dataset. The returned citation contains the database version
* in the {@linkplain Citation#getEdition() edition} attribute, together with date of last update in
* the {@linkplain Citation#getEditionDate() edition date}.
* Example (the exact content will vary with Apache SIS versions, JDBC driver and EPSG dataset versions):
*
* {@preformat text
* Citation
* ├─ Title ……………………………………………………… EPSG Geodetic Parameter Dataset
* ├─ Identifier ………………………………………… EPSG
* ├─ Online resource (1 of 2)
* │ ├─ Linkage ………………………………………… http://epsg-registry.org/
* │ └─ Function ……………………………………… Browse
* └─ Online resource (2 of 2)
* ├─ Linkage ………………………………………… jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
* ├─ Description ……………………………… EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
* └─ Function ……………………………………… Connection
* }
*/
@Override
public synchronized Citation getAuthority() {
/*
* We do not cache this citation because the caching service is already provided by ConcurrentAuthorityFactory.
*/
final DefaultCitation c = new DefaultCitation("EPSG Geodetic Parameter Dataset");
c.setIdentifiers(Collections.singleton(new ImmutableIdentifier(null, null, Constants.EPSG)));
try {
/*
* Get the most recent version number from the history table. We get the date in local timezone
* instead then UTC because the date is for information purpose only, and the local timezone is
* more likely to be shown nicely (without artificial hours) to the user.
*/
final String query = translator.apply("SELECT VERSION_NUMBER, VERSION_DATE FROM [Version History]" + " ORDER BY VERSION_DATE DESC, VERSION_HISTORY_CODE DESC");
String version = null;
try (Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(query)) {
while (result.next()) {
version = getOptionalString(result, 1);
// Local timezone.
final Date date = result.getDate(2);
if (version != null && date != null) {
// Paranoiac check.
c.setEdition(new SimpleInternationalString(version));
c.setEditionDate(date);
break;
}
}
}
/*
* Add some hard-coded links to EPSG resources, and finally add the JDBC driver name and version number.
* The list last OnlineResource looks like:
*
* Linkage: jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
* Function: Connection
* Description: EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
*
* TODO: A future version should use Citations.EPSG as a template.
* See the "EPSG" case in ServiceForUtility.createCitation(String).
*/
final DatabaseMetaData metadata = connection.getMetaData();
addURIs: for (int i = 0; ; i++) {
String url;
OnLineFunction function;
InternationalString description = null;
switch(i) {
case 0:
url = "http://epsg-registry.org/";
function = OnLineFunction.SEARCH;
break;
case 1:
url = "http://www.epsg.org/";
function = OnLineFunction.DOWNLOAD;
break;
case 2:
{
url = SQLUtilities.getSimplifiedURL(metadata);
function = OnLineFunction.valueOf(CONNECTION);
description = Resources.formatInternational(Resources.Keys.GeodeticDataBase_4, Constants.EPSG, version, metadata.getDatabaseProductName(), Version.valueOf(metadata.getDatabaseMajorVersion(), metadata.getDatabaseMinorVersion()));
break;
}
// Finished adding all URIs.
default:
break addURIs;
}
final DefaultOnlineResource r = new DefaultOnlineResource();
try {
r.setLinkage(new URI(url));
} catch (URISyntaxException exception) {
unexpectedException("getAuthority", exception);
}
r.setFunction(function);
r.setDescription(description);
c.getOnlineResources().add(r);
}
} catch (SQLException exception) {
unexpectedException("getAuthority", exception);
} finally {
c.freeze();
}
return c;
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class CommonAuthorityFactory method getDescriptionText.
/**
* Returns a description of the object corresponding to a code.
* The description can be used for example in a combo box in a graphical user interface.
*
* <p>Codes in the {@code "AUTO(2)"} namespace do not need parameters for this method.
* But if parameters are nevertheless specified, then they will be taken in account.</p>
*
* <table class="sis">
* <caption>Examples</caption>
* <tr><th>Argument value</th> <th>Return value</th></tr>
* <tr><td>{@code CRS:84}</td> <td>WGS 84</td></tr>
* <tr><td>{@code AUTO2:42001}</td> <td>WGS 84 / Auto UTM</td></tr>
* <tr><td>{@code AUTO2:42001,1,-100,45}</td> <td>WGS 84 / UTM zone 47N</td></tr>
* </table>
*
* @param code value in the CRS or AUTO(2) code space.
* @return a description of the object.
* @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
* @throws FactoryException if an error occurred while fetching the description.
*/
@Override
public InternationalString getDescriptionText(final String code) throws FactoryException {
final int s = skipNamespace(code) & ~LEGACY_MASK;
final String localCode = code.substring(s, CharSequences.skipTrailingWhitespaces(code, s, code.length()));
if (localCode.indexOf(SEPARATOR) < 0) {
/*
* For codes in the "AUTO(2)" namespace without parameters, we can not rely on the default implementation
* since it would fail to create the ProjectedCRS instance. Instead we return a generic description.
* Note that we do not execute this block if parametes were specified. If there is parameters,
* then we instead rely on the default implementation for a more accurate description text.
*/
final int codeValue;
try {
codeValue = Integer.parseInt(localCode);
} catch (NumberFormatException exception) {
throw noSuchAuthorityCode(localCode, code, exception);
}
final int i = codeValue - FIRST_PROJECTION_CODE;
if (i >= 0 && i < PROJECTION_NAMES.length) {
return new SimpleInternationalString(PROJECTION_NAMES[i]);
}
}
return new SimpleInternationalString(createCoordinateReferenceSystem(localCode).getName().getCode());
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class PT_FreeText method toCharSequence.
/**
* Returns the content of this {@code <gco:CharacterString>} as an {@code InternationalString}.
*
* @return the character sequence for this {@code <gco:CharacterString>}.
*/
@Override
protected CharSequence toCharSequence() {
// May be null.
String defaultValue = toString();
if (defaultValue != null && contains(defaultValue)) {
/*
* If the <gco:CharacterString> value is repeated in one of the
* <lan:LocalisedCharacterString> elements, keep only the localized
* version (because it specifies the locale, while the unlocalized
* string saids nothing on that matter).
*/
defaultValue = null;
}
/*
* Create the international string with all locales found in the <gml:textGroup>
* element. If the <gml:textGroup> element is missing or empty, then we will use
* an instance of SimpleInternationalString instead than the more heavy
* DefaultInternationalString.
*/
DefaultInternationalString i18n = null;
final TextGroup[] textGroup = this.textGroup;
if (textGroup != null) {
for (final TextGroup group : textGroup) {
if (group != null) {
final LocalisedCharacterString[] localised = group.localized;
if (localised != null) {
for (final LocalisedCharacterString text : localised) {
if (text != null) {
if (i18n == null) {
i18n = new DefaultInternationalString(defaultValue);
}
i18n.add(text.locale, text.text);
}
}
}
}
}
}
if (i18n == null && defaultValue != null) {
return new SimpleInternationalString(defaultValue);
}
return i18n;
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class Proj4Factory method getAuthority.
/**
* Returns the project that defines the codes recognized by this factory.
* The authority determines the {@linkplain #getCodeSpaces() code space}.
*
* @return {@link Citations#PROJ4}.
*/
@Override
public Citation getAuthority() {
Citation c = authority;
if (c == null) {
c = Citations.PROJ4;
final String release = Proj4.version();
if (release != null) {
final DefaultCitation df = new DefaultCitation(c);
df.setEdition(new SimpleInternationalString(release));
df.freeze();
c = df;
}
authority = c;
}
return c;
}
Aggregations