use of com.google.template.soy.data.SanitizedContent in project gerrit by GerritCodeReview.
the class IndexServlet method getTemplateData.
static SoyMapData getTemplateData(String canonicalURL, String cdnPath) throws URISyntaxException {
String canonicalPath = computeCanonicalPath(canonicalURL);
String staticPath = "";
if (cdnPath != null) {
staticPath = cdnPath;
} else if (canonicalPath != null) {
staticPath = canonicalPath;
}
// The resource path must be typed as safe for use in a script src.
// TODO(wyatta): Upgrade this to use an appropriate safe URL type.
SanitizedContent sanitizedStaticPath = UnsafeSanitizedContentOrdainer.ordainAsSafe(staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
return new SoyMapData("canonicalPath", canonicalPath, "staticResourcePath", sanitizedStaticPath);
}
use of com.google.template.soy.data.SanitizedContent in project gitiles by GerritCodeReview.
the class RepositoryIndexServlet method renderReadme.
private static Map<String, Object> renderReadme(HttpServletRequest req, RevWalk walk, GitilesView view, Config cfg, RevObject head) throws IOException {
RevTree rootTree;
try {
rootTree = walk.parseTree(head);
} catch (IncorrectObjectTypeException notTreeish) {
return null;
}
ReadmeHelper readme = new ReadmeHelper(walk.getObjectReader(), GitilesView.path().copyFrom(view).setRevision(Revision.HEAD).setPathPart("/").build(), MarkdownConfig.get(cfg), rootTree, req.getRequestURI());
readme.scanTree(rootTree);
if (readme.isPresent()) {
SanitizedContent html = readme.render();
if (html != null) {
return ImmutableMap.<String, Object>of("readmeHtml", html);
}
}
return null;
}
Aggregations