org.meshcms.core
Class WebSite

java.lang.Object
  extended byorg.meshcms.core.WebSite
Direct Known Subclasses:
MainWebSite, VirtualWebSite

public class WebSite
extends java.lang.Object


Field Summary
static java.lang.String ADMIN_ID_FILE
           
static java.lang.String ADMIN_THEME
          Name of the default admin theme folder.
protected  Path adminModulesPath
           
protected  Path adminPath
           
protected  Path adminScriptsPath
           
protected  Path adminThemePath
           
protected  Path adminThemesPath
           
static java.lang.String APP_NAME
           
static java.lang.String BACKUP_DIR_PREFIX
          A prefix to be used for every backup dir.
static java.lang.String BACKUP_PREFIX
          A prefix to be used for every backup file.
static java.lang.String CMS_ID_FILE
           
protected  Path cmsPath
           
protected  Path configFilePath
           
protected  Configuration configuration
           
protected  Path customModulesPath
           
protected  Path customThemesPath
           
protected  Path generatedFilesPath
           
protected  long lastAdminThemeBlock
           
protected  Path moduleDataPath
           
protected  Path privatePath
           
protected  Path propertiesFilePath
           
protected  Path repositoryPath
           
protected  java.io.File rootFile
           
protected  Path rootPath
           
protected  javax.servlet.ServletContext sc
           
protected  SiteInfo siteInfo
           
protected  SiteMap siteMap
           
protected  Path sitesFilePath
           
protected  int statsLength
           
protected  long statsZero
           
static java.lang.String TEMP_PREFIX
          A prefix to be used for every temporary file created in the repository.
protected  Path usersPath
           
static java.lang.String VERSION_ID
           
protected  Path virtualSitesPath
           
protected  java.lang.String[] welcomeFiles
           
 
Constructor Summary
protected WebSite()
           
 
Method Summary
 boolean copyFile(UserInfo user, Path oldPath, Path newPath)
          Copies a file (or directory) to another file (or directory).
 boolean copyFile(UserInfo user, Path filePath, java.lang.String newName)
          Copies a file to another file in the same directory.
protected static WebSite create(javax.servlet.ServletContext sc, java.lang.String[] welcomeFiles, java.io.File rootFile, Path rootPath, Path cmsPath)
           
 java.io.File createDir(Path path)
           
 boolean createDirectory(UserInfo user, Path dirPath)
          Creates a new directory.
 boolean createFile(UserInfo user, Path filePath)
          Creates a new file.
 boolean delete(UserInfo user, Path filePath, boolean deleteNonEmptyDirectories)
          Deletes a file or directory.
 Path findCurrentWelcome(Path dirPath)
          Returns the current welcome file path for the given folder.
 java.lang.String getAbsoluteLink(PageInfo pageInfo)
           
 java.lang.String getAbsoluteLink(Path path)
           
 java.lang.String getAdminMetaThemeTag()
          Returns the complete tag used by pages in the admin folder.
 Path getAdminModulesPath()
           
 Path getAdminPath()
          Returns the path of the admin directory.
 Path getAdminScriptsPath()
           
 Path getAdminThemePath()
           
 Path getAdminThemesPath()
           
 Path getCMSPath()
           
 Path getConfigFilePath()
           
 Configuration getConfiguration()
          Returns the current configuration of the web application.
 Path getCustomModulesPath()
           
 Path getCustomThemesPath()
           
 Path getDirectory(Path path)
          Returns the directory that contains the given path.
 java.lang.String getDummyMetaThemeTag()
           
 java.io.File getFile(Path path)
          Returns the file object for a given path in the web application.
 Path getGeneratedFilesPath()
           
 java.lang.String getHTMLTemplate(java.lang.String pageTitle)
          Returns a string containing a basic HTML page.
 long getLastAdminThemeBlock()
           
 Path getLink(PageInfo pageInfo, Path pagePath)
           
 Path getLink(Path path, Path pagePath)
           
 java.lang.String[] getLinkList(PageInfo[] pages, Path pagePath, java.lang.String target, java.lang.String style)
           
 Path getModuleDataPath()
           
 Path getModulePath(java.lang.String moduleName)
          Returns the path of the module file with the given name.
 Path getPath(java.io.File file)
          Returns the Path of a file in the context.
 Path getPrivatePath()
           
 Path getPropertiesFilePath()
           
 java.io.File getRepositoryFile(Path filePath, java.lang.String fileName)
          Returns the correct file in the repository.
 Path getRepositoryPath()
           
 Path getRequestedPath(javax.servlet.http.HttpServletRequest request)
           
 java.io.File getRootFile()
           
 Path getRootPath()
          Returns the site root path.
 Path getServedPath(javax.servlet.http.HttpServletRequest request)
           
 Path getServedPath(Path requestedPath)
           
protected  javax.servlet.ServletContext getServletContext()
           
 SiteInfo getSiteInfo()
          Returns the instance of the SiteInfo class that is managing the site information.
 SiteMap getSiteMap()
          Returns the instance of the SiteMap that is currently manage the site map.
 Path getSitesFilePath()
           
 int getStatsIndex()
          Returns the index of the current day in the array of stats included in any PageInfo instance.
 int getStatsLength()
          Returns the length of stats (hit counts) measured in days.
 Path getThemePath(Path pagePath)
          Returns the path of the theme to be applied to the given path.
 java.lang.String[] getTitles(PageInfo[] pages)
          Returns an array of menu titles for the given pages.
 java.lang.String getTypeDescription()
           
 Path getUsersPath()
           
 Path getVirtualSitesPath()
           
 WebSite getWebSite(javax.servlet.ServletRequest request)
           
 java.lang.String[] getWelcomeFileNames()
          Returns the array of welcome file names.
protected  void init(javax.servlet.ServletContext sc, java.lang.String[] welcomeFiles, java.io.File rootFile, Path rootPath, Path cmsPath)
           
 boolean isDirectory(Path path)
          Checks if the given path is a directory in the file system.
 boolean isInsideModules(Path path)
           
 boolean isInsideThemes(Path path)
           
 boolean isSystem(Path path)
          Determines if the given path is a system directory, or is contained in a system directory.
 boolean isVirtual()
           
 boolean isVisuallyEditable(Path path)
          Returns true if the extension of the path is known to denote a type of file that can be edited using the wysiwyg editor.
 boolean isWelcomeFileName(java.lang.String fileName)
          Checks if the file name is one of the welcome files.
 java.lang.Object loadFromXML(Path path)
           
protected  void log(java.lang.String s)
          Logs a string by calling ServletContext.log(s)
 void log(java.lang.String message, java.lang.Throwable throwable)
          Logs an exception by calling ServletContext.log(message, throwable)
 boolean move(UserInfo user, Path oldPath, Path newPath)
          Moves (or renames) a file.
 void readConfig()
           
 boolean rename(UserInfo user, Path filePath, java.lang.String newName)
          Renames a file.
 boolean saveToFile(UserInfo user, java.lang.Object saveThis, Path filePath)
          Stores an object into a file.
 boolean setFileTime(UserInfo user, Path filePath, long time)
           
 void setLastAdminThemeBlock(long lastAdminThemeBlock)
           
 boolean storeToXML(java.lang.Object o, Path path)
           
 java.lang.String toString()
           
 boolean touch(UserInfo user, Path filePath)
          Sets the last modified date of the file to the current time.
 void updateSiteMap(boolean force)
          Creates another instance of SiteMap.
 javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.ServletRequest request)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

APP_NAME

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

VERSION_ID

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

BACKUP_PREFIX

public static final java.lang.String BACKUP_PREFIX
A prefix to be used for every backup file.

See Also:
Constant Field Values

BACKUP_DIR_PREFIX

public static final java.lang.String BACKUP_DIR_PREFIX
A prefix to be used for every backup dir.

See Also:
Constant Field Values

TEMP_PREFIX

public static final java.lang.String TEMP_PREFIX
A prefix to be used for every temporary file created in the repository.

See Also:
Constant Field Values

ADMIN_THEME

public static final java.lang.String ADMIN_THEME
Name of the default admin theme folder.

See Also:
Constant Field Values

CMS_ID_FILE

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

ADMIN_ID_FILE

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

sc

protected javax.servlet.ServletContext sc

welcomeFiles

protected java.lang.String[] welcomeFiles

rootFile

protected java.io.File rootFile

lastAdminThemeBlock

protected long lastAdminThemeBlock

statsZero

protected long statsZero

statsLength

protected int statsLength

configuration

protected Configuration configuration

siteInfo

protected SiteInfo siteInfo

siteMap

protected SiteMap siteMap

rootPath

protected Path rootPath

cmsPath

protected Path cmsPath

adminPath

protected Path adminPath

adminThemePath

protected Path adminThemePath

adminModulesPath

protected Path adminModulesPath

adminThemesPath

protected Path adminThemesPath

adminScriptsPath

protected Path adminScriptsPath

privatePath

protected Path privatePath

usersPath

protected Path usersPath

virtualSitesPath

protected Path virtualSitesPath

repositoryPath

protected Path repositoryPath

customModulesPath

protected Path customModulesPath

generatedFilesPath

protected Path generatedFilesPath

moduleDataPath

protected Path moduleDataPath

customThemesPath

protected Path customThemesPath

configFilePath

protected Path configFilePath

propertiesFilePath

protected Path propertiesFilePath

sitesFilePath

protected Path sitesFilePath
Constructor Detail

WebSite

protected WebSite()
Method Detail

create

protected static WebSite create(javax.servlet.ServletContext sc,
                                java.lang.String[] welcomeFiles,
                                java.io.File rootFile,
                                Path rootPath,
                                Path cmsPath)

init

protected void init(javax.servlet.ServletContext sc,
                    java.lang.String[] welcomeFiles,
                    java.io.File rootFile,
                    Path rootPath,
                    Path cmsPath)

readConfig

public void readConfig()

getServletContext

protected javax.servlet.ServletContext getServletContext()

updateSiteMap

public void updateSiteMap(boolean force)
Creates another instance of SiteMap. If force is true, a new site map is always created and the method returns after the new site map is completed. If it is false, a new site map is created only if the current one is too old. In this case, the site map is created asynchronously and the method returns immediately. The repository will be cleaned too.

Parameters:
force - it to force the SiteMap creation.

getSiteMap

public SiteMap getSiteMap()
Returns the instance of the SiteMap that is currently manage the site map. Since this object can be replaced with a new one at any moment, a class that wants to use it should store it in a local variable and use it for all the operation/method.

Returns:
the current instance of SiteMap

getConfiguration

public Configuration getConfiguration()
Returns the current configuration of the web application.


getSiteInfo

public SiteInfo getSiteInfo()
Returns the instance of the SiteInfo class that is managing the site information.

See Also:
SiteInfo

getStatsIndex

public int getStatsIndex()
Returns the index of the current day in the array of stats included in any PageInfo instance.


getStatsLength

public int getStatsLength()
Returns the length of stats (hit counts) measured in days.


createDirectory

public boolean createDirectory(UserInfo user,
                               Path dirPath)
Creates a new directory.

Parameters:
user - the user that requests the creation of the directory
dirPath - the path of the new directory
Returns:
true if the directory has been created or already existed, false otherwise

createFile

public boolean createFile(UserInfo user,
                          Path filePath)
Creates a new file. If the extension of the file denotes a web page, the basic template is copied into the file, otherwise an empty file is created.

Parameters:
user - the user that requests the file creation
filePath - the path of the new file
Returns:
true if the new file has been created or already existed, false otherwise

copyFile

public boolean copyFile(UserInfo user,
                        Path filePath,
                        java.lang.String newName)
Copies a file to another file in the same directory. An existing file won't be overwritten.

Parameters:
user - the user that requests the operation
filePath - the path of the old file
newName - the name of the new file
Returns:
true if the new file has been copied, false otherwise

copyFile

public boolean copyFile(UserInfo user,
                        Path oldPath,
                        Path newPath)
Copies a file (or directory) to another file (or directory). Existing files won't be overwritten.

Parameters:
user - the user that requests the operation
oldPath - the location of the existing file
newPath - the location of the new copy of the file
Returns:
true if the new file has been copied, false otherwise

rename

public boolean rename(UserInfo user,
                      Path filePath,
                      java.lang.String newName)
Renames a file.

Parameters:
user - the user that requests the operation
filePath - the path of the file
newName - the name of the new file
Returns:
true if the new file has been renamed, false otherwise

move

public boolean move(UserInfo user,
                    Path oldPath,
                    Path newPath)
Moves (or renames) a file.

Parameters:
user - the user that requests the operation
oldPath - the current location of the file
newPath - the new location of the file
Returns:
true if the new file has been moved, false otherwise

delete

public boolean delete(UserInfo user,
                      Path filePath,
                      boolean deleteNonEmptyDirectories)
Deletes a file or directory.

Parameters:
user - the user that requests the operation
filePath - the path of the file
deleteNonEmptyDirectories - if true, non-empty directories will be deleted too
Returns:
true if the file has been deleted, false otherwise

touch

public boolean touch(UserInfo user,
                     Path filePath)
Sets the last modified date of the file to the current time.

Parameters:
user - the user that requests the operation
filePath - the path of the file
Returns:
true if the date has been changed, false otherwise

setFileTime

public boolean setFileTime(UserInfo user,
                           Path filePath,
                           long time)

saveToFile

public boolean saveToFile(UserInfo user,
                          java.lang.Object saveThis,
                          Path filePath)
Stores an object into a file. Supported objects are:

Parameters:
user - the user that requests the operation
saveThis - the object to be stored in the file
filePath - the path of the file to be written. If the file exists, it will be backed up and overwritten
Returns:
true if the operation has been completed successfully, false otherwise

getRepositoryFile

public java.io.File getRepositoryFile(Path filePath,
                                      java.lang.String fileName)
Returns the correct file in the repository. For example, if you need to create a temporary copy of /somedir/index.html, you could use filePath = /somedir/index.html and fileName = tmp.html.

Parameters:
filePath - the path where to search
fileName - the file name
Returns:
the searched file

createDir

public java.io.File createDir(Path path)

getFile

public java.io.File getFile(Path path)
Returns the file object for a given path in the web application. The file is not checked for existance.

Parameters:
path - the path representation of the file
Returns:
the file object for this path, or null if it's not found

getRootFile

public java.io.File getRootFile()

getRootPath

public Path getRootPath()
Returns the site root path.


getPath

public Path getPath(java.io.File file)
Returns the Path of a file in the context.

See Also:
getFile(org.meshcms.util.Path)

getRequestedPath

public Path getRequestedPath(javax.servlet.http.HttpServletRequest request)

getServedPath

public Path getServedPath(javax.servlet.http.HttpServletRequest request)

getServedPath

public Path getServedPath(Path requestedPath)

isDirectory

public boolean isDirectory(Path path)
Checks if the given path is a directory in the file system.

Parameters:
path - the Path to check
Returns:
true if the path is a directory.

getDirectory

public Path getDirectory(Path path)
Returns the directory that contains the given path. This is different from Path.getParent(), since if the path is known to be a directory in the web application, the path itself is returned.

Parameters:
path - the Path to check
Returns:
a directory(that contains the given path) as a Path object.

getLinkList

public java.lang.String[] getLinkList(PageInfo[] pages,
                                      Path pagePath,
                                      java.lang.String target,
                                      java.lang.String style)

getAbsoluteLink

public java.lang.String getAbsoluteLink(Path path)

getAbsoluteLink

public java.lang.String getAbsoluteLink(PageInfo pageInfo)

getLink

public Path getLink(Path path,
                    Path pagePath)

getLink

public Path getLink(PageInfo pageInfo,
                    Path pagePath)

getTitles

public java.lang.String[] getTitles(PageInfo[] pages)
Returns an array of menu titles for the given pages. SiteInfo is used to get the titles.

Parameters:
pages - an array of pages to be processed
Returns:
the array of titles for the given pages.

isSystem

public boolean isSystem(Path path)
Determines if the given path is a system directory, or is contained in a system directory. System directories are:

Parameters:
path - the given path(directory) to be checked
Returns:
true if it is a system directory, false otherwise

isVisuallyEditable

public boolean isVisuallyEditable(Path path)
Returns true if the extension of the path is known to denote a type of file that can be edited using the wysiwyg editor.


getModulePath

public Path getModulePath(java.lang.String moduleName)
Returns the path of the module file with the given name.


getAdminPath

public Path getAdminPath()
Returns the path of the admin directory.


getCMSPath

public Path getCMSPath()

isVirtual

public boolean isVirtual()

getAdminMetaThemeTag

public java.lang.String getAdminMetaThemeTag()
Returns the complete tag used by pages in the admin folder. This way those pages can set to be themed according to the site preferences (i.e. using a custom theme or the default admin theme).


getDummyMetaThemeTag

public java.lang.String getDummyMetaThemeTag()

getHTMLTemplate

public java.lang.String getHTMLTemplate(java.lang.String pageTitle)
                                 throws java.io.IOException
Returns a string containing a basic HTML page.

Parameters:
pageTitle - the content of the <title> tag (if null, the title will be "New Page")
Returns:
a basic "empty" HTML page
Throws:
java.io.IOException

isInsideModules

public boolean isInsideModules(Path path)

isInsideThemes

public boolean isInsideThemes(Path path)

log

protected void log(java.lang.String s)
Logs a string by calling ServletContext.log(s)


log

public void log(java.lang.String message,
                java.lang.Throwable throwable)
Logs an exception by calling ServletContext.log(message, throwable)


isWelcomeFileName

public boolean isWelcomeFileName(java.lang.String fileName)
Checks if the file name is one of the welcome files.

Parameters:
fileName - the file name to check
Returns:
true if the given file name is known to be a welcome file name.

getWelcomeFileNames

public java.lang.String[] getWelcomeFileNames()
Returns the array of welcome file names.

Returns:
an array of welcome file names for the current web application. Values are fetched from the web.xml file.

findCurrentWelcome

public Path findCurrentWelcome(Path dirPath)
Returns the current welcome file path for the given folder. If there is no welcome file in that folder, this method returns null.

Parameters:
dirPath - the folder where to search the welcome file
Returns:
the welcome file as a Path object of null if not found.

getWebSite

public WebSite getWebSite(javax.servlet.ServletRequest request)

wrapRequest

public javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.ServletRequest request)

getTypeDescription

public java.lang.String getTypeDescription()

toString

public java.lang.String toString()

loadFromXML

public java.lang.Object loadFromXML(Path path)

storeToXML

public boolean storeToXML(java.lang.Object o,
                          Path path)

getThemePath

public Path getThemePath(Path pagePath)
Returns the path of the theme to be applied to the given path. This depends on the stored values and on the option to use the default theme for the admin pages. This method returns null if no theme is found.

Parameters:
pagePath - the path of the page who's theme is searched.
Returns:
the theme of this page as a Path object

getAdminThemePath

public Path getAdminThemePath()

getAdminModulesPath

public Path getAdminModulesPath()

getModuleDataPath

public Path getModuleDataPath()

getAdminThemesPath

public Path getAdminThemesPath()

getAdminScriptsPath

public Path getAdminScriptsPath()

getPrivatePath

public Path getPrivatePath()

getUsersPath

public Path getUsersPath()

getVirtualSitesPath

public Path getVirtualSitesPath()

getRepositoryPath

public Path getRepositoryPath()

getCustomModulesPath

public Path getCustomModulesPath()

getGeneratedFilesPath

public Path getGeneratedFilesPath()

getCustomThemesPath

public Path getCustomThemesPath()

getConfigFilePath

public Path getConfigFilePath()

getPropertiesFilePath

public Path getPropertiesFilePath()

getSitesFilePath

public Path getSitesFilePath()

getLastAdminThemeBlock

public long getLastAdminThemeBlock()

setLastAdminThemeBlock

public void setLastAdminThemeBlock(long lastAdminThemeBlock)