Adds the given publish job to the list.<p>

@param publishJob the publish job object to add

@throws CmsException if something goes wrong
767327
protected void add(CmsPublishJobInfoBean publishJob) throws CmsException {

        OpenCms.getMemoryMonitor().cachePublishJobInHistory(publishJob);
        // write job to db if necessary
        if (OpenCms.getMemoryMonitor().requiresPersistency()) {
            CmsDbContext dbc = m_publishEngine.getDbContext(null);
            try {
                m_publishEngine.getDriverManager().writePublishJob(dbc, publishJob);
                // additionally, write the publish report
                m_publishEngine.getDriverManager().writePublishReport(dbc, publishJob);
                // delete publish list of started job
                m_publishEngine.getDriverManager().deletePublishList(dbc, publishJob.getPublishHistoryId());
            } catch (CmsException e) {
                dbc.rollback();
                LOG.error(e.getLocalizedMessage(), e);
                throw e;
            } finally {
                dbc.clear();
            }
        }
    }
502750
protected void initialize(CmsObject adminCms, boolean revive) {

        CmsDriverManager driverManager = m_publishEngine.getDriverManager();

        try {
            OpenCms.getMemoryMonitor().flushCache(CmsMemoryMonitor.CacheType.PUBLISH_QUEUE);
            if (revive) {
                // read all pending publish jobs from the database
                CmsDbContext dbc = m_publishEngine.getDbContext(null);
                List<CmsPublishJobInfoBean> publishJobs = null;
                try {
                    publishJobs = driverManager.readPublishJobs(dbc, 0L, 0L);
                } catch (Exception e) {
                    dbc.rollback();
                } finally {
                    dbc.clear();
                    dbc = null;
                }
                if (publishJobs != null) {
                    for (Iterator<CmsPublishJobInfoBean> i = publishJobs.iterator(); i.hasNext();) {
                        CmsPublishJobInfoBean job = i.next();
                        dbc = m_publishEngine.getDbContext(null);
                        if (!job.isStarted()) {
                            // add jobs not already started to queue again
                            try {
                                job.revive(adminCms, driverManager.readPublishList(dbc, job.getPublishHistoryId()));
                                m_publishEngine.lockPublishList(job);
                                OpenCms.getMemoryMonitor().cachePublishJob(job);
                            } catch (CmsException exc) {
                                // skip job
                                dbc.rollback();
                                if (LOG.isErrorEnabled()) {
                                    LOG.error(
                                        Messages.get().getBundle().key(
                                            Messages.ERR_PUBLISH_JOB_INVALID_1,
                                            job.getPublishHistoryId()),
                                        exc);
                                }
                                m_publishEngine.getDriverManager().deletePublishJob(dbc, job.getPublishHistoryId());
                            } finally {
                                dbc.clear();
                            }
                        } else {
                            try {
                                // remove locks, set finish info and move job to history
                                job.revive(adminCms, driverManager.readPublishList(dbc, job.getPublishHistoryId()));
                                m_publishEngine.unlockPublishList(job);
                                new CmsPublishJobEnqueued(job).m_publishJob.finish();
                                m_publishEngine.getPublishHistory().add(job);
                            } catch (CmsException exc) {
                                dbc.rollback();
                                LOG.error(exc.getLocalizedMessage(), exc);
                            } finally {
                                dbc.clear();
                            }
                        }
                    }
                }
            }
        } catch (CmsException exc) {
            if (LOG.isErrorEnabled()) {
                LOG.error(exc.getLocalizedMessage(), exc);
            }
        }
    }
7727
public void cmsEvent(CmsEvent event) {

        switch (event.getType()) {
            case I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES:
                List<String> indexNames = null;
                if ((event.getData() != null)
                    && CmsStringUtil.isNotEmptyOrWhitespaceOnly(
                        (String)event.getData().get(I_CmsEventListener.KEY_INDEX_NAMES))) {
                    indexNames = CmsStringUtil.splitAsList(
                        (String)event.getData().get(I_CmsEventListener.KEY_INDEX_NAMES),
                        ",",
                        true);
                }
                try {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_EVENT_REBUILD_SEARCHINDEX_1,
                                indexNames == null ? "" : CmsStringUtil.collectionAsString(indexNames, ",")),
                            new Exception());
                    }
                    if (indexNames == null) {
                        rebuildAllIndexes(getEventReport(event));
                    } else {
                        rebuildIndexes(indexNames, getEventReport(event));
                    }
                } catch (CmsException e) {
                    if (LOG.isErrorEnabled()) {
                        LOG.error(
                            Messages.get().getBundle().key(
                                Messages.ERR_EVENT_REBUILD_SEARCHINDEX_1,
                                indexNames == null ? "" : CmsStringUtil.collectionAsString(indexNames, ",")),
                            e);
                    }
                }
                break;
            case I_CmsEventListener.EVENT_CLEAR_CACHES:
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_EVENT_CLEAR_CACHES_0), new Exception());
                }
                break;
            case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
                // event data contains a list of the published resources
                CmsUUID publishHistoryId = new CmsUUID((String)event.getData().get(I_CmsEventListener.KEY_PUBLISHID));
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_EVENT_PUBLISH_PROJECT_1, publishHistoryId));
                }
                updateAllIndexes(m_adminCms, publishHistoryId, getEventReport(event));
                if (LOG.isDebugEnabled()) {
                    LOG.debug(
                        Messages.get().getBundle().key(
                            Messages.LOG_EVENT_PUBLISH_PROJECT_FINISHED_1,
                            publishHistoryId));
                }
                break;
            default:
                // no operation
        }
    }
1175180
public void setPublishQueueShutdowntime(String publishQueueShutdowntime) {

        if (m_frozen) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_CONFIG_FROZEN_0));
        }
        m_publishQueueShutdowntime = Integer.parseInt(publishQueueShutdowntime);
    }
1278959
public void actionPublish() throws JspException {

        try {
            boolean isFolder = false;
            if (!isMultiOperation()) {
                if (isDirectPublish()) {
                    isFolder = getCms().readResource(getParamResource(), CmsResourceFilter.ALL).isFolder();
                }
            }
            if (performDialogOperation()) {
                // if no exception is caused and "true" is returned publish operation was successful
                if (isMultiOperation() || isFolder) {
                    // set request attribute to reload the explorer tree view
                    List<String> folderList = new ArrayList<String>();
                    folderList.add(CmsResource.getParentFolder(getResourceList().get(0)));
                    Iterator<String> it = getResourceList().iterator();
                    while (it.hasNext()) {
                        String res = it.next();
                        if (CmsResource.isFolder(res)) {
                            folderList.add(res);
                        }
                    }
                    getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
                }
                actionCloseDialog();
            } else {
                // "false" returned, display "please wait" screen
                getJsp().include(FILE_DIALOG_SCREEN_WAIT);
            }
        } catch (Throwable e) {
            // prepare common message part
            includeErrorpage(this, e);
        }
    }
774703
public CmsUUID publishProject(CmsObject cms) throws Exception {

        return publishProject(cms, new CmsShellReport(cms.getRequestContext().getLocale()));
    }
63014
protected synchronized JobStatus addJob(JobID jobId, JobInProgress job) {
    totalSubmissions++;

    synchronized (jobs) {
      synchronized (taskScheduler) {
        jobs.put(job.getProfile().getJobID(), job);
        for (JobInProgressListener listener : jobInProgressListeners) {
          try {
            listener.jobAdded(job);
          } catch (IOException ioe) {
            LOG.warn("Failed to add and so skipping the job : "
                + job.getJobID() + ". Exception : " + ioe);
          }
        }
      }
    }
    myInstrumentation.submitJob(job.getJobConf(), jobId);
    String jobName = job.getJobConf().getJobName();
    int jobNameLen = 64;
    if (jobName.length() > jobNameLen) {
      jobName = jobName.substring(0, jobNameLen); // Truncate for logging.
    }
    LOG.info("Job " + jobId + "(" + jobName +
             ") added successfully for user '" + job.getJobConf().getUser() +
             "' to queue '" + job.getJobConf().getQueueName() + "'" +
             ", source " + job.getJobConf().getJobSource());
    return job.getStatus();
  }
861259
private void publishEvent(WSJobExecution execution, WSJobInstance jobInstance, BatchStatus batchStatus) {

        if (batchStatus == BatchStatus.FAILED) {
            publishEvent(execution, BatchEventsPublisher.TOPIC_EXECUTION_FAILED);
            publishEvent(jobInstance, BatchEventsPublisher.TOPIC_INSTANCE_FAILED);
        } else if (batchStatus == BatchStatus.COMPLETED) {
            publishEvent(execution, BatchEventsPublisher.TOPIC_EXECUTION_COMPLETED);
            publishEvent(jobInstance, BatchEventsPublisher.TOPIC_INSTANCE_COMPLETED);
        } else if (batchStatus == BatchStatus.STOPPED) {
            publishEvent(execution, BatchEventsPublisher.TOPIC_EXECUTION_STOPPED);
            publishEvent(jobInstance, BatchEventsPublisher.TOPIC_INSTANCE_STOPPED);
            //smf call to go here, eventually
        } else if (batchStatus == BatchStatus.STOPPING) {
            publishEvent(jobInstance, BatchEventsPublisher.TOPIC_INSTANCE_STOPPING);
            publishEvent(execution, BatchEventsPublisher.TOPIC_EXECUTION_STOPPING);
        } else if (batchStatus == BatchStatus.STARTED) {
            publishEvent(jobInstance, BatchEventsPublisher.TOPIC_INSTANCE_DISPATCHED);
            publishEvent(execution, BatchEventsPublisher.TOPIC_EXECUTION_STARTED);
        }

    }
792482
private void startPublishThread() {

        // create a publish thread from the current publish list
        CmsPublishList publishList = getSettings().getPublishList();
        try {
            OpenCms.getPublishManager().publishProject(
                getCms(),
                new CmsHtmlReport(getLocale(), getCms().getRequestContext().getSiteRoot()),
                publishList);
        } catch (CmsException e) {
            throw new CmsRuntimeException(e.getMessageContainer());
        }
        setParamAction(REPORT_END);
        setAction(ACTION_REPORT_END);
        setParamThreadHasNext(CmsStringUtil.FALSE);
    }
443039
void editJob(String jobId) {

        String stateEdit = CmsScheduledJobsAppConfig.APP_ID + "/" + CmsJobManagerApp.PATH_NAME_EDIT;
        stateEdit = A_CmsWorkplaceApp.addParamToState(stateEdit, CmsJobManagerApp.PARAM_JOB_ID, jobId);
        CmsAppWorkplaceUi.get().getNavigator().navigateTo(stateEdit);
    }
178773
public void setJobName(String jobName) {

        checkFrozen();
        if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName));

        }
        m_jobName = jobName;
    }
125120
public void checkPublishList(CmsPublishList publishList) throws CmsException {

        for (CmsResource resource : publishList.getAllResources()) {
            for (ForbiddenFolderEntry entry : m_forbiddenParentFolders.values()) {
                if (CmsStringUtil.isPrefixPath(entry.getRootPath(), resource.getRootPath())) {
                    throw new CmsPublishException(
                        Messages.get().container(
                            Messages.ERR_PUBLISH_FORBIDDEN_PARENT_FOLDER_3,
                            resource.getRootPath(),
                            entry.getRootPath(),
                            entry.getReason()));
                }
            }

        }
    }
377304
private String getResourcesHTML(CmsPublishJobBase job) throws CmsException {

        String ret = "";
        if (job instanceof CmsPublishJobEnqueued) {
            //job is enqueued ->go over publish list
            List<CmsResource> resources = ((CmsPublishJobEnqueued)job).getPublishList().getAllResources();
            for (CmsResource res : resources) {
                ret += res.getRootPath() + "<br/>";
            }
        } else {
            //job is running or finished
            List<CmsPublishedResource> resources = A_CmsUI.getCmsObject().readPublishedResources(
                job.getPublishHistoryId());
            for (CmsPublishedResource res : resources) {
                ret += res.getRootPath() + "<br/>";
            }
        }
        return ret;
    }
797148
public void upgradeContent(CmsObject cms) throws CmsException {

        if (m_content == null) {
            m_content = cms.readFile(m_resource).getContents();
        }
    }
138893
protected List<CmsPublishedResource> addMovedLinkSources(
        CmsObject cms,
        List<CmsPublishedResource> publishedResources) {

        long timer = System.currentTimeMillis();
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_SCRUB_EXPORT_START_MOVED_SOURCES_0));
        }
        publishedResources = new ArrayList<CmsPublishedResource>(publishedResources);
        Set<String> pubResources = new HashSet<String>(publishedResources.size());
        // this is needed since the CmsPublishedResource#equals(Object) method just compares ids and not paths
        // and with moved files you have 2 entries with the same id and different paths...
        for (CmsPublishedResource pubRes : publishedResources) {
            pubResources.add(pubRes.getRootPath());
        }
        boolean modified = true;
        // until no more resources are added
        while (modified) {
            modified = false;
            Iterator<CmsPublishedResource> itPrePubRes = new ArrayList<CmsPublishedResource>(
                publishedResources).iterator();
            while (itPrePubRes.hasNext()) {
                CmsPublishedResource res = itPrePubRes.next();
                if (res.getMovedState() != CmsPublishedResource.STATE_MOVED_DESTINATION) {
                    // handle only resources that are destination of move operations
                    continue;
                }
                List<CmsRelation> relations = null;
                try {
                    // get all link sources to this resource
                    relations = cms.getRelationsForResource(
                        cms.getRequestContext().removeSiteRoot(res.getRootPath()),
                        CmsRelationFilter.SOURCES);
                } catch (CmsException e) {
                    // should never happen
                    if (LOG.isErrorEnabled()) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }
                }
                if ((relations == null) || relations.isEmpty()) {
                    // continue with next resource if no link sources found
                    continue;
                }
                Iterator<CmsRelation> itRelations = relations.iterator();
                while (itRelations.hasNext()) {
                    CmsRelation relation = itRelations.next();
                    CmsPublishedResource source = null;
                    try {
                        // get the link source
                        source = new CmsPublishedResource(relation.getSource(cms, CmsResourceFilter.ALL));
                    } catch (CmsException e) {
                        // should never happen
                        if (LOG.isWarnEnabled()) {
                            LOG.warn(e.getLocalizedMessage());
                        }
                    }
                    if ((source == null) || pubResources.contains(source.getRootPath())) {
                        // continue if the link source could not been retrieved or if the list already contains it
                        continue;
                    }
                    // add it, and set the modified flag to give it another round
                    modified = true;
                    pubResources.add(source.getRootPath());
                    publishedResources.add(source);
                }
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_SCRUB_EXPORT_FINISH_MOVED_SOURCES_1,
                    (System.currentTimeMillis() - timer) + ""));
        }
        return publishedResources;
    }
353645
protected void publishJobStarted(CmsPublishJobInfoBean publishJob) {

        // update the job
        m_publishQueue.update(publishJob);

        // fire the publish start event
        m_listeners.fireStart(new CmsPublishJobEnqueued(publishJob));
    }
1184896
protected void start(CmsUUID threadUUID) {

        if (m_startTime != 0) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_PUBLISH_JOB_ALREADY_STARTED_0));
        }
        m_startTime = System.currentTimeMillis();
        m_threadUUID = threadUUID;
        if (getPublishReport() instanceof CmsPublishReport) {
            ((CmsPublishReport)m_publishReport).start();
        }
    }