예제 #1
0
 private void logResourceDirectory(Resource resource) {
   if (first) {
     first = false;
     if (logger != null && logger.isInfoEnabled() && resource instanceof InputStreamResource) {
       File file = ((InputStreamResource) resource).getFile();
       if (file != null && file.exists()) {
         String uri = resource.getName().replace('\\', '/');
         String abs = file.getAbsolutePath().replace('\\', '/');
         if (abs.endsWith(uri)) {
           abs = abs.substring(0, abs.length() - uri.length());
         } else {
           int i = abs.lastIndexOf('/');
           if (i > 0) {
             abs = abs.substring(0, i);
           } else {
             abs = "/";
           }
         }
         logger.info(
             "Load httl template from"
                 + (reloadable ? " RELOADABLE" : "")
                 + " directory "
                 + abs
                 + " by "
                 + getClass().getSimpleName()
                 + ".");
       }
     }
   }
 }
예제 #2
0
 private String findMessageByLocale(String key, Locale locale) {
   String file = messageBasename + (locale == null ? "" : "_" + locale) + messageSuffix;
   EncodingProperties properties = messageCache.get(file);
   if ((properties == null || reloadable) && engine.hasResource(file)) {
     if (properties == null) {
       properties = new EncodingProperties();
       EncodingProperties old = messageCache.putIfAbsent(file, properties);
       if (old != null) {
         properties = old;
       }
     }
     try {
       Resource resource = engine.getResource(file);
       if (properties.getLastModified() < resource.getLastModified()) {
         String encoding = (StringUtils.isEmpty(messageEncoding) ? "UTF-8" : messageEncoding);
         properties.load(resource.openStream(), encoding, resource.getLastModified());
       }
     } catch (IOException e) {
       if (logger != null && logger.isErrorEnabled()) {
         logger.error(
             "Failed to load httl message file "
                 + file
                 + " with locale "
                 + locale
                 + ", cause: "
                 + e.getMessage(),
             e);
       }
     }
   }
   if (properties != null) {
     String value = properties.getProperty(key);
     if (StringUtils.isNotEmpty(value)) {
       return value;
     }
   }
   if (locale != null) {
     return findMessageByLocale(key, LocaleUtils.getParentLocale(locale));
   }
   return null;
 }