/** * 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; }
/** * Creates a GroovyPageMetaInfo instance from the given Parse object, and initialises it with the * the specified last modifed date and InputStream * * @param parse The Parse object * @param lastModified The last modified date * @param in The InputStream instance * @return A GroovyPageMetaInfo instance */ private GroovyPageMetaInfo createPageMetaInfo( GroovyPageParser parse, long lastModified, InputStream in) { GroovyPageMetaInfo pageMeta = new GroovyPageMetaInfo(); pageMeta.setJspTagLibraryResolver(jspTagLibraryResolver); pageMeta.setTagLibraryLookup(tagLibraryLookup); pageMeta.setContentType(parse.getContentType()); pageMeta.setLineNumbers(parse.getLineNumberMatrix()); pageMeta.setLastModified(lastModified); pageMeta.setJspTags(parse.getJspTags()); pageMeta.setCodecName(parse.getDefaultCodecDirectiveValue()); pageMeta.initCodec(); // just return groovy and don't compile if asked if (isReloadEnabled() || GrailsUtil.isDevelopmentEnv()) { pageMeta.setGroovySource(in); } return pageMeta; }