public class MarkupFactory extends Object
This class is the main entry point to load markup. Nothing else should be required by Components. It manages caching markup as well as loading and merging (inheritance) of markup.
The markup returned is immutable as it gets re-used across multiple Component instances.
Constructor and Description |
---|
MarkupFactory()
Construct.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkMarkupType(MarkupContainer container)
Without a markup type we can not search for a file and we can not construct the cacheKey.
|
static MarkupFactory |
get() |
Class<?> |
getContainerClass(MarkupContainer container,
Class<?> clazz)
Gets and checks the container class
|
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 and optionally the Class.
|
protected IMarkupResourceStreamProvider |
getMarkupResourceStreamProvider(MarkupContainer container)
Get the markup resource stream provider registered with the factory.
|
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 IXmlPullParser |
newXmlPullParser()
Subclasses can override this to use custom parsers.
|
protected IMarkupFilter |
onAppendMarkupFilter(IMarkupFilter filter)
A callback method that is invoked prior to any
IMarkupFilter being registered with
MarkupParser . |
public static MarkupFactory get()
public IMarkupLoader getMarkupLoader()
DefaultMarkupLoader
will be returned. Via
subclassing you may return your own markup loader (chain).public MarkupParser newMarkupParser(MarkupResourceStream resource)
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; } }
resource
- The resource containing the markupMarkupParser
onAppendMarkupFilter(IMarkupFilter)
protected IXmlPullParser newXmlPullParser()
MarkupParser
to parse markup.protected IMarkupFilter onAppendMarkupFilter(IMarkupFilter filter)
IMarkupFilter
being registered with
MarkupParser
. Hence it allows to:
MarkupParser
instance is created for each markup resources being
loaded.
filter
- The filter to be registered with the MarkupParserpublic IMarkupCache getMarkupCache()
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.
public boolean hasMarkupCache()
true
if markup cache is available. Make sure you called
getMarkupCache()
at least once before to initialize the cache.public final Markup getMarkup(MarkupContainer container, boolean enforceReload)
container
- The container to find the markup forenforceReload
- If true, the cache will be ignored and all, including inherited markup files, will
be reloaded. Whatever is in the cache, it will be ignoredpublic final Markup getMarkup(MarkupContainer container, Class<?> clazz, boolean enforceReload)
The clazz parameter usually can be null, except for base (inherited) markup.
There are several means to disable markup caching. Caching can be disabled alltogether - getMarkupCache() return null -, or individually (cacheKey == null).
container
- The container to find the markup forclazz
- Must be the container class or any of its super classes. 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 ignoredprotected final boolean checkMarkupType(MarkupContainer container)
container
- The MarkupContainer which markup type has to checkedprotected final IMarkupResourceStreamProvider getMarkupResourceStreamProvider(MarkupContainer container)
If the 'container' implements IMarkupResourceStreamProvider
, the container itself
will be asked to provide the resource stream. Else Wicket's default implementation will be
used.
container
- The MarkupContainer requesting the markup resource streampublic final MarkupResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> clazz)
container
- The MarkupContainer which requests to load the Markup resource streamclazz
- Either the container class or any super class. Might be null.public final Class<?> getContainerClass(MarkupContainer container, Class<?> clazz)
container
- The MarkupContainer which requests to load the Markup resource streamclazz
- Either null, or a super class of containerpublic final Markup loadMarkup(MarkupContainer container, MarkupResourceStream markupResourceStream, boolean enforceReload)
Though the 'enforceReload' attribute seem to imply that the cache is consulted to retrieve
the markup, the cache in fact is only checked for retrieving the base (inherited) markup.
Please see getMarkup(MarkupContainer, boolean)
as well.
container
- The original requesting markup containermarkupResourceStream
- The markup resource stream to load, if already known.enforceReload
- The cache will be ignored and all, including inherited markup files, will be
reloaded. Whatever is in the cache, it will be ignoredCopyright © 2006–2022 Apache Software Foundation. All rights reserved.