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

File DefaultSkinReferenceFactory.java

 

Coverage histogram

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

Code metrics

4
13
2
1
95
54
5
0.38
6.5
2
2.5

Classes

Class Line # Actions
DefaultSkinReferenceFactory 47 13 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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.lesscss.internal.skin;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.lesscss.compiler.LESSCompilerException;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.DocumentReferenceResolver;
30    import org.xwiki.model.reference.EntityReferenceSerializer;
31    import org.xwiki.model.reference.WikiReference;
32    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
33   
34    import com.xpn.xwiki.XWiki;
35    import com.xpn.xwiki.XWikiContext;
36    import com.xpn.xwiki.XWikiException;
37    import com.xpn.xwiki.doc.XWikiDocument;
38   
39    /**
40    * Default implementation for {@link org.xwiki.lesscss.internal.skin.SkinReferenceFactory}.
41    *
42    * @since 6.4M2
43    * @version $Id: d883d5187685d2e9db21d9bb698aa488ce64a8ff $
44    */
45    @Component
46    @Singleton
 
47    public class DefaultSkinReferenceFactory implements SkinReferenceFactory
48    {
49    @Inject
50    private Provider<XWikiContext> xcontextProvider;
51   
52    @Inject
53    private DocumentReferenceResolver<String> documentReferenceResolver;
54   
55    @Inject
56    private WikiDescriptorManager wikiDescriptorManager;
57   
58    @Inject
59    private EntityReferenceSerializer<String> entityReferenceSerializer;
60   
 
61  2165 toggle @Override
62    public SkinReference createReference(String skinName) throws LESSCompilerException
63    {
64    // Get the XWIki Object
65  2165 XWikiContext xcontext = xcontextProvider.get();
66  2166 XWiki xwiki = xcontext.getWiki();
67   
68  2166 String currentWikiId = wikiDescriptorManager.getCurrentWikiId();
69   
70  2166 DocumentReference skinDocRef = documentReferenceResolver.resolve(skinName, new WikiReference(currentWikiId));
71   
72  2166 if (xwiki.exists(skinDocRef, xcontext)) {
73  3 try {
74  3 XWikiDocument skinDoc = xwiki.getDocument(skinDocRef, xcontext);
75  2 DocumentReference skinClassDocRef = new DocumentReference(skinDocRef.getWikiReference().getName(),
76    "XWiki", "XWikiSkins");
77   
78  2 if (skinDoc.getXObjectSize(skinClassDocRef) > 0) {
79  1 return createReference(skinDocRef);
80    }
81   
82    } catch (XWikiException e) {
83  1 throw new LESSCompilerException(String.format("Unable to read document [%s]", skinDocRef), e);
84    }
85    }
86   
87  2164 return new FSSkinReference(skinName);
88    }
89   
 
90  1 toggle @Override
91    public SkinReference createReference(DocumentReference documentReference)
92    {
93  1 return new DocumentSkinReference(documentReference, entityReferenceSerializer);
94    }
95    }