use of org.opengis.util.InternationalString in project sis by apache.
the class StringConverterTest method testInternationalString.
/**
* Tests conversions to {@link InternationalString}.
*/
@Test
public void testInternationalString() {
final ObjectConverter<String, InternationalString> c = new StringConverter.InternationalString();
runInvertibleConversion(c, "Some sentence", new SimpleInternationalString("Some sentence"));
assertSerializedEquals(c);
}
use of org.opengis.util.InternationalString in project sis by apache.
the class Formatter method appendForSubtypes.
/**
* Appends the anchor, scope and domain of validity of the given object. Those information are available
* only for {@link ReferenceSystem}, {@link Datum} and {@link CoordinateOperation} objects.
*/
private void appendForSubtypes(final IdentifiedObject object) {
final InternationalString anchor, scope;
final Extent area;
if (object instanceof ReferenceSystem) {
anchor = null;
scope = ((ReferenceSystem) object).getScope();
area = ((ReferenceSystem) object).getDomainOfValidity();
} else if (object instanceof Datum) {
anchor = ((Datum) object).getAnchorPoint();
scope = ((Datum) object).getScope();
area = ((Datum) object).getDomainOfValidity();
} else if (object instanceof CoordinateOperation) {
anchor = null;
scope = ((CoordinateOperation) object).getScope();
area = ((CoordinateOperation) object).getDomainOfValidity();
} else {
return;
}
appendOnNewLine(WKTKeywords.Anchor, anchor, null);
appendOnNewLine(WKTKeywords.Scope, scope, ElementKind.SCOPE);
if (area != null) {
appendOnNewLine(WKTKeywords.Area, area.getDescription(), ElementKind.EXTENT);
append(Extents.getGeographicBoundingBox(area), BBOX_ACCURACY);
appendVerticalExtent(Extents.getVerticalRange(area));
appendTemporalExtent(Extents.getTimeRange(area));
}
}
use of org.opengis.util.InternationalString in project sis by apache.
the class DefaultMetadata method setMetadataStandard.
/**
* Implementation of legacy {@link #setMetadataStandardName(String)} and
* {@link #setMetadataStandardVersion(String)} methods.
*/
private void setMetadataStandard(final boolean version, final String newValue) {
checkWritePermission();
final InternationalString i18n = (newValue != null) ? new SimpleInternationalString(newValue) : null;
final List<Citation> newValues = (metadataStandards != null) ? new ArrayList<>(metadataStandards) : new ArrayList<>(1);
DefaultCitation citation = newValues.isEmpty() ? null : DefaultCitation.castOrCopy(newValues.get(0));
if (citation == null) {
citation = new DefaultCitation();
}
if (version) {
citation.setEdition(i18n);
} else {
citation.setTitle(i18n);
}
if (newValues.isEmpty()) {
newValues.add(citation);
} else {
newValues.set(0, citation);
}
setMetadataStandards(newValues);
}
use of org.opengis.util.InternationalString in project sis by apache.
the class Warnings method toString.
/**
* Returns a string representation of the warning messages in the given locale.
* This method formats the warnings in a bullet list.
*
* @param locale the locale to use for formatting warning messages.
* @return a string representation of the warning messages.
*/
public String toString(final Locale locale) {
final StringBuilder buffer = new StringBuilder(250);
final String lineSeparator = System.lineSeparator();
final Messages resources = Messages.getResources(locale);
buffer.append(resources.getString(isParsing ? Messages.Keys.IncompleteParsing_1 : Messages.Keys.NonConformFormatting_1, root));
if (messages != null) {
for (final Iterator<?> it = messages.iterator(); it.hasNext(); ) {
final InternationalString i18n = (InternationalString) it.next();
Exception cause = (Exception) it.next();
final String message;
if (i18n != null) {
message = i18n.toString(locale);
} else {
/*
* If there is no message, then we must have at least an exception.
* Consequently a NullPointerException in following line would be a bug.
*/
final String[] sources = exceptionSources.get(cause);
if (sources != null) {
message = Errors.getResources(locale).getString(Errors.Keys.UnparsableStringInElement_2, sources);
} else {
message = cause.toString();
cause = null;
}
}
buffer.append(lineSeparator).append(" • ").append(message);
if (cause != null) {
String details = Exceptions.getLocalizedMessage(cause, locale);
if (details == null) {
details = cause.toString();
}
buffer.append(lineSeparator).append(" ").append(details);
}
}
}
/*
* If the parser found some unknown elements, formats an enclosed bullet list for them.
*/
if (!ignoredElements.isEmpty()) {
final Vocabulary vocabulary = Vocabulary.getResources(locale);
buffer.append(lineSeparator).append(" • ").append(resources.getString(Messages.Keys.UnknownElementsInText));
for (final Map.Entry<String, List<String>> entry : ignoredElements.entrySet()) {
buffer.append(lineSeparator).append(" ‣ ").append(vocabulary.getString(Vocabulary.Keys.Quoted_1, entry.getKey()));
String separator = vocabulary.getString(Vocabulary.Keys.InBetweenWords);
for (final String p : entry.getValue()) {
buffer.append(separator).append(p);
separator = ", ";
}
buffer.append('.');
}
}
/*
* There is intentionally line separator at the end of the last line, because the string returned by
* this method is typically written or logged by a call to System.out.println(…) or something equivalent.
* A trailing line separator cause a visual disruption in log records for instance.
*/
return buffer.toString();
}
use of org.opengis.util.InternationalString in project sis by apache.
the class Warnings method getMessage.
/**
* Returns a warning message.
*
* @param index 0 for the first warning, 1 for the second warning, <i>etc.</i> until {@link #getNumMessages()} - 1.
* @return the <var>i</var>-th warning message.
*/
public String getMessage(int index) {
ArgumentChecks.ensureValidIndex(getNumMessages(), index);
index *= 2;
final InternationalString i18n = (InternationalString) messages.get(index);
if (i18n != null) {
return i18n.toString(errorLocale);
} else {
final Exception cause = (Exception) messages.get(index + 1);
// See comment in 'toString(Locale)'.
final String[] sources = exceptionSources.get(cause);
if (sources != null) {
return Errors.getResources(errorLocale).getString(Errors.Keys.UnparsableStringInElement_2, sources);
} else {
return cause.toString();
}
}
}
Aggregations