Publishes the current project, printing messages to a shell report.<p>

@param cms the cms request context
@return the publish history id of the published project

@throws Exception if something goes wrong

@see CmsShellReport
774703
public CmsUUID publishProject(CmsObject cms) throws Exception {

        return publishProject(cms, new CmsShellReport(cms.getRequestContext().getLocale()));
    }
248193
public void finish() throws CmsException {

        m_finished = true;
        m_requiresCleanup = false;
        CmsProject project = getProject();
        CmsObject projectCms = OpenCms.initCmsObject(m_adminCms);
        projectCms.getRequestContext().setCurrentProject(project);
        if (m_configuration.isAutoPublish()) {
            // we don't necessarily publish with the user who has the locks on the resources, so we need to steal the locks
            List<CmsResource> projectResources = projectCms.readProjectView(project.getUuid(), CmsResource.STATE_KEEP);
            for (CmsResource projectResource : projectResources) {
                CmsLock lock = projectCms.getLock(projectResource);
                if (!lock.isUnlocked() && !lock.isLockableBy(projectCms.getRequestContext().getCurrentUser())) {
                    projectCms.changeLock(projectResource);
                }
            }
            OpenCms.getPublishManager().publishProject(
                projectCms,
                new CmsLogReport(Locale.ENGLISH, CmsUgcSession.class));
        } else {
            // try to unlock everything - we don't need this in case of auto-publish, since publishing already unlocks the resources
            projectCms.unlockProject(project.getUuid());
        }

    }
552371
public CmsProject setCurrentProject(String name) throws Exception {

        return m_cms.getRequestContext().setCurrentProject(m_cms.readProject(name));
    }
840007
protected static byte[] getHistoricalResourceContent(CmsObject cms, String resource, String version) {

        if (CmsStringUtil.isNotEmpty(resource) && CmsStringUtil.isNotEmpty(version)) {
            // try to load the historical resource
            I_CmsHistoryResource res = null;
            String storedSiteRoot = cms.getRequestContext().getSiteRoot();
            try {
                cms.getRequestContext().setSiteRoot("/");
                res = cms.readResource(
                    cms.readResource(resource, CmsResourceFilter.ALL).getStructureId(),
                    Integer.parseInt(version));
            } catch (CmsException e) {
                // can usually be ignored
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
                return "".getBytes();
            } finally {
                cms.getRequestContext().setSiteRoot(storedSiteRoot);
            }
            if (res.isFile()) {
                byte[] historyResourceContent = ((CmsFile)res).getContents();
                if ((historyResourceContent == null) || (historyResourceContent.length == 0)) {
                    try {
                        CmsFile file = cms.readFile((CmsResource)res);
                        historyResourceContent = file.getContents();
                    } catch (CmsException e) {
                        // ignore
                    }
                }
                historyResourceContent = CmsEncoder.changeEncoding(
                    historyResourceContent,
                    OpenCms.getSystemInfo().getDefaultEncoding(),
                    cms.getRequestContext().getEncoding());
                return historyResourceContent;
            }
        }
        return "".getBytes();
    }
496598
private CmsObject getAdminCms(CmsObject cms) throws CmsException {

        CmsObject adminCms = OpenCms.initCmsObject(m_adminCms);
        adminCms.getRequestContext().setSiteRoot(cms.getRequestContext().getSiteRoot());
        adminCms.getRequestContext().setRequestTime(cms.getRequestContext().getRequestTime());
        adminCms.getRequestContext().setCurrentProject(cms.getRequestContext().getCurrentProject());
        adminCms.getRequestContext().setEncoding(cms.getRequestContext().getEncoding());
        adminCms.getRequestContext().setUri(cms.getRequestContext().getUri());
        return adminCms;
    }
1310965
public void publishResources(List<CmsResource> resources) throws CmsException {

        CmsObject cms = m_cms;
        I_CmsReport report = new CmsWorkplaceReport(
            cms.getRequestContext().getLocale(),
            cms.getRequestContext().getSiteRoot(),
            null);
        CmsPublishManager publishManager = OpenCms.getPublishManager();
        CmsPublishList publishList = publishManager.getPublishListAll(m_cms, resources, false, true);
        OpenCms.getPublishManager().publishProject(m_cms, report, publishList);
    }
157502
public CmsHistoryProject readHistoryProject(CmsDbContext dbc, int publishTag) throws CmsException {

        return getHistoryDriver(dbc).readProject(dbc, publishTag);
    }
617492
public void createSharedFolder() throws Exception {

        String originalSiteRoot = m_cms.getRequestContext().getSiteRoot();
        CmsProject originalProject = m_cms.getRequestContext().getCurrentProject();
        try {
            m_cms.getRequestContext().setSiteRoot("");
            m_cms.getRequestContext().setCurrentProject(m_cms.createTempfileProject());
            if (!m_cms.existsResource("/shared")) {
                m_cms.createResource("/shared", OpenCms.getResourceManager().getResourceType("folder"));
            }

            try {
                m_cms.lockResourceTemporary("/shared");
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            try {
                m_cms.chacc("/shared", "group", "Users", "+v+w+r+i");
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            CmsResource shared = m_cms.readResource("/shared");
            try {
                OpenCms.getPublishManager().publishProject(
                    m_cms,
                    new CmsHtmlReport(m_cms.getRequestContext().getLocale(), m_cms.getRequestContext().getSiteRoot()),
                    shared,
                    false);
                OpenCms.getPublishManager().waitWhileRunning();
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        } finally {
            m_cms.getRequestContext().setSiteRoot(originalSiteRoot);
            m_cms.getRequestContext().setCurrentProject(originalProject);
        }

    }
861840
public CmsProject readProject(CmsUUID id) throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext();
        CmsProject result = null;
        try {
            result = m_driverManager.readProject(dbc, id);
        } catch (Exception e) {
            dbc.report(null, Messages.get().container(Messages.ERR_READ_PROJECT_FOR_ID_1, id), e);
        } finally {
            dbc.clear();
        }
        return result;
    }
386417
public String getPublishedByName(CmsObject cms) {

        try {
            return CmsPrincipal.readPrincipalIncludingHistory(cms, getPublishedBy()).getName();
        } catch (CmsException e) {
            return getPublishedBy().toString();
        }
    }
1337063
private void report(I_CmsReport report, int counter, int resCount, CmsResource resource) {

        // report entries
        report.print(
            org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_SUCCESSION_2,
                String.valueOf(counter),
                String.valueOf(resCount)),
            I_CmsReport.FORMAT_NOTE);
        report.print(
            org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_ARGUMENT_1,
                report.removeSiteRoot(resource.getRootPath())));
        report.print(
            org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0),
            I_CmsReport.FORMAT_DEFAULT);
    }
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();
        }
    }
473240
public static CmsResource readResource(CmsObject cms, CmsHistoryResourceBean bean) throws CmsException {

        CmsHistoryVersion versionBean = bean.getVersion();
        if (versionBean.getVersionNumber() != null) {
            return (CmsResource)(cms.readResource(bean.getStructureId(), versionBean.getVersionNumber().intValue()));
        } else {
            if (versionBean.isOnline()) {
                CmsObject onlineCms = OpenCms.initCmsObject(cms);
                onlineCms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                return onlineCms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            } else {
                return cms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            }
        }
    }
782805
public static CmsProjectBean createProjectBeanFromProject(CmsObject cms, CmsProject project) {

        CmsProjectBean manProj = new CmsProjectBean(
            project.getUuid(),
            project.getType().getMode(),
            org.opencms.ade.publish.Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key(
                org.opencms.ade.publish.Messages.GUI_NORMAL_PROJECT_1,
                getOuAwareName(cms, project.getName())),
            project.getDescription());
        return manProj;
    }
693454
public CmsUUID getProjectId(CmsDbContext dbc, int id) throws CmsException {

        Iterator<CmsProject> itProjects = getAllAccessibleProjects(
            dbc,
            readOrganizationalUnit(dbc, ""),
            true).iterator();
        while (itProjects.hasNext()) {
            CmsProject project = itProjects.next();
            if (project.getUuid().hashCode() == id) {
                return project.getUuid();
            }
        }
        return null;
    }
1349783
public void sendEmail(CmsObject cms) throws Exception {

        // create a plain text email
        CmsSimpleMail theMail = new CmsSimpleMail();
        theMail.setCharset(cms.getRequestContext().getEncoding());
        theMail.setFrom(cms.getRequestContext().getCurrentUser().getEmail(), getFrom());
        theMail.setTo(createInternetAddresses(getTo()));
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCc())) {
            theMail.setCc(createInternetAddresses(getCc()));
        }
        theMail.setSubject("[" + OpenCms.getSystemInfo().getServerName() + "] " + getSubject());
        theMail.setMsg(getMsg());
        // send the mail
        theMail.send();
    }
1091942
public void writeHistoryProject(CmsRequestContext context, int publishTag, long publishDate) throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        try {
            m_driverManager.writeHistoryProject(dbc, publishTag, publishDate);
        } catch (Exception e) {
            dbc.report(
                null,
                Messages.get().container(
                    Messages.ERR_HISTORY_PROJECT_4,
                    new Object[] {
                        new Integer(publishTag),
                        dbc.currentProject().getName(),
                        dbc.currentProject().getUuid(),
                        new Long(publishDate)}),
                e);
        } finally {
            dbc.clear();
        }
    }