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 class
GenericProxyReader.DropTagFilter
the tag handler implementation for tags to 'drop'protected class
GenericProxyReader.RenameTagFilter
the tag handler implementation for tags to 'stripe'protected class
GenericProxyReader.StripTagFilter
the tag handler implementation for tags to 'stripe'protected class
GenericProxyReader.TagFilterBase
the abstract tag handler base implementation
-
Field Summary
Fields Modifier and Type Field Description protected char[]
buffer
the buffer filled if a 'look forward' to find a tag name has found no tag to filter outprotected int
bufferPos
static String[]
DEFAULT_TO_DROP
static String[]
DEFAULT_TO_RENAME
static String[]
DEFAULT_TO_STRIP
protected Stack<com.composum.sling.core.proxy.GenericProxyReader.TagFilter>
openTags
the stack of handlers for open tags - the tomost handler is used for token readingprotected List<String>
toDrop
protected Map<String,String>
toRename
the 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 int
buffer(StringBuilder tagName)
fills up the buffer with the string builders content and returns a 'tag start' tokone ('<')protected com.composum.sling.core.proxy.GenericProxyReader.TagFilter
getFilter(String tagName)
protected int
next()
int
read()
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)int
read(char[] cbuf, int off, int len)
uses the single token read() method to fill the bufferprotected int
scan()
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 int
trim()
-
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 IOException
uses the single token read() method to fill the buffer- Overrides:
read
in classFilterReader
- Throws:
IOException
-
read
public int read() throws IOException
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)- Overrides:
read
in classFilterReader
- Throws:
IOException
-
scan
protected int scan() throws IOException
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 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
-
-