Search in sources :

Example 6 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultNotificationEmailUserPreferenceManager method getDiffType.

private NotificationEmailDiffType getDiffType(DocumentReference user) {
    try {
        // Get the config of the user
        DocumentReference emailClassReference = new DocumentReference(EMAIL_PREFERENCES_CLASS, user.getWikiReference());
        Object diffType = documentAccessBridge.getProperty(user, emailClassReference, DIFF_TYPE);
        if (diffType != null && StringUtils.isNotBlank((String) diffType)) {
            return NotificationEmailDiffType.valueOf((String) diffType);
        }
        // Get the config of the wiki
        DocumentReference xwikiPref = new DocumentReference(GLOBAL_PREFERENCES, user.getWikiReference());
        diffType = documentAccessBridge.getProperty(xwikiPref, emailClassReference, DIFF_TYPE);
        if (diffType != null && StringUtils.isNotBlank((String) diffType)) {
            return NotificationEmailDiffType.valueOf((String) diffType);
        }
        // Get the config of the main wiki
        WikiReference mainWiki = new WikiReference(wikiDescriptorManager.getMainWikiId());
        if (!user.getWikiReference().equals(mainWiki)) {
            xwikiPref = new DocumentReference(GLOBAL_PREFERENCES, mainWiki);
            emailClassReference = new DocumentReference(EMAIL_PREFERENCES_CLASS, mainWiki);
            diffType = documentAccessBridge.getProperty(xwikiPref, emailClassReference, DIFF_TYPE);
            if (diffType != null && StringUtils.isNotBlank((String) diffType)) {
                return NotificationEmailDiffType.valueOf((String) diffType);
            }
        }
    } catch (Exception e) {
        logger.warn("Failed to get the email diff type for the user [{}].", user, e);
    }
    // Fallback to the default value
    return NotificationEmailDiffType.STANDARD;
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 7 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class ExportAction method exportXAR.

private String exportXAR(XWikiContext context) throws XWikiException, IOException, FilterException {
    XWikiRequest request = context.getRequest();
    boolean history = Boolean.valueOf(request.get("history"));
    boolean backup = Boolean.valueOf(request.get("backup"));
    String author = request.get("author");
    String description = request.get("description");
    String licence = request.get("licence");
    String version = request.get("version");
    String name = request.get("name");
    String[] pages = request.getParameterValues("pages");
    boolean all = ArrayUtils.isEmpty(pages);
    if (!context.getWiki().getRightService().hasWikiAdminRights(context)) {
        context.put("message", "needadminrights");
        return "exception";
    }
    if (StringUtils.isEmpty(name)) {
        if (all) {
            name = "backup";
        } else {
            name = "export";
        }
    }
    if (context.getWiki().ParamAsLong("xwiki.action.export.xar.usefilter", 1) == 1) {
        // Create input wiki stream
        DocumentInstanceInputProperties inputProperties = new DocumentInstanceInputProperties();
        // We don't want to log the details
        inputProperties.setVerbose(false);
        inputProperties.setWithJRCSRevisions(history);
        inputProperties.setWithRevisions(false);
        EntityReferenceSet entities = new EntityReferenceSet();
        if (all) {
            entities.includes(new WikiReference(context.getWikiId()));
        } else {
            // Find all page references and add them for processing
            Collection<DocumentReference> pageList = resolvePagesToExport(pages, context);
            for (DocumentReference page : pageList) {
                entities.includes(page);
            }
        }
        inputProperties.setEntities(entities);
        InputFilterStreamFactory inputFilterStreamFactory = Utils.getComponent(InputFilterStreamFactory.class, FilterStreamType.XWIKI_INSTANCE.serialize());
        InputFilterStream inputFilterStream = inputFilterStreamFactory.createInputFilterStream(inputProperties);
        // Create output wiki stream
        XAROutputProperties xarProperties = new XAROutputProperties();
        // We don't want to log the details
        xarProperties.setVerbose(false);
        XWikiResponse response = context.getResponse();
        xarProperties.setTarget(new DefaultOutputStreamOutputTarget(response.getOutputStream()));
        xarProperties.setPackageName(name);
        if (description != null) {
            xarProperties.setPackageDescription(description);
        }
        if (licence != null) {
            xarProperties.setPackageLicense(licence);
        }
        if (author != null) {
            xarProperties.setPackageAuthor(author);
        }
        if (version != null) {
            xarProperties.setPackageVersion(version);
        }
        xarProperties.setPackageBackupPack(backup);
        xarProperties.setPreserveVersion(backup || history);
        BeanOutputFilterStreamFactory<XAROutputProperties> xarFilterStreamFactory = Utils.getComponent((Type) OutputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize());
        OutputFilterStream outputFilterStream = xarFilterStreamFactory.createOutputFilterStream(xarProperties);
        // Export
        response.setContentType("application/zip");
        response.addHeader("Content-disposition", "attachment; filename=" + Util.encodeURI(name, context) + ".xar");
        inputFilterStream.read(outputFilterStream.getFilter());
        inputFilterStream.close();
        outputFilterStream.close();
        // Flush
        response.getOutputStream().flush();
        // Indicate that we are done with the response so no need to add anything
        context.setFinished(true);
    } else {
        PackageAPI export = ((PackageAPI) context.getWiki().getPluginApi("package", context));
        if (export == null) {
            // No Packaging plugin configured
            return "exception";
        }
        export.setWithVersions(history);
        if (author != null) {
            export.setAuthorName(author);
        }
        if (description != null) {
            export.setDescription(description);
        }
        if (licence != null) {
            export.setLicence(licence);
        }
        if (version != null) {
            export.setVersion(version);
        }
        export.setBackupPack(backup);
        export.setName(name);
        if (all) {
            export.backupWiki();
        } else {
            if (pages != null) {
                for (String pageName : pages) {
                    String defaultAction = request.get("action_" + pageName);
                    int iAction;
                    try {
                        iAction = Integer.parseInt(defaultAction);
                    } catch (Exception e) {
                        iAction = 0;
                    }
                    export.add(pageName, iAction);
                }
            }
            export.export();
        }
    }
    return null;
}
Also used : PackageAPI(com.xpn.xwiki.plugin.packaging.PackageAPI) OutputFilterStreamFactory(org.xwiki.filter.output.OutputFilterStreamFactory) BeanOutputFilterStreamFactory(org.xwiki.filter.output.BeanOutputFilterStreamFactory) InputFilterStreamFactory(org.xwiki.filter.input.InputFilterStreamFactory) OutputFilterStream(org.xwiki.filter.output.OutputFilterStream) DefaultOutputStreamOutputTarget(org.xwiki.filter.output.DefaultOutputStreamOutputTarget) InputFilterStream(org.xwiki.filter.input.InputFilterStream) XAROutputProperties(org.xwiki.filter.xar.output.XAROutputProperties) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) IOException(java.io.IOException) FilterException(org.xwiki.filter.FilterException) EntityReferenceSet(org.xwiki.model.reference.EntityReferenceSet) DocumentInstanceInputProperties(org.xwiki.filter.instance.input.DocumentInstanceInputProperties) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 8 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class LogoutAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    XWikiResponse response = context.getResponse();
    // Destroy the current session, if any, so that any private data stored in the session won't be accessible by
    // the next user on the same computer
    HttpSession currentSession = request.getSession(false);
    if (currentSession != null) {
        synchronized (currentSession) {
            currentSession.invalidate();
            // Early registration of a new session, so that the client gets to know the new session identifier early
            // A new session is going to be needed after the redirect anyway
            request.getSession(true);
        }
    }
    // Process redirect
    String redirect;
    redirect = context.getRequest().getParameter("xredirect");
    if (StringUtils.isEmpty(redirect)) {
        DocumentReferenceResolver<EntityReference> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE);
        // Get default document
        DocumentReference reference = resolver.resolve(null, EntityType.DOCUMENT);
        // Set wiki reference to current wiki
        reference = reference.setWikiReference(new WikiReference(context.getWikiId()));
        // Create URL to the wiki home page
        redirect = context.getWiki().getURL(reference, "view", context);
    }
    sendRedirect(response, redirect);
    return false;
}
Also used : HttpSession(javax.servlet.http.HttpSession) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 9 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class MoveJobTest method moveMissingDocument.

@Test
public void moveMissingDocument() throws Throwable {
    DocumentReference sourceReference = new DocumentReference("foo", "A", "Page");
    run(createRequest(sourceReference, new SpaceReference("B", new WikiReference("bar"))));
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", sourceReference);
    verifyNoMove();
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class MoveJobTest method moveToUnsupportedDestination.

@Test
public void moveToUnsupportedDestination() throws Throwable {
    run(createRequest(new DocumentReference("wiki", "Space", "Page"), new WikiReference("test")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.", EntityType.WIKI);
    run(createRequest(new DocumentReference("wiki", "Space", "Page"), new DocumentReference("test", "A", "B")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a document.", EntityType.DOCUMENT);
    run(createRequest(new SpaceReference("Space", new WikiReference("wiki")), new DocumentReference("test", "A", "B")));
    verify(this.mocker.getMockedLogger()).error("Unsupported destination entity type [{}] for a space.", EntityType.DOCUMENT);
    verifyNoMove();
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8