org.opencms.publish
Class CmsPublishManager

java.lang.Object
  extended by org.opencms.publish.CmsPublishManager

public class CmsPublishManager
extends java.lang.Object

This manager provide access to the publish engine runtime information.

Since:
6.5.5
Version:
$Revision: 1.12 $
Author:
Michael Moossen

Field Summary
static int DEFAULT_HISTORY_SIZE
          The default history size.
static boolean DEFAULT_QUEUE_PERSISTANCE
          The default persistence setting for the publish queue.
static int DEFAULT_QUEUE_SHUTDOWNTIME
          The default shutdown time for the running publish job.
 
Constructor Summary
CmsPublishManager()
          Default constructor used in digester initialization.
CmsPublishManager(int historySize, boolean queuePersistance, int queueShutdowntime)
          Constructor used to create a pre-initialized instance.
 
Method Summary
 void abortPublishJob(CmsObject cms, CmsPublishJobEnqueued publishJob, boolean removeJob)
          Aborts the given publish job.
 void addPublishListener(I_CmsPublishEventListener listener)
          Adds a publish listener to listen on publish events.
 void checkCurrentPublishJobThread()
          Check if the thread for the current publish job is still active or was interrupted and so the next job in the queue can be started.
 void disablePublishing()
          Disables the publishing of resources.
 void enablePublishing()
          Enables the enqeueing of resources for publishing.
 CmsPublishJobRunning getCurrentPublishJob()
          Returns the current running publish job.
protected  CmsPublishEngine getEngine()
          Returns the currently used publish engine.
 CmsPublishJobBase getJobByPublishHistoryId(CmsUUID publishHistoryId)
          Returns a publish job based on its publish history id.
 java.util.List getPublishHistory()
          Returns the publish history list with already publish jobs.
 java.util.List getPublishHistory(CmsUser user)
          Returns the publish history list with already publish jobs, filtered by the given user.
 int getPublishHistorySize()
          Returns the publish History Size.
 CmsPublishList getPublishList(CmsObject cms)
          Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published.
 CmsPublishList getPublishList(CmsObject cms, CmsResource directPublishResource, boolean directPublishSiblings)
          Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a single resource.
 CmsPublishList getPublishList(CmsObject cms, java.util.List directPublishResources, boolean directPublishSiblings)
          Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.
 CmsPublishList getPublishList(CmsObject cms, java.util.List directPublishResources, boolean directPublishSiblings, boolean publishSubResources)
          Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.
 java.util.List getPublishQueue()
          Returns the queue with still waiting publish jobs.
 int getPublishQueueShutdowntime()
          Returns the amount of time in seconds the system will wait during shutdown for a running publish job.
 CmsPublishList getRelatedResourcesToPublish(CmsObject cms, CmsPublishList publishList)
          Returns a new publish list that contains the unpublished resources related to all resources in the given publish list, the related resources exclude all resources in the given publish list and also locked (by other users) resources.
 byte[] getReportContents(CmsPublishJobFinished publishJob)
          Returns the content of the publish report assigned to the given publish job.
 void initialize(CmsObject cms)
          Initializes the publish manager and the publish engine finally.
 boolean isPublishQueuePersistanceEnabled()
          Returns if the publish queue is persisted an will be re-initialized on startup.
 boolean isRunning()
          Returns the working state, that is if no publish job is waiting to be processed and there is no current running publish job.
 CmsPublishList mergePublishLists(CmsObject cms, CmsPublishList pubList1, CmsPublishList pubList2)
          Returns a new publish list that contains all resources of both given publish lists.
 CmsUUID publishProject(CmsObject cms)
          Publishes the current project, printing messages to a shell report.
 CmsUUID publishProject(CmsObject cms, I_CmsReport report)
          Publishes the current project.
 CmsUUID publishProject(CmsObject cms, I_CmsReport report, CmsPublishList publishList)
          Publishes the resources of a specified publish list.
 CmsUUID publishProject(CmsObject cms, I_CmsReport report, CmsResource directPublishResource, boolean directPublishSiblings)
          Direct publishes a specified resource.
 CmsUUID publishResource(CmsObject cms, java.lang.String resourcename)
          Publishes a single resource, printing messages to a shell report.
 CmsUUID publishResource(CmsObject cms, java.lang.String resourcename, boolean publishSiblings, I_CmsReport report)
          Publishes a single resource.
 void removePublishListener(I_CmsPublishEventListener listener)
          Removes the given publish listener.
 void setPublishEngine(CmsPublishEngine publishEngine)
          Sets the publish engine during initialization.
 void setPublishHistorySize(java.lang.String publishHistorySize)
          Sets the publish History Size.
 void setPublishQueuePersistance(java.lang.String publishQueuePersistance)
          Sets if the publish queue is re-initialized on startup.
 void setPublishQueueShutdowntime(java.lang.String publishQueueShutdowntime)
          Sets the publish queue shutdown time.
 void setSecurityManager(CmsSecurityManager securityManager)
          Sets the security manager during initialization.
 void startPublishing()
          Starts publishing of enqueued publish jobs.
 void stopPublishing()
          Stops the publishing of enqueued publish jobs.
 java.util.Map validateRelations(CmsObject cms, CmsPublishList publishList, I_CmsReport report)
          Validates the relations for the given resources.
 void waitWhileRunning()
          Waits until no publish jobs remain.
 void waitWhileRunning(long ms)
          Waits until no publish jobs remain or the given max milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HISTORY_SIZE

public static final int DEFAULT_HISTORY_SIZE
The default history size.

See Also:
Constant Field Values

DEFAULT_QUEUE_PERSISTANCE

public static final boolean DEFAULT_QUEUE_PERSISTANCE
The default persistence setting for the publish queue.

See Also:
Constant Field Values

DEFAULT_QUEUE_SHUTDOWNTIME

public static final int DEFAULT_QUEUE_SHUTDOWNTIME
The default shutdown time for the running publish job.

See Also:
Constant Field Values
Constructor Detail

CmsPublishManager

public CmsPublishManager()
Default constructor used in digester initialization.


CmsPublishManager

public CmsPublishManager(int historySize,
                         boolean queuePersistance,
                         int queueShutdowntime)
Constructor used to create a pre-initialized instance.

Parameters:
historySize - the size of the publish history
queuePersistance - indicates if the queue is re-initialized on startup
queueShutdowntime - the amount of time to wait for a publish job during shutdown
Method Detail

abortPublishJob

public void abortPublishJob(CmsObject cms,
                            CmsPublishJobEnqueued publishJob,
                            boolean removeJob)
                     throws CmsException,
                            CmsSecurityException,
                            CmsPublishException
Aborts the given publish job.

Parameters:
cms - the cms context
publishJob - the publish job to abort
removeJob - indicates if the job will be removed or added to history
Throws:
CmsException - if there is some problem during unlocking the resources
CmsSecurityException - if the current user has not enough permissions
CmsPublishException - if the publish job can not been aborted

addPublishListener

public void addPublishListener(I_CmsPublishEventListener listener)
Adds a publish listener to listen on publish events.

Parameters:
listener - the publish listener to add

checkCurrentPublishJobThread

public void checkCurrentPublishJobThread()
Check if the thread for the current publish job is still active or was interrupted and so the next job in the queue can be started.


disablePublishing

public void disablePublishing()
Disables the publishing of resources.


enablePublishing

public void enablePublishing()
Enables the enqeueing of resources for publishing.


getCurrentPublishJob

public CmsPublishJobRunning getCurrentPublishJob()
Returns the current running publish job.

Returns:
the current running publish job

getJobByPublishHistoryId

public CmsPublishJobBase getJobByPublishHistoryId(CmsUUID publishHistoryId)
Returns a publish job based on its publish history id.

The returned publish job may be an enqueued, running or finished publish job.

Parameters:
publishHistoryId - the publish history id to search for
Returns:
the publish job with the given publish history id, or null

getPublishHistory

public java.util.List getPublishHistory()
Returns the publish history list with already publish jobs.

Returns:
a list of CmsPublishJobFinished objects

getPublishHistory

public java.util.List getPublishHistory(CmsUser user)
Returns the publish history list with already publish jobs, filtered by the given user.

Parameters:
user - the user to filter the jobs with
Returns:
a list of CmsPublishJobFinished objects

getPublishHistorySize

public int getPublishHistorySize()
Returns the publish History Size.

Returns:
the publish History Size

getPublishList

public CmsPublishList getPublishList(CmsObject cms)
                              throws CmsException
Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published.

Parameters:
cms - the cms request context
Returns:
a publish list
Throws:
CmsException - if something goes wrong

getPublishList

public CmsPublishList getPublishList(CmsObject cms,
                                     CmsResource directPublishResource,
                                     boolean directPublishSiblings)
                              throws CmsException
Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a single resource.

Parameters:
cms - the cms request context
directPublishResource - the resource which will be directly published
directPublishSiblings - true, if all eventual siblings of the direct published resource should also get published.
Returns:
a publish list
Throws:
CmsException - if something goes wrong

getPublishList

public CmsPublishList getPublishList(CmsObject cms,
                                     java.util.List directPublishResources,
                                     boolean directPublishSiblings)
                              throws CmsException
Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.

Parameters:
cms - the cms request context
directPublishResources - the resources which will be directly published
directPublishSiblings - true, if all eventual siblings of the direct published resources should also get published.
Returns:
a publish list
Throws:
CmsException - if something goes wrong

getPublishList

public CmsPublishList getPublishList(CmsObject cms,
                                     java.util.List directPublishResources,
                                     boolean directPublishSiblings,
                                     boolean publishSubResources)
                              throws CmsException
Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.

Parameters:
cms - the cms request context
directPublishResources - the CmsResource objects which will be directly published
directPublishSiblings - true, if all eventual siblings of the direct published resources should also get published.
publishSubResources - indicates if sub-resources in folders should be published (for direct publish only)
Returns:
a publish list
Throws:
CmsException - if something goes wrong

getPublishQueue

public java.util.List getPublishQueue()
Returns the queue with still waiting publish jobs.

Returns:
a list of CmsPublishJobEnqueued objects

getPublishQueueShutdowntime

public int getPublishQueueShutdowntime()
Returns the amount of time in seconds the system will wait during shutdown for a running publish job.

Returns:
the shutdown time for a running publish job

getRelatedResourcesToPublish

public CmsPublishList getRelatedResourcesToPublish(CmsObject cms,
                                                   CmsPublishList publishList)
                                            throws CmsException
Returns a new publish list that contains the unpublished resources related to all resources in the given publish list, the related resources exclude all resources in the given publish list and also locked (by other users) resources.

Parameters:
cms - the cms request context
publishList - the publish list to exclude from result
Returns:
a new publish list that contains the related resources
Throws:
CmsException - if something goes wrong

getReportContents

public byte[] getReportContents(CmsPublishJobFinished publishJob)
                         throws CmsException
Returns the content of the publish report assigned to the given publish job.

Parameters:
publishJob - the published job
Returns:
the content of the assigned publish report
Throws:
CmsException - if something goes wrong

initialize

public void initialize(CmsObject cms)
                throws CmsException
Initializes the publish manager and the publish engine finally.

Parameters:
cms - an admin cms object
Throws:
CmsException - if something goes wrong

isPublishQueuePersistanceEnabled

public boolean isPublishQueuePersistanceEnabled()
Returns if the publish queue is persisted an will be re-initialized on startup.

Returns:
true if the publish queue is persisted

isRunning

public boolean isRunning()
Returns the working state, that is if no publish job is waiting to be processed and there is no current running publish job.

Returns:
the working state

mergePublishLists

public CmsPublishList mergePublishLists(CmsObject cms,
                                        CmsPublishList pubList1,
                                        CmsPublishList pubList2)
                                 throws CmsException
Returns a new publish list that contains all resources of both given publish lists.

Parameters:
cms - the cms request context
pubList1 - the first publish list
pubList2 - the second publish list
Returns:
a new publish list that contains all resources of both given publish lists
Throws:
CmsException - if something goes wrong

publishProject

public CmsUUID publishProject(CmsObject cms)
                       throws java.lang.Exception
Publishes the current project, printing messages to a shell report.

Parameters:
cms - the cms request context
Returns:
the publish history id of the published project
Throws:
java.lang.Exception - if something goes wrong
See Also:
CmsShellReport

publishProject

public CmsUUID publishProject(CmsObject cms,
                              I_CmsReport report)
                       throws CmsException
Publishes the current project.

Parameters:
cms - the cms request context
report - an instance of I_CmsReport to print messages
Returns:
the publish history id of the published project
Throws:
CmsException - if something goes wrong

validateRelations

public java.util.Map validateRelations(CmsObject cms,
                                       CmsPublishList publishList,
                                       I_CmsReport report)
                                throws java.lang.Exception
Validates the relations for the given resources.

Parameters:
cms - the cms request context
publishList - the publish list to validate against the online project
report - a report to write the messages to
Returns:
a map with lists of invalid links (CmsRelation} objects) keyed by root paths TODO: change return value to List of CmsRelation
Throws:
java.lang.Exception - if something goes wrong

publishProject

public CmsUUID publishProject(CmsObject cms,
                              I_CmsReport report,
                              CmsPublishList publishList)
                       throws CmsException
Publishes the resources of a specified publish list.

Parameters:
cms - the cms request context
report - an instance of I_CmsReport to print messages
publishList - a publish list
Returns:
the publish history id of the published project
Throws:
CmsException - if something goes wrong
See Also:
getPublishList(CmsObject), getPublishList(CmsObject, CmsResource, boolean), getPublishList(CmsObject, List, boolean)

publishProject

public CmsUUID publishProject(CmsObject cms,
                              I_CmsReport report,
                              CmsResource directPublishResource,
                              boolean directPublishSiblings)
                       throws CmsException
Direct publishes a specified resource.

Parameters:
cms - the cms request context
report - an instance of I_CmsReport to print messages
directPublishResource - a CmsResource that gets directly published; or null if an entire project gets published.
directPublishSiblings - if a CmsResource that should get published directly is provided as an argument, all eventual siblings of this resource get publish too, if this flag is true.
Returns:
the publish history id of the published project
Throws:
CmsException - if something goes wrong

publishResource

public CmsUUID publishResource(CmsObject cms,
                               java.lang.String resourcename)
                        throws java.lang.Exception
Publishes a single resource, printing messages to a shell report.

The siblings of the resource will not be published.

Parameters:
cms - the cms request context
resourcename - the name of the resource to be published
Returns:
the publish history id of the published project
Throws:
java.lang.Exception - if something goes wrong
See Also:
CmsShellReport

publishResource

public CmsUUID publishResource(CmsObject cms,
                               java.lang.String resourcename,
                               boolean publishSiblings,
                               I_CmsReport report)
                        throws java.lang.Exception
Publishes a single resource.

Parameters:
cms - the cms request context
resourcename - the name of the resource to be published
publishSiblings - if true, all siblings of the resource are also published
report - the report to write the progress information to
Returns:
the publish history id of the published project
Throws:
java.lang.Exception - if something goes wrong

removePublishListener

public void removePublishListener(I_CmsPublishEventListener listener)
Removes the given publish listener.

Parameters:
listener - the publish listener to remove

setPublishEngine

public void setPublishEngine(CmsPublishEngine publishEngine)
Sets the publish engine during initialization.

Parameters:
publishEngine - the publish engine instance

setPublishHistorySize

public void setPublishHistorySize(java.lang.String publishHistorySize)
Sets the publish History Size.

Parameters:
publishHistorySize - the publish History Size to set

setPublishQueuePersistance

public void setPublishQueuePersistance(java.lang.String publishQueuePersistance)
Sets if the publish queue is re-initialized on startup.

Parameters:
publishQueuePersistance - the persistence flag, parsed as boolean

setPublishQueueShutdowntime

public void setPublishQueueShutdowntime(java.lang.String publishQueueShutdowntime)
Sets the publish queue shutdown time.

Parameters:
publishQueueShutdowntime - the shutdown time to set, parsed as int

setSecurityManager

public void setSecurityManager(CmsSecurityManager securityManager)
Sets the security manager during initialization.

Parameters:
securityManager - the security manager

startPublishing

public void startPublishing()
Starts publishing of enqueued publish jobs.


stopPublishing

public void stopPublishing()
Stops the publishing of enqueued publish jobs.


waitWhileRunning

public void waitWhileRunning()
Waits until no publish jobs remain.


waitWhileRunning

public void waitWhileRunning(long ms)
Waits until no publish jobs remain or the given max milliseconds.

Parameters:
ms - the max milliseconds to wait

getEngine

protected CmsPublishEngine getEngine()
Returns the currently used publish engine.

Returns:
the publish engine