View Javadoc
1   /**
2    * Copyright 2007 Björn Voß
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.oxclient.service.client.module;
17  
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  import net.sf.oval.constraint.NotNull;
23  import net.sf.oval.guard.Guarded;
24  import net.sf.oxclient.beans.Folder;
25  import net.sf.oxclient.service.client.IOXFolderModule;
26  
27  /**
28   * @author Björn Voß
29   *
30   */
31  @Guarded
32  public class OXFolderModule extends AbsOXModule<Folder>
33  		implements IOXFolderModule {
34  
35  	public OXFolderModule() {
36  		super("folders", Folder.class);
37  	}
38  
39  	/* (non-Javadoc)
40  	 * @see net.sf.oxclient.service.AbsGroupwareModule#getDefaultFolder()
41  	 */
42  	@Override
43  	public Folder getDefaultFolder() {
44  		return RootFolder.getInstance();
45  	}
46  
47  	/* (non-Javadoc)
48  	 * @see net.sf.oxclient.IFolderModule#getRootFolders()
49  	 */
50  	public List<Folder> getRootFolders() {
51  		return getSubFolders(getDefaultFolder());
52  	}
53  
54  	/* (non-Javadoc)
55  	 * @see net.sf.oxclient.IFolderModule#getSubFolders(java.lang.Object)
56  	 */
57  	public List<Folder> getSubFolders(final Folder folder) {
58  		return list(folder);
59  	}
60  
61  	/* (non-Javadoc)
62  	 * @see net.sf.oxclient.service.AbsGroupwareModule#getListParameters(java.lang.Object)
63  	 */
64  	@Override
65  	public Map<String, String> getListParameters(@NotNull final Folder parent) {
66  		final String parentId = parent.getId();
67  		if (parentId == null) {
68  			throw new IllegalArgumentException("parent has no id");
69  		}
70  		final Map<String, String> result = new HashMap<String, String>();
71  		if (parent instanceof RootFolder) {
72  			result.put("action", "root");
73  		} else {
74  			result.put("action", "list");
75  			result.put("parent", parentId);
76  		}
77  		return result;
78  	}
79  
80  	/* (non-Javadoc)
81  	 * @see net.sf.oxclient.service.client.IOXFolderModule#getPrivateFolders()
82  	 */
83  	public List<Folder> getPrivateFolders() {
84  		final Folder privateFolder = new Folder();
85  		privateFolder.setId("1");
86  		return getSubFolders(privateFolder);
87  	}
88  
89  }