View Javadoc
1   /*
2    * Copyright (C) 2003-2009 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.wiki.mow.core.api.wiki;
18  
19  import org.chromattic.api.RelationshipType;
20  import org.chromattic.api.annotations.Create;
21  import org.chromattic.api.annotations.MappedBy;
22  import org.chromattic.api.annotations.OneToMany;
23  import org.exoplatform.services.log.ExoLogger;
24  import org.exoplatform.services.log.Log;
25  import org.exoplatform.wiki.WikiException;
26  import org.exoplatform.wiki.mow.api.Wiki;
27  import org.exoplatform.wiki.mow.core.api.MOWService;
28  
29  import java.util.Collection;
30  import java.util.List;
31  
32  /**
33   * @version $Revision$
34   */
35  public abstract class WikiContainer<T extends WikiImpl> {
36    
37    private static final Log      log               = ExoLogger.getLogger(WikiContainer.class);
38  
39    protected MOWService mowService;
40  
41    public void setMOWService(MOWService mowService) {
42      this.mowService = mowService;
43    }
44  
45    @OneToMany(type = RelationshipType.REFERENCE)
46    @MappedBy(WikiNodeType.Definition.WIKI_CONTAINER_REFERENCE)
47    public abstract Collection<T> getWikis();
48  
49    /*
50     * @OneToOne public abstract WikiStoreImpl getMultiWiki();
51     */
52  
53    public abstract T addWiki(Wiki wiki) throws WikiException;
54  
55    public abstract T createWiki(Wiki wiki) throws WikiException;
56  
57    @Create
58    public abstract T createWiki();  
59    
60    protected String validateWikiOwner(String wikiOwner){
61      return wikiOwner;
62    }
63  
64    public T getWiki(String wikiOwner) {
65      return contains(wikiOwner);
66    }
67  
68    public Collection<T> getAllWikis() {
69      return getWikis();
70    }
71    
72    /**
73     * Checks if current WikiContainer contains the wiki with specified wiki owner
74     * @param wikiOwner the wiki owner
75     * @return the wiki if it exists, otherwise null
76     */
77    public T contains(String wikiOwner) {
78      wikiOwner = validateWikiOwner(wikiOwner);
79      if (wikiOwner == null) {
80        return null;
81      }
82      return getWikiObject(wikiOwner);
83    }
84    
85    /**
86     * Gets the wiki in current WikiContainer by specified wiki owner
87     * @param wikiOwner the wiki owner
88     * @return the wiki object
89     */
90    abstract protected T getWikiObject(String wikiOwner);
91  
92  }