Package com.composum.sling.core.util
Class ValueEmbeddingReader
- java.lang.Object
-
- java.io.Reader
-
- com.composum.sling.core.util.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ValueEmbeddingReader.Key
-
Field Summary
Fields Modifier and Type Field Description protected char[]
buf
static int
BUFSIZE
protected boolean
eof
static char
FORMAT_SEPARATOR
protected boolean
keepUnresolvable
protected int
len
protected Locale
locale
static char
MEMBER_SEPARATOR
protected int
off
static char
PATH_SEPARATOR
protected Reader
reader
protected ResourceBundle
resourceBundle
protected Class<?>
resourceContext
static String
TYPE_RESOURCE
static char
TYPE_SEPARATOR
protected org.apache.sling.api.resource.ValueMap
values
-
Constructor Summary
Constructors Constructor Description ValueEmbeddingReader(@NotNull Reader reader, @NotNull Map<String,Object> values)
ValueEmbeddingReader(@NotNull Reader reader, @NotNull Map<String,Object> values, @Nullable Locale locale, @Nullable Class<?> resourceContext)
ValueEmbeddingReader(@NotNull Reader reader, @NotNull Map<String,Object> values, @Nullable Locale locale, @Nullable Class<?> resourceContext, @Nullable ResourceBundle resourceBundle)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected int
copy(char[] cbuf, int off, int len)
protected void
embedKey(ValueEmbeddingReader.Key key)
boolean
isKeepUnresolvable(boolean... decision)
protected void
load()
int
read(char[] cbuf, int off, int len)
-
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
-
-
-
-
Field Detail
-
TYPE_RESOURCE
public static final String TYPE_RESOURCE
- See Also:
- Constant Field Values
-
PATH_SEPARATOR
public static final char PATH_SEPARATOR
- See Also:
- Constant Field Values
-
MEMBER_SEPARATOR
public static final char MEMBER_SEPARATOR
- See Also:
- Constant Field Values
-
TYPE_SEPARATOR
public static final char TYPE_SEPARATOR
- See Also:
- Constant Field Values
-
FORMAT_SEPARATOR
public static final char FORMAT_SEPARATOR
- See Also:
- Constant Field Values
-
BUFSIZE
public static final int BUFSIZE
- See Also:
- Constant Field Values
-
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
-
resourceBundle
protected final ResourceBundle resourceBundle
-
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 placeholdersvalues
- 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 placeholdersvalues
- the set of available placeholderslocale
- the locale to use for value formattingresourceContext
- 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 placeholdersvalues
- the set of available placeholderslocale
- the locale to use for value formattingresourceContext
- the context class for resource loadingresourceBundle
- the translations bundle (switches translation on)
-
-
Method Detail
-
isKeepUnresolvable
public boolean isKeepUnresolvable(boolean... decision)
-
embedKey
protected void embedKey(ValueEmbeddingReader.Key key)
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
read
public int read(char[] cbuf, int off, int len) throws IOException
- Specified by:
read
in classReader
- Throws:
IOException
-
copy
protected int copy(char[] cbuf, int off, int len)
-
load
protected void load() throws IOException
- Throws:
IOException
-
-