本文整理汇总了Java中com.google.template.soy.data.UnsafeSanitizedContentOrdainer.ordainAsSafe方法的典型用法代码示例。如果您正苦于以下问题:Java UnsafeSanitizedContentOrdainer.ordainAsSafe方法的具体用法?Java UnsafeSanitizedContentOrdainer.ordainAsSafe怎么用?Java UnsafeSanitizedContentOrdainer.ordainAsSafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.template.soy.data.UnsafeSanitizedContentOrdainer
的用法示例。
在下文中一共展示了UnsafeSanitizedContentOrdainer.ordainAsSafe方法的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: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: computeForJava
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入方法依赖的package包/类
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue value = args.get(0);
return UnsafeSanitizedContentOrdainer.ordainAsSafe(
BidiFunctionsRuntime.bidiDirAttr(
bidiGlobalDirProvider.get(), value, (args.size() == 2 && args.get(1).booleanValue())),
ContentKind.ATTRIBUTES);
}
示例13: jsIdentifier
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入方法依赖的package包/类
/**
* Validates that {@code identifier} matches a safe pattern for JS identifiers and ordains the
* value as JS.
*
* <p>TODO: this appears to be redundant with some code in JsSrcUtils.
*/
public static SanitizedContent jsIdentifier(String identifier) {
checkArgument(
VALID_JS_IDENTIFIER_PATTERN.matcher(identifier).matches(),
"JS identifier '%s' should match the pattern '%s'",
identifier,
VALID_JS_IDENTIFIER_PATTERN.pattern());
checkArgument(
!INVALID_JS_IDENTIFIERS.contains(identifier),
"JS identifier '%s' should not be a reserved word or match a literal",
identifier);
return UnsafeSanitizedContentOrdainer.ordainAsSafe(identifier, ContentKind.JS);
}
示例14: testApplyForTofu
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入方法依赖的package包/类
@Test
public void testApplyForTofu() {
EscapeHtmlDirective escapeHtmlDirective = new EscapeHtmlDirective();
assertTofuOutput("", "", escapeHtmlDirective);
assertTofuOutput("a&b > c", "a&b > c", escapeHtmlDirective);
assertTofuOutput(
"<script>alert('boo');</script>",
"<script>alert('boo');</script>",
escapeHtmlDirective);
SanitizedContent fooTagHtml =
UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.HTML);
assertTofuOutput(
fooTagHtml,
// Sanitized HTML is not escaped.
fooTagHtml,
escapeHtmlDirective);
assertTofuOutput(
"<foo>",
// But JS_STR_CHARS are.
UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.JS),
escapeHtmlDirective);
assertTofuOutput(
"<foo>",
// But CSS is.
UnsafeSanitizedContentOrdainer.ordainAsSafe("<foo>", SanitizedContent.ContentKind.CSS),
escapeHtmlDirective);
}
示例15: ordainJson
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer; //导入方法依赖的package包/类
private static SanitizedContent ordainJson(String knownSafeJson) {
return UnsafeSanitizedContentOrdainer.ordainAsSafe(knownSafeJson, ContentKind.JS);
}