atg.sitemap
Class StaticSitemapGenerator

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.sitemap.StaticSitemapGenerator
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, SitemapGenerator, java.util.EventListener

public class StaticSitemapGenerator
extends GenericService
implements SitemapGenerator

Sitemap generator service that generates sitemap repository items in SitemapRepository for static pages. List of static pages sets in staticPages

This is an example of what will be generated:

 <?xml version="1.0" encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
 <url>
   <loc>http://www.example.com/</loc>
   <changefreq>monthly</changefreq>
   <priority>0.8</priority>
 </url>
 </urlset>
 

The available tags are described below:

For additional information see Sitemap protocol


Field Summary
static java.lang.String[] CHANGE_FREQUENCY_VALUES
           
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String COLON
          Valid value for change frequency.
static java.lang.String SITEMAP_FOOTER
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.sitemap.SitemapGenerator
MAX_SITEMAPS, MAX_SIZE, MAX_URLS
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
StaticSitemapGenerator()
           
 
Method Summary
protected  boolean addURLToSitemap(SitemapGeneratorService pSitemapGeneratorService, java.lang.StringBuilder pSitemap, java.lang.String pUrlXml, int pUrlCount, int pSitemapCount)
          Adds sitemap URL xml to sitemap.
 void findAllMatchedFiles(java.io.File pDir, java.lang.String pRegExp, java.util.List<java.lang.String> pMatchedFiles)
          Recursively goes through all files in specified directory including subdirectories and finds all files which names match a given regular expression.
 void generateSitemap(SitemapGeneratorService pSitemapGeneratorService)
          This method will generate sitemap from list of pages in staticPages
protected  void generateSitemapUrls(SitemapGeneratorService pSitemapGeneratorService, java.util.List<java.lang.String> pages, java.lang.String pSiteId)
          Generates sitemap URLs for given list of static pages and given site.
 java.lang.String getChangeFrequency()
          Returns how frequently the page is likely to change.
 java.lang.String getChangeFrequencyForPage(java.lang.String pEntry)
          Returns change frequency for specified page.
 java.lang.String getLocationForPage(java.lang.String pPageURL)
          Gets fully specified sitemap URL for a given relative page.
 java.lang.String getLocationForPage(java.lang.String pPageURL, java.lang.String pSiteId, SitemapGeneratorService pSitemapGeneratorService)
          Gets fully specified sitemap URL for a given page and site.
 java.util.List<java.lang.String> getMatchedFiles(java.io.File pDir, java.lang.String pRegExp)
          Gets all files in directory including subdirectories which names match given regular expression.
 java.lang.String getPageURL(java.lang.String pEntry)
          Returns relative page URL.
 java.lang.String getParametersForPage(java.lang.String pEntry)
          Returns parameters string for page in format: ::.
 java.lang.Float getPriority()
          Returns the priority of URL relative to other URLs on site.
 java.lang.Float getPriorityForPage(java.lang.String pEntry)
          Returns priority for specified page.
 java.lang.String getRegularExprForPattern(java.lang.String pPagePattern)
          Converts page pattern used in component configuration to java regular expression.
 java.util.List<java.lang.String> getResolvedStaticPages()
          Takes configured list of static pages, which can be either actual pages or page patterns with wildcards, and replaces pages that are using wildcards with corresponding matching pages.
 java.lang.String getSitemapFilePrefix()
          Returns Sitemap file prefix.
 java.util.List<java.lang.String> getStaticPages()
          Returns list of static pages which generator will use to build sitemap
 java.lang.String getUrlPrefix()
          Returns URL prefix to the application with protocol, host, port
 java.lang.String getWarDir()
          Returns path where applications's war is located.
 WebApp getWebApp()
          Returns representation of web application in WebApp.
 boolean isChangeFrequencyValid(java.lang.String pChangeFrequency)
          Checks that change frequency is from list of valid values.
 boolean isPriorityValid(java.lang.Float pPriority)
          Checks that priority is from 0.0 to 1.0 range.
 java.util.List<java.lang.String> resolvePagePattern(java.lang.String pPagePattern)
          Returns list of pages that match a given pattern.
 void setChangeFrequency(java.lang.String pChangeFrequency)
          Sets how frequently the page is likely to change.
 void setPriority(java.lang.Float pPriority)
          Sets the priority of URL relative to other URLs on site.
 void setSitemapFilePrefix(java.lang.String pSitemapFilePrefix)
          Sets Sitemap file prefix.
 void setStaticPages(java.util.List<java.lang.String> pStaticPages)
          Sets new list of static pages which generator will use to build sitemap
 void setUrlPrefix(java.lang.String pUrlPrefix)
          Sets new URL prefix to the application with protocol, host, port
 void setWarDir(java.lang.String pWarDir)
          Sets new path where to war directory.
 void setWebApp(WebApp pWebApp)
          Sets new WebApp component.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


COLON

public static final java.lang.String COLON
Valid value for change frequency. Specified in sitemaps.org protocol

See Also:
Constant Field Values

SITEMAP_FOOTER

public static final java.lang.String SITEMAP_FOOTER
See Also:
Constant Field Values

CHANGE_FREQUENCY_VALUES

public static final java.lang.String[] CHANGE_FREQUENCY_VALUES
Constructor Detail

StaticSitemapGenerator

public StaticSitemapGenerator()
Method Detail

getChangeFrequency

public java.lang.String getChangeFrequency()
Returns how frequently the page is likely to change.

Returns:
how frequently the page is likely to change.

setChangeFrequency

public void setChangeFrequency(java.lang.String pChangeFrequency)
Sets how frequently the page is likely to change.

Parameters:
pChangeFrequency - how frequently the page is likely to change.

getPriority

public java.lang.Float getPriority()
Returns the priority of URL relative to other URLs on site.

Returns:
the priority of URL relative to other URLs on site.

setPriority

public void setPriority(java.lang.Float pPriority)
Sets the priority of URL relative to other URLs on site.

Parameters:
pPriority - the priority of URL relative to other URLs on site.

getSitemapFilePrefix

public java.lang.String getSitemapFilePrefix()
Returns Sitemap file prefix. Sitemap file must have no more than 50,000 URLs and must be no larger than 10MB (10,485,760 bytes). If we list more page than this limitations, generator will split information into several files with names sitemapFilePrefix.xml, sitemapFilePrefix2.xml and so on.

Returns:
the Sitemap file prefix

setSitemapFilePrefix

public void setSitemapFilePrefix(java.lang.String pSitemapFilePrefix)
Sets Sitemap file prefix. Sitemap file must have no more than 50,000 URLs and must be no larger than 10MB (10,485,760 bytes). If we list more page than this limitations, generator will split information into several files with names sitemapFilePrefix.xml, sitemapFilePrefix2.xml and so on.

Parameters:
SitemapFilePrefix - the Sitemap file prefix

getWarDir

public java.lang.String getWarDir()
Returns path where applications's war is located.

Returns:
directory where application's war is located.

setWarDir

public void setWarDir(java.lang.String pWarDir)
Sets new path where to war directory.

Parameters:
WarDir - directory where application's war is located.

getStaticPages

public java.util.List<java.lang.String> getStaticPages()
Returns list of static pages which generator will use to build sitemap

Returns:
the List of static pages

setStaticPages

public void setStaticPages(java.util.List<java.lang.String> pStaticPages)
Sets new list of static pages which generator will use to build sitemap

Parameters:
StaticPages - the List of static pages

getUrlPrefix

public java.lang.String getUrlPrefix()
Returns URL prefix to the application with protocol, host, port

Returns:
URL prefix to the application with protocol, host, port

setUrlPrefix

public void setUrlPrefix(java.lang.String pUrlPrefix)
Sets new URL prefix to the application with protocol, host, port

Parameters:
UrlPrefix - new URL prefix to the application with protocol, host, port

getWebApp

public WebApp getWebApp()
Returns representation of web application in WebApp.

Returns:
the WebApp - component which represents web application

setWebApp

public void setWebApp(WebApp pWebApp)
Sets new WebApp component.

Parameters:
WebApp - new WebApp component

getResolvedStaticPages

public java.util.List<java.lang.String> getResolvedStaticPages()
Takes configured list of static pages, which can be either actual pages or page patterns with wildcards, and replaces pages that are using wildcards with corresponding matching pages.

Returns:
list of resolved pages

resolvePagePattern

public java.util.List<java.lang.String> resolvePagePattern(java.lang.String pPagePattern)
Returns list of pages that match a given pattern. If pPagePattern doesn't contains wildCards returns pPagePattern without changes, if it contains wildcards like * and ? then it resolves this pattern to actual list of pages. During resolving pattern with wildcards to actual list of pages it looks for matched files in the file system directory where applications's war is located. E.g., if pPagePattern equals "company/*.jsp" the returned list of pages will contain all pages under /company/ directory with extension .jsp not including subdirectories. If pPagePattern equals "company/** /*.jsp" the returned list of pages will contain all pages under /company/ including subdirectories with extension .jsp. "?" wildcard means any character, e.g., if pPagePattern equals "company/news??.jsp" this will match such pages like "company/news01.jsp", "company/news02.jsp", etc.

Parameters:
pPagePattern - page name pattern
Returns:
list of matching pages

getRegularExprForPattern

public java.lang.String getRegularExprForPattern(java.lang.String pPagePattern)
Converts page pattern used in component configuration to java regular expression.

Parameters:
pPagePattern - page pattern
Returns:
regular expression that corresponds given page pattern

findAllMatchedFiles

public void findAllMatchedFiles(java.io.File pDir,
                                java.lang.String pRegExp,
                                java.util.List<java.lang.String> pMatchedFiles)
Recursively goes through all files in specified directory including subdirectories and finds all files which names match a given regular expression. Resulted list of files are added to matchedFiles list

Parameters:
pDir - directory to be searched for matching files
pRegExp - regular expression
pMatchedFiles - list to that matched files should be added

getMatchedFiles

public java.util.List<java.lang.String> getMatchedFiles(java.io.File pDir,
                                                        java.lang.String pRegExp)
Gets all files in directory including subdirectories which names match given regular expression.

Parameters:
pDir - directory to be searched for matching files
pRegExp - regular expression
Returns:
list to that matched files should be added

getChangeFrequencyForPage

public java.lang.String getChangeFrequencyForPage(java.lang.String pEntry)
Returns change frequency for specified page. Takes page's relative URL parameter in format :: where and are optional. If change frequency is not set per page then default value is used. If default value is also not specified then null value is returned. If both default change frequency and change frequency in page URL parameter are not valid then null value is returned too.

Parameters:
pEntry - relative URL parameter in format ::
Returns:
change frequency for the specified page

isChangeFrequencyValid

public boolean isChangeFrequencyValid(java.lang.String pChangeFrequency)
Checks that change frequency is from list of valid values. Null is assumed to be valid value for change frequency because change frequency can be NOT specified according to sitemap.org protocol

Parameters:
pChangeFrequency - change frequency
Returns:
true if change frequency is valid value

getPriorityForPage

public java.lang.Float getPriorityForPage(java.lang.String pEntry)
Returns priority for specified page. Takes page's relative URL with parameters in format [::] where and are optional. If priority is not set per page then default value is used. If default value is also not specified then null value is returned. If both default priority and priority in page URL parameter are not valid then null value is returned too.

Parameters:
pEntry - page's relative URL with parameters in format [::]
Returns:
priority for the specified page

isPriorityValid

public boolean isPriorityValid(java.lang.Float pPriority)
Checks that priority is from 0.0 to 1.0 range. Null is assumed to be valid value for priority because priority can be NOT specified according to sitemap.org protocol

Parameters:
pPriority - priority
Returns:
true if priority is valid value

getPageURL

public java.lang.String getPageURL(java.lang.String pEntry)
Returns relative page URL. Takes page's relative URL parameter in format :: where and are optional.

Parameters:
pEntry - relative URL parameter in format ::
Returns:
priority for the specified page

getLocationForPage

public java.lang.String getLocationForPage(java.lang.String pPageURL)
Gets fully specified sitemap URL for a given relative page.

Parameters:
pPageURL - page's relative URL
Returns:
final sitemap URL

getLocationForPage

public java.lang.String getLocationForPage(java.lang.String pPageURL,
                                           java.lang.String pSiteId,
                                           SitemapGeneratorService pSitemapGeneratorService)
Gets fully specified sitemap URL for a given page and site. Takes page's relative URL. If site ID is not specified then fully specified URL is obtains by adding context root and configured urlPrefix. If site ID is specified then final URL is determined by SiteURLManager using site configuration.

Parameters:
pPageURL - page's relative URL
pSiteId - site ID *
Returns:
final sitemap URL

getParametersForPage

public java.lang.String getParametersForPage(java.lang.String pEntry)
Returns parameters string for page in format: ::. If page doesn't contain parameters returns empty string. Takes page's relative URL in format :: where and are optional.

Parameters:
pEntry - relative URL parameter in format ::
Returns:
priority for the specified page

generateSitemap

public void generateSitemap(SitemapGeneratorService pSitemapGeneratorService)
This method will generate sitemap from list of pages in staticPages

Specified by:
generateSitemap in interface SitemapGenerator

generateSitemapUrls

protected void generateSitemapUrls(SitemapGeneratorService pSitemapGeneratorService,
                                   java.util.List<java.lang.String> pages,
                                   java.lang.String pSiteId)
Generates sitemap URLs for given list of static pages and given site. Stores generated sitemap to repository.

Parameters:
pSitemapGeneratorService - Sitemap Generator service.
pages - list of static pages.
pSiteId - site ID.

addURLToSitemap

protected boolean addURLToSitemap(SitemapGeneratorService pSitemapGeneratorService,
                                  java.lang.StringBuilder pSitemap,
                                  java.lang.String pUrlXml,
                                  int pUrlCount,
                                  int pSitemapCount)
Adds sitemap URL xml to sitemap. If givent sitemap exceed maximum allowed size new sitemap is started and the old one is written to Sitemap Repository. Boolean indicating whether new sitemap has been started is returned.

Parameters:
pSitemapGeneratorService - Sitemap Generator Service
pSitemap - String builder containing generated sitemap
pUrlXml - URL XML to be added to sitemap
pUrlCount - current count of URLs in sitemap
Returns:
boolean indicating whether new sitemap has been started is returned.