Search in sources :

Example 16 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class DefaultColorThemeReferenceFactory method createReference.

@Override
public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException {
    // Get the XWiki Object
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    String currentWikiId = wikiDescriptorManager.getCurrentWikiId();
    DocumentReference colorThemeDocRef = documentReferenceResolver.resolve(colorThemeName, new WikiReference(currentWikiId));
    if (xwiki.exists(colorThemeDocRef, xcontext)) {
        try {
            XWikiDocument colorThemeDoc = xwiki.getDocument(colorThemeDocRef, xcontext);
            // Is there any color theme?
            DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass");
            if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) {
                return createReference(colorThemeDocRef);
            }
            // Is there any flamingo theme?
            DocumentReference flamingoThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "FlamingoThemesCode", "ThemeClass");
            if (colorThemeDoc.getXObjectSize(flamingoThemeClassRef) > 0) {
                return createReference(colorThemeDocRef);
            }
        } catch (XWikiException e) {
            throw new LESSCompilerException(String.format("Unable to read document [%s]", colorThemeDocRef));
        }
    }
    // Not an XWiki page so probably a file system color theme
    return new NamedColorThemeReference(colorThemeName);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) WikiReference(org.xwiki.model.reference.WikiReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

LESSCompilerException (org.xwiki.lesscss.compiler.LESSCompilerException)16 Test (org.junit.Test)9 LESSResourceReference (org.xwiki.lesscss.resources.LESSResourceReference)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 XWikiException (com.xpn.xwiki.XWikiException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Less4jException (com.github.sommeri.less4j.Less4jException)2 XWiki (com.xpn.xwiki.XWiki)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 StringWriter (java.io.StringWriter)2 ColorTheme (org.xwiki.lesscss.internal.colortheme.ColorTheme)2 ColorThemeReference (org.xwiki.lesscss.internal.colortheme.ColorThemeReference)2 SkinReference (org.xwiki.lesscss.internal.skin.SkinReference)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 VelocityContext (org.apache.velocity.VelocityContext)1 LESSCompiler (org.xwiki.lesscss.compiler.LESSCompiler)1 DefaultLESSCompiler (org.xwiki.lesscss.internal.compiler.DefaultLESSCompiler)1 LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)1 LESSResourceReferenceFactory (org.xwiki.lesscss.resources.LESSResourceReferenceFactory)1