Search in sources :

Example 6 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class SiteContentController method siteContentHomePage.

/**
 * controller for site content home pages
 */
@RequestMapping(name = "siteContentHome", value = "/s", method = RequestMethod.GET)
public String siteContentHomePage(Model model, @SiteParam Site site) throws IOException {
    Theme theme = site.getTheme();
    Map<String, Object> pageConfig = theme.getConfigMap("siteContent");
    String homeRepoKey = (String) pageConfig.get("homeRepoKey");
    if (homeRepoKey == null) {
        throw new RuntimeConfigurationException("Content repo key for site content home page not configured for theme " + theme.toString());
    }
    return renderSiteContent(model, site, homeRepoKey);
}
Also used : RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) Theme(org.ambraproject.wombat.config.theme.Theme) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class SiteSet method create.

public static SiteSet create(List<? extends Map<String, ?>> siteSpecifications, ThemeGraph themeGraph) {
    List<Site> sites = Lists.newArrayListWithCapacity(siteSpecifications.size());
    for (Map<String, ?> siteSpec : siteSpecifications) {
        String siteKey = (String) siteSpec.get("key");
        String themeKey = (String) siteSpec.get("theme");
        String siteType = (String) siteSpec.get("type");
        Theme theme = themeGraph.getTheme(themeKey);
        if (theme == null) {
            throw new RuntimeException(String.format("No theme with key=\"%s\" found (for site: %s)", themeKey, siteKey));
        }
        Map<String, ?> resolveDefinition = (Map<String, ?>) siteSpec.get("resolve");
        SiteRequestScheme requestScheme = resolveDefinition != null ? parseRequestScheme(resolveDefinition) : SiteRequestScheme.builder().setPathToken(siteKey).build();
        sites.add(new Site(siteKey, theme, requestScheme, siteType));
    }
    validateSchemes(sites);
    return new SiteSet(sites);
}
Also used : SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) Theme(org.ambraproject.wombat.config.theme.Theme) BiMap(com.google.common.collect.BiMap) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) HashBiMap(com.google.common.collect.HashBiMap) Map(java.util.Map)

Example 8 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class SiteTemplateLoader method buildLoaders.

private static ImmutableMap<String, TemplateLoader> buildLoaders(ServletContext servletContext, SiteSet siteSet) throws IOException {
    ImmutableMap.Builder<String, TemplateLoader> builder = ImmutableMap.builder();
    // Add the loader for the application root page
    builder.put("NULLSITE", new WebappTemplateLoader(servletContext, "/WEB-INF/themes/root/app/"));
    // Add loader for each site
    for (Site site : siteSet.getSites()) {
        Theme leaf = site.getTheme();
        List<TemplateLoader> loaders = Lists.newArrayList();
        for (Theme theme : leaf.getInheritanceChain()) {
            loaders.add(theme.getTemplateLoader());
        }
        MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]));
        builder.put(site.getKey(), multiLoader);
    }
    return builder.build();
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) WebappTemplateLoader(freemarker.cache.WebappTemplateLoader) DelegatingTemplateLoader(org.ambraproject.wombat.config.DelegatingTemplateLoader) TemplateLoader(freemarker.cache.TemplateLoader) WebappTemplateLoader(freemarker.cache.WebappTemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) Theme(org.ambraproject.wombat.config.theme.Theme) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class SiteTransformerFactory method createTemplate.

private Templates createTemplate(Site site) {
    TransformerFactory factory = newTransformerFactory();
    Theme theme = site.getTheme();
    try (ThemeUriResolver resolver = new ThemeUriResolver(theme);
        InputStream transformFile = theme.getStaticResource(rootPath + templateFilename)) {
        factory.setURIResolver(resolver);
        return factory.newTemplates(new StreamSource(transformFile));
    } catch (TransformerConfigurationException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Theme(org.ambraproject.wombat.config.theme.Theme) IOException(java.io.IOException)

Example 10 with Theme

use of org.ambraproject.wombat.config.theme.Theme in project wombat by PLOS.

the class SiteContentController method renderSiteContent.

@RequestMapping(name = "siteContent", value = "/s/{pageName}")
public String renderSiteContent(Model model, @SiteParam Site site, @PathVariable String pageName) throws IOException {
    Theme theme = site.getTheme();
    Map<String, Object> pageConfig = theme.getConfigMap("siteContent");
    String repoKeyPrefix = (String) pageConfig.get("contentRepoKeyPrefix");
    if (repoKeyPrefix == null) {
        throw new RuntimeConfigurationException("Content repo prefix not configured for theme " + theme.toString());
    }
    String repoKey = repoKeyPrefix + "." + pageName;
    CacheKey cacheKey = CacheKey.create("siteContent_meta", repoKey);
    // versioning is not supported for site content
    ContentKey version = ContentKey.createForLatestVersion(repoKey);
    try {
        // Check for validity of the content repo key prior to rendering page. Return a 404 if no object found.
        editorialContentApi.requestMetadata(cacheKey, version);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
    model.addAttribute("siteContentRepoKey", repoKey);
    return site + "/ftl/siteContent/container";
}
Also used : ContentKey(org.ambraproject.wombat.service.remote.ContentKey) RuntimeConfigurationException(org.ambraproject.wombat.config.RuntimeConfigurationException) Theme(org.ambraproject.wombat.config.theme.Theme) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) EntityNotFoundException(org.ambraproject.wombat.service.EntityNotFoundException) CacheKey(org.ambraproject.wombat.util.CacheKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Theme (org.ambraproject.wombat.config.theme.Theme)13 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Site (org.ambraproject.wombat.config.site.Site)3 Test (org.junit.Test)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 FileNotFoundException (java.io.FileNotFoundException)2 Map (java.util.Map)2 RuntimeConfigurationException (org.ambraproject.wombat.config.RuntimeConfigurationException)2 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)2 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1