001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.publish;
029
030import org.opencms.file.CmsObject;
031import org.opencms.main.CmsException;
032import org.opencms.util.CmsUUID;
033
034import java.util.Locale;
035
036/**
037 * Defines a read-only publish job.<p>
038 *
039 * @since 6.5.5
040 */
041public class CmsPublishJobBase {
042
043    /** The delegate publish job. */
044    protected CmsPublishJobInfoBean m_publishJob;
045
046    /**
047     * Internal constructor.<p>
048     *
049     * @param job the job used to initialize
050     */
051    protected CmsPublishJobBase(CmsPublishJobBase job) {
052
053        m_publishJob = job.m_publishJob;
054    }
055
056    /**
057     * Default constructor.<p>
058     *
059     * @param publishJob the delegate publish job
060     */
061    protected CmsPublishJobBase(CmsPublishJobInfoBean publishJob) {
062
063        m_publishJob = publishJob;
064    }
065
066    /**
067     * Returns the locale for this publish job.<p>
068     *
069     * @return the locale for this publish job
070     */
071    public Locale getLocale() {
072
073        return m_publishJob.getLocale();
074    }
075
076    /**
077     * Returns the project name or {@link org.opencms.publish.Messages#GUI_DIRECT_PUBLISH_PROJECT_NAME_0}
078     * if it is a direct publish job.<p>
079     *
080     * @return the project name
081     */
082    public String getProjectName() {
083
084        return m_publishJob.getProjectName();
085    }
086
087    /**
088     * Returns the publish history id.<p>
089     *
090     * @return the publish history id
091     */
092    public CmsUUID getPublishHistoryId() {
093
094        return m_publishJob.getPublishHistoryId();
095    }
096
097    /**
098     * Returns the number of resources in the publish list.<p>
099     *
100     * @return the number of resources in the publish list
101     */
102    public int getSize() {
103
104        return m_publishJob.getSize();
105    }
106
107    /**
108     * Returns the id of the user who initialized this publish job.<p>
109     *
110     * @return the id of the user who initialized this publish job
111     */
112    public CmsUUID getUserId() {
113
114        return m_publishJob.getUserId();
115    }
116
117    /**
118     * Returns the name of the user who initialized this publish job.<p>
119     *
120     * @param cms the cms object
121     *
122     * @return the name of the user who initialized this publish job
123     */
124    public String getUserName(CmsObject cms) {
125
126        String userName = getUserId().toString();
127        try {
128            userName = cms.readUser(getUserId()).getName();
129        } catch (CmsException e) {
130            // ignore
131        }
132        return userName;
133    }
134
135    /**
136     * Returns the direct publish state.<p>
137     *
138     * @return the direct publish state
139     */
140    public boolean isDirectPublish() {
141
142        return m_publishJob.isDirectPublish();
143    }
144}