1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro.wikibridge

File WikiMacroVisibility.java

 

Coverage histogram

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

Code metrics

2
7
2
1
77
25
3
0.43
3.5
2
1.5

Classes

Class Line # Actions
WikiMacroVisibility 32 7 0% 3 1
0.9090909490.9%
 

Contributing tests

This file is covered by 5 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.rendering.macro.wikibridge;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    /**
26    * The visibility of a Wiki Macro, ie whether it's visible to the current user only, to the current wiki only
27    * or globally.
28    *
29    * @version $Id: f81fbab0aeebe585eebad5f049baff54d75329f3 $
30    * @since 2.2M1
31    */
 
32    public enum WikiMacroVisibility
33    {
34    /**
35    * Macro visible only by the current user.
36    */
37    USER,
38   
39    /**
40    * Macro visible only for the current wiki.
41    */
42    WIKI,
43   
44    /**
45    * Macro visible for all wikis in a farm.
46    */
47    GLOBAL;
48   
49    /**
50    * Mapping between String definition of visibility and enums. The strings defined are coming from the
51    * Wiki Macro Class field definition for the Visibility property.
52    */
53    private static final Map<String, WikiMacroVisibility> MAPPINGS = new HashMap<String, WikiMacroVisibility>()
54    {
 
55  21 toggle {
56  21 put("Current User", USER);
57  21 put("Current Wiki", WIKI);
58  21 put("Global", GLOBAL);
59    }
60    };
61   
62    /**
63    * Convert between a string representation of a Macro visibility and its matching enum. If no matching enum is
64    * found then defaults to Wiki level visibility.
65    *
66    * @param visibilityAsString the visibility as a string
67    * @return the enum matching the visibility defined as a string
68    */
 
69  232 toggle public static WikiMacroVisibility fromString(String visibilityAsString)
70    {
71  232 WikiMacroVisibility visibility = WIKI;
72  232 if (MAPPINGS.containsKey(visibilityAsString)) {
73  232 visibility = MAPPINGS.get(visibilityAsString);
74    }
75  232 return visibility;
76    }
77    }