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

File AbstractSkin.java

 

Coverage histogram

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

Code metrics

16
38
11
1
174
117
22
0.58
3.45
11
2

Classes

Class Line # Actions
AbstractSkin 38 38 0% 22 11
0.8307692483.1%
 

Contributing tests

This file is covered by 33 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.rendering.syntax.SyntaxFactory;
30    import org.xwiki.skin.Resource;
31    import org.xwiki.skin.ResourceRepository;
32    import org.xwiki.skin.Skin;
33   
34    /**
35    * @version $Id: ba6f29db6da0be92201abb72308f74c03768557f $
36    * @since 6.4M1
37    */
 
38    public abstract class AbstractSkin implements Skin
39    {
40    protected Skin VOID = new Skin()
41    {
 
42  0 toggle @Override
43    public Resource<?> getResource(String resource)
44    {
45  0 return null;
46    }
47   
 
48  90824 toggle @Override
49    public Resource<?> getLocalResource(String resource)
50    {
51  90827 return null;
52    }
53   
 
54  91891 toggle @Override
55    public Skin getParent()
56    {
57  91889 return null;
58    }
59   
 
60  182764 toggle @Override
61    public String getId()
62    {
63  182754 return null;
64    }
65   
 
66  0 toggle @Override
67    public Syntax getOutputSyntax()
68    {
69  0 return null;
70    }
71    };
72   
73    protected InternalSkinManager skinManager;
74   
75    protected InternalSkinConfiguration configuration;
76   
77    protected String id;
78   
79    protected Skin parent;
80   
81    private Logger logger;
82   
83    private SyntaxFactory syntaxFactory;
84   
 
85  303676 toggle public AbstractSkin(String id, InternalSkinManager skinManager, InternalSkinConfiguration configuration,
86    Logger logger, SyntaxFactory syntaxFactory)
87    {
88  303669 this.id = id;
89  303663 this.skinManager = skinManager;
90  303665 this.configuration = configuration;
91  303665 this.logger = logger;
92  303665 this.syntaxFactory = syntaxFactory;
93    }
94   
 
95  257743 toggle @Override
96    public String getId()
97    {
98  257749 return this.id;
99    }
100   
 
101  93197 toggle @Override
102    public Skin getParent()
103    {
104  93200 if (this.parent == null) {
105  93201 this.parent = createParent();
106   
107  93194 if (this.parent == null) {
108  196 this.parent = this.skinManager.getSkin(this.configuration.getDefaultParentSkinId());
109    }
110    }
111   
112  93198 return this.parent;
113    }
114   
 
115  139017 toggle @Override
116    public Resource<?> getResource(String resourceName)
117    {
118  139018 Resource<?> resource = getLocalResource(resourceName);
119   
120  139010 if (resource == null) {
121    // Make sure to not try several times the same skin
122  90955 Set<String> skins = new HashSet<String>();
123  90956 skins.add(getId());
124  181780 for (ResourceRepository parent = getParent(); parent != null && resource == null
125    && !skins.contains(parent.getId()); parent = parent.getParent()) {
126  90835 resource = parent.getLocalResource(resourceName);
127  90829 skins.add(parent.getId());
128    }
129    }
130   
131  139002 return resource;
132    }
133   
134    protected abstract Skin createParent();
135   
 
136  11168 toggle @Override
137    public Syntax getOutputSyntax()
138    {
139  11169 Syntax targetSyntax = null;
140  11168 String targetSyntaxString = getOutputSyntaxString();
141  11168 if (StringUtils.isNotEmpty(targetSyntaxString)) {
142  11087 targetSyntax = parseSyntax(this, targetSyntaxString);
143  11082 if (targetSyntax != null) {
144  11080 return targetSyntax;
145    }
146    }
147   
148  81 Skin parent = getParent();
149  81 if (parent != null) {
150  0 targetSyntax = parent.getOutputSyntax();
151    }
152   
153    // Fallback to the XHTML 1.0 syntax for backward compatibility
154  81 return targetSyntax != null ? targetSyntax : Syntax.XHTML_1_0;
155    }
156   
157    /**
158    * @return the id of the syntax to use for this skin
159    */
160    protected abstract String getOutputSyntaxString();
161   
 
162  11086 toggle private Syntax parseSyntax(Skin skin, String syntax)
163    {
164  11087 try {
165  11086 return syntaxFactory.createSyntaxFromIdString(syntax);
166    } catch (ParseException e) {
167  0 logger.warn("Failed to parse the syntax [{}] configured by the skin [{}].",
168    syntax, skin.getId());
169    }
170   
171    // let getOutputSyntax() do the proper fallback
172  0 return null;
173    }
174    }