Class ValueEmbeddingReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable

    public class ValueEmbeddingReader
    extends Reader
    replace all '${key}' elements in the stream by their values from the value map; escape '$' and '\' with a prepended '\' - a key '${resource:/a/path/to/resource} is replaced by the content of the resource loaded by the class loader - if a value is a Reader the content of the reader is copied as value; caution a reader object can be read only once - a key can contain a format string (${name;format}); in this case the embedded value is formatted (@see #java.util.Formatter)
    • Field Detail

      • reader

        protected final Reader reader
      • values

        protected final org.apache.sling.api.resource.ValueMap values
      • locale

        protected final Locale locale
      • resourceContext

        protected final Class<?> resourceContext
      • keepUnresolvable

        protected boolean keepUnresolvable
      • eof

        protected boolean eof
      • buf

        protected char[] buf
      • off

        protected int off
      • len

        protected int len
    • Constructor Detail

      • ValueEmbeddingReader

        public ValueEmbeddingReader​(@NotNull
                                    @NotNull Reader reader,
                                    @NotNull
                                    @NotNull Map<String,​Object> values)
        Parameters:
        reader - the text to read - probably with embedded value placeholders
        values - the set of available placeholders
      • ValueEmbeddingReader

        public ValueEmbeddingReader​(@NotNull
                                    @NotNull Reader reader,
                                    @NotNull
                                    @NotNull Map<String,​Object> values,
                                    @Nullable
                                    @Nullable Locale locale,
                                    @Nullable
                                    @Nullable Class<?> resourceContext)
        Parameters:
        reader - the text to read - probably with embedded value placeholders
        values - the set of available placeholders
        locale - the locale to use for value formatting
        resourceContext - the context class for resource loading
      • ValueEmbeddingReader

        public ValueEmbeddingReader​(@NotNull
                                    @NotNull Reader reader,
                                    @NotNull
                                    @NotNull Map<String,​Object> values,
                                    @Nullable
                                    @Nullable Locale locale,
                                    @Nullable
                                    @Nullable Class<?> resourceContext,
                                    @Nullable
                                    @Nullable ResourceBundle resourceBundle)
        Parameters:
        reader - the text to read - probably with embedded value placeholders
        values - the set of available placeholders
        locale - the locale to use for value formatting
        resourceContext - the context class for resource loading
        resourceBundle - the translations bundle (switches translation on)