public class

ICUConfig

extends java.lang.Object

 java.lang.Object

↳androidx.core.i18n.messageformat_icu.impl.ICUConfig

Gradle dependencies

compile group: 'androidx.core', name: 'core-i18n', version: '1.0.0-alpha01'

  • groupId: androidx.core
  • artifactId: core-i18n
  • version: 1.0.0-alpha01

Artifact androidx.core:core-i18n:1.0.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

ICUConfig is a class used for accessing ICU4J runtime configuration.

Summary

Fields
public static final java.lang.StringCONFIG_PROPS_FILE

Constructors
publicICUConfig()

Methods
public static java.lang.Stringget(java.lang.String name)

Get ICU configuration property value for the given name.

public static java.lang.Stringget(java.lang.String name, java.lang.String def)

Get ICU configuration property value for the given name.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final java.lang.String CONFIG_PROPS_FILE

Constructors

public ICUConfig()

Methods

public static java.lang.String get(java.lang.String name)

Get ICU configuration property value for the given name.

Parameters:

name: The configuration property name

Returns:

The configuration property value, or null if it does not exist.

public static java.lang.String get(java.lang.String name, java.lang.String def)

Get ICU configuration property value for the given name.

Parameters:

name: The configuration property name
def: The default value

Returns:

The configuration property value. If the property does not exist, def is returned.

Source

/*
 *******************************************************************************
 * Copyright (C) 2008-2010, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
package androidx.core.i18n.messageformat_icu.impl;

import androidx.annotation.RestrictTo;

import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.MissingResourceException;
import java.util.Properties;

/**
 * ICUConfig is a class used for accessing ICU4J runtime configuration.
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class ICUConfig {
    public static final String CONFIG_PROPS_FILE = "/com/ibm/icu/ICUConfig.properties";
    private static final Properties CONFIG_PROPS;

    static {
        CONFIG_PROPS = new Properties();
        try {
            InputStream is = ICUData.getStream(CONFIG_PROPS_FILE);
            if (is != null) {
                CONFIG_PROPS.load(is);
            }
        } catch (MissingResourceException mre) {
            // If it does not exist, ignore.
        } catch (IOException ioe) {
            // Any IO errors, ignore
        }
    }

    /**
     * Get ICU configuration property value for the given name.
     * @param name The configuration property name
     * @return The configuration property value, or null if it does not exist.
     */
    public static String get(String name) {
        return get(name, null);
    }

    /**
     * Get ICU configuration property value for the given name.
     * @param name The configuration property name
     * @param def The default value
     * @return The configuration property value.  If the property does not
     * exist, <code>def</code> is returned.
     */
    public static String get(String name, String def) {
        String val = null;
        final String fname = name;
        if (System.getSecurityManager() != null) {
            try {
                val = AccessController.doPrivileged(new PrivilegedAction<String>() {
                    @Override
                    public String run() {
                        return System.getProperty(fname);
                    }
                });
            } catch (AccessControlException e) {
                // ignore
                // TODO log this message
            }
        } else {
            val = System.getProperty(name);
        }

        if (val == null) {
            val = CONFIG_PROPS.getProperty(name, def);
        }
        return val;
    }
}