Search in sources :

Example 6 with InternationalString

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();
}
Also used : Extent(org.opengis.metadata.extent.Extent) InternationalString(org.opengis.util.InternationalString) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) DataStoreException(org.apache.sis.storage.DataStoreException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) FactoryException(org.opengis.util.FactoryException)

Example 7 with InternationalString

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();
}
Also used : InternationalString(org.opengis.util.InternationalString) CodeType(org.apache.sis.internal.storage.CodeType) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) DataStoreException(org.apache.sis.storage.DataStoreException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) FactoryException(org.opengis.util.FactoryException)

Example 8 with InternationalString

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();
}
Also used : InternationalString(org.opengis.util.InternationalString) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) DataStoreException(org.apache.sis.storage.DataStoreException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) FactoryException(org.opengis.util.FactoryException)

Example 9 with InternationalString

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

Example 10 with InternationalString

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);
}
Also used : Context(org.apache.sis.internal.jaxb.Context) Anchor(org.apache.sis.internal.jaxb.gcx.Anchor) InternationalString(org.opengis.util.InternationalString) InternationalString(org.opengis.util.InternationalString) PT_FreeText(org.apache.sis.internal.jaxb.lan.PT_FreeText) XLink(org.apache.sis.xml.XLink)

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