Module org.apache.wicket.core
Class RelativePathPrefixHandler
java.lang.Object
org.apache.wicket.markup.parser.AbstractMarkupFilter
org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler
- All Implemented Interfaces:
Serializable
,IMarkupFilter
,IComponentResolver
,IClusterable
public final class RelativePathPrefixHandler
extends AbstractMarkupFilter
implements IComponentResolver
The purpose of this filter is to make all "href", "src" and "background" attributes found in the
markup which contain a relative URL like "myDir/myPage.gif" actually resolve in the output HTML,
by prefixing them with with an appropriate path to make the link work properly, even if the
current page is being displayed at a mounted URL or whatever. It is applied to all non wicket
component tags, except for auto-linked tags.
It achieves this by being both an IMarkupFilter and IComponentResolver, and works similarly to
the <wicket:message> code. For each tag, we look to see if the path in "href", "src" and
"background" attributes is relative. If it is, we assume it's relative to the context path and we
should prefix it appropriately so that it resolves correctly for the current request, even if
that's for something that's not at the context root. This is done for ServletWebRequests by
prepending with "../" tokens, for example.
- Author:
- Al Maw
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Behavior
Behavior that adds a prefix to src, href and background attributes to make them context-relativestatic final String
The id automatically assigned to tags without an id which we need to prepend a relative path to.Fields inherited from class org.apache.wicket.markup.parser.AbstractMarkupFilter
REQUEST_COUNTER_KEY
-
Constructor Summary
ConstructorDescriptionConstructor for the IComponentResolver role.Constructor for the IMarkupFilter role -
Method Summary
Modifier and TypeMethodDescriptionprotected final MarkupElement
Invoked when a ComponentTag was found.void
postProcess
(Markup markup) Called after all filters have been processed.resolve
(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) Try to resolve a component.Methods inherited from class org.apache.wicket.markup.parser.AbstractMarkupFilter
getMarkupResourceStream, getNextFilter, getRequestUniqueId, getWicketNamespace, getWicketNamespace, nextElement, onSpecialTag, setNextFilter
-
Field Details
-
WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID
The id automatically assigned to tags without an id which we need to prepend a relative path to.- See Also:
-
RELATIVE_PATH_BEHAVIOR
Behavior that adds a prefix to src, href and background attributes to make them context-relative
-
-
Constructor Details
-
RelativePathPrefixHandler
public RelativePathPrefixHandler()Constructor for the IComponentResolver role. -
RelativePathPrefixHandler
Constructor for the IMarkupFilter role- Parameters:
markup
- The markup created by reading the markup file
-
-
Method Details
-
onComponentTag
Description copied from class:AbstractMarkupFilter
Invoked when a ComponentTag was found.By default this method is also called for WicketTags.
- Specified by:
onComponentTag
in classAbstractMarkupFilter
- Returns:
- Usually the same as the tag attribute
- Throws:
ParseException
-
resolve
Description copied from interface:IComponentResolver
Try to resolve a component.- Specified by:
resolve
in interfaceIComponentResolver
- Parameters:
container
- The container parsing its markupmarkupStream
- The current markupStreamtag
- The current component tag while parsing the markup- Returns:
- component or
null
if not found
-
postProcess
Description copied from interface:IMarkupFilter
Called after all filters have been processed.- Specified by:
postProcess
in interfaceIMarkupFilter
- Overrides:
postProcess
in classAbstractMarkupFilter
-