@Override public SoyData apply(SoyData value, List<SoyData> args) { return value instanceof StringData ? value : SoyData.createFromExistingData(value.toString()); }
public SoyData convertToSoyData(Object value) { return SoyData.createFromExistingData(convertObject(value)); }
@Override public final SoyData apply(SoyData value, List<SoyData> args) { return SoyData.createFromExistingData(escape(value)); }
@Override public SoyData apply(SoyData value, List<SoyData> args) { return SoyData.createFromExistingData( NEWLINE_PATTERN.matcher(value.toString()).replaceAll("<br>")); }
/** * Filters noAutoescape input from explicitly tainted content. * * SanitizedContent.ContentKind.TEXT is used to explicitly mark input that is never meant to be * used unescaped. Specifically, {let} and {param} blocks of kind "text" are explicitly * forbidden from being noAutoescaped to avoid XSS regressions during application transition. */ public static SoyData filterNoAutoescape(SoyData data) { // TODO: Consider also checking for things that are never valid, like null characters. if (isSanitizedContentOfKind(data, SanitizedContent.ContentKind.TEXT)) { LOGGER.log(Level.WARNING, "|noAutoescape received data explicitly tagged as ContentKind.TEXT: {0}", data); return SoyData.createFromExistingData(EscapingConventions.INNOCUOUS_OUTPUT); } return data instanceof StringData ? data : SoyData.createFromExistingData(data.toString()); }
/** Initializes this SoyMapData from an existing map. */ public SoyMapData(Map<String, ?> data) { map = new LinkedHashMap<>(data.size()); for (Map.Entry<String, ?> entry : data.entrySet()) { String key; try { key = entry.getKey(); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to convert a map with non-string key to Soy data (key type " + ((Map.Entry<?, ?>) entry).getKey().getClass().getName() + ")."); } Object value = entry.getValue(); try { map.put(key, SoyData.createFromExistingData(value)); } catch (SoyDataException sde) { sde.prependKeyToDataPath(key); throw sde; } } }
@Override public SoyData load(final String from) { Object value; try { value = "class".equals(from) ? null : PropertyUtils.getProperty(delegate.get(), from); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { value = null; } return SoyData.createFromExistingData(soyDataConverter.convertObject(value)); } });
/** * Private helper shared by constructor SoyListData(Iterable) and add(Object...). * @param data The data to add. */ private void add(Iterable<?> data) { for (Object el : data) { try { add(SoyData.createFromExistingData(el)); } catch (SoyDataException sde) { sde.prependIndexToDataPath(list.size()); throw sde; } } }
/** * Private helper shared by constructor SoyListData(Iterable) and add(Object...). * * @param data The data to add. */ private void add(Iterable<?> data) { for (Object el : data) { try { add(SoyData.createFromExistingData(el)); } catch (SoyDataException sde) { sde.prependIndexToDataPath(list.size()); throw sde; } } }
/** * Constructor that initializes this SoyMapData from an existing map. * @param data The initial data in an existing map. */ public SoyMapData(Map<String, ?> data) { map = new LinkedHashMap<String, SoyData>(data.size()); for (Map.Entry<String, ?> entry : data.entrySet()) { String key; try { key = entry.getKey(); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to convert a map with non-string key to Soy data (key type " + ((Map.Entry<?, ?>) entry).getKey().getClass().getName() + ")."); } Object value = entry.getValue(); try { map.put(key, SoyData.createFromExistingData(value)); } catch (SoyDataException sde) { sde.prependKeyToDataPath(key); throw sde; } } }
/** * Constructor that initializes this SoyMapData from an existing map. * * @param data The initial data in an existing map. */ public SoyMapData(Map<String, ?> data) { map = new LinkedHashMap<>(data.size()); for (Map.Entry<String, ?> entry : data.entrySet()) { String key; try { key = entry.getKey(); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to convert a map with non-string key to Soy data (key type " + ((Map.Entry<?, ?>) entry).getKey().getClass().getName() + ")."); } Object value = entry.getValue(); try { map.put(key, SoyData.createFromExistingData(value)); } catch (SoyDataException sde) { sde.prependKeyToDataPath(key); throw sde; } } }
/** * Private helper shared by constructor SoyListData(Iterable) and add(Object...). * * @param data The data to add. */ private void add(Iterable<?> data) { for (Object el : data) { try { add(SoyData.createFromExistingData(el)); } catch (SoyDataException sde) { sde.prependIndexToDataPath(list.size()); throw sde; } } }
boolean isValidValue = true; try { SoyData value0 = SoyData.createFromExistingData(valueObj); if (!(value0 instanceof PrimitiveData)) { isValidValue = false;
/** * Convenience function to put multiple mappings in one call. * * @param data The mappings to put, as alternating keys/values. Indices 0, 2, 4, ... must be valid * key strings. Indices 1, 3, 5, ... must be valid Soy data values. * @throws SoyDataException When attempting to add an invalid varargs list or a mapping containing * an invalid key. */ public void put(Object... data) { // TODO: Perhaps change to only convert varargs to Map, and do put(Map) elsewhere. if (data.length % 2 != 0) { throw new SoyDataException( "Varargs to put(...) must have an even number of arguments (key-value pairs)."); } for (int i = 0; i < data.length; i += 2) { try { put((String) data[i], SoyData.createFromExistingData(data[i + 1])); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to add a mapping containing a non-string key (key type " + data[i].getClass().getName() + ")."); } } }
@Override public SoyData apply(SoyData value, List<SoyData> args) { String str = SoyBidiUtils.getBidiFormatter(bidiGlobalDirProvider.get().getStaticValue()) .unicodeWrap(value.toString(), true); return SoyData.createFromExistingData(str); }
/** * Convenience function to put multiple mappings in one call. * @param data The mappings to put, as alternating keys/values. Indices 0, 2, 4, ... must be valid * key strings. Indices 1, 3, 5, ... must be valid Soy data values. * @throws SoyDataException When attempting to add an invalid varargs list or a mapping containing * an invalid key. */ public void put(Object... data) { // TODO: Perhaps change to only convert varargs to Map, and do put(Map) elsewhere. if (data.length % 2 != 0) { throw new SoyDataException( "Varargs to put(...) must have an even number of arguments (key-value pairs)."); } for (int i = 0; i < data.length; i += 2) { try { put((String) data[i], SoyData.createFromExistingData(data[i + 1])); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to add a mapping containing a non-string key (key type " + data[i].getClass().getName() + ")."); } } }
@Override public SoyData apply(SoyData value, List<SoyData> args) { boolean isHtml = true; String html = SoyBidiUtils.getBidiFormatter(bidiGlobalDirProvider.get().getStaticValue()) .spanWrap(value.toString(), isHtml); // TODO(user): convert to HTML SanitizedContent when isHtml. return SoyData.createFromExistingData(html); }
/** * Convenience function to put multiple mappings in one call. * * @param data The mappings to put, as alternating keys/values. Indices 0, 2, 4, ... must be valid * key strings. Indices 1, 3, 5, ... must be valid Soy data values. * @throws SoyDataException When attempting to add an invalid varargs list or a mapping containing * an invalid key. */ public void put(Object... data) { // TODO: Perhaps change to only convert varargs to Map, and do put(Map) elsewhere. if (data.length % 2 != 0) { throw new SoyDataException( "Varargs to put(...) must have an even number of arguments (key-value pairs)."); } for (int i = 0; i < data.length; i += 2) { try { put((String) data[i], SoyData.createFromExistingData(data[i + 1])); } catch (ClassCastException cce) { throw new SoyDataException( "Attempting to add a mapping containing a non-string key (key type " + data[i].getClass().getName() + ")."); } } }
@Override public SoyData apply(SoyData value, List<SoyData> args) { if (value instanceof SanitizedContent) { SanitizedContent sanitizedContent = (SanitizedContent) value; if (sanitizedContent.getContentKind() == SanitizedContent.ContentKind.HTML) { return value; } } return SoyData.createFromExistingData( EscapingConventions.EscapeHtml.INSTANCE.escape(value.toString())); }
return createFromExistingData(((Future<?>) obj).get()); } catch (InterruptedException e) { throw new SoyDataException(