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);
}
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);
}
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();
}
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);
}
}
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";
}
Aggregations