public static Charset getDefaultCharset()

in src/java/org/apache/turbine/util/LocaleUtils.java [136:190]


    public static Charset getDefaultCharset()
    {
        if (defaultCharSet == null)
        {
            /* Get the default charset and cache it in a static variable. */
            String charSet = Turbine.getConfiguration()
                    .getString(TurbineConstants.LOCALE_DEFAULT_CHARSET_KEY,
                            TurbineConstants.LOCALE_DEFAULT_CHARSET_DEFAULT);

            if (StringUtils.isNotEmpty(charSet))
            {
                defaultCharSet = charSetForName(charSet);
                log.debug("defaultCharSet = {} (From Properties)", defaultCharSet);
            }
        }

        Charset charset = defaultCharSet;

        if (charset == null) // can happen if set explicitly in the configuration
        {
            log.debug("Default charset is empty!");
            /* Default charset isn't specified, get the locale specific one. */
            Locale locale = getDefaultLocale();
            log.debug("Locale is {}", locale);

            if (!locale.equals(Locale.US))
            {
                log.debug("We don't have US Locale!");
                ServiceManager serviceManager = TurbineServices.getInstance();
                if (serviceManager.isRegistered(MimeTypeService.ROLE))
                {
                    try
                    {
                        MimeTypeService mimeTypeService = (MimeTypeService) serviceManager.getService(MimeTypeService.ROLE);
                        charset = charSetForName(mimeTypeService.getCharSet(locale));
                    }
                    catch (Exception e)
                    {
                        throw new RuntimeException(e);
                    }

                    log.debug("Charset now {}", charset);
                }
            }

            // The fallback to end all fallbacks
            if (charset == null)
            {
                charset = StandardCharsets.ISO_8859_1;
            }
        }

        log.debug("Returning default Charset of {}", charset);
        return charset;
    }