Search in sources :

Example 66 with InternationalString

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);
}
Also used : InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test)

Example 67 with InternationalString

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));
    }
}
Also used : Datum(org.opengis.referencing.datum.Datum) InternationalString(org.opengis.util.InternationalString) TemporalExtent(org.opengis.metadata.extent.TemporalExtent) SimpleExtent(org.apache.sis.internal.simple.SimpleExtent) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) Extent(org.opengis.metadata.extent.Extent) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Example 68 with InternationalString

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);
}
Also used : InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) CI_Citation(org.apache.sis.internal.jaxb.metadata.CI_Citation)

Example 69 with InternationalString

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();
}
Also used : Vocabulary(org.apache.sis.util.resources.Vocabulary) Messages(org.apache.sis.util.resources.Messages) InternationalString(org.opengis.util.InternationalString) ArrayList(java.util.ArrayList) List(java.util.List) InternationalString(org.opengis.util.InternationalString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 70 with InternationalString

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();
        }
    }
}
Also used : InternationalString(org.opengis.util.InternationalString) InternationalString(org.opengis.util.InternationalString)

Aggregations

InternationalString (org.opengis.util.InternationalString)86 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)20 Test (org.junit.Test)17 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)13 IdentifiedObject (org.opengis.referencing.IdentifiedObject)10 ArrayList (java.util.ArrayList)7 Locale (java.util.Locale)6 GenericName (org.opengis.util.GenericName)6 Extent (org.opengis.metadata.extent.Extent)5 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 Vocabulary (org.apache.sis.util.resources.Vocabulary)4 Citation (org.opengis.metadata.citation.Citation)4 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TableAppender (org.apache.sis.io.TableAppender)3 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)3 DataStoreException (org.apache.sis.storage.DataStoreException)3