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

File LocalDocumentReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
16
11
1
157
59
12
0.75
1.45
11
1.09

Classes

Class Line # Actions
LocalDocumentReference 32 16 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 245 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.model.reference;
21   
22    import java.util.Locale;
23   
24    import org.xwiki.model.EntityType;
25   
26    /**
27    * Represents a reference to a document in the current wiki.
28    *
29    * @version $Id: 70096dd6c34a6718bf573d75ad5f7b40c37ba4ed $
30    * @since 5.0M1
31    */
 
32    public class LocalDocumentReference extends AbstractLocalizedEntityReference
33    {
34    /**
35    * Create a new Document reference in the current wiki.
36    *
37    * @param spaceName the name of the space containing the document, must not be null
38    * @param pageName the name of the document, must not be null
39    */
 
40  11759 toggle public LocalDocumentReference(String spaceName, String pageName)
41    {
42  11758 super(pageName, EntityType.DOCUMENT, new EntityReference(spaceName, EntityType.SPACE));
43    }
44   
45    /**
46    * Create a new Document reference in the current wiki.
47    *
48    * @param spaceNames an ordered list of the names of the spaces containing the document from root space to last one,
49    * must not be null
50    * @param pageName the name of the document
51    * @since 7.3M1
52    */
 
53  454 toggle public LocalDocumentReference(Iterable<String> spaceNames, String pageName)
54    {
55  454 super(pageName, EntityType.DOCUMENT, constructSpaceReference(spaceNames));
56    }
57   
58    /**
59    * Create a new Document reference in the current wiki.
60    *
61    * @param spaceName the name of the space containing the document, must not be null
62    * @param pageName the name of the document, must not be null
63    * @param locale the new locale for this reference
64    * @since 5.3RC1
65    */
 
66  20 toggle public LocalDocumentReference(String spaceName, String pageName, Locale locale)
67    {
68  20 super(pageName, EntityType.DOCUMENT, new EntityReference(spaceName, EntityType.SPACE), locale);
69    }
70   
71    /**
72    * @param documentReference the full document reference
73    * @since 5.2M2
74    */
 
75  49698 toggle public LocalDocumentReference(DocumentReference documentReference)
76    {
77  49697 super(documentReference, documentReference.getWikiReference(), null);
78    }
79   
80    /**
81    * @param reference the reference to clone
82    * @since 5.4RC1
83    */
 
84  62537 toggle public LocalDocumentReference(EntityReference reference)
85    {
86  62537 super(reference);
87    }
88   
89    /**
90    * @param entityReference the reference
91    * @param locale the new locale for this reference, if null, locale is removed
92    * @since 5.3RC1
93    */
 
94  187558 toggle public LocalDocumentReference(EntityReference entityReference, Locale locale)
95    {
96  187558 super(entityReference, locale);
97    }
98   
99    /**
100    * Create a new Document reference in the current wiki.
101    *
102    * @param pageName the name of the document, must not be null
103    * @param spaceReference the reference of the space, must not be null
104    * @since 7.2M1
105    */
 
106  13473 toggle public LocalDocumentReference(String pageName, EntityReference spaceReference)
107    {
108  13473 super(pageName, EntityType.DOCUMENT, spaceReference);
109    }
110   
111    /**
112    * Clone an LocalDocumentReference, but use the specified parent for its new parent.
113    *
114    * @param reference the reference to clone
115    * @param parent the new parent to use
116    * @since 10.8RC1
117    */
 
118  77 toggle public LocalDocumentReference(EntityReference reference, EntityReference parent)
119    {
120  77 super(reference, parent);
121    }
122   
123    /**
124    * Create a relative space reference in from a list of space names.
125    *
126    * @param spaceNames the list of space name from root to child
127    * @return the space reference
128    */
 
129  454 toggle private static EntityReference constructSpaceReference(Iterable<String> spaceNames)
130    {
131  454 EntityReference spaceReference = null;
132   
133  454 for (String spaceName : spaceNames) {
134  1172 spaceReference = new EntityReference(spaceName, EntityType.SPACE, spaceReference);
135    }
136   
137  454 return spaceReference;
138    }
139   
 
140  78 toggle @Override
141    public LocalDocumentReference replaceParent(EntityReference newParent)
142    {
143  78 if (newParent == getParent()) {
144  1 return this;
145    }
146   
147  77 return new LocalDocumentReference(this, newParent);
148    }
149   
 
150  2 toggle @Override
151    public String toString()
152    {
153    // Compared to EntityReference we don't print the type since the type is already indicated by the fact that
154    // this is a LocalDocumentReference instance.
155  2 return TOSTRING_SERIALIZER.serialize(this);
156    }
157    }