org.apache.wicket.markup
Class MarkupFactory

java.lang.Object
  extended by org.apache.wicket.markup.MarkupFactory

public class MarkupFactory
extends Object

Factory to load markup either from from cache or from a resource. In case of markup inheritance, merging the markup is managed transparently.

Author:
Juergen Donnerstag

Constructor Summary
MarkupFactory()
          Construct.
 
Method Summary
static MarkupFactory get()
           
 Markup getMarkup(MarkupContainer container, boolean enforceReload)
          Get the markup associated with the container.
 Markup getMarkup(MarkupContainer container, Class<?> clazz, boolean enforceReload)
          Get the markup associated with the container.
 IMarkupCache getMarkupCache()
          Get the markup cache which is registered with the factory.
 IMarkupLoader getMarkupLoader()
          MarkupLoaders are responsible to find and load the markup for a component.
 MarkupResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> clazz)
          Create a new markup resource stream for the container.
protected  IMarkupResourceStreamProvider getMarkupResourceStreamProvider(MarkupContainer container)
          Get the markup resource stream provider registered with the factory.
 boolean hasAssociatedMarkup(MarkupContainer container)
          Check if container has associated markup
 boolean hasMarkupCache()
           
 Markup loadMarkup(MarkupContainer container, MarkupResourceStream markupResourceStream, boolean enforceReload)
          Loads markup from a resource stream.
 MarkupParser newMarkupParser(MarkupResourceStream resource)
          Create a new markup parser.
protected  IMarkupFilter onAppendMarkupFilter(IMarkupFilter filter)
          A callback method that is invoked prior to any IMarkupFilter being registered with MarkupParser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkupFactory

public MarkupFactory()
Construct.

Method Detail

get

public static final MarkupFactory get()
Returns:
The markup factory associated with the application

getMarkupLoader

public IMarkupLoader getMarkupLoader()
MarkupLoaders are responsible to find and load the markup for a component. That may be a single file, but e.g. like in markup inheritance it could also be that the markup from different sources must be merged.

Returns:
By default an instance of DefaultMarkupLoader will be returned. Via subclassing you may return your markup loader..

newMarkupParser

public MarkupParser newMarkupParser(MarkupResourceStream resource)
Create a new markup parser. Markup parsers read the markup and dissect it in Wicket relevant pieces MarkupElement's (kind of Wicket's DOM).

MarkupParser's can be extended by means of IMarkupFilter. You can add your own filter as follows:

    public MyMarkupFactory {
      ...
      public MarkupParser newMarkupParser(final MarkupResourceStream resource) {
         MarkupParser parser = super.newMarkupParser(resource);
         parser.add(new MyFilter());
         return parser;
      }
    }
 

Parameters:
resource - The resource containing the markup
Returns:
A fresh instance of MarkupParser
See Also:
onAppendMarkupFilter(IMarkupFilter)

onAppendMarkupFilter

protected IMarkupFilter onAppendMarkupFilter(IMarkupFilter filter)
A callback method that is invoked prior to any IMarkupFilter being registered with MarkupParser. Hence it allows to: Note that a new MarkupParser instance is created for each markup resources being loaded.

Parameters:
filter - The filter to be registered with the MarkupParser
Returns:
The filter to be added. Null to ignore.

getMarkupCache

public IMarkupCache getMarkupCache()
Get the markup cache which is registered with the factory. Since the factory is registered with the application, only one cache per application exists.

Please note that markup cache is a pull through cache. It'll invoke a factory method getMarkupResourceStream(MarkupContainer, Class) to load the markup if not yet available in the cache.

Returns:
Null, to disable caching.

hasMarkupCache

public boolean hasMarkupCache()
Returns:
true if markup cache is available. Make sure you called getMarkupCache() at least once before to initialize the cache.

getMarkup

public final Markup getMarkup(MarkupContainer container,
                              boolean enforceReload)
Get the markup associated with the container.

Parameters:
container - The container to find the markup for
enforceReload - If true, the cache will be ignored and all, including inherited markup files, will be reloaded. Whatever is in the cache, it will be ignored
Returns:
The markup associated with the container

getMarkup

public final Markup getMarkup(MarkupContainer container,
                              Class<?> clazz,
                              boolean enforceReload)
Get the markup associated with the container.

Parameters:
container - The container to find the markup for
clazz - Must be the container class or any of its super classes.
enforceReload - The cache will be ignored and all, including inherited markup files, will be reloaded. Whatever is in the cache, it will be ignored
Returns:
The markup associated with the container

hasAssociatedMarkup

public final boolean hasAssociatedMarkup(MarkupContainer container)
Check if container has associated markup

Parameters:
container - The container to find the markup for
Returns:
True if this markup container has associated markup

getMarkupResourceStreamProvider

protected final IMarkupResourceStreamProvider getMarkupResourceStreamProvider(MarkupContainer container)
Get the markup resource stream provider registered with the factory.

If the 'container' implements IMarkupResourceStreamProvider, the container itself will be asked to provide the resource stream. Else Wicket's default implementation will be used.

Parameters:
container - The MarkupContainer requesting the markup resource stream
Returns:
IMarkupResourceStreamProvider

getMarkupResourceStream

public final MarkupResourceStream getMarkupResourceStream(MarkupContainer container,
                                                          Class<?> clazz)
Create a new markup resource stream for the container.

Parameters:
container - The MarkupContainer which requests to load the Markup resource stream
clazz - Either the container class or any super class
Returns:
A IResourceStream if the resource was found

loadMarkup

public final Markup loadMarkup(MarkupContainer container,
                               MarkupResourceStream markupResourceStream,
                               boolean enforceReload)
Loads markup from a resource stream.

Parameters:
container - The original requesting markup container
markupResourceStream - The markup resource stream to load. May be null.
enforceReload - The cache will be ignored and all, including inherited markup files, will be reloaded. Whatever is in the cache, it will be ignored
Returns:
The markup


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