Search in sources :

Example 56 with DocumentReference

use of org.xwiki.model.reference.DocumentReference 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 57 with DocumentReference

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

the class DefaultNotificationPreferenceManagerTest method getNotificationPreferences.

@Test
public void getNotificationPreferences() throws Exception {
    DocumentReference user = new DocumentReference("xwiki", "test", "user");
    mockPreferenceProviders(user);
    List<NotificationPreference> preferences = mocker.getComponentUnderTest().getAllPreferences(user);
    assertEquals(4, preferences.size());
    assertTrue(preferences.contains(mockPreference11));
    assertTrue(preferences.contains(mockPreference12));
    assertTrue(preferences.contains(mockPreference21));
    assertTrue(preferences.contains(mockPreference22));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 58 with DocumentReference

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

the class ImageFilter method filter.

@Override
public void filter(Document htmlDocument, Map<String, String> cleaningParams) {
    String targetDocumentName = cleaningParams.get("targetDocument");
    DocumentReference targetDocumentReference = targetDocumentName == null ? null : this.stringDocumentReferenceResolver.resolve(targetDocumentName);
    boolean attachEmbeddedImages = Boolean.valueOf(cleaningParams.get("attachEmbeddedImages"));
    if (attachEmbeddedImages) {
        htmlDocument.setUserData(EMBEDDED_IMAGES, new HashMap<String, byte[]>(), null);
    }
    List<Element> images = filterDescendants(htmlDocument.getDocumentElement(), new String[] { TAG_IMG });
    for (Element image : images) {
        Attr source = image.getAttributeNode(ATTRIBUTE_SRC);
        if (source != null && targetDocumentReference != null) {
            filterImageSource(source, targetDocumentReference);
        }
        // The 'align' attribute of images creates a lot of problems. First,the office server has a problem with
        // center aligning images (it aligns them to left). Next, the office server uses <br clear"xxx"> for
        // avoiding content wrapping around images which is not valid XHTML. There for, to be consistent and simple
        // we will remove the 'align' attribute of all the images so that they are all left aligned.
        image.removeAttribute(ATTRIBUTE_ALIGN);
    }
}
Also used : Element(org.w3c.dom.Element) DocumentReference(org.xwiki.model.reference.DocumentReference) Attr(org.w3c.dom.Attr)

Example 59 with DocumentReference

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

the class WikiSkinUtils method getSkinDocument.

public XWikiDocument getSkinDocument(String skin) {
    XWikiContext xcontext = this.xcontextProvider.get();
    if (xcontext != null) {
        DocumentReference skinReference = this.currentMixedDocumentReferenceResolver.resolve(skin);
        XWiki xwiki = xcontext.getWiki();
        if (xwiki != null && xwiki.getStore() != null) {
            XWikiDocument doc;
            try {
                doc = xwiki.getDocument(skinReference, xcontext);
            } catch (XWikiException e) {
                this.logger.error("Faied to get document [{}]", skinReference, e);
                return null;
            }
            if (!doc.isNew()) {
                return doc;
            }
        }
    }
    return null;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 60 with DocumentReference

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

the class ExplicitlyAllowedValuesDBListQueryBuilder method build.

@Override
public Query build(DBListClass dbListClass) throws QueryException {
    String statement = dbListClass.getSql();
    DocumentReference authorReference = dbListClass.getOwnerDocument().getAuthorReference();
    if (this.authorizationManager.hasAccess(Right.SCRIPT, authorReference, dbListClass.getReference())) {
        String namespace = this.entityReferenceSerializer.serialize(dbListClass.getDocumentReference());
        try {
            statement = this.authorExecutor.call(() -> {
                return evaluateVelocityCode(dbListClass.getSql(), namespace);
            }, authorReference);
        } catch (Exception e) {
            this.logger.warn("Failed to evaluate the Velocity code from the query [{}]." + " Root cause is [{}]. Continuing with the raw query.", statement, ExceptionUtils.getRootCauseMessage(e));
        }
    }
    Query query = this.secureQueryManager.createQuery(statement, Query.HQL);
    query.setWiki(dbListClass.getOwnerDocument().getDocumentReference().getWikiReference().getName());
    return query;
}
Also used : Query(org.xwiki.query.Query) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryException(org.xwiki.query.QueryException)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42