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

File DefaultColorThemeReferenceFactory.java

 

Coverage histogram

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

Code metrics

6
16
2
1
107
62
6
0.38
8
2
3

Classes

Class Line # Actions
DefaultColorThemeReferenceFactory 47 16 0% 6 1
0.958333395.8%
 

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.colortheme;
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.colortheme.ColorThemeReferenceFactory}.
41    *
42    * @since 6.4M2
43    * @version $Id: f1ade398aa3413492e4717286379420554aca073 $
44    */
45    @Component
46    @Singleton
 
47    public class DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory
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 ColorThemeReference createReference(String colorThemeName) 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 colorThemeDocRef =
71    documentReferenceResolver.resolve(colorThemeName, new WikiReference(currentWikiId));
72   
73  2166 if (xwiki.exists(colorThemeDocRef, xcontext)) {
74  238 try {
75  238 XWikiDocument colorThemeDoc = xwiki.getDocument(colorThemeDocRef, xcontext);
76   
77    // Is there any color theme?
78  238 DocumentReference colorThemeClassRef =
79    new DocumentReference(colorThemeDocRef.getWikiReference().getName(),
80    "ColorThemes", "ColorThemeClass");
81  238 if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) {
82  1 return createReference(colorThemeDocRef);
83    }
84   
85    // Is there any flamingo theme?
86  237 DocumentReference flamingoThemeClassRef =
87    new DocumentReference(colorThemeDocRef.getWikiReference().getName(),
88    "FlamingoThemesCode", "ThemeClass");
89  237 if (colorThemeDoc.getXObjectSize(flamingoThemeClassRef) > 0) {
90  25 return createReference(colorThemeDocRef);
91    }
92   
93    } catch (XWikiException e) {
94  0 throw new LESSCompilerException(String.format("Unable to read document [%s]", colorThemeDocRef));
95    }
96    }
97   
98    // Not an XWiki page so probably a file system color theme
99  2140 return new NamedColorThemeReference(colorThemeName);
100    }
101   
 
102  32 toggle @Override
103    public ColorThemeReference createReference(DocumentReference documentReference)
104    {
105  32 return new DocumentColorThemeReference(documentReference, entityReferenceSerializer);
106    }
107    }