public class SitemapUrl extends OutputFamily
The <o:sitemapUrl>
is a component which renders the given target URL or JSF view ID as a sitemap
URL with support for adding additional query string parameters to the URL via nested <f:param>
and <o:param>
.
This component is largely based off the Url
component behind <o:url>
, but then tailored
specifically for usage in sitemap.xml
file. The ViewResourceHandler
must be registered in
faces-config.xml
in order to get JSF components to run in /sitemap.xml
.
You can supply the sitemap URL via either the value
attribute or the viewId
attribute. When
both are specified, the value
attribute takes precedence and the viewId
attribute is ignored.
When the target URL is specified as viewId
, then the domain of the target URL defaults to the current
domain. It is possible to provide a full qualified domain name (FQDN) via the domain
attribute which
the URL is to be prefixed with. This can be useful if a canonical page shall point to a different domain or a
specific subdomain.
Valid formats and values for domain
attribute are:
<o:sitemapUrl ... domain="https://example.com" />
<o:sitemapUrl ... domain="//example.com" />
<o:sitemapUrl ... domain="example.com" />
<o:sitemapUrl ... domain="/" />
<o:sitemapUrl ... domain="//" />
The domain
value will be validated by URL
and throw an illegal argument exception when invalid.
If the domain equals /
, then the URL becomes domain-relative.
If the domain equals or starts with //
, or does not contain any scheme, then the URL becomes scheme-relative.
If the value
attribute is specified, then the domain
attribute is ignored.
You can add query string parameters to the URL via nested <f:param>
and <o:param>
.
To conditionally add or override, use the disabled
attribute of <f|o:param>
.
Usage example of /sitemap.xml
as a JSF view:
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:o="http://omnifaces.org/ui" > <ui:repeat value="#{sitemapBean.products}" var="product"> <o:sitemapUrl viewId="/product.xhtml" lastModified="#{product.lastModified}" changeFrequency="weekly" priority="1.0"> <o:param name="id" value="#{product}" converter="productConverter" /> </o:sitemapUrl> </ui:repeat> </urlset>
OutputFamily
,
ViewResourceHandler
Modifier and Type | Class and Description |
---|---|
static class |
SitemapUrl.ChangeFrequency
The available values of the "changefreq" element of the sitemap URL.
|
Modifier and Type | Field and Description |
---|---|
static String |
COMPONENT_TYPE
The standard component type.
|
COMPONENT_FAMILY
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY
Constructor and Description |
---|
SitemapUrl()
Constructs the
SitemapUrl component. |
Modifier and Type | Method and Description |
---|---|
void |
encodeBegin(FacesContext context)
Renders the start of the
<url> parent element. |
protected void |
encodeChangeFrequency(FacesContext context)
Renders the
<changefreq> child element with the value of getChangeFrequency() , if any. |
void |
encodeChildren(FacesContext context)
Delegates to
encodeLocation(FacesContext) , encodeLastModified(FacesContext) , encodeChangeFrequency(FacesContext) and
encodePriority(FacesContext) in this order. |
void |
encodeEnd(FacesContext context)
Renders the end of the
<url> parent element. |
protected void |
encodeLastModified(FacesContext context)
Renders the
<lastmod> child element with the value of getLastModified() , if any. |
protected void |
encodeLocation(FacesContext context)
Renders the
<loc> child element with either the value of getValue() ,
or the value of getViewId() and getDomain() combined. |
protected void |
encodePriority(FacesContext context)
Renders the
<priority> child element with the value of getPriority() , if any. |
SitemapUrl.ChangeFrequency |
getChangeFrequency()
Returns the value of the "changefreq" element of the sitemap URL.
|
String |
getDomain()
Returns the domain of the "loc" element of the sitemap URL.
|
Temporal |
getLastModified()
Returns the value of the "lastmod" element of the sitemap URL.
|
BigDecimal |
getPriority()
Returns the value of the "priority" element of the sitemap URL.
|
String |
getValue()
Returns the value of the "loc" element of the sitemap URL.
|
String |
getViewId()
Returns the view ID to create the URI part of the "loc" element of the sitemap URL for.
|
void |
setChangeFrequency(SitemapUrl.ChangeFrequency changeFrequency)
Sets the value of the "changefreq" element of the sitemap URL.
|
void |
setDomain(String domain)
Sets the domain of the "loc" element of the sitemap URL.
|
void |
setLastModified(Temporal lastModified)
Sets the value of the "lastmod" element of the sitemap URL.
|
void |
setPriority(BigDecimal priority)
Sets the value of the "priority" element of the sitemap URL.
|
void |
setValue(String value)
Sets the value of the "loc" element of the sitemap URL.
|
void |
setViewId(String viewId)
Sets the view ID to create the URI part of the "loc" element of the sitemap URL for.
|
getFamily, getRendersChildren
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
public static final String COMPONENT_TYPE
public SitemapUrl()
SitemapUrl
component.IllegalStateException
- when Application.getProjectStage()
is ProjectStage.Development
and
the current request is not for the ViewResourceHandler
at all.public void encodeBegin(FacesContext context) throws IOException
<url>
parent element.encodeBegin
in class UIComponentBase
IOException
public void encodeChildren(FacesContext context) throws IOException
encodeLocation(FacesContext)
, encodeLastModified(FacesContext)
, encodeChangeFrequency(FacesContext)
and
encodePriority(FacesContext)
in this order.encodeChildren
in class UIComponentBase
IOException
public void encodeEnd(FacesContext context) throws IOException
<url>
parent element.encodeEnd
in class UIComponentBase
IOException
protected void encodeLocation(FacesContext context) throws IOException
<loc>
child element with either the value of getValue()
,
or the value of getViewId()
and getDomain()
combined.context
- The involved faces context.IOException
- When an I/O error occurs.IllegalArgumentException
- When the getDomain()
does not represent a valid domain.protected void encodeLastModified(FacesContext context) throws IOException
<lastmod>
child element with the value of getLastModified()
, if any.
It may only encode formats specified in https://www.w3.org/TR/NOTE-datetimecontext
- The involved faces context.IOException
- When an I/O error occurs.protected void encodeChangeFrequency(FacesContext context) throws IOException
<changefreq>
child element with the value of getChangeFrequency()
, if any.context
- The involved faces context.IOException
- When an I/O error occurs.protected void encodePriority(FacesContext context) throws IOException
<priority>
child element with the value of getPriority()
, if any.context
- The involved faces context.IOException
- When an I/O error occurs.IllegalArgumentException
- When the getPriority()
is not between 0.0 and 1.0 (inclusive).public String getValue()
getViewId()
and getDomain()
are ignored.public void setValue(String value)
getViewId()
and getDomain()
are ignored.value
- The value of the "loc" element of the sitemap URL.public String getViewId()
getValue()
is specified.public void setViewId(String viewId)
getValue()
is specified.viewId
- The view ID to create the URI part of the "loc" element of the sitemap URL for.public String getDomain()
getValue()
is specified.public void setDomain(String domain)
getValue()
is specified.domain
- The domain of the "loc" element of the sitemap URL for.public Temporal getLastModified()
public void setLastModified(Temporal lastModified)
lastModified
- The value of the "lastmod" element of the sitemap URL.public SitemapUrl.ChangeFrequency getChangeFrequency()
public void setChangeFrequency(SitemapUrl.ChangeFrequency changeFrequency)
changeFrequency
- The value of the "changefreq" element of the sitemap URL.public BigDecimal getPriority()
public void setPriority(BigDecimal priority)
priority
- The value of the "priority" element of the sitemap URL.Copyright © 2012–2021 OmniFaces. All rights reserved.