use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DiffXarJob method diff.
private void diff(XWikiDocument document, ExtensionId extensionId) {
if (getRequest().isVerbose()) {
this.logger.info("Computing differences for document [{}]", document.getDocumentReferenceWithLocale());
}
// Use the extension id as the document version.
XWikiDocument previousDocument = document.duplicate(new DocumentVersionReference(document.getDocumentReference(), extensionId));
XWikiContext xcontext = this.xcontextProvider.get();
try {
XWikiDocument nextDocument = xcontext.getWiki().getDocument(document.getDocumentReferenceWithLocale(), xcontext);
if (nextDocument.isNew()) {
nextDocument = null;
}
maybeAddDocumentDiff(this.documentDiffBuilder.diff(previousDocument, nextDocument));
} catch (XWikiException e) {
this.logger.error("Failed to get document [{}] from the database.", document.getDocumentReference(), e);
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createInstallPlanRequest.
/**
* Create an {@link InstallRequest} instance based on given parameters, to be used to create the install plan.
*
* @param id the identifier of the extension to install
* @param version the version to install
* @param namespace the (optional) namespace where to install the extension; if {@code null} or empty, the extension
* will be installed in root namespace (globally)
* @return the {@link InstallRequest}
*/
public InstallRequest createInstallPlanRequest(String id, String version, String namespace) {
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, id, namespace));
installRequest.setInteractive(true);
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
XWikiContext xcontext = this.xcontextProvider.get();
// Indicate if it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(namespace == null || xcontext.isMainWiki(toWikiId(namespace)));
// Allow overwritting a few things in extensions descriptors
installRequest.setRewriter(new ScriptExtensionRewriter());
contextualize(installRequest);
setRightsProperties(installRequest);
return installRequest;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class XWikiContextCacheKeyFactoryTest method getCacheKey.
@Test
public void getCacheKey() throws Exception {
// Mocks
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
when(xcontext.getURLFactory()).thenReturn(urlFactory);
when(urlFactory.createSkinURL(any(), any(), any(XWikiContext.class))).thenReturn(new URL("http://host/path"));
// Test
assertEquals("XWikiContext[URLFactory[" + urlFactory.getClass().getName() + ", /path]]", mocker.getComponentUnderTest().getCacheKey());
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class CachedLESSCompiler method executeVelocity.
private String executeVelocity(String source, String skin) {
// Get the XWiki object
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
String currentSkin = xwiki.getSkin(xcontext);
try {
// was the current skin
if (!currentSkin.equals(skin)) {
xcontext.put(SKIN_CONTEXT_KEY, skin);
}
return xwiki.evaluateVelocity(source, xcontext.getDoc().getPrefixedFullName());
} finally {
// Reset the current skin to the old value
if (!currentSkin.equals(skin)) {
xcontext.put(SKIN_CONTEXT_KEY, currentSkin);
}
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class AbstractCachedCompiler method getResult.
/**
* Get the result of the compilation.
* @param lessResourceReference reference to the LESS content
* @param includeSkinStyle include the main LESS file of the skin in order to have variables and mix-ins
* defined there
* @param useVelocity either or not the resource be parsed by Velocity before compiling it
* @param force force the computation, even if the output is already in the cache (not recommended)
* @return the desired object
* @throws LESSCompilerException if problems occur
*/
public T getResult(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean force) throws LESSCompilerException {
XWikiContext context = xcontextProvider.get();
String skin = context.getWiki().getSkin(context);
return getResult(lessResourceReference, includeSkinStyle, useVelocity, skin, force);
}
Aggregations