org.liquidsite.app.admin
Class AdminUtils

java.lang.Object
  extended byorg.liquidsite.app.admin.AdminUtils

public class AdminUtils
extends java.lang.Object

A class containing general utility methods for the administration application.


Constructor Summary
AdminUtils()
           
 
Method Summary
static java.lang.String formatDate(User user, java.util.Date date)
          Formats a date to a printable string.
static java.lang.String formatFileSize(long size)
          Formats a file size to a printable string.
static Application getApplication()
          Returns the application currently used
static java.io.File getBackupDir()
          Returns the backup directory for the system.
static java.lang.String getCategory(int category)
          Returns a content category name.
static java.lang.String getCategory(java.lang.Object obj)
          Returns an object category name.
static ContentManager getContentManager()
          Returns the content manager for administration.
static java.text.SimpleDateFormat getDateFormat(User user)
          Returns a date format for the specified user.
static PersistentObject getReference(Request request)
          Returns the domain or content referenced by a request.
static java.lang.String getScriptDate(User user, java.util.Date date)
          Returns the JavaScript representation of a date.
static java.lang.String getScriptString(java.lang.String str)
          Returns the JavaScript representation of a string.
static java.io.File getStatisticsDir(Domain domain)
          Returns the statistics directory for a domain.
static java.lang.String getXmlString(java.lang.String str)
          Returns the XML representation of a string.
static boolean isOnline(java.lang.Object obj)
          Checks is a specified object is online.
static java.util.Date parseDate(User user, java.lang.String str)
          Parses a date string into a date.
static void sendTemplate(Request request, java.lang.String templateName)
          Processes a request to a template file.
static void setReference(Request request, PersistentObject obj)
          Sets the domain or content reference attributes in a request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdminUtils

public AdminUtils()
Method Detail

getApplication

public static Application getApplication()
Returns the application currently used

Returns:
the application currently used

getContentManager

public static ContentManager getContentManager()
                                        throws ContentException
Returns the content manager for administration.

Returns:
the content manager for administration
Throws:
ContentException - if no content manager exists

getBackupDir

public static java.io.File getBackupDir()
Returns the backup directory for the system.

Returns:
the backup directory, or null if not readable

getStatisticsDir

public static java.io.File getStatisticsDir(Domain domain)
Returns the statistics directory for a domain.

Parameters:
domain - the domain object
Returns:
the statistics directory, or null if not configured or readable

getDateFormat

public static java.text.SimpleDateFormat getDateFormat(User user)
Returns a date format for the specified user.

Parameters:
user - the user to create a date format for
Returns:
a date format for the specified user

formatDate

public static java.lang.String formatDate(User user,
                                          java.util.Date date)
Formats a date to a printable string. The user timezone will be used.

Parameters:
user - the current user
date - the date to format
Returns:
a printable string with the date

parseDate

public static java.util.Date parseDate(User user,
                                       java.lang.String str)
                                throws java.text.ParseException
Parses a date string into a date. The user timezone will be used.

Parameters:
user - the current user
str - the string containing the date
Returns:
the date found
Throws:
java.text.ParseException - if the string didn't contain a valid date

formatFileSize

public static java.lang.String formatFileSize(long size)
Formats a file size to a printable string.

Parameters:
size - the file size to format
Returns:
a printable string with the file size

getScriptDate

public static java.lang.String getScriptDate(User user,
                                             java.util.Date date)
Returns the JavaScript representation of a date. The user timezone will be used.

Parameters:
user - the user
date - the date to present, or null
Returns:
a JavaScript representation of the date

getScriptString

public static java.lang.String getScriptString(java.lang.String str)
Returns the JavaScript representation of a string. This method will take care of required character escapes.

Parameters:
str - the string to present, or null
Returns:
a JavaScript representation of the string

getXmlString

public static java.lang.String getXmlString(java.lang.String str)
Returns the XML representation of a string. This method will escape any XML reserved characters.

Parameters:
str - the string to transform
Returns:
an XML representation of the string

getCategory

public static java.lang.String getCategory(java.lang.Object obj)
Returns an object category name. The category name is used in various places to identify incoming or outgoing objects.

Parameters:
obj - the domain or content object
Returns:
the category name, or null if unknown

getCategory

public static java.lang.String getCategory(int category)
Returns a content category name. The category name is used in various places to identify incoming or outgoing objects.

Parameters:
category - the content category number
Returns:
the category name, or null if unknown

isOnline

public static boolean isOnline(java.lang.Object obj)
                        throws ContentException
Checks is a specified object is online. This method will check that all parent content objects are also online. For domain objects or null, this method always returns true.

Parameters:
obj - the domain or content object
Returns:
true if the object and all parents are online, or false otherwise
Throws:
ContentException - if the database couldn't be accessed properly

getReference

public static PersistentObject getReference(Request request)
                                     throws ContentException,
                                            ContentSecurityException
Returns the domain or content referenced by a request. When returning a content object, the latest revision (including work revisions) will be returned.

Parameters:
request - the request
Returns:
the domain or content object referenced, or null if not found
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user didn't have the required permissions

setReference

public static void setReference(Request request,
                                PersistentObject obj)
Sets the domain or content reference attributes in a request.

Parameters:
request - the request
obj - the domain or content object

sendTemplate

public static void sendTemplate(Request request,
                                java.lang.String templateName)
Processes a request to a template file. The template file name is relative to the web context directory, and the output MIME type will always be set to "text/html".

Parameters:
request - the request object
templateName - the template file name