1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.descriptor

File WikiDescriptor.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

8
42
22
1
308
148
27
0.64
1.91
22
1.23

Classes

Class Line # Actions
WikiDescriptor 40 42 0% 27 11
0.847222284.7%
 

Contributing tests

This file is covered by 44 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.wiki.descriptor;
21   
22    import java.util.ArrayList;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.apache.commons.lang3.builder.EqualsBuilder;
28    import org.apache.commons.lang3.builder.HashCodeBuilder;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.LocalDocumentReference;
31    import org.xwiki.model.reference.WikiReference;
32    import org.xwiki.wiki.properties.WikiPropertyGroup;
33   
34    /**
35    * This class is a descriptor for wiki.
36    *
37    * @version $Id: b1ba6f86b9545c08fb7d5eca81ea76e51ce2afa7 $
38    * @since 5.3M2
39    */
 
40    public class WikiDescriptor implements Cloneable
41    {
42    /**
43    * Default alias index.
44    */
45    private static final int DEFAULT_ALIAS_INDEX = 0;
46   
47    /**
48    * The ID is the unique identifier that designate this wiki.
49    */
50    private String id;
51   
52    /**
53    * Alias are names that can be used to designate this wiki in several places, like the URL.
54    */
55    private List<String> aliases = new ArrayList<String>();
56   
57    /**
58    * Pretty name.
59    */
60    private String prettyName;
61   
62    /**
63    * Default page.
64    */
65    private LocalDocumentReference mainPageReference = new LocalDocumentReference("Main", "WebHome");
66   
67    /**
68    * The owner of the wiki.
69    */
70    private String ownerId;
71   
72    /**
73    * Hidden.
74    */
75    private boolean isHidden;
76   
77    /**
78    * Description.
79    */
80    private String description;
81   
82    /**
83    * Properties groups that new modules can use to store their own value in the wiki descriptor.
84    */
85    private Map<String, WikiPropertyGroup> propertyGroups;
86   
87    /**
88    * Constructor.
89    *
90    * @param id Unique Id of the wiki
91    * @param defaultAlias Default alias of the wiki
92    */
 
93  203 toggle public WikiDescriptor(String id, String defaultAlias)
94    {
95  203 this.id = id;
96  203 this.aliases = new ArrayList<>();
97  203 this.propertyGroups = new HashMap<>();
98  203 setDefaultAlias(defaultAlias);
99    }
100   
101    /**
102    * @return the unique Id of the wiki.
103    */
 
104  15635 toggle public String getId()
105    {
106  15633 return this.id;
107    }
108   
109    /**
110    * The default alias is the alias used to generate URL for that wiki.
111    *
112    * @return the default alias.
113    */
 
114  46 toggle public String getDefaultAlias()
115    {
116  46 return aliases.get(DEFAULT_ALIAS_INDEX);
117    }
118   
119    /**
120    * Set the default alias.
121    *
122    * @param alias the new default alias
123    */
 
124  203 toggle public void setDefaultAlias(String alias)
125    {
126  203 if (aliases.isEmpty()) {
127  203 aliases.add(alias);
128    } else {
129  0 aliases.set(DEFAULT_ALIAS_INDEX, alias);
130    }
131    }
132   
133    /**
134    * @param alias the new alias to add
135    */
 
136  5 toggle public void addAlias(String alias)
137    {
138  5 aliases.add(alias);
139    }
140   
141    /**
142    * @return all aliases
143    */
 
144  163 toggle public List<String> getAliases()
145    {
146  163 return aliases;
147    }
148   
149    /**
150    * @return the pretty name of the wiki
151    */
 
152  4573 toggle public String getPrettyName()
153    {
154  4573 return prettyName;
155    }
156   
157    /**
158    * @param prettyName the new pretty name
159    */
 
160  118 toggle public void setPrettyName(String prettyName)
161    {
162  118 this.prettyName = prettyName;
163    }
164   
165    /**
166    * @return the Id of the owner of the wiki
167    */
 
168  111 toggle public String getOwnerId()
169    {
170  111 return ownerId;
171    }
172   
173    /**
174    * @param ownerId the Id of the owner of the wiki
175    */
 
176  127 toggle public void setOwnerId(String ownerId)
177    {
178  127 this.ownerId = ownerId;
179    }
180   
181    /**
182    * @return a reference to that wiki
183    */
 
184  1266 toggle public WikiReference getReference()
185    {
186  1266 return new WikiReference(getId());
187    }
188   
189    /**
190    * @return a reference to the main page of the wiki
191    */
 
192  2168 toggle public DocumentReference getMainPageReference()
193    {
194  2167 return new DocumentReference(mainPageReference, new WikiReference(getId()));
195    }
196   
197    /**
198    * @param reference Reference to the main page of the wiki
199    */
 
200  108 toggle public void setMainPageReference(DocumentReference reference)
201    {
202  108 this.mainPageReference = new LocalDocumentReference(reference);
203    }
204   
205    /**
206    * @return if the wiki is hidden
207    */
 
208  0 toggle public boolean isHidden()
209    {
210  0 return isHidden;
211    }
212   
213    /**
214    * Set if the wiki is hidden.
215    *
216    * @param hidden if the wiki is hidden or not
217    */
 
218  0 toggle public void setHidden(boolean hidden)
219    {
220  0 this.isHidden = hidden;
221    }
222   
223    /**
224    * @return the wiki description
225    */
 
226  10 toggle public String getDescription()
227    {
228  10 return description;
229    }
230   
231    /**
232    * @param description the description to set
233    */
 
234  114 toggle public void setDescription(String description)
235    {
236  114 this.description = description;
237    }
238   
239    /**
240    * @param propertyGroupId the id of the property group to retrieve
241    * @return the property group corresponding to the id, or null if no property group correspond to that Id.
242    */
 
243  17 toggle public WikiPropertyGroup getPropertyGroup(String propertyGroupId)
244    {
245  17 return propertyGroups.get(propertyGroupId);
246    }
247   
248    /**
249    * Add a property group to the wiki.
250    *
251    * @param group property group to add
252    */
 
253  17 toggle public void addPropertyGroup(WikiPropertyGroup group)
254    {
255  17 propertyGroups.put(group.getId(), group);
256    }
257   
 
258  10 toggle @Override
259    public int hashCode()
260    {
261  10 return new HashCodeBuilder(3, 3)
262    .append(getDefaultAlias())
263    .append(getId())
264    .toHashCode();
265    }
266   
 
267  18 toggle @Override
268    public boolean equals(Object object)
269    {
270  18 if (object == null) {
271  0 return false;
272    }
273  18 if (object == this) {
274  4 return true;
275    }
276  14 if (object.getClass() != getClass()) {
277  0 return false;
278    }
279  14 WikiDescriptor rhs = (WikiDescriptor) object;
280  14 return new EqualsBuilder()
281    .append(getDefaultAlias(), rhs.getDefaultAlias())
282    .append(getId(), rhs.getId())
283    .isEquals();
284    }
285   
 
286  19739 toggle @Override
287    public WikiDescriptor clone()
288    {
289  19737 WikiDescriptor descriptor;
290  19732 try {
291  19736 descriptor = (WikiDescriptor) super.clone();
292    } catch (CloneNotSupportedException e) {
293    // Supposed to be impossible
294  0 descriptor = new WikiDescriptor(getDescription(), getDefaultAlias());
295    }
296   
297    // Clone aliases
298  19731 descriptor.aliases = new ArrayList<>(this.aliases);
299   
300    // Clone properties
301  19722 descriptor.propertyGroups = new HashMap<>(this.propertyGroups.size());
302  19725 for (WikiPropertyGroup group : this.propertyGroups.values()) {
303  4038 descriptor.propertyGroups.put(group.getId(), group.clone());
304    }
305   
306  19719 return descriptor;
307    }
308    }