use of org.opengis.util.InternationalString in project sis by apache.
the class ReferencingFunctions method getDomainOfValidity.
/**
* Returns the domain of validity from an authority code.
*
* @param codeOrPath the code allocated by an authority, or the path to a file.
* @return the domain of validity.
*/
@Override
public String getDomainOfValidity(final String codeOrPath) {
final Object domain;
try {
final IdentifiedObject object = getIdentifiedObject(codeOrPath, null);
domain = IdentifiedObjects.getProperties(object).get(ReferenceSystem.DOMAIN_OF_VALIDITY_KEY);
} catch (Exception exception) {
return getLocalizedMessage(exception);
}
if (domain instanceof Extent) {
final InternationalString description = ((Extent) domain).getDescription();
if (description != null) {
return description.toString(getJavaLocale());
}
}
return noResultString();
}
use of org.opengis.util.InternationalString in project sis by apache.
the class ReferencingFunctions method getName.
/**
* Returns the identified object name from an authority code.
*
* @param codeOrPath the code allocated by an authority, or the path to a file.
* @return the object name.
*/
@Override
public String getName(final String codeOrPath) {
final InternationalString name;
try {
final IdentifiedObject object;
final CodeType type = CodeType.guess(codeOrPath);
if (type.isCRS) {
object = new CacheKey<>(IdentifiedObject.class, codeOrPath, null, null).peek();
} else {
object = getIdentifiedObject(codeOrPath, type);
}
if (object != null) {
return object.getName().getCode();
}
// In Apache SIS implementation, 'getDescriptionText' returns the name.
name = CRS.getAuthorityFactory(null).getDescriptionText(codeOrPath);
} catch (Exception exception) {
return getLocalizedMessage(exception);
}
return (name != null) ? name.toString(getJavaLocale()) : noResultString();
}
use of org.opengis.util.InternationalString in project sis by apache.
the class ReferencingFunctions method getScope.
/**
* Returns the identified object scope from an authority code.
*
* @param codeOrPath the code allocated by an authority, or the path to a file.
* @return the object scope.
*/
@Override
public String getScope(final String codeOrPath) {
final Object value;
try {
final IdentifiedObject object = getIdentifiedObject(codeOrPath, null);
value = IdentifiedObjects.getProperties(object).get(ReferenceSystem.SCOPE_KEY);
} catch (Exception exception) {
return getLocalizedMessage(exception);
}
return (value instanceof InternationalString) ? ((InternationalString) value).toString(getJavaLocale()) : noResultString();
}
use of org.opengis.util.InternationalString in project sis by apache.
the class NamedIdentifier method toString.
/**
* Returns the unlocalized string representation of the given code.
*/
private static String toString(final CharSequence code) {
ArgumentChecks.ensureNonNull("code", code);
final String c;
if (code instanceof InternationalString) {
c = ((InternationalString) code).toString(Locale.ROOT);
} else {
c = code.toString();
}
if (c != null) {
return c;
}
/*
* May happen if the user gave us an instance of 'org.apache.sis.internal.jaxb.gcx.Anchor' class
* (maybe he got the instance indirectly) and the construction of that instance is not completed.
*/
throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentClass_2, "code", code.getClass()));
}
use of org.opengis.util.InternationalString in project sis by apache.
the class CharSequenceAdapter method wrap.
/**
* Converts a {@linkplain CharSequence character sequence} to the object to be marshalled
* in a XML file or stream.
*
* @param value the character representation of the object being marshalled.
* @return the wrapper for the given character sequence, or {@code null}.
*/
static GO_CharacterString wrap(CharSequence value) {
if (value instanceof String) {
// Slightly more efficient variant of this method.
return wrap(Context.current(), value, (String) value);
}
/*
* <mdb:someElement xsi:type="lan:PT_FreeText_PropertyType">
* <gco:CharacterString>...</gco:CharacterString>
* <lan:PT_FreeText>
* ... see PT_FreeText ...
* </lan:PT_FreeText>
* </mdb:someElement>
*/
if (value instanceof InternationalString) {
final PT_FreeText ft = PT_FreeText.create((InternationalString) value);
if (ft != null) {
return ft;
}
}
/*
* Invoking (indirectly) CharSequence.subSequence(…) may change the kind of object.
* We know that Anchor is safe, and that most InternationalString implementations
* lost the localized strings. This is why we trim the white spaces only here.
*/
value = CharSequences.trimWhitespaces(value);
if (value == null || value.length() == 0) {
return null;
}
/*
* Substitute <gco:CharacterString> by <gcx:Anchor> if a linkage is found.
*/
if (!(value instanceof Anchor)) {
final String key = CharSequences.trimWhitespaces(value.toString());
if (key != null && !key.isEmpty()) {
final Context context = Context.current();
final XLink linkage = Context.resolver(context).anchor(context, value, key);
if (linkage != null) {
if (linkage instanceof Anchor) {
value = (Anchor) linkage;
} else {
value = new Anchor(linkage, key);
}
}
}
}
/*
* At this stage, the value (typically a String or InternationalString) may
* have been replaced by an Anchor. The output will be one of the following:
*
* ┌──────────────────────────────────────────────────┬────────────────────────────────┐
* │ <mdb:someElement> │ <mdb:someElement> │
* │ <gco:CharacterString>...</gco:CharacterString> │ <gcx:Anchor>...</gcx:Anchor> │
* │ </mdb:someElement> │ </mdb:someElement> │
* └──────────────────────────────────────────────────┴────────────────────────────────┘
*/
return new GO_CharacterString(value);
}
Aggregations