View Javadoc
1   /*
2    * Copyright (C) 2003-2010 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 java.util.Collection;
20  import java.util.Map;
21  
22  import org.chromattic.api.annotations.OneToMany;
23  import org.chromattic.api.annotations.Path;
24  import org.chromattic.api.annotations.PrimaryType;
25  
26  @PrimaryType(name = WikiNodeType.WIKI_TRASH)
27  public abstract class Trash {
28  
29    @Path
30    public abstract String getPath();
31    
32    /*@OneToMany
33    public abstract Collection<PageImpl> getChildPages();
34    
35    public void addRemovedWikiPage(PageImpl wikiPage) throws DuplicateNameException {
36      getChildPages().add(wikiPage);
37    }*/
38    
39    @OneToMany
40    public abstract Map<String, PageImpl> getChildren();
41  
42    public Collection<PageImpl> getChildPages() {
43      return getChildren().values();
44    }
45    
46    public boolean isHasPage(String name) {
47      return getChildren().containsKey(name) ;
48    }
49     
50    public void addRemovedWikiPage(PageImpl page) {
51      if (page == null) {
52        throw new NullPointerException();
53      }
54      addChild(page.getName(), page);
55    }
56  
57    public void addChild(String pageName, PageImpl page) {
58      if (pageName == null) {
59        throw new NullPointerException();
60      }
61      if (page == null) {
62        throw new NullPointerException();
63      }
64      Map<String, PageImpl> children = getChildren();
65      if (children.containsKey(pageName)) {
66        throw new IllegalStateException();
67      }
68      children.put(pageName, page);
69    }
70    
71    public PageImpl getPage(String pageName) {
72      if (pageName == null) {
73        throw new NullPointerException();
74      }
75      Map<String, PageImpl> children = getChildren();
76      return children.get(pageName);
77    }
78    
79  }