Retrieve a I18n instance by resource name.

@param resource resource name. See {@link
ResourceBundle#getBundle(String) ResourceBundle.getBundle()}
965986
public static synchronized I18n getI18n(String resource) {
        I18n instance = (I18n)mapping.get(resource);
        if (instance == null) {
            instance = new I18n(ResourceBundle.getBundle(resource,
                                                         Locale.getDefault(),
                                                         getClassLoader()));
            mapping.put(resource, instance);
        }
        return instance;
    }
781320
public static String getResourceUri(Resource resource) {
        try {
            return resource.getURI().toString();
        } catch (FileNotFoundException e) {
            return resource.getDescription();
        } catch (IOException e) {
            throw new RuntimeException("Could not create URI for resource: " + resource, e);
        }
    }
1032463
public static PropertyResourceBundle getBundle(String baseName, Locale locale) throws UnsupportedEncodingException, IOException{
		InputStream is = UTF8PropertyResourceBundle.class.getResourceAsStream("/"+baseName + "_"+locale.toString()+PROPERTIES_EXT);
		if(is != null){
			return new PropertyResourceBundle(new InputStreamReader(is, "UTF-8"));
		}
		return null;
	}
713113
@Override
	public Reader getResource(String resourceName) throws ResourceNotFoundException {

		return getResource(null, resourceName, false);
	}
778693
public static ResourceManager get(String bundleName) {
        ResourceManager rm = (ResourceManager) nameToRM.get(bundleName);
        if (rm == null) {
            ResourceBundle rb = ResourceBundle.getBundle(bundleName);
            rm = new ResourceManager(rb);
            nameToRM.put(bundleName, rm);
        }
        return rm;
    }
540526
@Override
	public String retrieveLocale(String lang) {
		String r = locales.get(lang);
		if (r == null) {
			try {
				URL u = getClass().getResource("/locales-" + lang + ".xml");
				if (u == null) {
					throw new IllegalArgumentException("Unable to load locale " +
							lang + ". Make sure you have a file called " +
							"'/locales-" + lang + ".xml' at the root of your " +
							"classpath. Did you add the CSL locale files to "
							+ "your classpath?");
				}
				r = CSLUtils.readURLToString(u, "UTF-8");
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			locales.put(lang, r);
		}
		return r;
	}
946401
public static List<URL> getResources(String resource) {
		final Enumeration<URL> resources;
		try {
			resources = ClassLoaderUtil.getClassLoader().getResources(resource);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		return CollectionUtil.newArrayList(resources);
	}
462513
public static InputStream getResourceAsInputStream(String resource) {
        InputStream in = classLoaderWrapper.getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        return in;
    }
267762
Boolean isResource(String resource) {
		Boolean isResource = false;
		if (!utils.isIdentifier(resource)) {
			try {
				String clazz = getControllerClass(resource);
				if (clazz != null) {
					Class.forName(clazz);
					isResource = true;
				}
			} catch (ClassNotFoundException e) {
				// It isn't a resource because there isn't a controller for it
			}
		}
		return isResource;
	}
387014
public static String getI18nString(ResourceBundle bundle, String key, String def) {
        String s = bundle != null ? bundle.getString(key) : null;
        return s != null ? s : def;
    }
1000486
@Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.properties")
    public Result getBundleResource(@PathParameter("file") String file,
                                    @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) {

        // Extract the locale from file
        if (Strings.isNullOrEmpty(file)) {
            return notFound().as(MimeTypes.TEXT);
        }

        Locale locale = InternationalizationService.DEFAULT_LOCALE;
        if (file.contains("_")) {
            // We got a locale
            locale = Locale.forLanguageTag(file.substring(file.indexOf('_') + 1).replace("_", "-"));
        }

        // Check if we have received a etag
        String etag = service.etag(locale);
        if (ifNoneMatch != null && ifNoneMatch.equals(etag)) {
            return new Result(Status.NOT_MODIFIED);
        }

        Collection<ResourceBundle> bundles = service.bundles(locale);

        // Do we have this locale
        if (bundles.isEmpty()) {
            // No, return not found
            return notFound().as(MimeTypes.TEXT);
        } else {
            StringBuilder builder = new StringBuilder();
            for (ResourceBundle bundle : bundles) {
                for (String key : bundle.keySet()) {
                    builder.append(key).append("=").append(bundle.getString(key)).append("\n");
                }
            }
            return ok(builder.toString()).as(MimeTypes.TEXT).with(HeaderNames.ETAG, etag);
        }
    }
171150
public static String readStr(String resource, Charset charset) {
		return getResourceObj(resource).readStr(charset);
	}
168084
protected String determineResourceName(final Resource resource) {
        String resourceName = null;

        if (resource instanceof ContextResource) {
            resourceName = ((ContextResource) resource).getPathWithinContext();

        } else if (resource instanceof ByteArrayResource) {
            resourceName = resource.getDescription();

        } else {
            try {
                resourceName = resource.getFile().getAbsolutePath();
            } catch (IOException e) {
                resourceName = resource.getFilename();
            }
        }
        return resourceName;
    }
449665
public String get(String key) {
        try { 
            return bundle.getString(key); 
        }catch(MissingResourceException e) { 
            logger.warn("Missing resource.", e);
            return key; 
        }
    }
217113
public static URL getResource(String resource, Class<?> context)
    {
        return getResource(resource, context, false);
    }
110292
private NameAndLocale getNameAndLocale(CmsResource bundleRes) {

        String fileName = bundleRes.getName();
        if (TYPE_PROPERTIES_BUNDLE.equals(OpenCms.getResourceManager().getResourceType(bundleRes).getTypeName())) {
            String localeSuffix = CmsStringUtil.getLocaleSuffixForName(fileName);
            if (localeSuffix == null) {
                return new NameAndLocale(fileName, null);
            } else {
                String base = fileName.substring(
                    0,
                    fileName.lastIndexOf(localeSuffix) - (1 /* cut off trailing underscore, too*/));
                Locale locale = CmsLocaleManager.getLocale(localeSuffix);
                return new NameAndLocale(base, locale);
            }
        } else {
            return new NameAndLocale(fileName, null);
        }
    }
202271
public static String getResourceAsString(Class<?> clazz, String resource) throws IOException {
        try (InputStream inputStream = clazz.getResourceAsStream(resource)) {
            return IoUtils.toString(inputStream);
        }
    }