1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.wiki.descriptor

File WikiDescriptor.java

 

Coverage histogram

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

Code metrics

8
46
26
1
349
161
31
0.67
1.77
26
1.19

Classes

Class Line # Actions
WikiDescriptor 40 46 0% 31 11
0.862586.3%
 

Contributing tests

This file is covered by 52 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: 711bf6855210791657dcf56b6f9d171ed29fc329 $
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<>();
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    * @see #isSecure()
84    */
85    private Boolean secure;
86   
87    /**
88    * @see #getPort()
89    */
90    private int port = -1;
91   
92    /**
93    * Properties groups that new modules can use to store their own value in the wiki descriptor.
94    */
95    private Map<String, WikiPropertyGroup> propertyGroups;
96   
97    /**
98    * Constructor.
99    *
100    * @param id Unique Id of the wiki
101    * @param defaultAlias Default alias of the wiki
102    */
 
103  311 toggle public WikiDescriptor(String id, String defaultAlias)
104    {
105  311 this.id = id;
106  313 this.aliases = new ArrayList<>();
107  312 this.propertyGroups = new HashMap<>();
108  311 setDefaultAlias(defaultAlias);
109    }
110   
111    /**
112    * @return the unique Id of the wiki.
113    */
 
114  229388 toggle public String getId()
115    {
116  229385 return this.id;
117    }
118   
119    /**
120    * The default alias is the alias used to generate URL for that wiki.
121    *
122    * @return the default alias.
123    */
 
124  111 toggle public String getDefaultAlias()
125    {
126  111 return aliases.get(DEFAULT_ALIAS_INDEX);
127    }
128   
129    /**
130    * Set the default alias.
131    *
132    * @param alias the new default alias
133    */
 
134  311 toggle public void setDefaultAlias(String alias)
135    {
136  313 if (aliases.isEmpty()) {
137  312 aliases.add(alias);
138    } else {
139  0 aliases.set(DEFAULT_ALIAS_INDEX, alias);
140    }
141    }
142   
143    /**
144    * @param alias the new alias to add
145    */
 
146  5 toggle public void addAlias(String alias)
147    {
148  5 aliases.add(alias);
149    }
150   
151    /**
152    * @return all aliases
153    */
 
154  172 toggle public List<String> getAliases()
155    {
156  172 return aliases;
157    }
158   
159    /**
160    * @return the pretty name of the wiki
161    */
 
162  301684 toggle public String getPrettyName()
163    {
164  301685 return prettyName;
165    }
166   
167    /**
168    * @param prettyName the new pretty name
169    */
 
170  130 toggle public void setPrettyName(String prettyName)
171    {
172  130 this.prettyName = prettyName;
173    }
174   
175    /**
176    * @return the Id of the owner of the wiki
177    */
 
178  184 toggle public String getOwnerId()
179    {
180  184 return ownerId;
181    }
182   
183    /**
184    * @param ownerId the Id of the owner of the wiki
185    */
 
186  139 toggle public void setOwnerId(String ownerId)
187    {
188  139 this.ownerId = ownerId;
189    }
190   
191    /**
192    * @return a reference to that wiki
193    */
 
194  158046 toggle public WikiReference getReference()
195    {
196  158046 return new WikiReference(getId());
197    }
198   
199    /**
200    * @return a reference to the main page of the wiki
201    */
 
202  35859 toggle public DocumentReference getMainPageReference()
203    {
204  35859 return new DocumentReference(mainPageReference, new WikiReference(getId()));
205    }
206   
207    /**
208    * @param reference Reference to the main page of the wiki
209    */
 
210  127 toggle public void setMainPageReference(DocumentReference reference)
211    {
212  127 this.mainPageReference = new LocalDocumentReference(reference);
213    }
214   
215    /**
216    * @return if the wiki is hidden
217    */
 
218  0 toggle public boolean isHidden()
219    {
220  0 return isHidden;
221    }
222   
223    /**
224    * Set if the wiki is hidden.
225    *
226    * @param hidden if the wiki is hidden or not
227    */
 
228  0 toggle public void setHidden(boolean hidden)
229    {
230  0 this.isHidden = hidden;
231    }
232   
233    /**
234    * @return the wiki description
235    */
 
236  8 toggle public String getDescription()
237    {
238  8 return description;
239    }
240   
241    /**
242    * @param description the description to set
243    */
 
244  125 toggle public void setDescription(String description)
245    {
246  126 this.description = description;
247    }
248   
249    /**
250    * @return true if the wiki should be accessed trough a secure connection (HTTPS), null means default
251    * @since 10.7RC1
252    */
 
253  10 toggle public Boolean isSecure()
254    {
255  10 return this.secure;
256    }
257   
258    /**
259    * @param secure true if the wiki should be accessed trough a secure connection (HTTPS), null means default
260    * @since 10.7RC1
261    */
 
262  121 toggle public void setSecure(Boolean secure)
263    {
264  121 this.secure = secure;
265    }
266   
267    /**
268    * @return the port to use when generating external URL for the wiki, -1 means default
269    * @since 10.7RC1
270    */
 
271  10 toggle public int getPort()
272    {
273  10 return this.port;
274    }
275   
276    /**
277    * @param port the port to use when generating external URL for the wiki, -1 means default
278    * @since 10.7RC1
279    */
 
280  121 toggle public void setPort(int port)
281    {
282  121 this.port = port;
283    }
284   
285    /**
286    * @param propertyGroupId the id of the property group to retrieve
287    * @return the property group corresponding to the id, or null if no property group correspond to that Id.
288    */
 
289  11 toggle public WikiPropertyGroup getPropertyGroup(String propertyGroupId)
290    {
291  11 return propertyGroups.get(propertyGroupId);
292    }
293   
294    /**
295    * Add a property group to the wiki.
296    *
297    * @param group property group to add
298    */
 
299  27 toggle public void addPropertyGroup(WikiPropertyGroup group)
300    {
301  27 propertyGroups.put(group.getId(), group);
302    }
303   
 
304  28 toggle @Override
305    public int hashCode()
306    {
307  28 return new HashCodeBuilder(3, 3).append(getDefaultAlias()).append(getId()).toHashCode();
308    }
309   
 
310  18 toggle @Override
311    public boolean equals(Object object)
312    {
313  18 if (object == null) {
314  0 return false;
315    }
316  18 if (object == this) {
317  4 return true;
318    }
319  14 if (object.getClass() != getClass()) {
320  0 return false;
321    }
322  14 WikiDescriptor rhs = (WikiDescriptor) object;
323  14 return new EqualsBuilder().append(getDefaultAlias(), rhs.getDefaultAlias()).append(getId(), rhs.getId())
324    .isEquals();
325    }
326   
 
327  530725 toggle @Override
328    public WikiDescriptor clone()
329    {
330  530735 WikiDescriptor descriptor;
331  530738 try {
332  530739 descriptor = (WikiDescriptor) super.clone();
333    } catch (CloneNotSupportedException e) {
334    // Supposed to be impossible
335  0 descriptor = new WikiDescriptor(getDescription(), getDefaultAlias());
336    }
337   
338    // Clone aliases
339  530750 descriptor.aliases = new ArrayList<>(this.aliases);
340   
341    // Clone properties
342  530741 descriptor.propertyGroups = new HashMap<>(this.propertyGroups.size());
343  530747 for (WikiPropertyGroup group : this.propertyGroups.values()) {
344  514111 descriptor.propertyGroups.put(group.getId(), group.clone());
345    }
346   
347  530727 return descriptor;
348    }
349    }