use of com.xpn.xwiki.api.Attachment in project xwiki-platform by xwiki.
the class MailTemplateImageAttachmentsExtractor method getImages.
/**
* @param documentReference the reference of the document
* @return all images contained in the attachments of the given document
* @throws Exception if an error occurs
*/
public Collection<Attachment> getImages(DocumentReference documentReference) throws Exception {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
Document document = new Document(xwiki.getDocument(documentReference, context), context);
return document.getAttachmentList().stream().filter(att -> att.isImage()).collect(Collectors.toList());
}
use of com.xpn.xwiki.api.Attachment in project xwiki-platform by xwiki.
the class WatchListEventMimeMessageIterator method updateFactoryParameters.
/**
* Update the factory's parameters with the values specific to the message we are going to send right now.
*
* @param watchListMessageData the messageData to use for the new message
* @param factoryParameters the factory parameters we wish to update
*/
private void updateFactoryParameters(Map<String, Object> factoryParameters, WatchListMessageData watchListMessageData) {
Map<String, Object> velocityVariables = (Map<String, Object>) factoryParameters.get("velocityVariables");
// Set the list of events, containing 1 event per document.
List<WatchListEvent> events = watchListMessageData.getEvents();
velocityVariables.put("events", events);
// Compute the list of modified documents.
List<String> modifiedDocuments = new ArrayList<>();
for (WatchListEvent event : events) {
if (!modifiedDocuments.contains(event.getPrefixedFullName())) {
modifiedDocuments.add(event.getPrefixedFullName());
}
}
velocityVariables.put("modifiedDocuments", modifiedDocuments);
velocityVariables.put(XWIKI_USER_CLASS_FIRST_NAME_PROP, watchListMessageData.getFirstName());
velocityVariables.put(XWIKI_USER_CLASS_LAST_NAME_PROP, watchListMessageData.getLastName());
velocityVariables.put(SUBSCRIBER_REFERENCE, watchListMessageData.getUserReference());
// Attach the avatars of the authors of the events we are notifying about.
if (parameters.get(WatchListEventMimeMessageFactory.ATTACH_AUTHOR_AVATARS_PARAMETER) == Boolean.TRUE) {
List<Attachment> templateExtraAttachments = getTemplateExtraAttachments(factoryParameters, events);
factoryParameters.put(TEMPLATE_FACTORY_ATTACHMENTS_PARAMETER, templateExtraAttachments);
}
}
use of com.xpn.xwiki.api.Attachment in project xwiki-platform by xwiki.
the class WatchListEventMimeMessageIterator method getTemplateExtraAttachments.
private List<Attachment> getTemplateExtraAttachments(Map<String, Object> factoryParameters, List<WatchListEvent> events) {
// Append to any existing list of extra attachments specified by the caller.
List<Attachment> templateExtraAttachments = new ArrayList<>();
if (originalTemplateExtraParameters != null) {
templateExtraAttachments.addAll(originalTemplateExtraParameters);
}
Set<DocumentReference> processedAuthors = new HashSet<DocumentReference>();
for (WatchListEvent event : events) {
for (DocumentReference authorReference : event.getAuthorReferences()) {
// instead since that would also work across messages and would be much more useful.
if (!processedAuthors.contains(authorReference)) {
Attachment avatarAttachment = avatarExtractor.getUserAvatar(authorReference);
if (avatarAttachment != null) {
templateExtraAttachments.add(avatarAttachment);
}
processedAuthors.add(authorReference);
}
}
}
return templateExtraAttachments;
}
use of com.xpn.xwiki.api.Attachment in project xwiki-platform by xwiki.
the class ZipExplorerPlugin method getFileList.
/**
* @param document the document containing the ZIP file as an attachment
* @param attachmentName the name under which the ZIP file is attached in the document
* @param context not used
* @return the list of file entries in the ZIP file attached under the passed attachment name inside the passed
* document
* @see com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPluginAPI#getFileList
*/
public List<String> getFileList(Document document, String attachmentName, XWikiContext context) {
List<String> zipList = new ArrayList<String>();
Attachment attachment = document.getAttachment(attachmentName);
InputStream stream = null;
try {
stream = new ByteArrayInputStream(attachment.getContent());
if (isZipFile(stream)) {
ZipInputStream zis = new ZipInputStream(stream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
zipList.add(entry.getName());
}
}
} catch (XWikiException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return zipList;
}
use of com.xpn.xwiki.api.Attachment in project celements-blog by celements.
the class NewsletterAttachmentService method addAttachment.
@Override
public void addAttachment(String attFullname) {
Attachment att = getAttachmentForFullname(attFullname);
extendAttachmentList(att, DEFAULT_NL_ATTACHMENT_LIST);
extendAttachmentList(att, DEFAULT_NL_NO_IMG_ATT_LIST);
}
Aggregations