Package com.composum.sling.core.proxy
Class GenericProxyReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- com.composum.sling.core.proxy.GenericProxyReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
public class GenericProxyReader extends FilterReader
a filter reader implementation to filter out HTML tags from the base reader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classGenericProxyReader.DropTagFilterthe tag handler implementation for tags to 'drop'protected classGenericProxyReader.RenameTagFilterthe tag handler implementation for tags to 'stripe'protected classGenericProxyReader.StripTagFilterthe tag handler implementation for tags to 'stripe'protected classGenericProxyReader.TagFilterBasethe abstract tag handler base implementation
-
Field Summary
Fields Modifier and Type Field Description protected char[]bufferthe buffer filled if a 'look forward' to find a tag name has found no tag to filter outprotected intbufferPosstatic String[]DEFAULT_TO_DROPstatic String[]DEFAULT_TO_RENAMEstatic String[]DEFAULT_TO_STRIPprotected Stack<com.composum.sling.core.proxy.GenericProxyReader.TagFilter>openTagsthe stack of handlers for open tags - the tomost handler is used for token readingprotected List<String>toDropprotected Map<String,String>toRenamethe tag names configuration of the filter readerprotected List<String>toStrip-
Fields inherited from class java.io.FilterReader
in
-
-
Constructor Summary
Constructors Constructor Description GenericProxyReader(@NotNull InputStream in)GenericProxyReader(@NotNull InputStream in, @NotNull String[] toRename, @NotNull String[] toStrip, @NotNull String[] toDrop)GenericProxyReader(@NotNull Reader in)GenericProxyReader(@NotNull Reader in, @NotNull String[] toRename, @NotNull String[] toStrip, @NotNull String[] toDrop)Creates a tag filtering reader to filter out the tags configured as sets of tag names
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intbuffer(StringBuilder tagName)fills up the buffer with the string builders content and returns a 'tag start' tokone ('<')protected com.composum.sling.core.proxy.GenericProxyReader.TagFiltergetFilter(String tagName)protected intnext()intread()delegates the read to the current tag handler or to the 'scan' if no such handler is active (the handlers are also using the 'scan' method to find tags inside of open tags)intread(char[] cbuf, int off, int len)uses the single token read() method to fill the bufferprotected intscan()scans the token from the 'original' reader and determines tag starts / ends and the tag names controls the tag handler stack if tags found which should be filteredprotected inttrim()-
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset, skip
-
Methods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
-
-
-
Field Detail
-
DEFAULT_TO_RENAME
public static final String[] DEFAULT_TO_RENAME
-
DEFAULT_TO_STRIP
public static final String[] DEFAULT_TO_STRIP
-
DEFAULT_TO_DROP
public static final String[] DEFAULT_TO_DROP
-
toRename
protected final Map<String,String> toRename
the tag names configuration of the filter reader
-
openTags
protected Stack<com.composum.sling.core.proxy.GenericProxyReader.TagFilter> openTags
the stack of handlers for open tags - the tomost handler is used for token reading
-
buffer
protected char[] buffer
the buffer filled if a 'look forward' to find a tag name has found no tag to filter out
-
bufferPos
protected int bufferPos
-
-
Constructor Detail
-
GenericProxyReader
public GenericProxyReader(@NotNull @NotNull Reader in, @NotNull @NotNull String[] toRename, @NotNull @NotNull String[] toStrip, @NotNull @NotNull String[] toDrop)Creates a tag filtering reader to filter out the tags configured as sets of tag names- Parameters:
in- the reader to filter during readtoRename- the set of tag names which should be kept but renamed (e.g. 'html:div' to keep the root)toStrip- the set of tag names to 'stripe' - remove the tags around and keep the body of the tagstoDrop- the set of tag names to 'drop' - remove the tags including their body
-
GenericProxyReader
public GenericProxyReader(@NotNull @NotNull InputStream in, @NotNull @NotNull String[] toRename, @NotNull @NotNull String[] toStrip, @NotNull @NotNull String[] toDrop)
-
GenericProxyReader
public GenericProxyReader(@NotNull @NotNull InputStream in)
-
GenericProxyReader
public GenericProxyReader(@NotNull @NotNull Reader in)
-
-
Method Detail
-
read
public int read(char[] cbuf, int off, int len) throws IOExceptionuses the single token read() method to fill the buffer- Overrides:
readin classFilterReader- Throws:
IOException
-
read
public int read() throws IOExceptiondelegates the read to the current tag handler or to the 'scan' if no such handler is active (the handlers are also using the 'scan' method to find tags inside of open tags)- Overrides:
readin classFilterReader- Throws:
IOException
-
scan
protected int scan() throws IOExceptionscans the token from the 'original' reader and determines tag starts / ends and the tag names controls the tag handler stack if tags found which should be filtered- Returns:
- the next token for the readers 'read' method
- Throws:
IOException
-
next
protected int next() throws IOException- Returns:
- the next token from the 'original' reader
- Throws:
IOException
-
trim
protected int trim() throws IOException- Returns:
- the next non space token
- Throws:
IOException
-
buffer
protected int buffer(StringBuilder tagName)
fills up the buffer with the string builders content and returns a 'tag start' tokone ('<')
-
getFilter
protected com.composum.sling.core.proxy.GenericProxyReader.TagFilter getFilter(String tagName)
- Returns:
- the filter to handle the found tag name; 'null' if the tag name is not configured for this filter
-
-