use of org.openntf.domino.EmbeddedObject in project org.openntf.domino by OpenNTF.
the class RichTextItem method replaceAttachment.
@Override
public EmbeddedObject replaceAttachment(final String filename, final String sourcePath) {
// System.out.println("TEMP DEBUG replacing filename " + filename + " from source at " + sourcePath);
EmbeddedObject result = null;
RichTextNavigator navigator = this.createNavigator();
EmbeddedObject eo = (EmbeddedObject) navigator.getFirstElement(RTELEM_TYPE_FILEATTACHMENT);
boolean replaced = false;
while (eo != null) {
if (filename.equals(eo.getSource())) {
// System.out.println("TEMP DEBUG Found matching embeddedobject for name " + filename);
beginInsert(eo, true);
// $NON-NLS-1$ //$NON-NLS-2$
result = embedObject(org.openntf.domino.EmbeddedObject.Type.EMBED_ATTACHMENT.getValue(), "", sourcePath, "");
endInsert();
eo.remove();
replaced = true;
break;
}
eo = (EmbeddedObject) navigator.getNextElement(RTELEM_TYPE_FILEATTACHMENT);
}
if (!replaced) {
// $NON-NLS-1$ //$NON-NLS-2$
result = embedObject(org.openntf.domino.EmbeddedObject.Type.EMBED_ATTACHMENT.getValue(), "", sourcePath, "");
}
return result;
}
use of org.openntf.domino.EmbeddedObject in project org.openntf.domino by OpenNTF.
the class RichTextItem method removeAttachment.
@Override
public boolean removeAttachment(final String filename) {
boolean result = false;
RichTextNavigator navigator = this.createNavigator();
EmbeddedObject eo = (EmbeddedObject) navigator.getFirstElement(RTELEM_TYPE_FILEATTACHMENT);
while (eo != null) {
if (filename.equals(eo.getSource())) {
eo.remove();
result = true;
break;
}
eo = (EmbeddedObject) navigator.getNextElement(RTELEM_TYPE_FILEATTACHMENT);
}
return result;
}
use of org.openntf.domino.EmbeddedObject in project org.openntf.domino by OpenNTF.
the class DominoEmail method addAttachments.
/* (non-Javadoc)
* @see org.openntf.domino.email.IEmail#addAttachments(java.util.ArrayList, org.openntf.domino.MIMEEntity)
*/
@Override
public void addAttachments(final MIMEEntity parent) {
try {
Stream streamFile = null;
for (IEmailAttachment attach : getAttachments()) {
InputStream is = null;
EmbeddedObject eo = null;
String fileName = attach.getFileName();
// Get content type
String contentType = URLConnection.guessContentTypeFromName(fileName);
if (null == contentType) {
// $NON-NLS-1$
contentType = "application/octet-stream";
}
// $NON-NLS-1$
int idex = StringUtil.indexOfIgnoreCase(fileName, ".", fileName.length() - 6);
if (idex > -1) {
String extension = fileName.substring(idex);
if (StringUtil.equals("gif", extension)) {
// $NON-NLS-1$
// $NON-NLS-1$
contentType = "image/gif";
} else if (StringUtil.equals("jpg", extension) || StringUtil.equals("jpeg", extension)) {
// $NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-1$
contentType = "image/jpeg";
} else if (StringUtil.equals("png", extension)) {
// $NON-NLS-1$
// $NON-NLS-1$
contentType = "image/png";
}
}
// $NON-NLS-1$ //$NON-NLS-2$
contentType += "; name=\"" + fileName + "\"";
try {
Type attachmentType = attach.getAttachmentType();
if (attachmentType == Type.DOCUMENT) {
// retrieve the document containing the attachment to send from the relevant
Database dbFile = getSession().getDatabase(getSession().getServerName(), attach.getDbPath());
Document docFile = dbFile.getDocumentByUNID(attach.getUnid());
if (null != docFile) {
eo = docFile.getAttachment(attach.getFileName());
is = eo.getInputStream();
}
} else if (attachmentType == Type.FILE) {
Path path = Paths.get(attach.getPath()).resolve(attach.getFileName());
is = Files.newInputStream(path);
} else if (attachmentType == Type.STREAM) {
is = attach.getInputStream();
} else {
is = new ByteArrayInputStream(attach.getBytes());
}
if (null != is) {
MIMEEntity mimeChild = parent.createChildEntity();
// $NON-NLS-1$
MIMEHeader mimeHeader = mimeChild.createHeader("Content-Disposition");
if (attach.isInlineImage()) {
// $NON-NLS-1$ //$NON-NLS-2$
mimeHeader.setHeaderVal("inline; filename=\"" + attach.getFileName() + "\"");
} else {
// $NON-NLS-1$ //$NON-NLS-2$
mimeHeader.setHeaderVal("attachment; filename=\"" + attach.getFileName() + "\"");
}
// $NON-NLS-1$
mimeHeader = mimeChild.createHeader("Content-ID");
// $NON-NLS-1$ //$NON-NLS-2$
mimeHeader.setHeaderVal("<" + attach.getContentId() + ">");
streamFile = getSession().createStream();
streamFile.setContents(is);
mimeChild.setContentFromBytes(streamFile, contentType, MIMEEntity.ENC_IDENTITY_BINARY);
streamFile.close();
}
} catch (Exception e) {
DominoUtils.handleException(e);
} finally {
if (null != is) {
is.close();
}
}
}
} catch (Throwable t) {
DominoUtils.handleException(t);
}
}
Aggregations