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

File Scope.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
22
8
1
164
60
13
0.59
2.75
8
1.62

Classes

Class Line # Actions
Scope 27 22 0% 13 36
0.00%
 

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.criteria.impl;
21   
22    /**
23    * Immutable scope for retrieving statistics. A scope is associated with a single document but it can match any number
24    * of documents. Here, a document can be a page, a space, a wiki or the entire application as a unit. For instance, a
25    * scope associated with a space can match all the pages within that space.
26    */
 
27    public class Scope
28    {
29    /**
30    * Any scope that is associated with a page
31    */
32    public static final int PAGE_SCOPE = 1;
33   
34    /**
35    * Any scope that is associated with a space
36    */
37    public static final int SPACE_SCOPE = 2;
38   
39    /**
40    * Any scope that is associated with a wiki
41    */
42    public static final int WIKI_SCOPE = 3;
43   
44    /**
45    * The scope that is associated with the entire application as a unit
46    */
47    public static final int GLOBAL_SCOPE = 4;
48   
49    /**
50    * The type of the scope. It can be {@link #PAGE_SCOPE}, {@link #SPACE_SCOPE}, {@link #WIKI_SCOPE} or
51    * {@link #GLOBAL_SCOPE}
52    */
53    private int type;
54   
55    /**
56    * Depending on the scope type it can mean:
57    * <ul>
58    * <li>the name of the page associated with this scope, for {@link #PAGE_SCOPE}</li>
59    * <li>the name of the space associated with this scope, for {@link #SPACE_SCOPE}</li>
60    * <li>the name of the wiki associated with this scope, for {@link #WIKI_SCOPE}</li>
61    * <li>empty string, for {@link #GLOBAL_SCOPE}</li>
62    * </ul>
63    */
64    private String name;
65   
66    /**
67    * Specifies whether the document given by the {@link #name} field should be considered as a unit or not. When
68    * {@link #deep} is <code>false</code> the scope matches only the document with the given {@link #name} (taken as a
69    * unit). Otherwise the scope matches all its sub documents (like all pages within a space).
70    */
71    private boolean deep;
72   
73    /**
74    * Creates a new Scope instance with the specified field values.
75    *
76    * @param type The type of the scope
77    * @param name The name of the document associated with this scope
78    * @param deep <code>true</code> for matching all sub documents; <code>false</code> for matching the associated
79    * document as a unit
80    */
 
81  0 toggle public Scope(int type, String name, boolean deep)
82    {
83  0 this.type = type;
84  0 this.name = name;
85  0 this.deep = deep;
86    }
87   
88    /**
89    * @see #type
90    */
 
91  0 toggle public int getType()
92    {
93  0 return this.type;
94    }
95   
96    /**
97    * @see #name
98    */
 
99  0 toggle public String getName()
100    {
101  0 return this.name;
102    }
103   
104    /**
105    * @see #deep
106    */
 
107  0 toggle public boolean isDeep()
108    {
109  0 return this.deep;
110    }
111   
112    /**
113    * @return The pattern used for matching document names in the database
114    */
 
115  0 toggle public String getPattern()
116    {
117  0 switch (this.type) {
118  0 case PAGE_SCOPE:
119  0 return getPagePattern();
120  0 case SPACE_SCOPE:
121  0 return getSpacePattern();
122  0 default:
123  0 return getGlobalPattern();
124    }
125    }
126   
127    /**
128    * @return The pattern used in the case of a {@link #PAGE_SCOPE}
129    * @see #getPattern()
130    */
 
131  0 toggle private String getPagePattern()
132    {
133    // ignore deep
134  0 if ("".equals(this.name)) {
135    // a pattern to match any page name
136  0 return "%.%";
137    }
138  0 return this.name;
139    }
140   
141    /**
142    * @return The pattern used in the case of a {@link #SPACE_SCOPE}
143    * @see #getPattern()
144    */
 
145  0 toggle private String getSpacePattern()
146    {
147  0 if ("".equals(this.name)) {
148    // TODO a pattern to match any space name
149  0 return null;
150  0 } else if (this.deep) {
151  0 return this.name + ".%";
152    }
153  0 return this.name;
154    }
155   
156    /**
157    * @return The pattern used in the case of a {@link #GLOBAL_SCOPE}
158    * @see #getPattern()
159    */
 
160  0 toggle private String getGlobalPattern()
161    {
162  0 return "";
163    }
164    }