Exemplo n.º 1
0
  private Asset getLocalizedAssetFromResource(Resource unlocalized, Locale locale) {
    Resource localized = locale == null ? unlocalized : unlocalized.forLocale(locale);

    if (localized == null || !localized.exists())
      throw new RuntimeException(
          String.format("Unable to locate asset '%s' (the file does not exist).", unlocalized));

    return getAssetForResource(localized);
  }
Exemplo n.º 2
0
  /**
   * Finds a localized resource.
   *
   * @param baseResource base resource, or null for classpath root
   * @param path path from baseResource to expected resource
   * @param locale locale to localize for, or null to not localize
   * @return resource, which may not exist
   */
  private Resource findLocalizedResource(Resource baseResource, String path, Locale locale) {
    Resource unlocalized = findResource(baseResource, path);

    if (locale == null || !unlocalized.exists()) {
      return unlocalized;
    }

    return localize(unlocalized, locale);
  }
Exemplo n.º 3
0
  private Asset getComponentAsset(
      ComponentResources resources, String expandedPath, Resource metaResource) {

    if (expandedPath.contains(":") || expandedPath.startsWith("/")) {
      return getAssetInLocale(resources.getBaseResource(), expandedPath, resources.getLocale());
    }

    // So, it's relative to the component.  First, check if there's a match using the 5.4 rules.

    if (metaResource.exists()) {
      return getAssetForResource(metaResource);
    }

    Resource oldStyle =
        findLocalizedResource(resources.getBaseResource(), expandedPath, resources.getLocale());

    if (oldStyle == null || !oldStyle.exists()) {
      return null;
    }

    return getAssetForResource(oldStyle);
  }
  private Asset getLocaleAsset(Locale locale, String jQueryUIPath) {

    final String prefix =
        String.format("%s/i18n/jquery.ui.datepicker-%s", jQueryUIPath, locale.getLanguage());
    final Resource withCountryExtension =
        typeCoercer.coerce(String.format("%s-%s.js", prefix, locale.getCountry()), Resource.class);

    if (withCountryExtension.exists()) {

      return assetSource.getClasspathAsset(withCountryExtension.getPath());
    }

    final Resource withLanguageExtension =
        typeCoercer.coerce(String.format("%s.js", prefix), Resource.class);

    if (withLanguageExtension.exists()) {

      return assetSource.getClasspathAsset(withLanguageExtension.getPath());
    }

    return null;
  }