@Override public ThemeResource getResource(String name, Optional<Breakpoint> breakpoint) { try { ThemeResource result = getResource(getActiveTheme(), name, breakpoint); return result; } catch (IOException e) { this.logger.warn("I/O Exception while resolving resource [{}]", name, e); return null; } }
private String getTemplateContent(String name, Optional<Breakpoint> breakpoint) throws TemplateNotFoundException, IOException { String result = getTemplateContent(getActiveTheme(), name, breakpoint); if (result == null) { throw new TemplateNotFoundException(); } return result; }
public Theme getTheme(Tenant tenant) { String themeId = getActiveThemeId(tenant); return getTheme(themeId, Optional.of(tenant), Collections.<Level>emptyList()); }
themeDirectory = getTenantThemeDirectory(tenant.get().getSlug(), themeId); themeDirectory = getGlobalThemeDirectory(themeId); Optional<Path> path = getClasspathThemePath(themeId); if (path.isPresent() && !ignore.contains(Level.CLASSPATH)) { try { parent = getTheme(themeId, Optional.<Tenant>absent(), Arrays.asList(level)); if (!level.equals(Level.THEME_DIRECTORY)) {
@Override public Template getTemplate(Theme theme, String name, Optional<Breakpoint> breakpoint) throws TemplateNotFoundException { try { String content = this.getTemplateContent(theme, name, breakpoint); Template template = new Template(generateTemplateId(name, breakpoint), content, true); return template; } catch (IOException e) { throw new TemplateNotFoundException(e); } }
public Theme getTheme(String themeName) { return getTheme(themeName, Optional.<Tenant>absent(), Collections.<Level>emptyList()); }
/** * Tries to get template content for a certain theme and breakpoint. Tries in order : - tenant theme folder in * persistent directory (example : data/tenants/thetenant/themes/thetheme/[breakpoint/]filename - global theme * folder in persistent directory (example : data/themes/thetheme/[breakpoint/]filename) - classpath (example uri : * /themes/thetheme/[breakpoint/]filename) For each step, checks the breakpoint (if set) and fallback on the * no-breakpoint file * * @param theme the theme for which to try and get the template content * @param name the name of the template to get * @param breakpoint the breakpoint for which to get the template content * @return the content of the template, or null if not found * @throws IOException when there is an IO exception getting the content */ private String getTemplateContent(Theme theme, String name, Optional<Breakpoint> breakpoint) throws IOException { ThemeResource resource = this.getResource(theme, name, breakpoint); if (resource == null) { return null; } switch (resource.getType()) { default: case FILE: return Files.toString(resource.getPath().toFile(), Charsets.UTF_8); case CLASSPATH_RESOURCE: return Resources.toString(Resources.getResource(resource.getPath().toString()), Charsets.UTF_8); } }
@Override public Optional<String> resolveModelPath(String id) { if (getThemeDefinition() == null) { return Optional.absent(); } Map<String, Model> models = getThemeDefinition().getModels(); if (models.containsKey(id)) { return Optional.fromNullable(models.get(id).getFile()); } return Optional.absent(); }
@Override public Template getGlobalTemplate(String name, Optional<Breakpoint> breakpoint) throws TemplateNotFoundException { try { return new Template(generateTemplateId(name, breakpoint), Resources.toString(Resources.getResource("templates/" + name), Charsets.UTF_8), true); } catch (IOException e) { throw new TemplateNotFoundException(); } }
@Override public Template getIndexTemplate(Optional<Breakpoint> breakpoint) throws TemplateNotFoundException { try { String content = this.getTemplateContent(INDEX_HTML, breakpoint); Template template = new Template(generateTemplateId(INDEX_HTML, breakpoint), content); return template; } catch (IOException e) { throw new TemplateNotFoundException(e); } }
public Theme getTheme() { return getTheme(this.context.getTenant()); }
return getResource(theme, name, Optional.<Breakpoint>absent()); return getResource(theme.getParent(), name, breakpoint);
@Override public Template getTemplate(String name, Optional<Breakpoint> breakpoint) throws TemplateNotFoundException { try { String content = this.getTemplateContent(name, breakpoint); Template template = new Template(generateTemplateId(name, breakpoint), content, true); return template; } catch (IOException e) { throw new TemplateNotFoundException(e); } }
public Theme getDefaultTheme() { return getTheme(themeSettings.getActive().getDefaultValue(), Optional.<Tenant>absent(), Collections.<Level>emptyList()); }