use of com.xpn.xwiki.doc.XWikiAttachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testEmbedImagesInContent_inner.
@Test
public void testEmbedImagesInContent_inner() throws Exception {
DocumentReference docRef = new DocumentReference(getContext().getDatabase(), "Test", "Img");
XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
XWikiAttachment att = new XWikiAttachment();
expect(attService.getAttachmentNameEqual(same(doc), eq("file.jpg"))).andReturn(att).anyTimes();
expect(attService.getApiAttachment(same(att))).andReturn(new Attachment(new Document(doc, getContext()), att, getContext()));
expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).once();
String imgTag = "<img class=\"abc\" src=\"/download/Test/Img/file.jpg?bla=123\" />";
String content = "Test text with " + imgTag + " image included";
Set<String> tags = new HashSet<>();
tags.add(imgTag);
replayDefault();
String result = service.embedImagesInContent(content, tags);
verifyDefault();
assertTrue(result, result.contains("src=\"cid:file.jpg\""));
assertFalse(result, result.contains("/download/"));
}
use of com.xpn.xwiki.doc.XWikiAttachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testGetImageURL_notEmbedded.
@Test
public void testGetImageURL_notEmbedded() throws Exception {
String expectedResult = "/download/Test/Img/file.jpg";
XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
XWikiAttachment att = new XWikiAttachment();
expect(attService.getAttachmentNameEqual(same(doc), eq("file.jpg"))).andReturn(att).anyTimes();
expect(doc.getAttachmentURL(eq("file.jpg"), eq("download"), same(getContext()))).andReturn(expectedResult).once();
expect(xwiki.getDocument(eq("Test.Img"), same(getContext()))).andReturn(doc).once();
replayDefault();
assertTrue(service.getImageURL("Test.Img;file.jpg", false).startsWith(expectedResult));
verifyDefault();
}
use of com.xpn.xwiki.doc.XWikiAttachment in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testEmbedImagesInContent.
@Test
public void testEmbedImagesInContent() throws Exception {
DocumentReference docRef = new DocumentReference(getContext().getDatabase(), "Test", "Img");
XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
XWikiAttachment att = new XWikiAttachment();
expect(attService.getAttachmentNameEqual(same(doc), eq("file.jpg"))).andReturn(att).anyTimes();
expect(attService.getApiAttachment(same(att))).andReturn(new Attachment(new Document(doc, getContext()), att, getContext()));
expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).once();
String imgTag = "<img class=\"abc\" src=\"/download/Test/Img/file.jpg?bla=123\" />";
String content = "Test text with " + imgTag + " image included";
replayDefault();
String result = service.embedImagesInContent(content);
verifyDefault();
assertTrue(result, result.contains("src=\"cid:file.jpg\""));
assertFalse(result, result.contains("/download/"));
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class DocumentInstanceOutputFilterStream method setAuthors.
private void setAuthors(XWikiDocument document, XWikiDocument inputDocument) {
// Document author
document.setAuthorReference(inputDocument.getAuthorReference());
document.setContentAuthorReference(inputDocument.getContentAuthorReference());
if (document.isNew()) {
document.setCreatorReference(inputDocument.getCreatorReference());
}
// Attachments author
for (XWikiAttachment currentAttachment : document.getAttachmentList()) {
currentAttachment.setAuthorReference(inputDocument.getAttachment(currentAttachment.getFilename()).getAuthorReference());
}
}
use of com.xpn.xwiki.doc.XWikiAttachment in project xwiki-platform by xwiki.
the class XWikiAttachmentOutputFilterStream method onWikiAttachment.
@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) throws FilterException {
if (this.entity == null) {
this.entity = new XWikiAttachment();
}
this.entity.setFilename(name);
if (content != null) {
try {
this.entity.setContent(content);
} catch (IOException e) {
throw new FilterException("Failed to set attachment content", e);
}
}
// Author
this.entity.setAuthorReference(getUserReference(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, parameters, null));
if (this.properties == null || this.properties.isVersionPreserved()) {
setVersion(parameters);
this.entity.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));
this.entity.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
this.entity.setMimeType(getString(WikiAttachmentFilter.PARAMETER_MIMETYPE, parameters, null));
String revisions = getString(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, parameters, null);
if (revisions != null) {
try {
this.entity.setArchive(revisions);
} catch (XWikiException e) {
throw new FilterException("Failed to set attachment archive", e);
}
}
this.entity.setMetaDataDirty(false);
}
}
Aggregations