Search in sources :

Example 36 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class ActionExecutionEventConverter method fromRemote.

@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
    if (remoteEvent.getEvent() instanceof ActionExecutedEvent || remoteEvent.getEvent() instanceof ActionExecutingEvent) {
        // fill the local event
        XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
        try {
            if (xcontext != null) {
                localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
                localEvent.setData(xcontext);
                localEvent.setEvent((Event) remoteEvent.getEvent());
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
        }
        return true;
    }
    return false;
}
Also used : ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) XWikiException(com.xpn.xwiki.XWikiException)

Example 37 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class DocumentEventConverter method fromRemote.

@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
    if (EVENTS.contains(remoteEvent.getEvent().getClass())) {
        // fill the local event
        XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
        try {
            if (xcontext != null) {
                localEvent.setData(xcontext);
                localEvent.setEvent((Event) remoteEvent.getEvent());
                if (remoteEvent.getEvent() instanceof DocumentDeletedEvent) {
                    localEvent.setSource(unserializeDeletdDocument(remoteEvent.getSource(), xcontext));
                } else {
                    localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
                }
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
        }
        return true;
    }
    return false;
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 38 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class WikiEventConverter method fromRemote.

@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
    if (this.events.contains(remoteEvent.getEvent().getClass())) {
        // fill the local event
        XWikiContext context = unserializeXWikiContext(remoteEvent.getData());
        if (context != null) {
            localEvent.setEvent((Event) remoteEvent.getEvent());
            localEvent.setSource(remoteEvent.getSource());
            localEvent.setData(unserializeXWikiContext(remoteEvent.getData()));
        }
        return true;
    }
    return false;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext)

Example 39 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class FOPXSLFORenderer method extendConfiguration.

private void extendConfiguration(DefaultConfiguration writableConfiguration) {
    // Add XWiki fonts folder to the configuration.
    try {
        String fontsPath = this.environment.getResource(FONTS_PATH).getPath();
        XWikiContext xcontext = this.xcontextProvider.get();
        if (xcontext != null) {
            XWikiRequest request = xcontext.getRequest();
            if (request != null && request.getSession() != null) {
                fontsPath = request.getSession().getServletContext().getRealPath(FONTS_PATH);
            }
        }
        // <renderers>
        DefaultConfiguration renderersConfiguration = (DefaultConfiguration) writableConfiguration.getChild(RENDERERS, false);
        if (renderersConfiguration == null) {
            renderersConfiguration = new DefaultConfiguration(RENDERERS);
            writableConfiguration.addChild(renderersConfiguration);
        }
        // Ensure we have support for PDF rendering.
        // <renderer mime="application/pdf">
        DefaultConfiguration pdfRenderer = null;
        for (Configuration renderer : renderersConfiguration.getChildren()) {
            if (MIME_TYPE_PDF.equals(renderer.getAttribute(MIME))) {
                pdfRenderer = (DefaultConfiguration) renderer;
            }
        }
        if (pdfRenderer == null) {
            pdfRenderer = new DefaultConfiguration("renderer");
            pdfRenderer.setAttribute(MIME, MIME_TYPE_PDF);
            renderersConfiguration.addChild(pdfRenderer);
        }
        // <fonts>
        DefaultConfiguration fontsConfiguration = (DefaultConfiguration) pdfRenderer.getChild(FONTS, false);
        if (fontsConfiguration == null) {
            fontsConfiguration = new DefaultConfiguration(FONTS);
            pdfRenderer.addChild(fontsConfiguration);
        }
        // <directory>fontdirectory</directory>
        DefaultConfiguration directoryConfiguration = new DefaultConfiguration("directory");
        directoryConfiguration.setValue(fontsPath);
        fontsConfiguration.addChild(directoryConfiguration);
    } catch (Exception e) {
        this.logger.warn("Starting with 1.5, XWiki uses the WEB-INF/fonts/ directory as the font directory, " + "and it should contain the FreeFont (http://savannah.gnu.org/projects/freefont/) fonts. " + "FOP cannot access this directory. If this is an upgrade from a previous version, " + "make sure you also copy the WEB-INF/fonts directory from the new distribution package.");
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) Configuration(org.apache.avalon.framework.configuration.Configuration) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) ConfigurationException(org.apache.avalon.framework.configuration.ConfigurationException)

Example 40 with XWikiContext

use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.

the class DefaultAuthorExecutor method after.

@Override
public void after(AutoCloseable context) {
    XWikiContext xwikiContext = this.xcontextProvider.get();
    if (xwikiContext != null) {
        DefaultAuthorExecutorContext internalContext = (DefaultAuthorExecutorContext) context;
        // Restore context document's content author
        xwikiContext.put(XWikiDocument.CKEY_SDOC, internalContext.currentSecureDocument);
        // Restore XWikiContext#dropPermission hack
        if (internalContext.xwikiContextDropPermissionHack != null) {
            xwikiContext.put(XWikiConstant.DROPPED_PERMISSIONS, internalContext.xwikiContextDropPermissionHack);
        }
        // Restore Document#dropPermission hack
        if (internalContext.documentDropPermissionHack != null) {
            ExecutionContext econtext = this.execution.getContext();
            econtext.setProperty(XWikiConstant.DROPPED_PERMISSIONS, internalContext.documentDropPermissionHack);
        }
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) 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