org.opencms.staticexport
Class CmsStaticExportManager

java.lang.Object
  extended by org.opencms.staticexport.CmsStaticExportManager
All Implemented Interfaces:
I_CmsEventListener

public class CmsStaticExportManager
extends java.lang.Object
implements I_CmsEventListener

Provides the functionality to export resources from the OpenCms VFS to the file system.

Since:
6.0.0
Version:
$Revision: 1.136 $
Author:
Alexander Kandzior, Michael Moossen

Field Summary
static java.lang.String EXPORT_ATTRIBUTE_ERROR_MESSAGE
          Marker for error message attribute.
static java.lang.String EXPORT_ATTRIBUTE_ERROR_REQUEST_URI
          Marker for error request uri attribute.
static java.lang.String EXPORT_ATTRIBUTE_ERROR_SERVLET_NAME
          Marker for error servlet name attribute.
static java.lang.String EXPORT_ATTRIBUTE_ERROR_STATUS_CODE
          Marker for error status code attribute.
static java.lang.String EXPORT_BACKUP_FOLDER_NAME
          Name for the backup folder default name.
static java.lang.Integer EXPORT_DEFAULT_BACKUPS
          Name for the default work path.
static java.lang.String EXPORT_DEFAULT_FILE
          Name for the folder default index file.
static java.lang.String EXPORT_DEFAULT_WORKPATH
          Name for the default work path.
static int EXPORT_LINK_WITH_PARAMETER
          Flag value for links without parameters.
static int EXPORT_LINK_WITHOUT_PARAMETER
          Flag value for links without parameters.
static java.lang.String EXPORT_MARKER
          Marker for externally redirected 404 uri's.
static int HANDLER_FINISH_TIME
          Time given (in seconds) to the static export handler to finish a publish task.
 
Fields inherited from interface org.opencms.main.I_CmsEventListener
EVENT_BEFORE_PUBLISH_PROJECT, EVENT_CLEAR_CACHES, EVENT_CLEAR_OFFLINE_CACHES, EVENT_CLEAR_ONLINE_CACHES, EVENT_CLEAR_PRINCIPAL_CACHES, EVENT_FLEX_CACHE_CLEAR, EVENT_FLEX_PURGE_JSP_REPOSITORY, EVENT_FULLSTATIC_EXPORT, EVENT_GROUP_MODIFIED, EVENT_LOGIN_USER, EVENT_OU_MODIFIED, EVENT_PROJECT_MODIFIED, EVENT_PROPERTY_DEFINITION_CREATED, EVENT_PROPERTY_DEFINITION_MODIFIED, EVENT_PROPERTY_MODIFIED, EVENT_PUBLISH_PROJECT, EVENT_REBUILD_SEARCHINDEXES, EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, EVENT_RESOURCE_COPIED, EVENT_RESOURCE_CREATED, EVENT_RESOURCE_DELETED, EVENT_RESOURCE_MODIFIED, EVENT_RESOURCE_MOVED, EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, EVENT_RESOURCES_MODIFIED, EVENT_UPDATE_EXPORTS, EVENT_USER_MODIFIED, KEY_CHANGE, KEY_DBCONTEXT, KEY_GROUP_ID, KEY_GROUP_NAME, KEY_INDEX_NAMES, KEY_OU_ID, KEY_OU_NAME, KEY_PROJECTID, KEY_PUBLISHID, KEY_PUBLISHLIST, KEY_REPORT, KEY_RESOURCE, KEY_RESOURCES, KEY_USER_ACTION, KEY_USER_ID, KEY_USER_NAME, LISTENERS_FOR_ALL_EVENTS, VALUE_GROUP_MODIFIED_ACTION_CREATE, VALUE_GROUP_MODIFIED_ACTION_DELETE, VALUE_GROUP_MODIFIED_ACTION_WRITE, VALUE_OU_MODIFIED_ACTION_CREATE, VALUE_OU_MODIFIED_ACTION_DELETE, VALUE_USER_MODIFIED_ACTION_ADD_USER_TO_GROUP, VALUE_USER_MODIFIED_ACTION_CREATE_USER, VALUE_USER_MODIFIED_ACTION_DELETE_USER, VALUE_USER_MODIFIED_ACTION_REMOVE_USER_FROM_GROUP, VALUE_USER_MODIFIED_ACTION_RESET_PASSWORD, VALUE_USER_MODIFIED_ACTION_SET_OU, VALUE_USER_MODIFIED_ACTION_WRITE_USER
 
Constructor Summary
CmsStaticExportManager()
          Creates a new static export property object.
 
Method Summary
 void addExportRule(java.lang.String name, java.lang.String description)
          Adds a new export rule to the configuration.
 void addExportRuleRegex(java.lang.String regex)
          Adds a regex to the latest export rule.
 void addExportRuleUri(java.lang.String exportUri)
          Adds a export uri to the latest export rule.
 void addRfsRule(java.lang.String name, java.lang.String description, java.lang.String source, java.lang.String rfsPrefix, java.lang.String exportPath, java.lang.String exportWorkPath, java.lang.String exportBackups, java.lang.String useRelativeLinks)
          Adds a new rfs rule to the configuration.
 void addRfsRuleSystemRes(java.lang.String regex)
          Adds a regex of related system resources to the latest rfs-rule.
 void cacheExportUri(java.lang.String rfsName, java.lang.String vfsName, java.lang.String parameters)
          Caches a calculated export uri.
 void cacheOnlineLink(java.lang.Object linkName, java.lang.Object vfsName)
          Caches a calculated online link.
protected  void clearCaches(CmsEvent event)
          Clears the caches in the export manager.
 void cmsEvent(CmsEvent event)
          Implements the CmsEvent interface, the static export properties uses the events to clear the list of cached keys in case a project is published.
protected  void createExportBackupFolders(java.io.File staticExport, java.lang.String exportPath, int exportBackups, java.lang.String ruleBackupExtension)
          Creates the backup folders for the given export folder and deletes the oldest if the maximum number is reached.
protected  void createExportFolder(java.lang.String exportPath, java.lang.String rfsName)
          Creates the parent folder for a exported resource in the RFS.
 int export(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, CmsObject cms, CmsStaticExportData data)
          Exports the requested uri and at the same time writes the uri to the response output stream if required.
 void exportFullStaticRender(boolean purgeFirst, I_CmsReport report)
          Starts a complete static export of all resources.
 java.lang.String getAcceptCharsetHeader()
          Returns the accept-charset header used for internal requests.
 java.lang.String getAcceptLanguageHeader()
          Returns the accept-language header used for internal requests.
 CmsStaticExportData getCachedExportUri(java.lang.String rfsName)
          Returns a cached export data for the given rfs name.
 java.lang.String getCachedOnlineLink(java.lang.String vfsName)
          Returns a cached link for the given vfs name.
 java.lang.String getCacheKey(java.lang.String siteRoot, java.lang.String uri)
          Returns the key for the online, export and secure cache.
 java.lang.String getDefault()
          Gets the default property value as a string representation.
 java.lang.String getDefaultAcceptCharsetHeader()
          Returns the current default charset header.
 java.lang.String getDefaultAcceptLanguageHeader()
          Returns the current default locale header.
 java.lang.String getDefaultRfsPrefix()
          Returns the default prefix for exported links in the "real" file system.
 java.lang.Integer getExportBackups()
          Returns the number of stored backups.
 CmsStaticExportData getExportData(javax.servlet.http.HttpServletRequest request, CmsObject cms)
          Returns the export data for the request, if null is returned no export is required.
 CmsStaticExportData getExportData(java.lang.String vfsName, CmsObject cms)
          Returns the export data for a requested resource, if null is returned no export is required.
protected  CmsStaticExportData getExportData(java.lang.String rfsName, java.lang.String vfsName, CmsObject cms)
          Returns the export data for a requested resource, if null is returned no export is required.
 java.lang.String getExportEnabled()
          Gets the export enabled value as a string representation.
 CmsExportFolderMatcher getExportFolderMatcher()
          Returns the current folder matcher.
 java.util.List getExportFolderPatterns()
          Returns list of resources patterns which are part of the export.
 java.util.List getExportHeaders()
          Returns specific http headers for the static export.
 java.util.Map getExportnames()
          Returns the list of all resources that have the "exportname" property set.
 java.lang.String getExportPath(java.lang.String vfsName)
          Returns the export path for the static export, that is the folder where the static exported resources will be written to.
 java.lang.String getExportPathForConfiguration()
          Returns the original configured export path for the static export without the complete rfs path, to be used when re-writing the configuration.
 boolean getExportPropertyDefault()
          Returns true if the default value for the resource property "export" is true.
 java.util.List getExportRules()
          Returns the export Rules.
 java.util.List getExportSuffixes()
          Gets the list of resource suffixes which will be exported by default.
 java.lang.String getExportUrl()
          Returns the export URL used for internal requests for exporting resources that require a request / response (like JSP).
 java.lang.String getExportUrlForConfiguration()
          Returns the export URL used for internal requests with unsubstituted context values, to be used when re-writing the configuration.
 java.lang.String getExportUrlPrefix()
          Returns the export URL used for internal requests for exporting resources that require a request / response (like JSP) without http://servername.
 java.lang.String getExportWorkPath()
          Returns the export work path for the static export, that is the folder where the static exported resources will be written to during the export process.
 java.lang.String getExportWorkPathForConfiguration()
          Returns the original configured export work path for the static export without the complete rfs path, to be used when re-writing the configuration.
 I_CmsStaticExportHandler getHandler()
          Returns the configured static export handler class.
 I_CmsLinkSubstitutionHandler getLinkSubstitutionHandler()
          Returns the configured link substitution handler class.
 java.lang.String getPlainExportOptimization()
          Gets the plain export optimization value as a string representation.
 boolean getQuickPlainExport()
          Returns true if the quick plain export is enabled.
 java.lang.String getRelativeLinks()
          Gets the relative links value as a string representation.
 java.lang.String getRemoteAddr()
          Returns the remote address used for internal requests.
 java.lang.String getRemoteAddress()
          Returns the remote address.
 java.lang.String getRfsName(CmsObject cms, java.lang.String vfsName)
          Returns the static export rfs name for a given vfs resource.
 java.lang.String getRfsName(CmsObject cms, java.lang.String vfsName, java.lang.String parameters)
          Returns the static export rfs name for a given vfs resource where the link to the resource includes request parameters.
 java.lang.String getRfsPrefix(java.lang.String vfsName)
          Returns the prefix for exported links in the "real" file system.
 java.lang.String getRfsPrefixForConfiguration()
          Returns the original configured prefix for exported links in the "real" file, to be used when re-writing the configuration.
protected  java.lang.String getRfsPrefixForRfsName(java.lang.String rfsName)
          Returns the longest rfs prefix matching a given already translated rfs name.
 java.util.List getRfsRules()
          Returns the rfs Rules.
 java.lang.String getTestResource()
          Returns the vfs name of the test resource.
 java.lang.String getVfsName(CmsObject cms, java.lang.String rfsName)
          Returns the VFS name for the given RFS name, being the exact reverse of getRfsName(CmsObject, String).
protected  java.lang.String getVfsNameInternal(CmsObject cms, java.lang.String rfsName)
          Returns the VFS name from a given RFS name.
 java.lang.String getVfsPrefix()
          Returns the prefix for the internal in the VFS.
 java.lang.String getVfsPrefixForConfiguration()
          Returns the original configured prefix for internal links in the VFS, to be used when re-writing the configuration.
 void initialize(CmsObject cms)
          Initializes the static export manager with the OpenCms system configuration.
protected  java.lang.String insertContextStrings(java.lang.String path)
          Substitutes the ${CONTEXT_NAME} and ${SERVLET_NAME} in a path with the real values.
 boolean isExportLink(CmsObject cms, java.lang.String vfsName)
          Checks if the static export is required for the given VFS resource.
 boolean isFullStaticExport()
          Returns true if the export process is a full static export.
 boolean isSecureLink(CmsObject cms, java.lang.String vfsName)
          Returns true if the given VFS resource should be transported through a secure channel.
 boolean isSecureLink(CmsObject cms, java.lang.String vfsName, java.lang.String siteRoot)
          Returns true if the given VFS resource that is located under the given site root should be transported through a secure channel.
 boolean isStaticExportEnabled()
          Returns true if the static export is enabled.
 boolean isSuffixExportable(java.lang.String resourceName)
          Returns true if the given resource name is exportable because of it's suffix.
 boolean isUseTempDir()
          Checks if we have to use temporary directories during export.
protected  boolean isValidRfsName(java.lang.String rfsName)
          Returns true if the rfs Name match against any of the defined export urls.
protected  boolean isValidURL(java.lang.String inputString)
          Checks if a String is a valid URL.
protected  java.lang.String normalizeExportPath(java.lang.String exportPath)
          Returns a normalized export path.
protected  java.lang.String normalizeRfsPrefix(java.lang.String rfsPrefix)
          Returns a normalized rfs prefix.
 boolean relativeLinksInExport(java.lang.String vfsName)
          Returns true if the links in the static export should be relative.
protected  void scrubExportFolders(I_CmsReport report)
          Scrubs all the "export" folders.
 void setAcceptCharsetHeader(java.lang.String value)
          Sets the accept-charset header value.
 void setAcceptLanguageHeader(java.lang.String value)
          Sets the accept-language header value.
 void setDefault(java.lang.String value)
          Sets the default property value.
 void setExportBackups(java.lang.String backup)
          Sets the number of backups for the static export.
 void setExportEnabled(java.lang.String value)
          Sets the export enabled value.
 void setExportFolderPattern(java.lang.String folder)
          Adds a resource pattern to the list of resources which are part of the export.
 void setExportHeader(java.lang.String exportHeader)
          Sets specific http header for the static export.
protected  void setExportnames()
          Set the list of all resources that have the "exportname" property set.
 void setExportPath(java.lang.String path)
          Sets the path where the static export is written.
 void setExportSuffix(java.lang.String suffix)
          Adds a suffix to the list of resource suffixes which will be exported by default.
 void setExportUrl(java.lang.String url)
          Sets the export url.
 void setExportWorkPath(java.lang.String path)
          Sets the path where the static export is temporarily written.
 void setHandler(java.lang.String handlerClassName)
          Sets the link substitution handler class.
 void setLinkSubstitutionHandler(java.lang.String handlerClassName)
          Sets the static export handler class.
 void setPlainExportOptimization(java.lang.String value)
          Sets the plain export optimization value.
 void setRelativeLinks(java.lang.String value)
          Sets the relative links value.
 void setRemoteAddr(java.lang.String addr)
          Sets the remote address which will be used for internal requests during the static export.
 void setRfsPrefix(java.lang.String rfsPrefix)
          Sets the prefix for exported links in the "real" file system.
 void setTestResource(java.lang.String testResource)
          Sets the test resource.
 void setVfsPrefix(java.lang.String vfsPrefix)
          Sets the prefix for internal links in the vfs.
 void shutDown()
          Shuts down all this static export manager.
protected  void writeResource(javax.servlet.http.HttpServletRequest req, java.lang.String exportPath, java.lang.String rfsName, CmsResource resource, byte[] content)
          Writes a resource to the given export path with the given rfs name and the given content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPORT_ATTRIBUTE_ERROR_MESSAGE

public static final java.lang.String EXPORT_ATTRIBUTE_ERROR_MESSAGE
Marker for error message attribute.

See Also:
Constant Field Values

EXPORT_ATTRIBUTE_ERROR_REQUEST_URI

public static final java.lang.String EXPORT_ATTRIBUTE_ERROR_REQUEST_URI
Marker for error request uri attribute.

See Also:
Constant Field Values

EXPORT_ATTRIBUTE_ERROR_SERVLET_NAME

public static final java.lang.String EXPORT_ATTRIBUTE_ERROR_SERVLET_NAME
Marker for error servlet name attribute.

See Also:
Constant Field Values

EXPORT_ATTRIBUTE_ERROR_STATUS_CODE

public static final java.lang.String EXPORT_ATTRIBUTE_ERROR_STATUS_CODE
Marker for error status code attribute.

See Also:
Constant Field Values

EXPORT_BACKUP_FOLDER_NAME

public static final java.lang.String EXPORT_BACKUP_FOLDER_NAME
Name for the backup folder default name.

See Also:
Constant Field Values

EXPORT_DEFAULT_BACKUPS

public static final java.lang.Integer EXPORT_DEFAULT_BACKUPS
Name for the default work path.


EXPORT_DEFAULT_FILE

public static final java.lang.String EXPORT_DEFAULT_FILE
Name for the folder default index file.

See Also:
Constant Field Values

EXPORT_DEFAULT_WORKPATH

public static final java.lang.String EXPORT_DEFAULT_WORKPATH
Name for the default work path.


EXPORT_LINK_WITH_PARAMETER

public static final int EXPORT_LINK_WITH_PARAMETER
Flag value for links without parameters.

See Also:
Constant Field Values

EXPORT_LINK_WITHOUT_PARAMETER

public static final int EXPORT_LINK_WITHOUT_PARAMETER
Flag value for links without parameters.

See Also:
Constant Field Values

EXPORT_MARKER

public static final java.lang.String EXPORT_MARKER
Marker for externally redirected 404 uri's.

See Also:
Constant Field Values

HANDLER_FINISH_TIME

public static final int HANDLER_FINISH_TIME
Time given (in seconds) to the static export handler to finish a publish task.

See Also:
Constant Field Values
Constructor Detail

CmsStaticExportManager

public CmsStaticExportManager()
Creates a new static export property object.

Method Detail

addExportRule

public void addExportRule(java.lang.String name,
                          java.lang.String description)
Adds a new export rule to the configuration.

Parameters:
name - the name of the rule
description - the description for the rule

addExportRuleRegex

public void addExportRuleRegex(java.lang.String regex)
Adds a regex to the latest export rule.

Parameters:
regex - the regex to add

addExportRuleUri

public void addExportRuleUri(java.lang.String exportUri)
Adds a export uri to the latest export rule.

Parameters:
exportUri - the export uri to add

addRfsRule

public void addRfsRule(java.lang.String name,
                       java.lang.String description,
                       java.lang.String source,
                       java.lang.String rfsPrefix,
                       java.lang.String exportPath,
                       java.lang.String exportWorkPath,
                       java.lang.String exportBackups,
                       java.lang.String useRelativeLinks)
Adds a new rfs rule to the configuration.

Parameters:
name - the name of the rule
description - the description for the rule
source - the source regex
rfsPrefix - the url prefix
exportPath - the rfs export path
exportWorkPath - the rfs export work path
exportBackups - the number of backups
useRelativeLinks - the relative links value

addRfsRuleSystemRes

public void addRfsRuleSystemRes(java.lang.String regex)
Adds a regex of related system resources to the latest rfs-rule.

Parameters:
regex - the regex to add

cacheExportUri

public void cacheExportUri(java.lang.String rfsName,
                           java.lang.String vfsName,
                           java.lang.String parameters)
Caches a calculated export uri.

Parameters:
rfsName - the name of the resource in the "real" file system
vfsName - the name of the resource in the VFS
parameters - the optional parameters for the generation of the resource

cacheOnlineLink

public void cacheOnlineLink(java.lang.Object linkName,
                            java.lang.Object vfsName)
Caches a calculated online link.

Parameters:
linkName - the link
vfsName - the name of the VFS resource

cmsEvent

public void cmsEvent(CmsEvent event)
Implements the CmsEvent interface, the static export properties uses the events to clear the list of cached keys in case a project is published.

Specified by:
cmsEvent in interface I_CmsEventListener
Parameters:
event - CmsEvent that has occurred

export

public int export(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res,
                  CmsObject cms,
                  CmsStaticExportData data)
           throws CmsException,
                  java.io.IOException,
                  javax.servlet.ServletException,
                  CmsStaticExportException
Exports the requested uri and at the same time writes the uri to the response output stream if required.

Parameters:
req - the current request
res - the current response
cms - an initialized cms context (should be initialized with the "Guest" user only)
data - the static export data set
Returns:
status code of the export operation, status codes are the same as http status codes (200,303,304)
Throws:
CmsException - in case of errors accessing the VFS
javax.servlet.ServletException - in case of errors accessing the servlet
java.io.IOException - in case of errors writing to the export output stream
CmsStaticExportException - if static export is disabled

exportFullStaticRender

public void exportFullStaticRender(boolean purgeFirst,
                                   I_CmsReport report)
                            throws CmsException,
                                   java.io.IOException,
                                   javax.servlet.ServletException
Starts a complete static export of all resources.

Parameters:
purgeFirst - flag to delete all resources in the export folder of the rfs
report - an I_CmsReport instance to print output message, or null to write messages to the log file
Throws:
CmsException - in case of errors accessing the VFS
java.io.IOException - in case of errors writing to the export output stream
javax.servlet.ServletException - in case of errors accessing the servlet

getAcceptCharsetHeader

public java.lang.String getAcceptCharsetHeader()
Returns the accept-charset header used for internal requests.

Returns:
the accept-charset header

getAcceptLanguageHeader

public java.lang.String getAcceptLanguageHeader()
Returns the accept-language header used for internal requests.

Returns:
the accept-language header

getCachedExportUri

public CmsStaticExportData getCachedExportUri(java.lang.String rfsName)
Returns a cached export data for the given rfs name.

Please note that this export data contains only the vfs name and the parameters, not the resource itself. It can therefore not directly be used as a return value for the static export.

Parameters:
rfsName - the name of the resource in the real file system to get the cached vfs resource name for
Returns:
a cached vfs resource name for the given rfs name, or null

getCachedOnlineLink

public java.lang.String getCachedOnlineLink(java.lang.String vfsName)
Returns a cached link for the given vfs name.

Parameters:
vfsName - the name of the vfs resource to get the cached link for
Returns:
a cached link for the given vfs name, or null

getCacheKey

public java.lang.String getCacheKey(java.lang.String siteRoot,
                                    java.lang.String uri)
Returns the key for the online, export and secure cache.

Parameters:
siteRoot - the site root of the resource
uri - the URI of the resource
Returns:
a key for the cache

getDefault

public java.lang.String getDefault()
Gets the default property value as a string representation.

Returns:
"true" or "false"

getDefaultAcceptCharsetHeader

public java.lang.String getDefaultAcceptCharsetHeader()
Returns the current default charset header.

Returns:
the current default charset header

getDefaultAcceptLanguageHeader

public java.lang.String getDefaultAcceptLanguageHeader()
Returns the current default locale header.

Returns:
the current default locale header

getDefaultRfsPrefix

public java.lang.String getDefaultRfsPrefix()
Returns the default prefix for exported links in the "real" file system.

Returns:
the default prefix for exported links in the "real" file system

getExportBackups

public java.lang.Integer getExportBackups()
Returns the number of stored backups.

Returns:
the number of stored backups

getExportData

public CmsStaticExportData getExportData(javax.servlet.http.HttpServletRequest request,
                                         CmsObject cms)
Returns the export data for the request, if null is returned no export is required.

Parameters:
request - the request to check for export data
cms - an initialized cms context (should be initialized with the "Guest" user only
Returns:
the export data for the request, if null is returned no export is required

getExportData

public CmsStaticExportData getExportData(java.lang.String vfsName,
                                         CmsObject cms)
Returns the export data for a requested resource, if null is returned no export is required.

Parameters:
vfsName - the VFS name of the resource requested
cms - an initialized cms context (should be initialized with the "Guest" user only
Returns:
the export data for the request, if null is returned no export is required

getExportEnabled

public java.lang.String getExportEnabled()
Gets the export enabled value as a string representation.

Returns:
"true" or "false"

getExportFolderMatcher

public CmsExportFolderMatcher getExportFolderMatcher()
Returns the current folder matcher.

Returns:
the current folder matcher

getExportFolderPatterns

public java.util.List getExportFolderPatterns()
Returns list of resources patterns which are part of the export.

Returns:
the of resources patterns which are part of the export.

getExportHeaders

public java.util.List getExportHeaders()
Returns specific http headers for the static export.

If the header Cache-Control is set, OpenCms will not use its default headers.

Returns:
the list of http export headers

getExportnames

public java.util.Map getExportnames()
Returns the list of all resources that have the "exportname" property set.

Returns:
the list of all resources that have the "exportname" property set

getExportPath

public java.lang.String getExportPath(java.lang.String vfsName)
Returns the export path for the static export, that is the folder where the static exported resources will be written to.

The returned value will be a directory like prefix. The value is configured in the opencms-importexport.xml configuration file. An optimization of the configured value will be performed, where all relative path information is resolved (for example /export/../static will be resolved to /export. Moreover, if the configured path ends with a /, this will be cut off (for example /export/ becomes /export.

This is resource name based, and based on the rfs-rules defined in the opencms-importexport.xml configuration file.

Parameters:
vfsName - the name of the resource to export
Returns:
the export path for the static export, that is the folder where the
See Also:
getRfsPrefix(String), getVfsPrefix()

getExportPathForConfiguration

public java.lang.String getExportPathForConfiguration()
Returns the original configured export path for the static export without the complete rfs path, to be used when re-writing the configuration.

This is required only to serialize the configuration again exactly as it was configured. This method should not be used otherwise. Use getExportPath(String) to obtain the export path to use when exporting.

Returns:
the original configured export path for the static export without the complete rfs path

getExportPropertyDefault

public boolean getExportPropertyDefault()
Returns true if the default value for the resource property "export" is true.

Returns:
true if the default value for the resource property "export" is true

getExportRules

public java.util.List getExportRules()
Returns the export Rules.

Returns:
the export Rules

getExportSuffixes

public java.util.List getExportSuffixes()
Gets the list of resource suffixes which will be exported by default.

Returns:
list of resource suffixes

getExportUrl

public java.lang.String getExportUrl()
Returns the export URL used for internal requests for exporting resources that require a request / response (like JSP).

Returns:
the export URL used for internal requests for exporting resources like JSP

getExportUrlForConfiguration

public java.lang.String getExportUrlForConfiguration()
Returns the export URL used for internal requests with unsubstituted context values, to be used when re-writing the configuration.

This is required only to serialize the configuration again exactly as it was configured. This method should not be used otherwise. Use getExportUrl() to obtain the export path to use when exporting.

Returns:
the export URL used for internal requests with unsubstituted context values

getExportUrlPrefix

public java.lang.String getExportUrlPrefix()
Returns the export URL used for internal requests for exporting resources that require a request / response (like JSP) without http://servername.

Returns:
the export URL used for internal requests for exporting resources like JSP without http://servername

getExportWorkPath

public java.lang.String getExportWorkPath()
Returns the export work path for the static export, that is the folder where the static exported resources will be written to during the export process.

Returns:
the export work path for the static export

getExportWorkPathForConfiguration

public java.lang.String getExportWorkPathForConfiguration()
Returns the original configured export work path for the static export without the complete rfs path, to be used when re-writing the configuration.

Returns:
the original configured export work path for the static export without the complete rfs path

getHandler

public I_CmsStaticExportHandler getHandler()
Returns the configured static export handler class.

If not set, a new CmsAfterPublishStaticExportHandler is created and returned.

Returns:
the configured static export handler class

getLinkSubstitutionHandler

public I_CmsLinkSubstitutionHandler getLinkSubstitutionHandler()
Returns the configured link substitution handler class.

If not set, a new CmsDefaultLinkSubstitutionHandler is created and returned.

Returns:
the configured link substitution handler class

getPlainExportOptimization

public java.lang.String getPlainExportOptimization()
Gets the plain export optimization value as a string representation.

Returns:
"true" or "false"

getQuickPlainExport

public boolean getQuickPlainExport()
Returns true if the quick plain export is enabled.

Returns:
true if the quick plain export is enabled

getRelativeLinks

public java.lang.String getRelativeLinks()
Gets the relative links value as a string representation.

Returns:
"true" or "false"

getRemoteAddr

public java.lang.String getRemoteAddr()
Returns the remote address used for internal requests.

Returns:
the remote address

getRemoteAddress

public java.lang.String getRemoteAddress()
Returns the remote address.

Returns:
the remote address

getRfsName

public java.lang.String getRfsName(CmsObject cms,
                                   java.lang.String vfsName)
Returns the static export rfs name for a given vfs resource.

Parameters:
cms - an initialized cms context
vfsName - the name of the vfs resource
Returns:
the static export rfs name for a give vfs resource
See Also:
getVfsName(CmsObject, String), getRfsName(CmsObject, String, String)

getRfsName

public java.lang.String getRfsName(CmsObject cms,
                                   java.lang.String vfsName,
                                   java.lang.String parameters)
Returns the static export rfs name for a given vfs resource where the link to the resource includes request parameters.

Parameters:
cms - an initialized cms context
vfsName - the name of the vfs resource
parameters - the parameters of the link pointing to the resource
Returns:
the static export rfs name for a give vfs resource

getRfsPrefix

public java.lang.String getRfsPrefix(java.lang.String vfsName)
Returns the prefix for exported links in the "real" file system.

The returned value will be a directory like prefix. The value is configured in the opencms-importexport.xml configuration file. An optimization of the configured value will be performed, where all relative path information is resolved (for example /export/../static will be resolved to /export. Moreover, if the configured path ends with a /, this will be cut off (for example /export/ becomes /export.

This is resource name based, and based on the rfs-rules defined in the opencms-importexport.xml configuration file.

Parameters:
vfsName - the name of the resource to export
Returns:
the prefix for exported links in the "real" file system
See Also:
getExportPath(String), getVfsPrefix()

getRfsPrefixForConfiguration

public java.lang.String getRfsPrefixForConfiguration()
Returns the original configured prefix for exported links in the "real" file, to be used when re-writing the configuration.

This is required only to serialize the configuration again exactly as it was configured. This method should not be used otherwise. Use getRfsPrefix(String) to obtain the rfs prefix to use for the exported links.

Returns:
the original configured prefix for exported links in the "real" file

getRfsRules

public java.util.List getRfsRules()
Returns the rfs Rules.

Returns:
the rfs Rules

getTestResource

public java.lang.String getTestResource()
Returns the vfs name of the test resource.

Returns:
the vfs name of the test resource.

getVfsName

public java.lang.String getVfsName(CmsObject cms,
                                   java.lang.String rfsName)
Returns the VFS name for the given RFS name, being the exact reverse of getRfsName(CmsObject, String).

Returns null if no matching VFS resource can be found for the given RFS name.

Parameters:
cms - the current users OpenCms context
rfsName - the RFS name to get the VFS name for
Returns:
the VFS name for the given RFS name, or null if the RFS name does not match to the VFS
See Also:
getRfsName(CmsObject, String)

getVfsPrefix

public java.lang.String getVfsPrefix()
Returns the prefix for the internal in the VFS.

The returned value will be a directory like prefix. The value is configured in the opencms-importexport.xml configuration file. An optimization of the configured value will be performed, where all relative path information is resolved (for example /opencms/../mycms will be resolved to /mycms. Moreover, if the configured path ends with a /, this will be cut off (for example /opencms/ becomes /opencms.

Returns:
the prefix for the internal in the VFS
See Also:
getExportPath(String), getRfsPrefix(String)

getVfsPrefixForConfiguration

public java.lang.String getVfsPrefixForConfiguration()
Returns the original configured prefix for internal links in the VFS, to be used when re-writing the configuration.

This is required only to serialize the configuration again exactly as it was configured. This method should not be used otherwise. Use getVfsPrefix() to obtain the VFS prefix to use for the internal links.

Returns:
the original configured prefix for internal links in the VFS

initialize

public void initialize(CmsObject cms)
Initializes the static export manager with the OpenCms system configuration.

Parameters:
cms - an OpenCms context object

isExportLink

public boolean isExportLink(CmsObject cms,
                            java.lang.String vfsName)
Checks if the static export is required for the given VFS resource.

Please note that the given OpenCms user context is NOT used to read the resource. The check for export is always done with the permissions of the "Export" user. The provided user context is just used to get the current site root.

Since the "Export" user always operates in the "Online" project, the resource is also read from the "Online" project, not from the current project of the given OpenCms context.

Parameters:
cms - the current users OpenCms context
vfsName - the VFS resource name to check
Returns:
true if static export is required for the given VFS resource

isFullStaticExport

public boolean isFullStaticExport()
Returns true if the export process is a full static export.

Returns:
true if the export process is a full static export

isSecureLink

public boolean isSecureLink(CmsObject cms,
                            java.lang.String vfsName)
Returns true if the given VFS resource should be transported through a secure channel.

The secure mode is only checked in the "Online" project. If the given OpenCms context is currently not in the "Online" project, false is returned.

The given resource is read from the site root of the provided OpenCms context.

Parameters:
cms - the current users OpenCms context
vfsName - the VFS resource name to check
Returns:
true if the given VFS resource should be transported through a secure channel
See Also:
isSecureLink(CmsObject, String, String)

isSecureLink

public boolean isSecureLink(CmsObject cms,
                            java.lang.String vfsName,
                            java.lang.String siteRoot)
Returns true if the given VFS resource that is located under the given site root should be transported through a secure channel.

Parameters:
cms - the current users OpenCms context
vfsName - the VFS resource name to check
siteRoot - the site root where the the VFS resource should be read
Returns:
true if the given VFS resource should be transported through a secure channel
See Also:
isSecureLink(CmsObject, String)

isStaticExportEnabled

public boolean isStaticExportEnabled()
Returns true if the static export is enabled.

Returns:
true if the static export is enabled

isSuffixExportable

public boolean isSuffixExportable(java.lang.String resourceName)
Returns true if the given resource name is exportable because of it's suffix.

Parameters:
resourceName - the name to check
Returns:
true if the given resource name is exportable because of it's suffix

isUseTempDir

public boolean isUseTempDir()
Checks if we have to use temporary directories during export.

Returns:
true if using temporary directories

relativeLinksInExport

public boolean relativeLinksInExport(java.lang.String vfsName)
Returns true if the links in the static export should be relative.

Parameters:
vfsName - the name of the resource to export
Returns:
true if the links in the static export should be relative

setAcceptCharsetHeader

public void setAcceptCharsetHeader(java.lang.String value)
Sets the accept-charset header value.

Parameters:
value - accept-language header value

setAcceptLanguageHeader

public void setAcceptLanguageHeader(java.lang.String value)
Sets the accept-language header value.

Parameters:
value - accept-language header value

setDefault

public void setDefault(java.lang.String value)
Sets the default property value.

Parameters:
value - must be true or false

setExportBackups

public void setExportBackups(java.lang.String backup)
Sets the number of backups for the static export.

Parameters:
backup - number of backups

setExportEnabled

public void setExportEnabled(java.lang.String value)
Sets the export enabled value.

Parameters:
value - must be true or false

setExportFolderPattern

public void setExportFolderPattern(java.lang.String folder)
Adds a resource pattern to the list of resources which are part of the export.

Parameters:
folder - the folder pattern to add to the list.

setExportHeader

public void setExportHeader(java.lang.String exportHeader)
Sets specific http header for the static export.

The format of the headers must be "header:value".

Parameters:
exportHeader - a specific http header

setExportPath

public void setExportPath(java.lang.String path)
Sets the path where the static export is written.

Parameters:
path - the path where the static export is written

setExportSuffix

public void setExportSuffix(java.lang.String suffix)
Adds a suffix to the list of resource suffixes which will be exported by default.

Parameters:
suffix - the suffix to add to the list.

setExportUrl

public void setExportUrl(java.lang.String url)
Sets the export url.

Parameters:
url - the export url

setExportWorkPath

public void setExportWorkPath(java.lang.String path)
Sets the path where the static export is temporarily written.

Parameters:
path - the path where the static export is temporarily written

setHandler

public void setHandler(java.lang.String handlerClassName)
Sets the link substitution handler class.

Parameters:
handlerClassName - the link substitution handler class name

setLinkSubstitutionHandler

public void setLinkSubstitutionHandler(java.lang.String handlerClassName)
Sets the static export handler class.

Parameters:
handlerClassName - the static export handler class name

setPlainExportOptimization

public void setPlainExportOptimization(java.lang.String value)
Sets the plain export optimization value.

Parameters:
value - must be true or false

setRelativeLinks

public void setRelativeLinks(java.lang.String value)
Sets the relative links value.

Parameters:
value - must be true or false

setRemoteAddr

public void setRemoteAddr(java.lang.String addr)
Sets the remote address which will be used for internal requests during the static export.

Parameters:
addr - the remote address to be used

setRfsPrefix

public void setRfsPrefix(java.lang.String rfsPrefix)
Sets the prefix for exported links in the "real" file system.

Parameters:
rfsPrefix - the prefix for exported links in the "real" file system

setTestResource

public void setTestResource(java.lang.String testResource)
Sets the test resource.

Parameters:
testResource - the vfs name of the test resource

setVfsPrefix

public void setVfsPrefix(java.lang.String vfsPrefix)
Sets the prefix for internal links in the vfs.

Parameters:
vfsPrefix - the prefix for internal links in the vfs

shutDown

public void shutDown()
Shuts down all this static export manager.

This is required since there may still be a thread running when the system is being shut down.


clearCaches

protected void clearCaches(CmsEvent event)
Clears the caches in the export manager.

Parameters:
event - the event that requested to clear the caches

createExportBackupFolders

protected void createExportBackupFolders(java.io.File staticExport,
                                         java.lang.String exportPath,
                                         int exportBackups,
                                         java.lang.String ruleBackupExtension)
Creates the backup folders for the given export folder and deletes the oldest if the maximum number is reached.

Parameters:
staticExport - folder for which a new backup folder has to be created
exportPath - export path to create backup path out of it
exportBackups - number of maximum
ruleBackupExtension - extension for rule based backups

createExportFolder

protected void createExportFolder(java.lang.String exportPath,
                                  java.lang.String rfsName)
                           throws CmsException
Creates the parent folder for a exported resource in the RFS.

Parameters:
exportPath - the path to export the file
rfsName - the rfs name of the resource
Throws:
CmsException - if the folder could not be created

getExportData

protected CmsStaticExportData getExportData(java.lang.String rfsName,
                                            java.lang.String vfsName,
                                            CmsObject cms)
Returns the export data for a requested resource, if null is returned no export is required.

Parameters:
rfsName - the RFS name of the resource requested
vfsName - the VFS name of the resource requested
cms - an initialized cms context (should be initialized with the "Guest" user only
Returns:
the export data for the request, if null is returned no export is required

getRfsPrefixForRfsName

protected java.lang.String getRfsPrefixForRfsName(java.lang.String rfsName)
Returns the longest rfs prefix matching a given already translated rfs name.

Parameters:
rfsName - the rfs name
Returns:
its rfs prefix
See Also:
getRfsPrefix(String)

getVfsNameInternal

protected java.lang.String getVfsNameInternal(CmsObject cms,
                                              java.lang.String rfsName)
Returns the VFS name from a given RFS name.

The RFS name must not contain the RFS prefix.

Parameters:
cms - an initialized OpenCms user context
rfsName - the name of the RFS resource
Returns:
the name of the VFS resource

insertContextStrings

protected java.lang.String insertContextStrings(java.lang.String path)
Substitutes the ${CONTEXT_NAME} and ${SERVLET_NAME} in a path with the real values.

Parameters:
path - the path to substitute
Returns:
path with real context values

isValidRfsName

protected boolean isValidRfsName(java.lang.String rfsName)
Returns true if the rfs Name match against any of the defined export urls.

Parameters:
rfsName - the rfs Name to validate
Returns:
true if the rfs Name match against any of the defined export urls

isValidURL

protected boolean isValidURL(java.lang.String inputString)
Checks if a String is a valid URL.

Parameters:
inputString - The String to check can be null
Returns:
true if the String is not null and a valid URL

normalizeExportPath

protected java.lang.String normalizeExportPath(java.lang.String exportPath)
Returns a normalized export path.

Replacing macros, normalizing the path and taking care of relative paths.

Parameters:
exportPath - the export path to normalize
Returns:
the normalized export path

normalizeRfsPrefix

protected java.lang.String normalizeRfsPrefix(java.lang.String rfsPrefix)
Returns a normalized rfs prefix.

Replacing macros and normalizing the path.

Parameters:
rfsPrefix - the prefix to normalize
Returns:
the normalized rfs prefix

scrubExportFolders

protected void scrubExportFolders(I_CmsReport report)
Scrubs all the "export" folders.

Parameters:
report - an I_CmsReport instance to print output message, or null to write messages to the log file

setExportnames

protected void setExportnames()
Set the list of all resources that have the "exportname" property set.


writeResource

protected void writeResource(javax.servlet.http.HttpServletRequest req,
                             java.lang.String exportPath,
                             java.lang.String rfsName,
                             CmsResource resource,
                             byte[] content)
                      throws CmsException
Writes a resource to the given export path with the given rfs name and the given content.

Parameters:
req - the current request
exportPath - the path to export the resource
rfsName - the rfs name
resource - the resource
content - the content
Throws:
CmsException - if something goes wrong