本文整理汇总了Java中com.google.common.html.types.TrustedResourceUrl类的典型用法代码示例。如果您正苦于以下问题:Java TrustedResourceUrl类的具体用法?Java TrustedResourceUrl怎么用?Java TrustedResourceUrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TrustedResourceUrl类属于com.google.common.html.types包,在下文中一共展示了TrustedResourceUrl类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderWall
import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
@VisibleForTesting
void renderWall(Target target, Update u, final Writer out)
throws IOException {
Nonce oneTimeCspNonce = Nonce.create(nonceGenerator);
ImmutableMap<String, Object> data = ImmutableMap.<String, Object>of(
"nonce", target.nonce.get().text,
"wall", u.getItems(),
"version", u.getVersion(),
"styles", ImmutableList.<TrustedResourceUrl>of(
TrustedResourceUrls.fromConstant(WebFiles.CSS_WALL_MAIN_CSS)),
"scripts", ImmutableList.<TrustedResourceUrl>of(
TrustedResourceUrls.fromConstant(WebFiles.JS_MAIN_JS),
TrustedResourceUrls.fromConstant(WebFiles.JS_COM_EXAMPLE_WALL_JS),
WALL_ITEM_JS.get(variant))
);
ImmutableMap<String, Object> ijData = ImmutableMap.<String, Object>of(
"csp_nonce", oneTimeCspNonce.text);
if (variant == DemoVariant.INSECURE) {
AdHocHtml.write(data, oneTimeCspNonce, this.cssRenamingMap, out);
return;
}
SoySauce.Renderer renderer = soySauce
.renderTemplate("com.example.demo.Wall")
.setData(data)
.setIj(ijData)
// .setMsgBundle(msgBundle)
// .setXidRenamingMap(idRenamingMap)
.setCssRenamingMap(cssRenamingMap)
;
try (ResponseWriter rw = new ResponseWriter(out)) {
WriteContinuation wc = renderer.render(rw);
while (!wc.result().isDone()) {
wc = wc.continueRender();
}
}
}
示例2: write
import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
static void write(
Map<String, ?> data, Nonce cspNonce, SoyCssRenamingMap cssRenamingMap,
Writer out)
throws IOException {
out.write("<!doctype html>");
out.write("<html>");
out.write("<head>");
out.write("<title>Wall</title>");
for (Object style : (Iterable<?>) data.get("styles")) {
String href = ((TrustedResourceUrl) style).getTrustedResourceUrlString();
out.write("<link rel=\"stylesheet\" href=\"" + href + "\" />");
}
for (Object script : (Iterable<?>) data.get("scripts")) {
String src = ((TrustedResourceUrl) script).getTrustedResourceUrlString();
out.write("<script src=\"" + src + "\""
+ " nonce=\"" + cspNonce.text + "\" nonce=\"" + cspNonce.text
+ "\"></script>");
}
out.write("</head>");
out.write("<body data-wall-version=\"" + data.get("version") + "\">");
out.write("<ul class=\"" + cssRenamingMap.get("wall") + "\">");
WallItems wallItems = (WallItems) data.get("wall");
for (WallItem item : wallItems.getItemList()) {
out.write("<li class=\"" + cssRenamingMap.get("wall-item") + "\""
+ " style=\"/*" + cspNonce.text + "*/"
+ "left: " + item.getCentroid().getXPercent() + "%;"
+ " top: " + item.getCentroid().getYPercent() + "%\">"
+ item.getHtmlUntrusted() // Intentional XSS Vulnerability
+ "</li>");
}
out.write("<li id=\"chip\" class=\"" + cssRenamingMap.get("blank") + "\">");
out.write("</li>");
out.write("</ul>");
out.write("<form id=\"scribble\" action=\"#\""
+ " onsubmit=\"/*" + cspNonce.text + "*/return false\">");
out.write("<table align=center>");
out.write("<tr>");
out.write("<th colspan=2>Enter some HTML<tr>");
out.write("<td>");
out.write("<textarea id=\"html\" rows=6 cols=60>"
+ "Hello, <b ><span style=color:blue >"
+ "W</span ><span style=color:green >o</span >"
+ "<span style=color:yellow>r</span >"
+ "<span style=color:orange>l</span >"
+ "<span style=color:red >d</span>"
+ "</b ><span style=color:purple >"
+ "!</span> ☺</textarea>");
out.write("<td rowspan=2>");
out.write("<input type=range min=0 max=100 value=50 step=0.5 id=y"
+ " orient=vertical>");
out.write("<tr>");
out.write("<td>");
out.write("<input type=range min=0 max=100 value=50 step=0.5 id=x>");
out.write("<br>");
out.write("<button id=\"scribble-submit\" type=\"button\">"
+ "Scribble</button>");
out.write("</table>");
out.write("</form>");
out.write("</body>");
out.write("</html>");
}
示例3: fromTrustedResourceUrl
import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
/**
* Converts a {@link TrustedResourceUrl} into a Soy {@link SanitizedContent} of kind
* TRUSTED_RESOURCE_URI.
*/
public static SanitizedContent fromTrustedResourceUrl(TrustedResourceUrl url) {
return SanitizedContent.create(
url.getTrustedResourceUrlString(), ContentKind.TRUSTED_RESOURCE_URI, Dir.LTR);
}
示例4: apply
import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
@Override
public SoyValueProvider apply(Object obj) {
return SanitizedContents.fromTrustedResourceUrl((TrustedResourceUrl) obj);
}
示例5: newTrustedResourceUrlForTest
import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
/**
* Creates a {@link TrustedResourceUrl} wrapping the given {@code string}. No validation is
* performed.
*
* <p>If possible please use the production API in
* {@link com.google.common.html.types.TrustedResourceUrls}
* instead.
*/
public static TrustedResourceUrl newTrustedResourceUrlForTest(String string) {
return UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract(string);
}