Search in sources :

Example 96 with XWikiContext

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentVersionReference(org.xwiki.extension.xar.job.diff.DocumentVersionReference) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 97 with XWikiContext

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;
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest) XWikiContext(com.xpn.xwiki.XWikiContext) ExtensionId(org.xwiki.extension.ExtensionId)

Example 98 with XWikiContext

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());
}
Also used : XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) XWikiContext(com.xpn.xwiki.XWikiContext) URL(java.net.URL) Test(org.junit.Test)

Example 99 with XWikiContext

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);
        }
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki)

Example 100 with XWikiContext

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);
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)564 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)203 XWikiException (com.xpn.xwiki.XWikiException)195 DocumentReference (org.xwiki.model.reference.DocumentReference)150 XWiki (com.xpn.xwiki.XWiki)106 BaseObject (com.xpn.xwiki.objects.BaseObject)104 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)55 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)43 ExecutionContext (org.xwiki.context.ExecutionContext)43 Session (org.hibernate.Session)37 InitializationException (org.xwiki.component.phase.InitializationException)36 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)34 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)33 WikiReference (org.xwiki.model.reference.WikiReference)31 Before (org.junit.Before)29 EntityReference (org.xwiki.model.reference.EntityReference)28 QueryException (org.xwiki.query.QueryException)28 Execution (org.xwiki.context.Execution)27 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)24