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, 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.ade.publish;
029
030import org.opencms.ade.publish.shared.CmsProjectBean;
031import org.opencms.ade.publish.shared.CmsPublishOptions;
032import org.opencms.file.CmsObject;
033import org.opencms.file.CmsProject;
034import org.opencms.file.CmsResource;
035import org.opencms.main.CmsException;
036import org.opencms.main.OpenCms;
037import org.opencms.util.CmsUUID;
038import org.opencms.workflow.CmsDefaultWorkflowManager;
039
040import java.util.ArrayList;
041import java.util.List;
042import java.util.Locale;
043import java.util.Map;
044
045/**
046 * Wrapper to use real OpenCms projects through the I_CmsVirtualProject interface.<p>
047 */
048public class CmsRealProjectVirtualWrapper implements I_CmsVirtualProject {
049
050    /** The project id. */
051    private CmsUUID m_projectId;
052
053    /**
054     * Creates a new wrapper instance.<p>
055     *
056     * @param id the project id
057     */
058    public CmsRealProjectVirtualWrapper(CmsUUID id) {
059
060        m_projectId = id;
061
062    }
063
064    /**
065     * @see org.opencms.ade.publish.I_CmsVirtualProject#getProjectBean(org.opencms.file.CmsObject, java.util.Map)
066     */
067    public CmsProjectBean getProjectBean(CmsObject cms, Map<String, String> params) {
068
069        try {
070            CmsProject project = cms.readProject(getProjectId());
071            CmsProjectBean result = CmsDefaultWorkflowManager.createProjectBeanFromProject(cms, project);
072            Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
073            String name = Messages.get().getBundle(locale).key(Messages.GUI_NORMAL_PROJECT_1, project.getName());
074            result.setDefaultGroupName(name);
075            return result;
076        } catch (CmsException e) {
077            return null;
078        }
079    }
080
081    /**
082     * @see org.opencms.ade.publish.I_CmsVirtualProject#getProjectId()
083     */
084    public CmsUUID getProjectId() {
085
086        return m_projectId;
087    }
088
089    /**
090     * @see org.opencms.ade.publish.I_CmsVirtualProject#getRelatedResourceProvider(org.opencms.file.CmsObject, org.opencms.ade.publish.shared.CmsPublishOptions)
091     */
092    public I_CmsPublishRelatedResourceProvider getRelatedResourceProvider(
093        CmsObject cmsObject,
094        CmsPublishOptions options) {
095
096        return CmsDummyRelatedResourceProvider.INSTANCE;
097    }
098
099    /**
100     * @see org.opencms.ade.publish.I_CmsVirtualProject#getResources(org.opencms.file.CmsObject, java.util.Map, java.lang.String)
101     */
102    public List<CmsResource> getResources(CmsObject cms, Map<String, String> params, String workflowId)
103    throws CmsException {
104
105        List<CmsResource> rawResourceList = new ArrayList<CmsResource>();
106        CmsProject project = cms.getRequestContext().getCurrentProject();
107        try {
108            project = cms.readProject(getProjectId());
109        } catch (CmsException e) {
110            // ignore
111        }
112        // get the project publish list
113        CmsProject originalProject = cms.getRequestContext().getCurrentProject();
114        try {
115            cms.getRequestContext().setCurrentProject(project);
116            rawResourceList.addAll(OpenCms.getPublishManager().getPublishList(cms).getAllResources());
117        } finally {
118            cms.getRequestContext().setCurrentProject(originalProject);
119        }
120        return rawResourceList;
121    }
122
123    /**
124     * @see org.opencms.ade.publish.I_CmsVirtualProject#isAutoSelectable()
125     */
126    public boolean isAutoSelectable() {
127
128        return false;
129    }
130
131}