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 classValueEmbeddingReader.Key 
- 
Field Summary
Fields Modifier and Type Field Description protected char[]bufstatic intBUFSIZEprotected booleaneofstatic charFORMAT_SEPARATORprotected booleankeepUnresolvableprotected intlenprotected Localelocalestatic charMEMBER_SEPARATORprotected intoffstatic charPATH_SEPARATORprotected Readerreaderprotected ResourceBundleresourceBundleprotected Class<?>resourceContextstatic StringTYPE_RESOURCEstatic charTYPE_SEPARATORprotected org.apache.sling.api.resource.ValueMapvalues 
- 
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 voidclose()protected intcopy(char[] cbuf, int off, int len)protected voidembedKey(ValueEmbeddingReader.Key key)booleanisKeepUnresolvable(boolean... decision)protected voidload()intread(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:
 closein interfaceAutoCloseable- Specified by:
 closein interfaceCloseable- Specified by:
 closein classReader- Throws:
 IOException
 
- 
read
public int read(char[] cbuf, int off, int len) throws IOException- Specified by:
 readin classReader- Throws:
 IOException
 
- 
copy
protected int copy(char[] cbuf, int off, int len) 
- 
load
protected void load() throws IOException- Throws:
 IOException
 
 - 
 
 -