use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.
the class LessCompilerScriptService method clearCacheFromSkin.
/**
* Remove every generated files corresponding to a filesystem skin.
* The script calling this method needs the programming rights.
* @param skin name of the filesystem skin
* @return true if the operation succeed
*
* @since 6.4M2
*/
public boolean clearCacheFromSkin(String skin) {
XWikiContext xcontext = xcontextProvider.get();
// Check if the current script has the programing rights
if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc().getDocumentReference())) {
return false;
}
try {
SkinReference skinReference = skinReferenceFactory.createReference(skin);
lessCache.clearFromSkin(skinReference);
colorThemeCache.clearFromSkin(skinReference);
return true;
} catch (LESSCompilerException e) {
return false;
}
}
use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.
the class LESSSkinFileResourceReferenceTest method getContentWhenFileDoesNotExist.
@Test
public void getContentWhenFileDoesNotExist() throws Exception {
LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("not-existing-file.less", templateManager, skinManager);
// Test
LESSCompilerException caughtException = null;
try {
lessSkinFileResourceReference.getContent("skin");
} catch (LESSCompilerException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("The template [not-existing-file.less] does not exists.", caughtException.getMessage());
}
use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.
the class LESSSkinFileResourceReferenceTest method getContentWhenException.
@Test
public void getContentWhenException() throws Exception {
LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("file.less", templateManager, skinManager);
// Mocks
Template template = mock(Template.class);
when(templateManager.getTemplate("less/file.less", skin)).thenReturn(template);
Exception exception = new Exception("exception");
when(template.getContent()).thenThrow(exception);
// Test
LESSCompilerException caughtException = null;
try {
lessSkinFileResourceReference.getContent("skin");
} catch (LESSCompilerException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to get the content of the template [file.less].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.
the class DefaultSkinReferenceFactoryTest method createReferenceWhenSkinOnDBWithException.
@Test
public void createReferenceWhenSkinOnDBWithException() throws Exception {
// Mocks
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
DocumentReference skinDocRef = new DocumentReference("wikiId", "XWiki", "MySkin");
when(documentReferenceResolver.resolve(eq("XWiki.MySkin"), eq(new WikiReference("wikiId")))).thenReturn(skinDocRef);
when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true);
Exception exception = new XWikiException();
when(xwiki.getDocument(skinDocRef, xcontext)).thenThrow(exception);
// Test
LESSCompilerException caughtException = null;
try {
mocker.getComponentUnderTest().createReference("XWiki.MySkin");
} catch (LESSCompilerException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals(exception, caughtException.getCause());
assertEquals("Unable to read document [wikiId:XWiki.MySkin]", caughtException.getMessage());
}
use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.
the class LessCompilerScriptService method clearCacheFromColorTheme.
/**
* Remove every generated files corresponding to a color theme.
* The script calling this method needs the programming rights.
* @param colorTheme fullname of the color theme
* @return true if the operation succeed
*/
public boolean clearCacheFromColorTheme(String colorTheme) {
XWikiContext xcontext = xcontextProvider.get();
// Check if the current script has the programing rights
if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc().getDocumentReference())) {
return false;
}
try {
ColorThemeReference colorThemeReference = colorThemeReferenceFactory.createReference(colorTheme);
lessCache.clearFromColorTheme(colorThemeReference);
colorThemeCache.clearFromColorTheme(colorThemeReference);
return true;
} catch (LESSCompilerException e) {
return false;
}
}
Aggregations