本文整理汇总了Java中com.google.template.soy.data.UnsafeSanitizedContentOrdainer类的典型用法代码示例。如果您正苦于以下问题:Java UnsafeSanitizedContentOrdainer类的具体用法?Java UnsafeSanitizedContentOrdainer怎么用?Java UnsafeSanitizedContentOrdainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnsafeSanitizedContentOrdainer类属于com.google.template.soy.data包,在下文中一共展示了UnsafeSanitizedContentOrdainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTemplateData
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
static SoyMapData getTemplateData(String canonicalURL, String cdnPath, String faviconPath)
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,
"faviconPath", faviconPath);
}
示例2: strictContinuation
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
/**
* Return a {@link SanitizedContent} valued continuation. Rendering logic is delegated to the
* {@link WriteContinuation}, but it is assumed that the builder is the render target.
*/
static Continuation<SanitizedContent> strictContinuation(
WriteContinuation delegate,
final StringBuilder buffer,
OutputAppendable appendable,
final ContentKind kind) {
if (delegate.result().isDone()) {
return new ResultContinuation<>(
UnsafeSanitizedContentOrdainer.ordainAsSafe(buffer.toString(), kind));
}
return new AbstractContinuation<SanitizedContent>(delegate, appendable) {
@Override
Continuation<SanitizedContent> nextContinuation(WriteContinuation next) {
return strictContinuation(next, buffer, appendable, kind);
}
};
}
示例3: render
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Override
public RenderResult render(LoggingAdvisingAppendable appendable, RenderContext context)
throws IOException {
RenderResult result = delegate.render(buffer, context);
if (result.isDone()) {
SoyValue resultData =
kind == null
? StringData.forValue(buffer.toString())
: UnsafeSanitizedContentOrdainer.ordainAsSafe(buffer.toString(), kind);
for (SoyJavaPrintDirective directive : directives) {
resultData = directive.applyForJava(resultData, ImmutableList.<SoyValue>of());
}
appendable.append(resultData.coerceToString());
}
return result;
}
示例4: getResolvedValue
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
private SoyString getResolvedValue() {
SoyString local = resolvedValue;
if (local == null) {
if (buffer != null) {
String string = buffer.toString();
// This drops logs, but that is sometimes necessary. We should make sure this only happens
// when it has to by making sure that renderAndResolve is used for all printing usecases
if (contentKind != null) {
local = UnsafeSanitizedContentOrdainer.ordainAsSafe(string, contentKind);
} else {
local = StringData.forValue(string);
}
resolvedValue = local;
} else {
throw new AssertionError("getResolvedValue() should only be called if the value isDone.");
}
}
return local;
}
示例5: renderStrict
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Override
public SanitizedContent renderStrict() {
StringBuilder sb = new StringBuilder();
TemplateNode template =
baseTofu.renderMain(
sb,
templateName,
data,
ijData,
activeDelPackageNames,
msgBundle,
idRenamingMap,
cssRenamingMap,
debugSoyTemplateInfo);
enforceContentKind(template);
// Use the expected instead of actual content kind; that way, if an HTML template is rendered
// as TEXT, we will return TEXT.
return UnsafeSanitizedContentOrdainer.ordainAsSafe(sb.toString(), expectedContentKind);
}
示例6: escapeHtml
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
public static SanitizedContent escapeHtml(SoyValue value) {
if (value == null) {
// jbcsrc uses null as null.
value = NullData.INSTANCE;
}
Dir valueDir = null;
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
if (sanitizedContent.getContentKind() == SanitizedContent.ContentKind.HTML) {
return (SanitizedContent) value;
}
valueDir = sanitizedContent.getContentDirection();
}
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
EscapingConventions.EscapeHtml.INSTANCE.escape(value.coerceToString()),
SanitizedContent.ContentKind.HTML,
valueDir);
}
示例7: changeNewlineToBr
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
public static SoyString changeNewlineToBr(SoyValue value) {
String result = NEWLINE_PATTERN.matcher(coerceToString(value)).replaceAll("<br>");
// Make sure to transmit the known direction, if any, to any downstream directive that may need
// it, e.g. BidiSpanWrapDirective. Since a known direction is carried only by SanitizedContent,
// and the transformation we make is only valid in HTML, we only transmit the direction when we
// get HTML SanitizedContent.
// TODO(user): Consider always returning HTML SanitizedContent.
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
if (sanitizedContent.getContentKind() == ContentKind.HTML) {
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
result, ContentKind.HTML, sanitizedContent.getContentDirection());
}
}
return StringData.forValue(result);
}
示例8: insertWordBreaks
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
public static SoyString insertWordBreaks(SoyValue value, int maxCharsBetweenWordBreaks) {
String result =
new InsertWordBreaks(maxCharsBetweenWordBreaks).processString(coerceToString(value));
// Make sure to transmit the known direction, if any, to any downstream directive that may need
// it, e.g. BidiSpanWrapDirective. Since a known direction is carried only by SanitizedContent,
// and the transformation we make is only valid in HTML, we only transmit the direction when we
// get HTML SanitizedContent.
// TODO(user): Consider always returning HTML SanitizedContent.
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
if (sanitizedContent.getContentKind() == ContentKind.HTML) {
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
result, ContentKind.HTML, sanitizedContent.getContentDirection());
}
}
return StringData.forValue(result);
}
示例9: testEscapeJsValue
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Test
public void testEscapeJsValue() {
assertEquals( // Adds quotes.
"'Don\\x27t run with \\x22scissors\\x22.\\n'",
Sanitizers.escapeJsValue("Don't run with \"scissors\".\n"));
assertEquals( // SoyValue version does the same as String version.
"'Don\\x27t run with \\x22scissors\\x22.\\n'",
Sanitizers.escapeJsValue(StringData.forValue("Don't run with \"scissors\".\n")));
assertEquals(" 4.0 ", Sanitizers.escapeJsValue(IntegerData.forValue(4)));
assertEquals(" 4.5 ", Sanitizers.escapeJsValue(FloatData.forValue(4.5)));
assertEquals(" true ", Sanitizers.escapeJsValue(BooleanData.TRUE));
assertEquals(" null ", Sanitizers.escapeJsValue(NullData.INSTANCE));
assertEquals(
"foo() + bar",
Sanitizers.escapeJsValue(
UnsafeSanitizedContentOrdainer.ordainAsSafe(
"foo() + bar", SanitizedContent.ContentKind.JS)));
// Wrong content kind should be wrapped in a string.
assertEquals(
"'foo() + bar'",
Sanitizers.escapeJsValue(
UnsafeSanitizedContentOrdainer.ordainAsSafe(
"foo() + bar", SanitizedContent.ContentKind.HTML)));
}
示例10: testCleanHtml
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Test
public void testCleanHtml() {
assertEquals(
UnsafeSanitizedContentOrdainer.ordainAsSafe("<em>foo</em>", ContentKind.HTML),
Sanitizers.cleanHtml("<em>f<object>oo</em>"));
assertEquals(
UnsafeSanitizedContentOrdainer.ordainAsSafe("<em>foo</em>", ContentKind.HTML),
Sanitizers.cleanHtml(StringData.forValue("<em>f<object>oo</em>")));
assertEquals(
UnsafeSanitizedContentOrdainer.ordainAsSafe("<em>foo</em>", ContentKind.HTML, Dir.LTR),
Sanitizers.cleanHtml(
UnsafeSanitizedContentOrdainer.ordainAsSafe("<em>f<object>oo</em>", ContentKind.CSS)));
// Input of ContentKind.HTML is left alone.
assertEquals(
UnsafeSanitizedContentOrdainer.ordainAsSafe("<script>notevil()</script>", ContentKind.HTML),
Sanitizers.cleanHtml(
UnsafeSanitizedContentOrdainer.ordainAsSafe(
"<script>notevil()</script>", ContentKind.HTML)));
}
示例11: testApplyForTofu
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Test
public void testApplyForTofu() {
NoAutoescapeDirective noAutoescapeDirective = new NoAutoescapeDirective();
assertTofuOutput("", "", noAutoescapeDirective);
assertTofuOutput("identName", "identName", noAutoescapeDirective);
assertTofuOutput("<b>rich text</b>", "<b>rich text</b>", noAutoescapeDirective);
assertTofuOutput(
"not.html { font-name: \"Arial\" 'Helvetica' }",
"not.html { font-name: \"Arial\" 'Helvetica' }",
noAutoescapeDirective);
// Explicitly reject "text".
assertTofuOutput(
"zSoyz",
UnsafeSanitizedContentOrdainer.ordainAsSafe("xyz", SanitizedContent.ContentKind.TEXT),
noAutoescapeDirective);
}
示例12: testEscapeUri
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
@Test
public final void testEscapeUri() {
BasicEscapeDirective escapeUri = new BasicEscapeDirective.EscapeUri();
assertTofuOutput("", "", escapeUri);
assertTofuOutput("a%25b%20%3E%20c", "a%b > c", escapeUri);
assertTofuOutput(
"a%25bc%20%3E%20d",
UnsafeSanitizedContentOrdainer.ordainAsSafe("a%bc > d", SanitizedContent.ContentKind.HTML),
escapeUri);
// NOTE: URIs are not treated specially (e.g. /redirect?continue={$url} should not allow $url
// to break out and add other query params, and would be unexpected.)
assertTofuOutput(
"a%25bc%20%3E%20d",
UnsafeSanitizedContentOrdainer.ordainAsSafe("a%bc > d", SanitizedContent.ContentKind.URI),
escapeUri);
new JsSrcPrintDirectiveTestBuilder()
.addTest("", "''", escapeUri)
.addTest("a%25b%20%3E%20c", " 'a%b > c' ", escapeUri)
.addTest(
"a%25bc%20%3E%20d", "soydata.VERY_UNSAFE.ordainSanitizedHtml('a%bc > d')", escapeUri)
.addTest(
"a%25bc%20%3E%20d", "soydata.VERY_UNSAFE.ordainSanitizedUri('a%bc > d')", escapeUri)
.runTests();
}
示例13: cleanHtml
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
/**
* Normalizes the input HTML of a given directionality while preserving "safe" tags.
*
* @param optionalSafeTags to add to the basic whitelist of formatting safe tags
* @return the normalized input, in the form of {@link SanitizedContent} of {@link
* ContentKind#HTML}
*/
public static SanitizedContent cleanHtml(
String value, Dir contentDir, Collection<? extends OptionalSafeTag> optionalSafeTags) {
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
stripHtmlTags(value, TagWhitelist.FORMATTING.withOptionalSafeTags(optionalSafeTags), true),
ContentKind.HTML,
contentDir);
}
示例14: filterImageDataUri
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
/** Makes sure that the given input is a data URI corresponding to an image. */
public static SanitizedContent filterImageDataUri(String value) {
if (EscapingConventions.FilterImageDataUri.INSTANCE.getValueFilter().matcher(value).find()) {
// NOTE: No need to escape.
return UnsafeSanitizedContentOrdainer.ordainAsSafe(value, ContentKind.URI);
}
logger.log(Level.WARNING, "|filterImageDataUri received bad value ''{0}''", value);
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
EscapingConventions.FilterImageDataUri.INSTANCE.getInnocuousOutput(),
SanitizedContent.ContentKind.URI);
}
示例15: filterTelUri
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入依赖的package包/类
/** Makes sure that the given input is a tel URI. */
public static SanitizedContent filterTelUri(String value) {
if (EscapingConventions.FilterTelUri.INSTANCE.getValueFilter().matcher(value).find()) {
// NOTE: No need to escape. Escaping for other contexts (e.g. HTML) happen after this.
return UnsafeSanitizedContentOrdainer.ordainAsSafe(value, ContentKind.URI);
}
logger.log(Level.WARNING, "|filterTelUri received bad value ''{0}''", value);
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
EscapingConventions.FilterTelUri.INSTANCE.getInnocuousOutput(),
SanitizedContent.ContentKind.URI);
}