org.apache.wicket.markup.parser.filter
Class RelativePathPrefixHandler

java.lang.Object
  extended by org.apache.wicket.markup.parser.AbstractMarkupFilter
      extended by org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler
All Implemented Interfaces:
java.io.Serializable, IClusterable, IMarkupFilter, IComponentResolver

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:
Serialized Form

Field Summary
static IBehavior RELATIVE_PATH_BEHAVIOR
          Behavior that adds a prefix to src, href and background attributes to make them context-relative
static java.lang.String WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID
          The id automatically assigned to tags without an id which we need to prepend a relative path to.
 
Constructor Summary
RelativePathPrefixHandler()
           
 
Method Summary
 MarkupElement nextTag()
          Get the next MarkupElement from the parent MarkupFilter and handle it if the specific filter criteria are met.
 boolean resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag)
          Try to resolve the tag, then create a component, add it to the container and render it.
 
Methods inherited from class org.apache.wicket.markup.parser.AbstractMarkupFilter
getParent, nextComponentTag, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WICKET_RELATIVE_PATH_PREFIX_CONTAINER_ID

public static final java.lang.String 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:
Constant Field Values

RELATIVE_PATH_BEHAVIOR

public static final IBehavior RELATIVE_PATH_BEHAVIOR
Behavior that adds a prefix to src, href and background attributes to make them context-relative

Constructor Detail

RelativePathPrefixHandler

public RelativePathPrefixHandler()
Method Detail

nextTag

public MarkupElement nextTag()
                      throws java.text.ParseException
Get the next MarkupElement from the parent MarkupFilter and handle it if the specific filter criteria are met. Depending on the filter, it may return the MarkupElement unchanged, modified or it remove by asking the parent handler for the next tag.

Specified by:
nextTag in interface IMarkupFilter
Returns:
Return the next eligible MarkupElement
Throws:
java.text.ParseException
See Also:
IMarkupFilter.nextTag()

resolve

public boolean resolve(MarkupContainer container,
                       MarkupStream markupStream,
                       ComponentTag tag)
Description copied from interface: IComponentResolver
Try to resolve the tag, then create a component, add it to the container and render it.

Specified by:
resolve in interface IComponentResolver
Parameters:
container - The container parsing its markup
markupStream - The current markupStream
tag - The current component tag while parsing the markup
Returns:
True if component-id was handled by the resolver, false otherwise.
See Also:
IComponentResolver.resolve(org.apache.wicket.MarkupContainer, org.apache.wicket.markup.MarkupStream, org.apache.wicket.markup.ComponentTag)


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.