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;
}
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));
}
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);
}
}
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;
}
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;
}
Aggregations