@Test public void createReferenceWhenItIsAColorTheme() throws Exception { DocumentReference colorThemeDocRef = new DocumentReference("otherWiki", "ColorThemes", "colorTheme"); when(documentReferenceResolver.resolve(eq("colorTheme"), eq(new WikiReference("wikiId")))).thenReturn( colorThemeDocRef); when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(true); XWikiDocument colorThemeDoc = mock(XWikiDocument.class); when(xwiki.getDocument(colorThemeDocRef, xcontext)).thenReturn(colorThemeDoc); when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "ColorThemes", "ColorThemeClass")))). thenReturn(1); assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"), null), mocker.getComponentUnderTest().createReference("colorTheme")); }
@Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { 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); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } 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)); } } return new NamedColorThemeReference(colorThemeName); }
DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory { @Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { 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); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } 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)); } } return new NamedColorThemeReference(colorThemeName); } }
DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory { @Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { 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); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } 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)); } } return new NamedColorThemeReference(colorThemeName); }  }
DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory { @Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { 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); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } 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)); } } return new NamedColorThemeReference(colorThemeName); }  @Override ColorThemeReference createReference(String colorThemeName); @Override ColorThemeReference createReference(DocumentReference documentReference); }
DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory { @Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { 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); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } 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)); } } return new NamedColorThemeReference(colorThemeName); }  @Override ColorThemeReference createReference(String colorThemeName); @Override ColorThemeReference createReference(DocumentReference documentReference);  }