Package org.takes.facets.fork
Class FkRegex
- java.lang.Object
-
- org.takes.facets.fork.FkRegex
-
- All Implemented Interfaces:
Fork
public final class FkRegex extends Object implements Fork
Fork by regular expression pattern.Use this class in combination with
TkFork
, for example:Take take = new TkFork( new FkRegex("/home", new TkHome()), new FkRegex("/account", new TkAccount()) );
Each instance of
FkRegex
is being asked only once byTkFork
whether the request is good enough to be processed. If the request is suitable for this particular fork, it will return the relevantTake
.Also, keep in mind that the second argument of the constructor may be of type
TkRegex
and accept an instance ofRqRegex
, which makes it very convenient to reuse regular expression matcher, for example:Take take = new TkFork( new FkRegex( "/file(.*)", new Target<RqRegex>() { @Override public Response act(final RqRegex req) { // Here we immediately getting access to the // matcher that was used during parsing of // the incoming request final String file = req.matcher().group(1); } } ) );
The class is immutable and thread-safe.
-
-
Constructor Summary
Constructors Constructor Description FkRegex(String ptn, String text)
Ctor.FkRegex(String ptn, TkRegex tke)
Ctor.FkRegex(String ptn, Response rsp)
Ctor.FkRegex(String ptn, Take tke)
Ctor.FkRegex(Pattern ptn, org.cactoos.Scalar<TkRegex> tke)
Ctor.FkRegex(Pattern ptn, TkRegex tke)
Ctor.FkRegex(Pattern ptn, Response rsp)
Ctor.FkRegex(Pattern ptn, Take tke)
Ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Opt<Response>
route(Request req)
Process this request or ignore it.FkRegex
setRemoveTrailingSlash(boolean enabled)
Allows disabling the standard way for handling trailing slashes.
-
-
-
Method Detail
-
setRemoveTrailingSlash
public FkRegex setRemoveTrailingSlash(boolean enabled)
Allows disabling the standard way for handling trailing slashes.- Parameters:
enabled
- Enables/Disables the removal of a trailing slash.- Returns:
- FkRegex
-
-