Java Code Examples for org.opengis.util.InternationalString#toString()
The following examples show how to use
org.opengis.util.InternationalString#toString() .
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 File: ShapefileAssistantPage3.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); String text = null; if (value != null) { Style style = (Style) value; InternationalString title = style.getDescription().getTitle(); if (title != null) { text = title.toString(); }else { text = "Default Styler"; } } label.setText(text); return label; }
Example 2
Source File: Warnings.java From sis with Apache License 2.0 | 6 votes |
/** * 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); final String[] sources = exceptionSources.get(cause); // See comment in 'toString(Locale)'. if (sources != null) { return Errors.getResources(errorLocale).getString(Errors.Keys.UnparsableStringInElement_2, sources); } else { return cause.toString(); } } }
Example 3
Source File: NameToIdentifier.java From sis with Apache License 2.0 | 6 votes |
/** * Returns a string representation of the given name in the given locale, with paranoiac checks against null value. * Such null values should never happen since the properties used here are mandatory, but we try to make this class * robust to broken implementations. * * @param name the name from which to get the localized string, or {@code null}. * @param locale the locale, or {@code null} for a call to {@code name.toString()}. * @return the localized string representation, or {@code null} if the given name was null. */ public static String toString(final GenericName name, final Locale locale) { if (name != null) { if (locale != null) { final InternationalString i18n = name.toInternationalString(); if (i18n != null) { final String s = i18n.toString(locale); if (s != null) { return s; } } } return name.toString(); } return null; }
Example 4
Source File: PT_FreeText.java From sis with Apache License 2.0 | 6 votes |
/** * Constructs a {@linkplain TextGroup text group} from the given {@link InternationalString} * if it contains at least one non-root locale. Otherwise returns {@code null}, meaning that * the simpler {@link GO_CharacterString} construct should be used instead. * * @param text an international string which could have several translations embedded for the same text. * @return a {@code PT_FreeText} instance if the given text has several translations, or {@code null} otherwise. */ public static PT_FreeText create(final InternationalString text) { if (text instanceof DefaultInternationalString) { final DefaultInternationalString df = (DefaultInternationalString) text; final Set<Locale> locales = df.getLocales(); final TextGroup[] textGroup = new TextGroup[locales.size()]; int n = 0; for (final Locale locale : locales) { if (locale != null && !locale.equals(Locale.ROOT)) { textGroup[n++] = new TextGroup(locale, text.toString(locale)); } } if (n != 0) { /* * Invoke toString(Locale) instead than toString() even if the locale is null, * since the desired fallback is typically Locale.ROOT instead than the system * default. It is usually safer to avoid null value, but in this particular case * the implementation (DefaultInternationalString) is known to support null. */ final Context context = Context.current(); return new PT_FreeText(df.toString(context != null ? context.getLocale() : null), ArraysExt.resize(textGroup, n)); } } return null; }
Example 5
Source File: DefaultMetadata.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the file identifier of the metadata to which this metadata is a subset (child). * * @return identifier of the metadata to which this metadata is a subset, or {@code null}. * * @deprecated As of ISO 19115:2014, replaced by {@link #getParentMetadata()}. */ @Override @Deprecated @Dependencies("getParentMetadata") @XmlElement(name = "parentIdentifier", namespace = LegacyNamespaces.GMD) public String getParentIdentifier() { if (FilterByVersion.LEGACY_METADATA.accept()) { final Citation parentMetadata = getParentMetadata(); if (parentMetadata != null) { final InternationalString title = parentMetadata.getTitle(); if (title != null) { return title.toString(); } } } return null; }
Example 6
Source File: TransformCommand.java From sis with Apache License 2.0 | 6 votes |
/** * 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 7
Source File: ReferencingFunctions.java From sis with Apache License 2.0 | 6 votes |
/** * 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(); }
Example 8
Source File: ReferencingFunctions.java From sis with Apache License 2.0 | 6 votes |
/** * 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(); }
Example 9
Source File: Citations.java From sis with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if at least one {@linkplain DefaultCitation#getTitle() title} or * {@linkplain DefaultCitation#getAlternateTitles() alternate title} in {@code c1} is leniently * equal to a title or alternate title in {@code c2}. The comparison is case-insensitive * and ignores every character which is not a {@linkplain Character#isLetterOrDigit(int) * letter or a digit}. The titles ordering is not significant. * * @param c1 the first citation to compare, or {@code null}. * @param c2 the second citation to compare, or {@code null}. * @return {@code true} if both arguments are non-null, and at least one title or alternate title matches. */ public static boolean titleMatches(final Citation c1, final Citation c2) { if (c1 != null && c2 != null) { if (c1 == c2) { return true; // Optimisation for a common case. } InternationalString candidate = c2.getTitle(); Iterator<? extends InternationalString> iterator = null; do { if (candidate != null) { final String unlocalized = candidate.toString(Locale.ROOT); if (titleMatches(c1, unlocalized)) { return true; } final String localized = candidate.toString(); if (!Objects.equals(localized, unlocalized) // Slight optimization for a common case. && titleMatches(c1, localized)) { return true; } } if (iterator == null) { iterator = nonEmptyIterator(c2.getAlternateTitles()); if (iterator == null) break; } if (!iterator.hasNext()) break; candidate = iterator.next(); } while (true); } return false; }
Example 10
Source File: Citations.java From sis with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: ResourceTree.java From sis with Apache License 2.0 | 5 votes |
/** * 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 File: Anchor.java From sis with Apache License 2.0 | 5 votes |
/** * Compares the value of this object with the given international string for order. * Null values are sorted last. * * @param other the string to compare with this anchor type. */ @Override public int compareTo(final InternationalString other) { final String ot; if (other == null || (ot = other.toString()) == null) { return (value != null) ? -1 : 0; } return (value != null) ? value.compareTo(ot) : +1; }
Example 13
Source File: WmsAssistantPage3.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); String text = null; if (value != null) { StyleImpl style = (StyleImpl) value; InternationalString title = style.getTitle(); text = title.toString(); } label.setText(text); return label; }
Example 14
Source File: SimpleIdentifier.java From sis with Apache License 2.0 | 5 votes |
/** * Version identifier for the namespace, as specified by the code authority. * When appropriate, the edition is identified by the effective date, coded * using ISO 8601 date format. * * @return a version inferred from the authority given at construction time, or {@code null} if none. */ @Override public String getVersion() { if (authority != null) { final InternationalString version = authority.getEdition(); if (version != null) { return version.toString(); } } return null; }
Example 15
Source File: Exceptions.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the message of the given exception, localized in the given locale if possible. * Some exceptions created by SIS can format a message in different locales. This method * returns such localized message if possible, or fallback on the standard JDK methods otherwise. * More specifically: * * <ul> * <li>If the given {@code exception} is null, then this method returns {@code null}.</li> * <li>Otherwise if the given {@code locale} is null, then this method returns {@link Exception#getMessage()}. * This is consistent with the {@link Localized} policy saying that null locale stands for "unlocalized" * message (usually in English) or message in the JVM {@linkplain Locale#getDefault() default locale}.</li> * <li>Otherwise if the given {@code exception} is an instance of {@link LocalizedException} providing * a non-null {@linkplain LocalizedException#getInternationalMessage() international message}, * then this method returns the result of {@link InternationalString#toString(Locale)}.</li> * <li>Otherwise this method returns {@link Exception#getLocalizedMessage()}.</li> * </ul> * * @param exception the exception from which to get the localize message, or {@code null}. * @param locale the preferred locale for the message, or {@code null} for the JVM default locale. * This locale is honored on a <cite>best-effort</cite> basis only. * @return the message in the given locale if possible, or {@code null} if the {@code exception} * argument was {@code null} or if the exception does not contain a message. * * @see LocalizedException#getLocalizedMessage() */ public static String getLocalizedMessage(final Throwable exception, final Locale locale) { if (exception == null) { return null; } if (locale == null) { return exception.getMessage(); // See the policy documented in LocalizedException.getMessage() } if (exception instanceof LocalizedException) { final InternationalString i18n = ((LocalizedException) exception).getInternationalMessage(); if (i18n != null) { final String message = i18n.toString(locale); if (message != null) { return message; } } } return exception.getLocalizedMessage(); }
Example 16
Source File: LocationFormat.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a localized version of the given international string, or {@code null} if none. */ private static String toString(final InternationalString i18n, final Locale locale) { return (i18n != null) ? i18n.toString(locale) : null; }
Example 17
Source File: StandardPanel.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Populate standard data. * * @param standardData the standard data */ private void populateStandardData(StandardData standardData) { Description description = standardData.description; String titleString = ""; String descriptionString = ""; if (description != null) { InternationalString title = description.getTitle(); if (title != null) { titleString = title.toString(); } InternationalString abstractDesc = description.getAbstract(); if (abstractDesc != null) { descriptionString = abstractDesc.toString(); } } if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.NAME) != null) { fieldConfigVisitor.populateTextField(FieldIdEnum.NAME, standardData.name); } if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.TITLE) != null) { fieldConfigVisitor.populateTextField(FieldIdEnum.TITLE, titleString); } if (fieldConfigVisitor.getFieldConfig(FieldIdEnum.DESCRIPTION) != null) { fieldConfigVisitor.populateTextField(FieldIdEnum.DESCRIPTION, descriptionString); } FieldConfigBase uomFieldConfig = fieldConfigManager.get(FieldIdEnum.UOM); if (uomFieldConfig != null) { uomFieldConfig.updateAttributeSelection(SelectedSymbol.getInstance().isRasterSymbol()); String uomString = ""; if (standardData.unit != null) { uomString = standardData.unit.getSEString(); fieldConfigVisitor.populateField( FieldIdEnum.UOM, getFilterFactory().literal(uomString)); } } }
Example 18
Source File: NameMeaning.java From sis with Apache License 2.0 | 3 votes |
/** * Returns the version of the namespace managed by the given authority. * Current Apache SIS implementation searches this information in the {@link Citation#getEdition()} property. * This approach is based on the assumption that the authority is some specification document or reference to * a database, not an organization. However this policy may be revisited in any future SIS version. * * @param authority the authority from which to get a version, or {@code null}. * @return the version, or {@code null} if none. * * @since 0.7 */ public static String getVersion(final Citation authority) { if (authority != null) { final InternationalString i18n = authority.getEdition(); if (i18n != null) { return i18n.toString(Locale.US); } } return null; }
Example 19
Source File: HTMLGenerator.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the localized version of the given string, or {@code null} if none. * * @param text the text to localize, or {@code null}. * @return the localized test, or {@code null}. * * @see #LOCALE */ static String toLocalizedString(final InternationalString text) { return (text != null) ? text.toString(LOCALE) : null; }
Example 20
Source File: Types.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the given international string in the given locale, or {@code null} if the given string is null. * If the given locale is {@code null}, then the {@code i18n} default locale is used. * * @param i18n the international string to get as a localized string, or {@code null} if none. * @param locale the desired locale, or {@code null} for the {@code i18n} default locale. * @return the localized string, or {@code null} if {@code i18n} is {@code null}. * * @since 0.8 */ public static String toString(final InternationalString i18n, final Locale locale) { return (i18n == null) ? null : (locale == null) ? i18n.toString() : i18n.toString(locale); }