Java Code Examples for org.opengis.util.InternationalString

The following examples show how to use org.opengis.util.InternationalString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sis   Source File: DefaultFormula.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Formats this formula as a pseudo-<cite>Well Known Text</cite> element.
 *
 * <div class="note"><b>Compatibility note:</b>
 * ISO 19162 does not define a WKT representation for {@code Formula} objects.
 * The text formatted by this method is SIS-specific and causes the text to be
 * flagged as {@linkplain Formatter#setInvalidWKT(Class, Exception) invalid WKT}.
 * The WKT content of this element may change in any future SIS version.</div>
 *
 * @return {@code "Formula"}.
 */
@Override
protected String formatTo(final Formatter formatter) {
    InternationalString text = null;
    final Citation citation = getCitation();    // Gives to users a chance to override properties.
    if (citation != null) {
        text = citation.getTitle();
    }
    if (text == null) {
        text = getFormula();
    }
    if (text != null) {
        formatter.append(text.toString(formatter.getLocale()), ElementKind.REMARKS);
    }
    formatter.setInvalidWKT(Formula.class, null);
    return WKTKeywords.Formula;
}
 
Example 2
Source Project: sis   Source File: TransformCommand.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Prints a textual description of the domain of validity. This method tries to reduce the string length by
 * the use of some heuristic rules based on the syntax used in EPSG dataset. For example the following string:
 *
 * <blockquote>Canada - onshore and offshore - Alberta; British Columbia (BC); Manitoba; New Brunswick (NB);
 * Newfoundland and Labrador; Northwest Territories (NWT); Nova Scotia (NS); Nunavut; Ontario; Prince Edward
 * Island (PEI); Quebec; Saskatchewan; Yukon.</blockquote>
 *
 * is replaced by:
 *
 * <blockquote>Canada - onshore and offshore</blockquote>
 */
private void printDomainOfValidity(final Extent domain) throws IOException {
    if (domain != null) {
        final InternationalString description = domain.getDescription();
        if (description != null) {
            String text = description.toString(locale);
            if (text.length() >= 80) {
                int end = text.indexOf(';');
                if (end >= 0) {
                    int s = text.lastIndexOf('-', end);
                    if (s >= 0) {
                        end = s;
                    }
                    text = text.substring(0, end).trim();
                }
            }
            printHeader(Vocabulary.Keys.Domain);
            outHeader.append(text);
            outHeader.nextLine();
        }
    }
}
 
Example 3
Source Project: sis   Source File: DefaultResponsibleParty.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name or the position of the first individual. If no individual is found in the list of parties,
 * then this method will search in the list of organization members. The later structure is used by our netCDF
 * reader.
 *
 * @param  position {@code true} for returning the position name instead than individual name.
 * @return the name or position of the first individual, or {@code null}.
 *
 * @see #getIndividualName()
 * @see #getPositionName()
 */
private InternationalString getIndividual(final boolean position) {
    final Collection<AbstractParty> parties = getParties();
    InternationalString name = getName(parties, DefaultIndividual.class, position);
    if (name == null && parties != null) {
        for (final AbstractParty party : parties) {
            if (party instanceof DefaultOrganisation) {
                name = getName(((DefaultOrganisation) party).getIndividual(), DefaultIndividual.class, position);
                if (name != null) {
                    break;
                }
            }
        }
    }
    return name;
}
 
Example 4
Source Project: sis   Source File: DefaultResponsibleParty.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name of the first party of the given type, or {@code null} if none.
 *
 * @param  position {@code true} for returning the position name instead than individual name.
 * @return the name or position of the first individual, or {@code null}.
 *
 * @see #getOrganisationName()
 * @see #getIndividualName()
 * @see #getPositionName()
 */
private static InternationalString getName(final Collection<? extends AbstractParty> parties,
        final Class<? extends AbstractParty> type, final boolean position)
{
    InternationalString name = null;
    if (parties != null) {                              // May be null on marshalling.
        for (final AbstractParty party : parties) {
            if (type.isInstance(party)) {
                if (name != null) {
                    LegacyPropertyAdapter.warnIgnoredExtraneous(type, DefaultResponsibleParty.class,
                            position ? "getPositionName" : (type == DefaultIndividual.class)
                                     ? "getIndividualName" : "getOrganisationName");
                    break;
                }
                name = position ? ((DefaultIndividual) party).getPositionName() : party.getName();
            }
        }
    }
    return name;
}
 
Example 5
Source Project: sis   Source File: StringAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string representation of the given character sequence. If the given
 * sequence is an instance of {@link InternationalString}, then the locale from
 * the current unmashalling context is used in order to get a string.
 * If the context is {@code null} or does not specify any locale, then the choice
 * of locale is left to the {@link InternationalString#toString()} implementation.
 *
 * @param  text  the {@code CharSequence} to convert to a {@code String}, or {@code null}.
 * @return the localized representation of the given text, or {@code null} if the text was null.
 *
 * @see org.apache.sis.xml.XML#LOCALE
 */
public static String toString(final CharSequence text) {
    if (text == null) {
        return null;
    }
    if (text instanceof InternationalString) {
        final Context context = Context.current();
        if (context != null) {
            final Locale locale = context.getLocale();
            if (locale != null) {
                /*
                 * While Apache SIS accepts null locale, foreigner
                 * implementations are not guaranteed to support null.
                 */
                return ((InternationalString) text).toString(locale);
            }
        }
    }
    return text.toString();
}
 
Example 6
Source Project: sis   Source File: IndexedResourceBundleTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the formatting of an international string.
 */
@Test
@DependsOnMethod("testGetResources")
public void testFormatInternational() {
    InternationalString i18n = Errors.formatInternational(Errors.Keys.NullArgument_1);
    assertEquals("Argument ‘{0}’ shall not be null.",      i18n.toString(Locale.ROOT));
    assertEquals("Argument ‘{0}’ shall not be null.",      i18n.toString(Locale.ENGLISH));
    assertEquals("L’argument ‘{0}’ ne doit pas être nul.", i18n.toString(Locale.FRENCH));
    assertNotSame(i18n, assertSerializedEquals(i18n));

    i18n = Errors.formatInternational(Errors.Keys.NullArgument_1, "CRS");
    assertEquals("Argument ‘CRS’ shall not be null.",      i18n.toString(Locale.ROOT));
    assertEquals("Argument ‘CRS’ shall not be null.",      i18n.toString(Locale.ENGLISH));
    assertEquals("L’argument ‘CRS’ ne doit pas être nul.", i18n.toString(Locale.FRENCH));
    assertNotSame(i18n, assertSerializedEquals(i18n));
}
 
Example 7
Source Project: sldeditor   Source File: DataSourceInfo.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();

                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type =
                        featureTypeFactory.createGeometryType(
                                new NameImpl(RASTER_GEOMETRY_FIELD),
                                GridCoverage2D.class,
                                crs,
                                isIdentifiable,
                                isAbstract,
                                restrictions,
                                superType,
                                description);
                GeometryDescriptor descriptor =
                        featureTypeFactory.createGeometryDescriptor(
                                type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);

                rasterPropertyDescriptorList.add(descriptor);
            }

            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
 
Example 8
Source Project: sis   Source File: PropertyInformation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns valid values that can be assigned to the extended element, or {@code null} if none.
 * In the particular case of SIS implementation, this method may return a subclass of
 * {@link org.apache.sis.measure.NumberRange}.
 */
@Override
@SuppressWarnings({"unchecked","rawtypes"})
public InternationalString getDomainValue() {
    Object domain = domainValue;
    if (domain != null) {
        if (!(domain instanceof DomainRange)) {
            try {
                // Not a big deal if we create two instances of that in two concurrent threads.
                domain = new DomainRange(elementType, (ValueRange) domain);
            } catch (IllegalArgumentException e) {
                /*
                 * May happen only if a ValueRange annotation is applied on the wrong method.
                 * The JUnit tests ensure that this never happen at least for the SIS metadata
                 * implementation. If this error happen anyway, the user probably doesn't expect
                 * to have an IllegalArgumentException while he didn't provided any argument.
                 * Returning null as a fallback is compliant with the method contract.
                 */
                Logging.unexpectedException(Logging.getLogger(Modules.METADATA),
                        PropertyInformation.class, "getDomainValue", e);
                domain = null;
            }
            domainValue = domain;
        }
    }
    return (DomainRange) domain;
}
 
Example 9
Source Project: sis   Source File: DefaultKeywords.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates keywords initialized to the given key word.
 *
 * @param keywords  commonly used words or formalised words or phrases used to describe the subject,
 *                  or {@code null} if none.
 */
public DefaultKeywords(final CharSequence... keywords) {
    if (keywords != null) {
        for (final CharSequence keyword : keywords) {
            final InternationalString i18n = Types.toInternationalString(keyword);
            if (this.keywords == null) {
                this.keywords = singleton(i18n, InternationalString.class);
            } else {
                this.keywords.add(i18n);
            }
        }
    }
}
 
Example 10
public void beginTask( String name, int totalWork ) {
    this.totalWork = totalWork;
    runningWork = 0;
    geotoolsMonitor.started();
    InternationalString iName = new SimpleInternationalString(name);
    geotoolsMonitor.setTask(iName);
}
 
Example 11
Source Project: sis   Source File: ResourceTree.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a label for a resource. Current implementation builds a string containing the resource title
 * if non-ambiguous, followed by filename in order to resolve ambiguity that may be caused by different
 * files having the same resource identification in their metadata.
 *
 * @param  name      the result of {@link DataStore#getDisplayName()}, or {@code null} if unknown.
 * @param  metadata  the result of {@link DataStore#getMetadata()} (may be {@code null}).
 */
private static String getTitle(final String name, final Metadata metadata) {
    if (metadata != null) {
        String title = null;
        for (final Identification identification : CollectionsExt.nonNull(metadata.getIdentificationInfo())) {
            final Citation citation = identification.getCitation();
            if (citation != null) {
                final InternationalString i18n = citation.getTitle();
                String id;
                if (i18n != null) {
                    id = i18n.toString();                   // TODO: use display locale.
                } else {
                    id = Citations.getIdentifier(identification.getCitation());
                }
                if (id != null && !(id = id.trim()).isEmpty()) {
                    if (title == null) {
                        title = id;
                    } else if (!title.equals(id)) {
                        return name;                        // Ambiguity - will use the filename instead.
                    }
                }
            }
        }
        if (title != null) {
            if (name != null) {
                title += " (" + name + ')';
            }
            return title;
        }
    }
    return name;
}
 
Example 12
Source Project: sis   Source File: MetadataBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the concatenation of the given strings. The previous string may be {@code null}.
 * This method does nothing if the previous string already contains the one to append.
 */
private static InternationalString append(final InternationalString previous, final InternationalString toAdd) {
    if (previous == null) {
        return toAdd;
    }
    final String p = previous.toString();
    final String a = toAdd.toString();
    if (p.contains(a)) {
        return previous;
    }
    return Types.toInternationalString(p + System.lineSeparator() + a);
}
 
Example 13
Source Project: sis   Source File: Citations.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the {@linkplain DefaultCitation#getTitle() title} or any
 * {@linkplain DefaultCitation#getAlternateTitles() alternate title} in the given citation
 * matches the given string. The comparison is case-insensitive and ignores every character
 * which is not a {@linkplain Character#isLetterOrDigit(int) letter or a digit}.
 *
 * @param  citation  the citation to check for, or {@code null}.
 * @param  title     the title or alternate title to compare, or {@code null}.
 * @return {@code true} if both arguments are non-null, and the title or an alternate
 *         title matches the given string.
 */
public static boolean titleMatches(final Citation citation, final String title) {
    if (citation != null && title != null) {
        InternationalString candidate = citation.getTitle();
        Iterator<? extends InternationalString> iterator = null;
        do {
            if (candidate != null) {
                final String unlocalized = candidate.toString(Locale.ROOT);
                if (equalsFiltered(unlocalized, title)) {
                    return true;
                }
                final String localized = candidate.toString();
                if (!Objects.equals(localized, unlocalized)             // Slight optimization for a common case.
                        && equalsFiltered(localized, title))
                {
                    return true;
                }
            }
            if (iterator == null) {
                iterator = nonEmptyIterator(citation.getAlternateTitles());
                if (iterator == null) break;
            }
            if (!iterator.hasNext()) break;
            candidate = iterator.next();
        } while (true);
    }
    return false;
}
 
Example 14
Source Project: sis   Source File: Types.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a description for the given class, or {@code null} if none.
 * This method can be used for GeoAPI interfaces or {@link CodeList}.
 *
 * @param  type  the GeoAPI interface or code list from which to get the description, or {@code null}.
 * @return the description, or {@code null} if none or if the given type is {@code null}.
 *
 * @see #getDescription(CodeList)
 */
public static InternationalString getDescription(final Class<?> type) {
    final String name = getStandardName(type);
    if (name != null) {
        final String resources = getResources(type.getName());
        if (resources != null) {
            return new Description(resources, name);
        }
    }
    return null;
}
 
Example 15
Source Project: sis   Source File: AbstractIdentifiedObject.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB for setting the remarks.
 *
 * @see #getRemarks()
 */
private void setRemarks(final InternationalString value) {
    if (remarks == null) {
        remarks = value;
    } else {
        MetadataUtilities.propertyAlreadySet(AbstractIdentifiedObject.class, "setRemarks", "remarks");
    }
}
 
Example 16
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    boolean useDefaultSymbol = false;
    JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
    if(useDefaultSymbolElement != null)
    {
        useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
    }

    JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
    if(jsonElement != null)
    {
        namedLayer.setName(jsonElement.getAsString());
    }
    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
    if(element != null)
    {
        JsonArray valueList = element.getAsJsonArray();

        for(int index = 0; index < valueList.size(); index ++)
        {
            JsonElement valueElement = valueList.get(index);
            if(valueElement != null)
            {
                Rule rule = styleFactory.createRule();
                JsonObject valueObj = valueElement.getAsJsonObject();

                String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);

                String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
                rule.setName(label);

                createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);

                // Heading /description
                String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
                @SuppressWarnings("unused")
                String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);

                if((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty())
                {
                    if(label == null)
                    {
                        label = "";
                    }
                    InternationalString titleString = Text.text(label);
                    
                    if(heading == null)
                    {
                        heading = "";
                    }

                    InternationalString descriptionString = Text.text(heading);

                    Description descriptionObj = styleFactory.description(titleString, descriptionString);

                    rule.setDescription(descriptionObj);
                }

                if(minScale > 0.0)
                {
                    rule.setMinScaleDenominator(minScale);
                }

                if(maxScale > 0.0)
                {
                    rule.setMaxScaleDenominator(maxScale);
                }

                JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
                SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);

                if(useDefaultSymbol && value == null)
                {
                    rule.setIsElseFilter(true);
                }
                fts.rules().add(rule);
            }
        }
    }
    return sld;
}
 
Example 17
Source Project: sis   Source File: DefaultSeries.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the name of the series, or aggregate dataset, of which the dataset is a part.
 *
 * @return the name of the series or aggregate dataset, or {@code null}.
 */
@Override
@XmlElement(name = "name")
public InternationalString getName() {
    return name;
}
 
Example 18
Source Project: sis   Source File: DefaultCitation.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the version of the cited resource.
 *
 * @return the version, or {@code null} if none.
 */
@Override
@XmlElement(name = "edition")
public InternationalString getEdition() {
    return edition;
}
 
Example 19
Source Project: sis   Source File: DefaultInstrument.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the textual description of the instrument. {@code null} if unspecified.
 *
 * @return textual description, or {@code null}.
 */
@Override
@XmlElement(name = "description")
public InternationalString getDescription() {
    return description;
}
 
Example 20
Source Project: sis   Source File: AbstractIdentification.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a brief narrative summary of the resource(s).
 *
 * @return brief narrative summary of the resource(s).
 */
@Override
@XmlElement(name = "abstract", required = true)
public InternationalString getAbstract() {
    return abstracts;
}
 
Example 21
Source Project: sis   Source File: Column.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the header label.
 */
@Override
public InternationalString getHeader() {
    return Vocabulary.formatInternational(target ? Vocabulary.Keys.Destination : Vocabulary.Keys.Source);
}
 
Example 22
Source Project: sis   Source File: DefaultUsage.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns applications, determined by the user for which the resource and/or resource series is not suitable.
 *
 * @return applications for which the resource and/or resource series is not suitable, or {@code null}.
 */
@Override
@XmlElement(name = "userDeterminedLimitations")
public InternationalString getUserDeterminedLimitations() {
    return userDeterminedLimitations;
}
 
Example 23
Source Project: sis   Source File: SimpleFormat.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated Replaced by {@link #getAlternateTitles()}
 *
 * @return name of the data transfer format(s).
 */
@Override
@Deprecated
public InternationalString getName() {
    return super.getTitle();
}
 
Example 24
Source Project: sis   Source File: SimpleMetadata.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Other information required to complete the citation that is not recorded elsewhere.
 * This is part of the information returned by {@link #getCitation()}.
 */
@Override
public InternationalString getOtherCitationDetails() {
    return null;
}
 
Example 25
Source Project: sis   Source File: SimpleCitation.java    License: Apache License 2.0 4 votes vote down vote up
@Deprecated
@Override public InternationalString                        getCollectiveTitle()         {return null;}
 
Example 26
Source Project: sis   Source File: AuthorityFactoryProxy.java    License: Apache License 2.0 4 votes vote down vote up
@Override AuthorityFactoryProxy<InternationalString> specialize(String typeName) {
    return this;
}
 
Example 27
public InternationalString getRemarks() {
	return base.getRemarks();
}
 
Example 28
Source Project: sis   Source File: AbstractParty.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return the name of the party.
 *
 * @return name of the party.
 */
@XmlElement(name = "name")
@UML(identifier="name", obligation=CONDITIONAL, specification=ISO_19115)
public InternationalString getName() {
    return name;
}
 
Example 29
Source Project: sis   Source File: DefaultIndividual.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns position of the individual in an organization, or {@code null} if none.
 *
 * @return position of the individual in an organization, or {@code null} if none.
 */
@XmlElement(name = "positionName")
@UML(identifier="positionName", obligation=CONDITIONAL, specification=ISO_19115)
public InternationalString getPositionName() {
    return positionName;
}
 
Example 30
public InternationalString getRemarks() {
	return base.getRemarks();
}