1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.doc

File XWikiSpace.java

 

Coverage histogram

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

Code metrics

12
26
18
1
230
109
26
1
1.44
18
1.44

Classes

Class Line # Actions
XWikiSpace 40 26 0% 26 8
0.8571428785.7%
 

Contributing tests

No tests hitting this source file were found.

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 com.xpn.xwiki.doc;
21   
22    import org.apache.commons.lang3.StringUtils;
23    import org.xwiki.model.EntityType;
24    import org.xwiki.model.internal.reference.DefaultSymbolScheme;
25    import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer;
26    import org.xwiki.model.internal.reference.LocalUidStringEntityReferenceSerializer;
27    import org.xwiki.model.reference.SpaceReference;
28    import org.xwiki.model.reference.SpaceReferenceResolver;
29   
30    import com.xpn.xwiki.store.XWikiStoreInterface;
31    import com.xpn.xwiki.util.Util;
32    import com.xpn.xwiki.web.Utils;
33   
34    /**
35    * Represent a space.
36    *
37    * @version $Id: 2aad826e028fe0a9151aa0a9f3b0685c0a1a4aae $
38    * @since 7.2M1
39    */
 
40    public class XWikiSpace
41    {
42    private static final String CURRENT = "current";
43   
44    private static final LocalStringEntityReferenceSerializer SERIALIZER =
45    new LocalStringEntityReferenceSerializer(new DefaultSymbolScheme());
46   
47    private final XWikiStoreInterface store;
48   
49    /**
50    * Synthetic id.
51    */
52    private Long id;
53   
54    private String name;
55   
56    private String parent;
57   
58    private boolean hidden;
59   
60    /**
61    * @see #getReference()
62    */
63    private SpaceReference reference;
64   
65    /**
66    * Required by Hibernate.
67    */
 
68  0 toggle protected XWikiSpace()
69    {
70  0 this(null, null);
71    }
72   
73    /**
74    * @param reference the complete reference of the space
75    */
 
76  0 toggle public XWikiSpace(SpaceReference reference)
77    {
78  0 this(reference, null);
79    }
80   
81    /**
82    * @param reference the complete reference of the space
83    * @param hidden true if all the documents in the space are hidden
84    */
 
85  278 toggle public XWikiSpace(SpaceReference reference, boolean hidden)
86    {
87  278 this(reference, null);
88   
89  278 setHidden(hidden);
90    }
91   
92    /**
93    * @param reference the complete reference of the space
94    * @param store the store where the {@link XWikiSpace} instance come from
95    */
 
96  3922 toggle public XWikiSpace(SpaceReference reference, XWikiStoreInterface store)
97    {
98  3922 this.reference = reference;
99  3922 this.store = store;
100    }
101   
 
102  3303 toggle private static SpaceReferenceResolver<String> getCurrentSpaceResolver()
103    {
104  3303 return Utils.getComponent(SpaceReferenceResolver.TYPE_STRING, CURRENT);
105    }
106   
107    /**
108    * @return the store where the {@link XWikiSpace} instance come from
109    */
 
110  0 toggle public XWikiStoreInterface getStore()
111    {
112  0 return this.store;
113    }
114   
115    /**
116    * @return the synthetic id of this deleted document. unique only for document.
117    */
 
118  7629 toggle public long getId()
119    {
120  7629 if (this.id == null) {
121  3922 this.id = Util.getHash(LocalUidStringEntityReferenceSerializer.INSTANCE.serialize(getSpaceReference()));
122    }
123   
124  7629 return this.id;
125    }
126   
127    /**
128    * Required by Hibernate.
129    *
130    * @param id the synthetic id to set.
131    */
 
132  3859 toggle protected void setId(long id)
133    {
134  3859 this.id = id;
135    }
136   
137    /**
138    * @return the name of the space.
139    */
 
140  3985 toggle public String getName()
141    {
142  3985 if (this.name == null && this.reference != null) {
143  341 this.name = this.reference.getName();
144    }
145   
146  3985 return this.name;
147    }
148   
149    /**
150    * Required by Hibernate.
151    *
152    * @param name the name of the space
153    */
 
154  3303 toggle protected void setName(String name)
155    {
156  3303 this.name = name;
157    }
158   
159    /**
160    * @return the reference of the space parent
161    */
 
162  3985 toggle public String getParent()
163    {
164  3985 if (this.parent == null && this.reference != null) {
165  341 this.parent =
166  341 this.reference.getParent().getType() == EntityType.SPACE ? SERIALIZER.serialize(this.reference
167    .getParent()) : "";
168    }
169   
170  3985 return StringUtils.isEmpty(this.parent) ? null : this.parent;
171    }
172   
173    /**
174    * Required by Hibernate.
175    *
176    * @param parent the reference of the space parent
177    */
 
178  3303 toggle protected void setParent(String parent)
179    {
180  3303 this.parent = StringUtils.isEmpty(parent) ? "" : parent;
181    }
182   
183    /**
184    * @return the complete reference of the space
185    */
 
186  3985 toggle public String getReference()
187    {
188  3985 return SERIALIZER.serialize(this.reference);
189    }
190   
191    /**
192    * @return true if all the documents in the space are hidden
193    */
 
194  7374 toggle public boolean isHidden()
195    {
196  7374 return this.hidden;
197    }
198   
199    /**
200    * @param hidden true if all the documents in the space are hidden
201    */
 
202  3610 toggle public void setHidden(boolean hidden)
203    {
204  3610 this.hidden = hidden;
205    }
206   
207    /**
208    * Required by Hibernate.
209    *
210    * @param reference
211    */
 
212  3303 toggle protected void setReference(String reference)
213    {
214  3303 this.reference = getCurrentSpaceResolver().resolve(reference);
215    }
216   
217    /**
218    * @return the complete reference of the space
219    */
 
220  4289 toggle public SpaceReference getSpaceReference()
221    {
222  4289 return this.reference;
223    }
224   
 
225  0 toggle @Override
226    public String toString()
227    {
228  0 return getSpaceReference().toString();
229    }
230    }