public class DefaultReverseProxyTextLineContentRewriter extends AbstractTextLineContentRewriter
This implementation uses a regular expression (see LINK_PATTERN
) to find
all the DOM elements containing any of href
, src
and action
attributes and rewrite those URI attribute values by a resolved ProxyMapping
from the
internal ProxyMappingRegistry
in the current reverse proxy processing context.
Modifier and Type | Field and Description |
---|---|
protected static Pattern |
LINK_PATTERN
The regular expression pattern to find and replace URI attribute values in DOM elements.
|
Constructor and Description |
---|
DefaultReverseProxyTextLineContentRewriter()
Zero-argument default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
isRewritableURI(String uri)
Returns true if the given
uri can be rewritten by this. |
protected String |
rewriteLine(String line,
ContentRewritingContext context)
Translates the given
line and returns the translated string. |
protected String |
rewriteURI(String uri,
ContentRewritingContext context)
Rewrites the given
uri by resolving a ProxyMapping from the internal
ProxyMappingRegistry in the current ContentRewritingContext and ProxyContext . |
rewrite
protected static final Pattern LINK_PATTERN
public DefaultReverseProxyTextLineContentRewriter()
protected String rewriteLine(String line, ContentRewritingContext context) throws ContentRewritingException, IOException
line
and returns the translated string.
For example, suppose the source
contains the following lines:
${message.greeting} Copyright ${copyright.holder} ${copyright.years}
Then, one implementation of this method might want to return "Hello, World!" for the first text line,
and "Copyright Apache Software Foundation 2014" for instance to let the sink
have the following:
Hello, World! Copyright Apache Software Foundation 2014
Even better, for example, if the given context
contains all those variables (i.e, ${copyright.holder} and ${copyright.years}),
then the implementation of this method can resolve those variables dynamically and translates them based on the variables given
by the runtime.
This implementation uses a regular expression (see LINK_PATTERN
) to find
all the DOM elements containing any of href
, src
and action
attributes and rewrite those URI attribute values (see rewriteURI(String, ContentRewritingContext)
)
by a resolved ProxyMapping
from the internal ProxyMappingRegistry
in the current reverse proxy processing context.
rewriteLine
in class AbstractTextLineContentRewriter
line
- a text line from the source
context
- the content rewriting context given by the runtimeContentRewritingException
IOException
protected String rewriteURI(String uri, ContentRewritingContext context)
uri
by resolving a ProxyMapping
from the internal
ProxyMappingRegistry
in the current ContentRewritingContext
and ProxyContext
.uri
- context
- protected boolean isRewritableURI(String uri)
uri
can be rewritten by this. Otherwise it returns false.uri
- Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.