View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.ecm.publication.impl;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.jcr.Node;
23  
24  import org.exoplatform.services.ecm.publication.NotInPublicationLifecycleException;
25  import org.exoplatform.services.ecm.publication.PublicationPlugin;
26  import org.exoplatform.services.ecm.publication.PublicationPresentationService;
27  import org.exoplatform.services.ecm.publication.PublicationService;
28  import org.exoplatform.services.log.ExoLogger;
29  import org.exoplatform.services.log.Log;
30  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
31  import org.exoplatform.webui.core.UIComponent;
32  import org.exoplatform.webui.form.UIForm;
33  
34  /**
35   * Created by The eXo Platform SAS
36   * Author : Romain Dénarié
37   *          romain.denarie@exoplatform.com
38   * 7 mai 08
39   */
40  public class PublicationPresentationServiceImpl implements PublicationPresentationService {
41  
42    private static final Log LOG  = ExoLogger.getLogger(PublicationPresentationServiceImpl.class.getName());
43    private Map<String, PublicationPlugin> publicationPlugins_ = new HashMap<String,PublicationPlugin>();
44  
45    public PublicationPresentationServiceImpl () {
46      if (LOG.isInfoEnabled()) {
47        LOG.info("# PublicationPresentationService initialization #");
48      }
49      this.publicationPlugins_ = new HashMap<String, PublicationPlugin>();
50    }
51  
52    /* (non-Javadoc)
53     * @see org.exoplatform.services.cms.publication.PublicationService#getStateUI(javax.jcr.Node)
54     */
55    public UIForm getStateUI(Node node, UIComponent component) throws NotInPublicationLifecycleException, Exception {
56      PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
57  
58      if (!publicationService.isNodeEnrolledInLifecycle(node)) {
59        throw new NotInPublicationLifecycleException();
60      }
61      String lifecycleName=publicationService.getNodeLifecycleName(node);
62      PublicationPlugin nodePlugin = this.publicationPlugins_.get(lifecycleName);
63      return nodePlugin.getStateUI(node,component);
64    }
65  
66    /**
67     * Add a Publication Plugin to the service.
68     * The method caches all added plugins.
69     *
70     * @param p the plugin to add
71     */
72    public void addPublicationPlugin(PublicationPlugin p) {
73      this.publicationPlugins_.put(p.getLifecycleName(),p);
74    }
75  }