org.apache.tiles.request.ApplicationContext.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.apache.tiles.request.ApplicationContext.getResource()方法的一些代码示例,展示了ApplicationContext.getResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getResource()方法的具体详情如下:
包路径:org.apache.tiles.request.ApplicationContext
类名称:ApplicationContext
方法名:getResource

ApplicationContext.getResource介绍

[英]Return the application resource mapped to the specified path.
[中]返回映射到指定路径的应用程序资源。

代码示例

代码示例来源:origin: org.apache.tiles/tiles-request-api

/** {@inheritDoc} */
public ApplicationResource getResource(String localePath) {
  return context.getResource(localePath);
}

代码示例来源:origin: org.apache.tiles/tiles-test-common

/** {@inheritDoc} */
  @Override
  protected List<ApplicationResource> getSources(ApplicationContext applicationContext) {
    List<ApplicationResource> urls = new ArrayList<ApplicationResource>();
    urls.addAll(applicationContext
        .getResources("/WEB-INF/**/tiles-defs*.xml"));
    urls.add(applicationContext.getResource(
        "classpath:/org/apache/tiles/classpath-defs.xml"));
    urls.add(applicationContext.getResource(
        "classpath:/org/apache/tiles/freemarker-classpath-defs.xml"));
    urls.add(applicationContext.getResource(
      "classpath:/org/apache/tiles/velocity-classpath-defs.xml"));
    return urls;
  }
}

代码示例来源:origin: org.apache.tiles/tiles-extras

Collection<ApplicationResource> resources = applicationContext
    .getResources("classpath*:META-INF/MANIFEST.MF");
ApplicationResource mainResource = applicationContext.getResource("/META-INF/MANIFEST.MF");
if (mainResource != null) {
  resources.add(mainResource);

代码示例来源:origin: org.apache.tiles/tiles-request-api

/** {@inheritDoc} */
public ApplicationResource getResource(ApplicationResource base, Locale locale) {
  return context.getResource(base, locale);
}

代码示例来源:origin: org.apache.tiles/tiles-test-alt

/** {@inheritDoc} */
@Override
protected List<ApplicationResource> getSources(ApplicationContext applicationContext) {
  List<ApplicationResource> urls = new ArrayList<ApplicationResource>(URL_COUNT);
  urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-defs.xml"));
  urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-freemarker-defs.xml"));
  urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-velocity-defs.xml"));
  return urls;
}

代码示例来源:origin: org.apache.tiles/tiles-core

/**
 * Returns a list containing the resources to be parsed. By default, it returns a
 * list containing the resource at "/WEB-INF/tiles.xml".
 * @param applicationContext The Tiles application context.
 * @return The resources.
 * @since 2.1.1
 */
protected List<ApplicationResource> getSources(ApplicationContext applicationContext) {
  List<ApplicationResource> retValue = new ArrayList<ApplicationResource>(1);
  retValue.add(applicationContext.getResource("/WEB-INF/tiles.xml"));
  return retValue;
}

代码示例来源:origin: org.apache.tiles/tiles-core

/** {@inheritDoc} */
public boolean refreshRequired() {
  boolean status = false;
  Set<String> paths = lastModifiedDates.keySet();
  try {
    for (String path : paths) {
      Long lastModifiedDate = lastModifiedDates.get(path);
      ApplicationResource resource = applicationContext.getResource(path);
      long newModDate = resource.getLastModified();
      if (newModDate != lastModifiedDate) {
        status = true;
        break;
      }
    }
  } catch (IOException e) {
    log.warn("Exception while monitoring update times.", e);
    return true;
  }
  return status;
}

代码示例来源:origin: org.apache.tiles/tiles-core

/** {@inheritDoc} */
public Map<String, Definition> getDefinitions(Locale customizationKey) {
  ArrayList<Locale> postfixes = computeLocales(customizationKey);
  Map<String, Definition> localeDefsMap = new HashMap<String, Definition>();
  // process the postfixes from the root to the most specific
  for (Locale postfix : postfixes) {
    // For each postfix, all the sources must be loaded.
    for (ApplicationResource resource : sources) {
      ApplicationResource newResource = applicationContext.getResource(resource, postfix);
      if (newResource != null) {
        Map<String, Definition> defsMap = loadDefinitionsFromResource(newResource);
        if (defsMap != null) {
          localeDefsMap.putAll(defsMap);
        }
      }
    }
  }
  return localeDefsMap;
}

代码示例来源:origin: org.apache.tiles/tiles-extras

private boolean renderAttempt(final String template, final Request request) throws IOException {
  boolean result = false;
  if (Cache.attemptTemplate(template)) {
    try {
      if (null != applicationContext.getResource(template)) {
        renderer.render(template, request);
        result = true;
      }
    } catch (IOException ex) {
      if (ex.getMessage().contains(template)) {
        // expected outcome. continue loop.
        LOG.trace(ex.getMessage());
      } else {
        // comes from an inner templateAttribute.render(..) so throw on
        throw ex;
      }
    } catch (RuntimeException ex) {
      if (ex.getMessage().contains(template)) {
        // expected outcome. continue loop.
        LOG.trace(ex.getMessage());
      } else {
        // comes from an inner templateAttribute.render(..) so throw on
        throw ex;
      }
    }
    Cache.update(template, result);
  }
  return result;
}

代码示例来源:origin: org.apache.tiles/tiles-core

/**
 * Loads the raw definitions from the sources associated with a locale.
 *
 * @param customizationKey The locale to use when loading Resources.
 * @return The loaded definitions.
 * @since 2.1.3
 */
protected Map<String, Definition> loadRawDefinitionsFromResources(
    Locale customizationKey) {
  Map<String, Definition> localeDefsMap;
  Locale parentLocale = LocaleUtil.getParentLocale(customizationKey);
  localeDefsMap = new LinkedHashMap<String, Definition>();
  if (parentLocale != null) {
    Map<String, Definition> parentDefs = loadRawDefinitionsFromResources(parentLocale);
    if (parentDefs != null) {
      localeDefsMap.putAll(parentDefs);
    }
  }
  // For each source, the resource must be loaded.
  for (ApplicationResource resource : sources) {
    ApplicationResource newResource = applicationContext.getResource(resource, customizationKey);
    if (newResource != null) {
      Map<String, Definition> defsMap = loadDefinitionsFromResource(newResource);
      if (defsMap != null) {
        localeDefsMap.putAll(defsMap);
      }
    }
  }
  return localeDefsMap;
}

相关文章