atg.sitemap
Class SitemapTools

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

public class SitemapTools
extends GenericService

Utility methods for sitemap and siteindex items handling.


Field Summary
static java.lang.String CLASS_VERSION
           
static java.lang.String FILE_SEPARATOR
           
static java.lang.String SITEINDEX_FOOTER
           
static java.lang.String SITEINDEX_HEADER
           
static java.lang.String SITEMAP_FOOTER
           
static java.lang.String SITEMAP_HEADER
           
static java.lang.String SLASH
           
static char SLASH_CHAR
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
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
SitemapTools()
           
 
Method Summary
static java.lang.String addPrefixToUrl(java.lang.String pUrlPrefix, java.lang.String pUrl)
          Adds specified URL prefix to URL.
static void addPrefixToUrl(java.lang.String pUrlPrefix, java.lang.StringBuilder pUrl)
          Adds specified URL prefix to URL.
 void addSitemapEntry(java.lang.StringBuilder pStringBuilder, java.lang.String pSitemapUrl, boolean pDebugMode)
          Generates and apppends sitemap entry of view:
 void appendSiteindexFooter(java.lang.StringBuilder pSiteindexXML)
          Appends siteindex footer to pSiteindexXML
 void appendSiteindexHeader(java.lang.StringBuilder pSiteindexXML)
          Appends siteindex header to pSiteindexXML
 void appendSitemapFooter(java.lang.StringBuilder pSitemapXML)
          Appends sitemap footer to pSitemapXML
 void appendSitemapHeader(java.lang.StringBuilder pSitemapXML)
          Appends sitemap header to pSitemapXML
 void deleteAllItems(RepositoryItemDescriptor pDesc)
          Deletes all items which repository item descriptor is pDesc.
 void deleteSiteindexItems()
          Deletes all siteindex repository items from repository
 void deleteSitemapItems()
          Deletes all sitemap repository items from repository
static java.lang.String encodeURLParameter(java.lang.String pParameter)
          Encodes the given text to UTF-8 so that it can be added to a URL.
static java.lang.String escapeURL(java.lang.String pURL)
          Replaces the following characters in the URL string with their entity escape codes: &,',",<,>.
static java.lang.String formatWarDir(java.lang.String pWarDir)
          Returns formatted path to WarDir using '/' as file separator and not ended with file separator.
 java.lang.String generateSitemapUrlXml(java.lang.String pUrl, java.lang.String pFrequency, java.lang.String pPriority, boolean pDebugMode)
          Generates sitemap URL XML for a given repository item:
 SitemapPropertiesManager getSitemapPropertiesManager()
           
 MutableRepository getSitemapRepository()
           
 RepositoryItem[] lookupAllItems(RepositoryItemDescriptor pDesc)
          Returns an array of repository items which repository item descriptor is pDesc.
 RepositoryItem[] lookupSiteindexItems()
          Returns an array of siteindex repository items.
 RepositoryItem[] lookupSitemapItems()
          Returns an array of sitemap repository items.
 void setSitemapPropertiesManager(SitemapPropertiesManager pSitemapPropertiesManager)
           
 void setSitemapRepository(MutableRepository pSitemapRepository)
           
 boolean validateSitemapSize(java.lang.String pStaticUrlXml, java.lang.StringBuilder pStringBuilder, int pMaxSitemapSize)
          Checks if static URL can be added to sitemap so that maximum allowed file size will not be exceeded.
 void writeSiteindex(java.lang.StringBuilder pSiteindexXML, java.lang.String pFilename)
          Writes siteindex to SitemapRepository
 void writeSitemap(java.lang.StringBuilder pSitemapXML, java.lang.String pFilename)
          Writes sitemap to SitemapRepository
 void writeSitemap(java.lang.StringBuilder pSitemapXML, java.lang.String pFilenamePrefix, int sitemapCount)
          Writes sitemap to SitemapRepository.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, 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, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, 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

SITEMAP_HEADER

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

SITEMAP_FOOTER

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

SITEINDEX_HEADER

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

SITEINDEX_FOOTER

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

FILE_SEPARATOR

public static final java.lang.String FILE_SEPARATOR

SLASH

public static java.lang.String SLASH

SLASH_CHAR

public static char SLASH_CHAR
Constructor Detail

SitemapTools

public SitemapTools()
Method Detail

getSitemapRepository

public MutableRepository getSitemapRepository()
Returns:
the Sitemap repository

setSitemapRepository

public void setSitemapRepository(MutableRepository pSitemapRepository)
Parameters:
SitemapRepository - Sitemap repository

getSitemapPropertiesManager

public SitemapPropertiesManager getSitemapPropertiesManager()
Returns:
the SitemapPropertiesManager Sitemap repository props manager

setSitemapPropertiesManager

public void setSitemapPropertiesManager(SitemapPropertiesManager pSitemapPropertiesManager)
Parameters:
SitemapPropertiesManager - Sitemap repository props manager

lookupSiteindexItems

public RepositoryItem[] lookupSiteindexItems()
                                      throws RepositoryException
Returns an array of siteindex repository items.

Returns:
array of siteindex repository items.
Throws:
RepositoryException - if repository exception occurs

lookupSitemapItems

public RepositoryItem[] lookupSitemapItems()
                                    throws RepositoryException
Returns an array of sitemap repository items.

Returns:
array of sitemap repository items
Throws:
RepositoryException - if repository exception occurs

deleteSitemapItems

public void deleteSitemapItems()
                        throws RepositoryException
Deletes all sitemap repository items from repository

Throws:
RepositoryException - if repository exception occurs

deleteSiteindexItems

public void deleteSiteindexItems()
                          throws RepositoryException
Deletes all siteindex repository items from repository

Throws:
RepositoryException - if repository exception occurs

lookupAllItems

public RepositoryItem[] lookupAllItems(RepositoryItemDescriptor pDesc)
                                throws RepositoryException
Returns an array of repository items which repository item descriptor is pDesc.

Parameters:
pDesc - repository item descriptor
Returns:
array of repository items
Throws:
RepositoryException - if repository exception occurs

deleteAllItems

public void deleteAllItems(RepositoryItemDescriptor pDesc)
                    throws RepositoryException
Deletes all items which repository item descriptor is pDesc.

Parameters:
pDesc - repository item descriptor
Throws:
RepositoryException - if repository exception occurs

appendSiteindexFooter

public void appendSiteindexFooter(java.lang.StringBuilder pSiteindexXML)
Appends siteindex footer to pSiteindexXML

Parameters:
pSiteindexXML - String builder with siteindex XML

appendSiteindexHeader

public void appendSiteindexHeader(java.lang.StringBuilder pSiteindexXML)
Appends siteindex header to pSiteindexXML

Parameters:
pSiteindexXML - String builder with siteindex XML

appendSitemapFooter

public void appendSitemapFooter(java.lang.StringBuilder pSitemapXML)
Appends sitemap footer to pSitemapXML

Parameters:
pSitemapXML - String builder with sitemap XML

appendSitemapHeader

public void appendSitemapHeader(java.lang.StringBuilder pSitemapXML)
Appends sitemap header to pSitemapXML

Parameters:
pSitemapXML - String builder with sitemap XML

writeSitemap

public void writeSitemap(java.lang.StringBuilder pSitemapXML,
                         java.lang.String pFilename)
Writes sitemap to SitemapRepository

Parameters:
pSitemapXML - XML with siteindex information
pFilename - sitemap filename

writeSitemap

public void writeSitemap(java.lang.StringBuilder pSitemapXML,
                         java.lang.String pFilenamePrefix,
                         int sitemapCount)
Writes sitemap to SitemapRepository. Adds index to sitemap file name if the current number of sitemaps is greater than 1, e.g. sitemap.xml, sitemap2.xml, and so on.

Parameters:
pSitemapXML - XML with siteindex information
pFilename - sitemap filename

writeSiteindex

public void writeSiteindex(java.lang.StringBuilder pSiteindexXML,
                           java.lang.String pFilename)
Writes siteindex to SitemapRepository

Parameters:
pSiteindexXML - XML with siteindex information
pFilename - siteindex filename

addSitemapEntry

public void addSitemapEntry(java.lang.StringBuilder pStringBuilder,
                            java.lang.String pSitemapUrl,
                            boolean pDebugMode)
Generates and apppends sitemap entry of view:
 <sitemap>
   <loc>http://www.example.com/sitemap1.xml</loc>
 </sitemap>
 

Parameters:
pStringBuilder - string builder to append sitemap entry
pSitemapUrl - fully specified sitemap URL
pDebugMode - whether debug mode or not

generateSitemapUrlXml

public java.lang.String generateSitemapUrlXml(java.lang.String pUrl,
                                              java.lang.String pFrequency,
                                              java.lang.String pPriority,
                                              boolean pDebugMode)
Generates sitemap URL XML for a given repository item:
 <url>
   <loc>http://www.example.com/</loc>
   <changefreq>monthly</changefreq>
   <priority>0.8</priority>
 </url>
 

Parameters:
pUrl - URL to page
pFrequency - change frequency
pPriority - priority
pDebugMode - whether debug mode or not
Returns:
sitemap url entry

validateSitemapSize

public boolean validateSitemapSize(java.lang.String pStaticUrlXml,
                                   java.lang.StringBuilder pStringBuilder,
                                   int pMaxSitemapSize)
Checks if static URL can be added to sitemap so that maximum allowed file size will not be exceeded.

Parameters:
pStaticUrlXml - - static URL XML that is going to be added next to sitemap
pStringBuilder - - StringBuidler that contains XML string with sitemap for static pages
Returns:
true if maximum allowed size will be not exceeded by adding given static URL

addPrefixToUrl

public static java.lang.String addPrefixToUrl(java.lang.String pUrlPrefix,
                                              java.lang.String pUrl)
Adds specified URL prefix to URL.

Parameters:
pUrlPrefix - - URL prefix to add
pUrl - - URL to be prepended with prefix
Returns:
URL with specified prefix

addPrefixToUrl

public static void addPrefixToUrl(java.lang.String pUrlPrefix,
                                  java.lang.StringBuilder pUrl)
Adds specified URL prefix to URL.

Parameters:
pUrlPrefix - - URL prefix to add
pUrl - - StringBuilder with URL where URL prefix should be added

formatWarDir

public static java.lang.String formatWarDir(java.lang.String pWarDir)
Returns formatted path to WarDir using '/' as file separator and not ended with file separator.

Returns:
formatted path to war directory

encodeURLParameter

public static java.lang.String encodeURLParameter(java.lang.String pParameter)
Encodes the given text to UTF-8 so that it can be added to a URL.

Parameters:
pText - The String object containing the text to be encoded.
Returns:
encoded to UTF-8 string

escapeURL

public static java.lang.String escapeURL(java.lang.String pURL)
Replaces the following characters in the URL string with their entity escape codes: &,',",<,>.

Parameters:
pURL - URL to be escaped
Returns:
escaped URL