当前位置: 首页>>代码示例>>Java>>正文


Java TrustedResourceUrl类代码示例

本文整理汇总了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();
      }
    }
  }
 
开发者ID:mikesamuel,项目名称:closure-maven-plugin,代码行数:40,代码来源:Demo.java

示例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, &lt;b &gt;&lt;span style=color:blue  &gt;"
             + "W&lt;/span &gt;&lt;span style=color:green &gt;o&lt;/span &gt;"
             + "&lt;span style=color:yellow&gt;r&lt;/span &gt;"
             + "&lt;span style=color:orange&gt;l&lt;/span &gt;"
             + "&lt;span style=color:red    &gt;d&lt;/span&gt;"
             + "&lt;/b &gt;&lt;span style=color:purple &gt;"
             + "!&lt;/span&gt; &#9786;</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>");
 }
 
开发者ID:mikesamuel,项目名称:closure-maven-plugin,代码行数:62,代码来源:AdHocHtml.java

示例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);
}
 
开发者ID:google,项目名称:closure-templates,代码行数:9,代码来源:SanitizedContents.java

示例4: apply

import com.google.common.html.types.TrustedResourceUrl; //导入依赖的package包/类
@Override
public SoyValueProvider apply(Object obj) {
  return SanitizedContents.fromTrustedResourceUrl((TrustedResourceUrl) obj);
}
 
开发者ID:google,项目名称:closure-templates,代码行数:5,代码来源:SafeStringTypes.java

示例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);
}
 
开发者ID:google,项目名称:safe-html-types,代码行数:12,代码来源:HtmlConversions.java


注:本文中的com.google.common.html.types.TrustedResourceUrl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。