コード例 #1
0
  /**
   * Constructs a GroovyPageMetaInfo instance which holds the script class, modified date and so on
   *
   * @param inputStream The InputStream to construct the GroovyPageMetaInfo instance from
   * @param res The Spring Resource to construct the MetaInfo from
   * @param pageName The name of the page (can be null, in which case method responsible for
   *     calculating appropriate alternative)
   * @return The GroovyPageMetaInfo instance
   */
  protected GroovyPageMetaInfo buildPageMetaInfo(
      InputStream inputStream, Resource res, String pageName) {
    String name = establishPageName(res, pageName);

    long lastModified = establishLastModified(res);

    GroovyPageParser parser;
    String path = getPathForResource(res);
    try {
      parser = new GroovyPageParser(name, path, path, inputStream);
    } catch (IOException e) {
      throw new GroovyPagesException(
          "I/O parsing Groovy page ["
              + (res != null ? res.getDescription() : name)
              + "]: "
              + e.getMessage(),
          e);
    }
    InputStream in = parser.parse();

    // Make a new metaInfo
    GroovyPageMetaInfo metaInfo = createPageMetaInfo(parser, lastModified, in);
    try {
      metaInfo.setPageClass(compileGroovyPage(in, name, path, metaInfo));
      metaInfo.setHtmlParts(parser.getHtmlPartsArray());
    } catch (GroovyPagesException e) {
      metaInfo.setCompilationException(e);
    }

    if (!name.startsWith(GENERATED_GSP_NAME_PREFIX)) {
      pageCache.put(name, metaInfo);
    }

    return metaInfo;
  }