use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class GroupsClassPropertyValuesProvider method getIcon.
@Override
protected String getIcon(DocumentReference groupReference) {
XWikiContext xcontext = this.xcontextProvider.get();
try {
XWikiDocument groupProfileDocument = xcontext.getWiki().getDocument(groupReference, xcontext);
XWikiAttachment avatarAttachment = getFirstImageAttachment(groupProfileDocument, xcontext);
if (avatarAttachment != null) {
return xcontext.getWiki().getURL(avatarAttachment.getReference(), "download", "width=30&height=30&keepAspectRatio=true", null, xcontext);
}
} catch (XWikiException e) {
this.logger.warn("Failed to read the avatar of group [{}]. Root cause is [{}]. Using the default avatar instead.", groupReference.getName(), ExceptionUtils.getRootCauseMessage(e));
}
return xcontext.getWiki().getSkinFile("icons/xwiki/noavatargroup.png", true, xcontext);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class UsersClassPropertyValuesProvider method getIcon.
@Override
protected String getIcon(DocumentReference userReference) {
XWikiContext xcontext = this.xcontextProvider.get();
try {
XWikiDocument userProfileDocument = xcontext.getWiki().getDocument(userReference, xcontext);
String avatar = userProfileDocument.getStringValue("avatar");
XWikiAttachment avatarAttachment = userProfileDocument.getAttachment(avatar);
if (avatarAttachment != null && avatarAttachment.isImage(xcontext)) {
return xcontext.getWiki().getURL(avatarAttachment.getReference(), "download", "width=30&height=30&keepAspectRatio=true", null, xcontext);
}
} catch (XWikiException e) {
this.logger.warn("Failed to read the avatar of user [{}]. Root cause is [{}]. Using the default avatar instead.", userReference.getName(), ExceptionUtils.getRootCauseMessage(e));
}
return xcontext.getWiki().getSkinFile("icons/xwiki/noavatar.png", true, xcontext);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class ZipExplorerTest method testDownloadAttachmentWhenURLIsNotZipFile.
public void testDownloadAttachmentWhenURLIsNotZipFile() throws Exception {
Mock mockDocument = mock(XWikiDocument.class);
mockDocument.stubs().method("getDocumentReference").will(returnValue(new DocumentReference("wiki", "Main", "Document")));
XWikiAttachment originalAttachment = createAttachment("somefile.whatever", null, (XWikiDocument) mockDocument.proxy());
XWikiContext context = createXWikiContext("http://server/xwiki/bin/download/Main/Document/somefile.whatever");
XWikiAttachment newAttachment = this.plugin.downloadAttachment(originalAttachment, context);
Assert.assertSame(originalAttachment, newAttachment);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class ZipExplorerTest method testDownloadAttachmentWhenURLIsZipButNotPointingInsideZip.
public void testDownloadAttachmentWhenURLIsZipButNotPointingInsideZip() throws Exception {
Mock mockDocument = mock(XWikiDocument.class);
mockDocument.stubs().method("getDocumentReference").will(returnValue(new DocumentReference("wiki", "Main", "Document")));
XWikiAttachment originalAttachment = createAttachment("zipfile.zip", null, (XWikiDocument) mockDocument.proxy());
XWikiContext context = createXWikiContext("http://server/xwiki/bin/download/Main/Document/zipfile.zip");
XWikiAttachment newAttachment = this.plugin.downloadAttachment(originalAttachment, context);
Assert.assertSame(originalAttachment, newAttachment);
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class ZipExplorerTest method testDownloadAttachmentWithInvalidZipURL.
public void testDownloadAttachmentWithInvalidZipURL() throws Exception {
Mock mockDocument = mock(XWikiDocument.class);
mockDocument.stubs().method("getDocumentReference").will(returnValue(new DocumentReference("wiki", "Main", "Document")));
XWikiAttachment originalAttachment = createAttachment("someFile.txt", "Some text".getBytes(), (XWikiDocument) mockDocument.proxy());
XWikiContext context = createXWikiContext("http://server/xwiki/bin/download/Main/Document/someFile.txt");
XWikiAttachment newAttachment = this.plugin.downloadAttachment(originalAttachment, context);
Assert.assertSame(originalAttachment, newAttachment);
}
Aggregations