1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.skin

File AbstractSkin.java

 

Coverage histogram

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

Code metrics

16
37
11
1
169
113
22
0.59
3.36
11
2

Classes

Class Line # Actions
AbstractSkin 37 37 0% 22 7
0.89062589.1%
 

Contributing tests

This file is covered by 36 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 com.xpn.xwiki.internal.skin;
21   
22    import java.util.HashSet;
23    import java.util.Set;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.slf4j.Logger;
27    import org.xwiki.rendering.parser.ParseException;
28    import org.xwiki.rendering.syntax.Syntax;
29    import org.xwiki.skin.Resource;
30    import org.xwiki.skin.ResourceRepository;
31    import org.xwiki.skin.Skin;
32   
33    /**
34    * @version $Id: 5f733689ab9786ac1ff5a71fbac41ae9f4a2bd05 $
35    * @since 6.4M1
36    */
 
37    public abstract class AbstractSkin implements Skin
38    {
39    protected Skin VOID = new Skin()
40    {
 
41  0 toggle @Override
42    public Resource<?> getResource(String resource)
43    {
44  0 return null;
45    }
46   
 
47  833140 toggle @Override
48    public Resource<?> getLocalResource(String resource)
49    {
50  833194 return null;
51    }
52   
 
53  834092 toggle @Override
54    public Skin getParent()
55    {
56  834160 return null;
57    }
58   
 
59  1666342 toggle @Override
60    public String getId()
61    {
62  1666405 return null;
63    }
64   
 
65  0 toggle @Override
66    public Syntax getOutputSyntax()
67    {
68  0 return null;
69    }
70    };
71   
72    protected InternalSkinManager skinManager;
73   
74    protected InternalSkinConfiguration configuration;
75   
76    protected String id;
77   
78    protected Skin parent;
79   
80    private Logger logger;
81   
 
82  5167727 toggle public AbstractSkin(String id, InternalSkinManager skinManager, InternalSkinConfiguration configuration,
83    Logger logger)
84    {
85  5170512 this.id = id;
86  5171870 this.skinManager = skinManager;
87  5170831 this.configuration = configuration;
88  5170759 this.logger = logger;
89    }
90   
 
91  6789244 toggle @Override
92    public String getId()
93    {
94  6791568 return this.id;
95    }
96   
 
97  2283122 toggle @Override
98    public Skin getParent()
99    {
100  2284507 if (this.parent == null) {
101  2276660 this.parent = createParent();
102   
103  2275144 if (this.parent == null) {
104  9668 this.parent = this.skinManager.getSkin(this.configuration.getDefaultParentSkinId());
105    }
106    }
107   
108  2283574 return this.parent;
109    }
110   
 
111  1362999 toggle @Override
112    public Resource<?> getResource(String resourceName)
113    {
114  1363787 Resource<?> resource = getLocalResource(resourceName);
115   
116  1362981 if (resource == null) {
117    // Make sure to not try several times the same skin
118  1204331 Set<String> skins = new HashSet<String>();
119  1203916 skins.add(getId());
120  3009004 for (ResourceRepository parent = getParent(); parent != null && resource == null
121    && !skins.contains(parent.getId()); parent = parent.getParent()) {
122  1805758 resource = parent.getLocalResource(resourceName);
123  1804842 skins.add(parent.getId());
124    }
125    }
126   
127  1362969 return resource;
128    }
129   
130    protected abstract Skin createParent();
131   
 
132  225888 toggle @Override
133    public Syntax getOutputSyntax()
134    {
135  226184 Syntax targetSyntax = null;
136  226397 String targetSyntaxString = getOutputSyntaxString();
137  226288 if (StringUtils.isNotEmpty(targetSyntaxString)) {
138  121021 targetSyntax = parseSyntax(this, targetSyntaxString);
139  120590 if (targetSyntax != null) {
140  120835 return targetSyntax;
141    }
142    }
143   
144  105131 Skin parent = getParent();
145  105373 if (parent != null) {
146  105043 targetSyntax = parent.getOutputSyntax();
147    }
148   
149    // Fallback to the XHTML 1.0 syntax for backward compatibility
150  105357 return targetSyntax != null ? targetSyntax : Syntax.XHTML_1_0;
151    }
152   
153    /**
154    * @return the id of the syntax to use for this skin
155    */
156    protected abstract String getOutputSyntaxString();
157   
 
158  120945 toggle private Syntax parseSyntax(Skin skin, String syntax)
159    {
160  121120 try {
161  121039 return Syntax.valueOf(syntax);
162    } catch (ParseException e) {
163  0 logger.warn("Failed to parse the syntax [{}] configured by the skin [{}].", syntax, skin.getId());
164    }
165   
166    // let getOutputSyntax() do the proper fallback
167  0 return null;
168    }
169    }