diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.html
index 025d848bf32..65d0eaffff6 100644
--- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.html
+++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.html
@@ -61,7 +61,7 @@
-
+
@@ -77,7 +77,7 @@
-
+
diff --git a/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/TestIntegrationObjectWrapperFactory.java b/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/TestIntegrationObjectWrapperFactory.java
index 71b49188cea..86b6c4435dc 100644
--- a/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/TestIntegrationObjectWrapperFactory.java
+++ b/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/TestIntegrationObjectWrapperFactory.java
@@ -29,12 +29,12 @@
import java.io.File;
import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
+import java.util.stream.Collectors;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemName;
+import com.evolveum.midpoint.prism.path.UniformItemPath;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
@@ -109,10 +109,38 @@ public class TestIntegrationObjectWrapperFactory extends AbstractInitializedGuiI
private static final String USER_NEWMAN_EMPLOYEE_NUMBER = "N00001";
private static final String USER_NEWMAN_SHIP = "Nova";
- private static final int BASIC_USERS_CONTAINERS = 9;
- private static final int BASIC_SHADOW_CONTAINERS = 10;
- private static final int BASIC_ORG_CONTAINERS = 15;
-
+ private static final List BASIC_USER_CONTAINERS_PATHS = Arrays.asList(
+ ItemPath.EMPTY_PATH,
+ UserType.F_EXTENSION,
+ UserType.F_METADATA,
+ UserType.F_ASSIGNMENT,
+ UserType.F_ACTIVATION,
+ UserType.F_CREDENTIALS,
+ UserType.F_ADMIN_GUI_CONFIGURATION);
+ private static final List BASIC_SHADOW_CONTAINERS_PATHS = Arrays.asList(
+ ItemPath.EMPTY_PATH,
+ ShadowType.F_EXTENSION,
+ ShadowType.F_METADATA,
+ ShadowType.F_PENDING_OPERATION,
+ ShadowType.F_ATTRIBUTES,
+ ShadowType.F_ASSOCIATION,
+ ShadowType.F_ACTIVATION,
+ ShadowType.F_CREDENTIALS);
+ private static final List BASIC_ORG_CONTAINERS_PATHS = Arrays.asList(
+ ItemPath.EMPTY_PATH,
+ OrgType.F_EXTENSION,
+ OrgType.F_METADATA,
+ OrgType.F_ASSIGNMENT,
+ OrgType.F_ACTIVATION,
+ OrgType.F_INDUCEMENT,
+ OrgType.F_AUTHORIZATION,
+ OrgType.F_EXCLUSION,
+ OrgType.F_CONDITION,
+ OrgType.F_POLICY_CONSTRAINTS,
+ OrgType.F_ADMIN_GUI_CONFIGURATION,
+ OrgType.F_DATA_PROTECTION,
+ OrgType.F_AUTOASSIGN);
+
private String userWallyOid;
private String accountWallyOid;
@@ -146,7 +174,7 @@ public void test100CreateWrapperUserJack() throws Exception {
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.MODIFYING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_USERS_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
ContainerWrapper mainContainerWrapper = objectWrapper.findContainerWrapper(null);
WrapperTestUtil.assertWrapper(mainContainerWrapper, getString("prismContainer.mainPanelDisplayName"), (ItemPath)null, user, ContainerStatus.MODIFYING);
@@ -190,7 +218,17 @@ public void test100CreateWrapperUserJack() throws Exception {
display("Delta", objectDelta);
assertTrue("non-empty delta produced from wrapper: "+objectDelta, objectDelta.isEmpty());
}
-
+
+ private void assertContainersPaths(ObjectWrapper> objectWrapper, Collection expectedPaths) {
+ Set expectedUniformPaths = expectedPaths.stream()
+ .map(p -> prismContext.toUniformPath(p))
+ .collect(Collectors.toSet());
+ Set realUniformPaths = objectWrapper.getContainers().stream()
+ .map(c -> prismContext.toUniformPath(c.getPath()))
+ .collect(Collectors.toSet());
+ assertEquals("wrong container paths in "+objectWrapper, expectedUniformPaths, realUniformPaths);
+ }
+
/**
* Create wrapper for brand new empty user.
*/
@@ -215,7 +253,7 @@ public void test110CreateWrapperUserNewEmpty() throws Exception {
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.ADDING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_USERS_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
ContainerWrapper mainContainerWrapper = objectWrapper.findContainerWrapper(null);
WrapperTestUtil.assertWrapper(mainContainerWrapper, getString("prismContainer.mainPanelDisplayName"), (ItemPath)null, user, ContainerStatus.ADDING);
@@ -293,7 +331,7 @@ public void test112CreateWrapperUserNewman() throws Exception {
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.ADDING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_USERS_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
WrapperTestUtil.assertWrapper(mainContainerWrapper, getString("prismContainer.mainPanelDisplayName"), (ItemPath)null, user, ContainerStatus.ADDING);
assertEquals("wrong number of containers in "+mainContainerWrapper, 1, mainContainerWrapper.getValues().size());
@@ -360,7 +398,7 @@ public void test102CreateWrapperUserEmpty() throws Exception {
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "user display name", "user description", user, ContainerStatus.MODIFYING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_USERS_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_USER_CONTAINERS_PATHS);
ContainerWrapper mainContainerWrapper = objectWrapper.findContainerWrapper(null);
WrapperTestUtil.assertWrapper(mainContainerWrapper, getString("prismContainer.mainPanelDisplayName"), (ItemPath)null, user, ContainerStatus.MODIFYING);
@@ -419,7 +457,7 @@ public void test150CreateWrapperShadow() throws Exception {
display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_SHADOW_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_SHADOW_CONTAINERS_PATHS);
ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(ShadowType.F_ATTRIBUTES);
assertEquals("wrong number of values in "+attributesContainerWrapper, 1, attributesContainerWrapper.getValues().size());
@@ -481,7 +519,7 @@ public void test160CreateWrapperOrgScummBar() throws Exception {
IntegrationTestTools.display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "org display name", "org description", org, ContainerStatus.MODIFYING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_ORG_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_ORG_CONTAINERS_PATHS);
ContainerWrapper mainContainerWrapper = objectWrapper.findContainerWrapper(null);
WrapperTestUtil.assertWrapper(mainContainerWrapper, getString("prismContainer.mainPanelDisplayName"), (ItemPath)null, org, ContainerStatus.MODIFYING);
@@ -570,7 +608,7 @@ public void test220AssignRoleLandluberToWally() throws Exception {
display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
- assertEquals("wrong number of containers in "+objectWrapper, BASIC_SHADOW_CONTAINERS, objectWrapper.getContainers().size());
+ assertContainersPaths(objectWrapper, BASIC_SHADOW_CONTAINERS_PATHS);
ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(ShadowType.F_ATTRIBUTES);
WrapperTestUtil.assertWrapper(attributesContainerWrapper, "Attributes", ShadowType.F_ATTRIBUTES, shadow.findContainer(ShadowType.F_ATTRIBUTES),
diff --git a/model/notifications-api/src/main/java/com/evolveum/midpoint/notifications/api/transports/Message.java b/model/notifications-api/src/main/java/com/evolveum/midpoint/notifications/api/transports/Message.java
index 432a1a9389b..efb2b6bfef2 100644
--- a/model/notifications-api/src/main/java/com/evolveum/midpoint/notifications/api/transports/Message.java
+++ b/model/notifications-api/src/main/java/com/evolveum/midpoint/notifications/api/transports/Message.java
@@ -52,7 +52,7 @@ public Message(NotificationMessageType message) {
contentType = message.getContentType();
attachments.addAll(message.getAttachment());
}
-
+
public String getBody() {
return body;
}
@@ -116,19 +116,51 @@ public void setFrom(String from) {
public List getAttachments() {
return attachments;
}
+
+ public void setAttachments(@NotNull List attachments) {
+ this.attachments = attachments;
+ }
@Override
public String toString() {
- return "Message{" +
- "to='" + to + '\'' +
- (from != null ? ", from='" + from + "'" : "") +
- ", cc='" + cc + "'" +
- ", bcc='" + bcc + "'" +
- ", subject='" + subject + '\'' +
- ", contentType='" + contentType + '\'' +
- ", body='" + body + '\'' +
- ", attachments: " + attachments.size() + // TODO provide a short information here (the same as in debugDump below)
- '}';
+ StringBuilder sb = new StringBuilder();
+ sb.append("Message{")
+ .append("to='").append(to).append("'")
+ .append((from != null ? ", from='" + from + "'" : ""))
+ .append(", cc='").append(cc).append("'")
+ .append(", bcc='").append(bcc).append("'")
+ .append(", subject='").append(subject).append("'")
+ .append(", contentType='").append(contentType).append("'")
+ .append(", body='").append(body).append("'")
+ .append(", attachmentsCount: ").append(attachments.size());
+ if(attachments.size() > 0) {
+ sb.append(", attachments: {");
+ boolean isFirst = true;
+ for(NotificationMessageAttachmentType attachment : attachments) {
+ if(!isFirst) {
+ sb.append(", ");
+ }
+ isFirst= false;
+ sb.append("[")
+ .append("contentType='").append(attachment.getContentType()).append("'")
+ .append(attachment.getContentFromFile() != null ?
+ ", contentFromFile='" + attachment.getContentFromFile() + "'" : "");
+ if(attachment.getContent() != null) {
+ if(attachment.getContent() instanceof String) {
+ sb.append(", contentLength='").append(((String)attachment.getContent()).length()).append("'");
+ } else if(attachment.getContent() != null && attachment.getContent() instanceof String) {
+ sb.append(", contentSizeOfByte='").append(((byte[])attachment.getContent()).length).append("'");
+ } else {
+ sb.append(", content='").append(attachment.getContent().toString()).append("'");
+ }
+ }
+ sb.append(attachment.getFileName() != null ?
+ ", fileName='" + attachment.getFileName() + "'" : "")
+ .append("]");
+ };
+ sb.append("}");
+ }
+ return sb.toString();
}
@Override
@@ -159,10 +191,44 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabel(rv, "Subject", subject, indent+1);
rv.append("\n");
+
+ DebugUtil.debugDumpWithLabel(rv, "Content type", contentType, indent+1);
+ rv.append("\n");
DebugUtil.debugDumpWithLabel(rv, "Body", DebugUtil.fixIndentInMultiline(indent+1, DebugDumpable.INDENT_STRING, body), indent+1);
-
- // TODO attachments (instead of content provide only information about e.g. its size in case of byte[] or length in case of String)
+ rv.append("\n");
+
+ DebugUtil.debugDumpLabel(rv, "Attachments", indent);
+ rv.append("\n");
+
+ attachments.forEach(attachment -> {
+
+ DebugUtil.debugDumpLabel(rv, "Attachment", indent+2);
+ rv.append("\n");
+
+ DebugUtil.debugDumpWithLabel(rv, "Content type", attachment.getContentType(), indent+3);
+ rv.append("\n");
+
+ if (from != null){
+ DebugUtil.debugDumpWithLabel(rv, "Content from file", attachment.getContentFromFile(), indent+3);
+ rv.append("\n");
+ }
+
+ if(attachment.getContent() != null) {
+ if(attachment.getContent() instanceof String) {
+ DebugUtil.debugDumpWithLabel(rv, "Content length", ((String)attachment.getContent()).length(), indent+3);
+ rv.append("\n");
+ } else if(attachment.getContent() != null && attachment.getContent() instanceof String) {
+ DebugUtil.debugDumpWithLabel(rv, "Content size of byte", ((byte[])attachment.getContent()).length, indent+3);
+ rv.append("\n");
+ }
+ }
+
+ if (from != null){
+ DebugUtil.debugDumpWithLabel(rv, "File name", attachment.getFileName(), indent+3);
+ rv.append("\n");
+ }
+ });
return rv.toString();
}
}
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java
index 297c9037384..6d35e89bf42 100644
--- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java
@@ -16,39 +16,61 @@
package com.evolveum.midpoint.notifications.impl.api.transports;
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Date;
import java.util.Properties;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.activation.FileTypeMap;
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.activation.MimetypesFileTypeMap;
import javax.annotation.PostConstruct;
+import javax.mail.BodyPart;
import javax.mail.MessagingException;
+import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimeUtility;
import com.evolveum.midpoint.notifications.api.events.Event;
import org.apache.commons.lang.StringUtils;
+import org.bouncycastle.asn1.dvcs.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
+import org.springframework.util.MimeTypeUtils;
+import com.evolveum.midpoint.model.api.util.ModelUtils;
import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.notifications.api.transports.Transport;
import com.evolveum.midpoint.notifications.impl.NotificationFunctionsImpl;
+import com.evolveum.midpoint.notifications.impl.util.MimeTypeUtil;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
+import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MailTransportSecurityType;
+import com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
+import com.evolveum.prism.xml.ns._public.types_3.RawType;
import static com.evolveum.midpoint.notifications.impl.api.transports.TransportUtil.formatToFileOld;
@@ -205,7 +227,68 @@ public void send(Message mailMessage, String transportName, Event event, Task ta
if (StringUtils.isEmpty(contentType)) {
contentType = "text/plain; charset=UTF-8";
}
- mimeMessage.setContent(mailMessage.getBody(), contentType);
+ BodyPart messageBody = new MimeBodyPart();
+ messageBody.setContent(mailMessage.getBody(), contentType);
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(messageBody);
+ for(NotificationMessageAttachmentType attachment : mailMessage.getAttachments()) {
+
+ if(attachment.getContent() != null || attachment.getContentFromFile() != null) {
+ String fileName = null;
+ BodyPart attachmentBody = new MimeBodyPart();
+ if(attachment.getContent() != null) {
+ Object content = null;
+ if(attachment.getContent() instanceof RawType) {
+ try {
+ content = TransportUtil.getStringOrByteArrayFromRawType((RawType)attachment.getContent());
+ if(content == null) {
+ LOGGER.warn("RawType " + attachment.getContent() + " isn't possible to parse.");
+ return;
+ }
+ } catch (SchemaException e) {
+ LOGGER.warn("RawType " + attachment.getContent() + " isn't possible to parse.");
+ return;
+ }
+ } else {
+ content = attachment.getContent();
+ }
+ attachmentBody.setContent(content, attachment.getContentType());
+ if(StringUtils.isBlank(attachment.getFileName())) {
+ fileName = "attachment";
+ } else {
+ fileName = attachment.getFileName();
+ }
+ } else {
+ if(!Files.isReadable(Paths.get(attachment.getContentFromFile()))) {
+ LOGGER.warn("File " + attachment.getContentFromFile() + " non exist or isn't readable.");
+ return;
+ }
+
+ DataSource source = new FileDataSource(attachment.getContentFromFile()) {
+ @Override
+ public String getContentType() {
+ return attachment.getContentType();
+ }
+ };
+ attachmentBody.setDataHandler(new DataHandler(source));
+ if(StringUtils.isBlank(attachment.getFileName())) {
+ fileName = source.getName();
+ } else {
+ fileName = attachment.getFileName();
+ }
+ }
+
+ if(!fileName.contains(".")) {
+ fileName += MimeTypeUtil.getDefaultExt(attachment.getContentType());
+ }
+ attachmentBody.setFileName(fileName);
+ multipart.addBodyPart(attachmentBody);
+ } else {
+ LOGGER.warn("NotificationMessageAttachmentType doesn't contain content.");
+ }
+ }
+
+ mimeMessage.setContent(multipart);
javax.mail.Transport t = session.getTransport("smtp");
if (StringUtils.isNotEmpty(mailServerConfigurationType.getUsername())) {
ProtectedStringType passwordProtected = mailServerConfigurationType.getPassword();
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/TransportUtil.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/TransportUtil.java
index e4acf9e50da..9d36e7e9da2 100644
--- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/TransportUtil.java
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/TransportUtil.java
@@ -18,13 +18,19 @@
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.notifications.impl.NotificationFunctionsImpl;
+import com.evolveum.midpoint.prism.xnode.PrimitiveXNode;
+import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
+import com.evolveum.midpoint.util.DOMUtil;
+import com.evolveum.midpoint.util.QNameUtil;
+import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NamedConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
+import com.evolveum.prism.xml.ns._public.types_3.RawType;
import java.io.FileWriter;
import java.io.IOException;
@@ -32,6 +38,8 @@
import java.util.List;
import java.util.function.Function;
+import javax.xml.namespace.QName;
+
/**
* @author mederly
*/
@@ -86,5 +94,19 @@ public static String formatToFileOld(Message message) {
public static String formatToFileNew(Message message, String transport) {
return "================ " + new Date() + " ======= [" + transport + "]\n" + message.debugDump() + "\n\n";
}
+
+ public static Object getStringOrByteArrayFromRawType(RawType raw) throws SchemaException {
+ Object object = null;
+ XNode xnode = raw.getXnode();
+ if(!(xnode instanceof PrimitiveXNode)) {
+ return null;
+ }
+ object = ((PrimitiveXNode>) xnode).getValue();
+ System.out.println("XX object: " + object);
+ if(!(object instanceof String) && !(object instanceof byte[])) {
+ return null;
+ }
+ return object;
+ }
}
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/handlers/BaseHandler.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/handlers/BaseHandler.java
index c66742a4b10..90119869316 100644
--- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/handlers/BaseHandler.java
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/handlers/BaseHandler.java
@@ -31,6 +31,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
+import com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -104,6 +105,11 @@ protected List evaluateExpressionChecked(ExpressionType expressionType,
String shortDesc, Task task, OperationResult result) {
return expressionHelper.evaluateExpressionChecked(expressionType, expressionVariables, shortDesc, task, result);
}
+
+ protected List evaluateNotificationMessageAttachmentTypeExpressionChecked(ExpressionType expressionType, ExpressionVariables expressionVariables,
+ String shortDesc, Task task, OperationResult result) {
+ return expressionHelper.evaluateNotificationMessageAttachmentTypeExpressionChecked(expressionType, expressionVariables, shortDesc, task, result);
+ }
protected ExpressionVariables getDefaultVariables(Event event, OperationResult result) {
return expressionHelper.getDefaultVariables(event, result);
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/helpers/NotificationExpressionHelper.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/helpers/NotificationExpressionHelper.java
index a21062b7d92..85a7549d484 100644
--- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/helpers/NotificationExpressionHelper.java
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/helpers/NotificationExpressionHelper.java
@@ -37,6 +37,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
+import com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
@@ -129,6 +130,44 @@ private List evaluateExpression(ExpressionType expressionType, Expressio
}
return retval;
}
+
+ public List evaluateNotificationMessageAttachmentTypeExpressionChecked(ExpressionType expressionType, ExpressionVariables expressionVariables,
+ String shortDesc, Task task, OperationResult result) {
+
+ Throwable failReason;
+ try {
+ return evaluateNotificationMessageAttachmentTypeExpression(expressionType, expressionVariables, shortDesc, task, result);
+ } catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | SecurityViolationException e) {
+ failReason = e;
+ }
+
+ LoggingUtils.logException(LOGGER, "Couldn't evaluate {} {}", failReason, shortDesc, expressionType);
+ result.recordFatalError("Couldn't evaluate " + shortDesc, failReason);
+ throw new SystemException(failReason);
+ }
+
+ public List evaluateNotificationMessageAttachmentTypeExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc,
+ Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
+
+ QName resultName = new QName(SchemaConstants.NS_C, "result");
+ PrismPropertyDefinition resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, NotificationMessageAttachmentType.COMPLEX_TYPE);
+ Expression,PrismPropertyDefinition> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
+ ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
+
+ PrismValueDeltaSetTriple> exprResultTriple = ModelExpressionThreadLocalHolder
+ .evaluateExpressionInContext(expression, params, task, result);
+
+ Collection> exprResult = exprResultTriple.getZeroSet();
+ if (exprResult.size() == 0) {
+ return null;
+ }
+
+ List retval = new ArrayList<>();
+ for (PrismPropertyValue item : exprResult) {
+ retval.add(item.getValue());
+ }
+ return retval;
+ }
public ExpressionVariables getDefaultVariables(Event event, OperationResult result) {
ExpressionVariables expressionVariables = new ExpressionVariables();
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/notifiers/GeneralNotifier.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/notifiers/GeneralNotifier.java
index 22421991979..917f56127a8 100644
--- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/notifiers/GeneralNotifier.java
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/notifiers/GeneralNotifier.java
@@ -124,6 +124,7 @@ public boolean processEvent(Event event, EventHandlerType eventHandlerType, Noti
String subject = getSubjectFromExpression(event, generalNotifierType, variables, task, result);
String from = getFromFromExpression(event, generalNotifierType, variables, task, result);
String contentType = getContentTypeFromExpression(event, generalNotifierType, variables, task, result);
+ List attachments = getAttachementsFromExpression(event, generalNotifierType, variables, task, result);
if (body == null) {
body = getBody(event, generalNotifierType, transportName, task, result);
@@ -132,6 +133,15 @@ public boolean processEvent(Event event, EventHandlerType eventHandlerType, Noti
subject = generalNotifierType.getSubjectPrefix() != null ? generalNotifierType.getSubjectPrefix() : "";
subject += getSubject(event, generalNotifierType, transportName, task, result);
}
+
+ if (attachments == null) {
+ attachments = generalNotifierType.getAttachment();
+ if(attachments == null) {
+ attachments = getAttachment(event, generalNotifierType, transportName, task, result);
+ }
+ } else if(generalNotifierType.getAttachment() != null) {
+ attachments.addAll(generalNotifierType.getAttachment());
+ }
Message message = new Message();
message.setBody(body != null ? body : "");
@@ -149,6 +159,10 @@ public boolean processEvent(Event event, EventHandlerType eventHandlerType, Noti
message.setCc(getCcBccAddresses(generalNotifierType.getCcExpression(), variables, "notification cc-expression", task, result));
message.setBcc(getCcBccAddresses(generalNotifierType.getBccExpression(), variables, "notification bcc-expression", task, result));
+ if (attachments != null) {
+ message.setAttachments(attachments);
+ }
+
getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
transport.send(message, transportName, event, task, result);
} else {
@@ -169,7 +183,7 @@ public boolean processEvent(Event event, EventHandlerType eventHandlerType, Noti
return true; // not-applicable notifiers do not stop processing of other notifiers
}
- protected boolean quickCheckApplicability(Event event, GeneralNotifierType generalNotifierType, OperationResult result) {
+ protected boolean quickCheckApplicability(Event event, GeneralNotifierType generalNotifierType, OperationResult result) {
return true;
}
@@ -184,6 +198,11 @@ protected String getSubject(Event event, GeneralNotifierType generalNotifierType
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) throws SchemaException {
return null;
}
+
+ protected List getAttachment(Event event, GeneralNotifierType generalNotifierType,
+ String transportName, Task task, OperationResult result) {
+ return null;
+ }
protected UserType getDefaultRecipient(Event event, GeneralNotifierType generalNotifierType, OperationResult result) {
ObjectType objectType = functions.getObjectType(event.getRequestee(), true, result);
@@ -239,58 +258,37 @@ protected List getCcBccAddresses(List expressions, Expre
protected String getSubjectFromExpression(Event event, GeneralNotifierType generalNotifierType, ExpressionVariables variables,
Task task, OperationResult result) {
- if (generalNotifierType.getSubjectExpression() != null) {
- List subjectList = evaluateExpressionChecked(generalNotifierType.getSubjectExpression(), variables, "subject expression",
- task, result);
- if (subjectList == null || subjectList.isEmpty()) {
- getLogger().warn("Subject expression for event " + event.getId() + " returned nothing.");
- return "";
- }
- if (subjectList.size() > 1) {
- getLogger().warn("Subject expression for event " + event.getId() + " returned more than 1 item.");
- }
- return subjectList.get(0);
- } else {
- return null;
- }
+ return getStringFromExpression(event, variables, task, result, generalNotifierType.getSubjectExpression(), "subject", false);
}
protected String getFromFromExpression(Event event, GeneralNotifierType generalNotifierType, ExpressionVariables variables,
Task task, OperationResult result) {
- if (generalNotifierType.getFromExpression() != null) {
- List fromList = evaluateExpressionChecked(generalNotifierType.getFromExpression(), variables, "from expression",
- task, result);
- if (fromList == null || fromList.isEmpty()) {
- getLogger().info("from expression for event " + event.getId() + " returned nothing.");
- return null;
- }
- if (fromList.size() > 1) {
- getLogger().warn("from expression for event " + event.getId() + " returned more than 1 item.");
- }
- return fromList.get(0);
- } else {
- return null;
- }
+ return getStringFromExpression(event, variables, task, result, generalNotifierType.getFromExpression(), "from", true);
}
protected String getContentTypeFromExpression(Event event, GeneralNotifierType generalNotifierType, ExpressionVariables variables,
Task task, OperationResult result) {
- if (generalNotifierType.getContentTypeExpression() != null) {
- List contentTypeList = evaluateExpressionChecked(generalNotifierType.getContentTypeExpression(), variables, "contentType expression",
+ return getStringFromExpression(event, variables, task, result, generalNotifierType.getContentTypeExpression(), "contentType", true);
+ }
+
+ protected String getStringFromExpression(Event event, ExpressionVariables variables,
+ Task task, OperationResult result, ExpressionType expression, String expressionTypeName, boolean canBeNull) {
+ if (expression != null) {
+ List contentTypeList = evaluateExpressionChecked(expression, variables, expressionTypeName + " expression",
task, result);
if (contentTypeList == null || contentTypeList.isEmpty()) {
- getLogger().info("contentType expression for event " + event.getId() + " returned nothing.");
- return null;
+ getLogger().info(expressionTypeName + " expression for event " + event.getId() + " returned nothing.");
+ return canBeNull ? null : "";
}
if (contentTypeList.size() > 1) {
- getLogger().warn("contentType expression for event " + event.getId() + " returned more than 1 item.");
+ getLogger().warn(expressionTypeName + " expression for event " + event.getId() + " returned more than 1 item.");
}
return contentTypeList.get(0);
} else {
return null;
}
}
-
+
protected String getBodyFromExpression(Event event, GeneralNotifierType generalNotifierType, ExpressionVariables variables,
Task task, OperationResult result) {
if (generalNotifierType.getBodyExpression() != null) {
@@ -309,7 +307,22 @@ protected String getBodyFromExpression(Event event, GeneralNotifierType generalN
return null;
}
}
-
+
+ protected List getAttachementsFromExpression(Event event, GeneralNotifierType generalNotifierType, ExpressionVariables variables,
+ Task task, OperationResult result) {
+ if (generalNotifierType.getAttachmentExpression() != null) {
+ List attachment = evaluateNotificationMessageAttachmentTypeExpressionChecked(generalNotifierType.getAttachmentExpression(), variables, "contentType expression",
+ task, result);
+ if (attachment == null) {
+ getLogger().info("attachment expression for event " + event.getId() + " returned nothing.");
+ return null;
+ }
+ return attachment;
+ } else {
+ return null;
+ }
+ }
+
// TODO implement more efficiently
// precondition: delta is MODIFY delta
protected boolean deltaContainsOtherPathsThan(ObjectDelta extends ObjectType> delta, List paths) {
diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/util/MimeTypeUtil.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/util/MimeTypeUtil.java
new file mode 100644
index 00000000000..b76e4a76c0d
--- /dev/null
+++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/util/MimeTypeUtil.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2010-2019 Evolveum
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.evolveum.midpoint.notifications.impl.util;
+
+import java.util.HashMap;
+
+/**
+ * @author skublik
+ */
+public class MimeTypeUtil {
+
+ public static final String MIME_APPLICATION_ANDREW_INSET = "application/andrew-inset";
+ public static final String MIME_APPLICATION_JSON = "application/json";
+ public static final String MIME_APPLICATION_ZIP = "application/zip";
+ public static final String MIME_APPLICATION_X_GZIP = "application/x-gzip";
+ public static final String MIME_APPLICATION_TGZ = "application/tgz";
+ public static final String MIME_APPLICATION_MSWORD = "application/msword";
+ public static final String MIME_APPLICATION_MSWORD_2007 = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+ public static final String MIME_APPLICATION_VND_TEXT = "application/vnd.oasis.opendocument.text";
+ public static final String MIME_APPLICATION_POSTSCRIPT = "application/postscript";
+ public static final String MIME_APPLICATION_PDF = "application/pdf";
+ public static final String MIME_APPLICATION_JNLP = "application/jnlp";
+ public static final String MIME_APPLICATION_MAC_BINHEX40 = "application/mac-binhex40";
+ public static final String MIME_APPLICATION_MAC_COMPACTPRO = "application/mac-compactpro";
+ public static final String MIME_APPLICATION_MATHML_XML = "application/mathml+xml";
+ public static final String MIME_APPLICATION_OCTET_STREAM = "application/octet-stream";
+ public static final String MIME_APPLICATION_ODA = "application/oda";
+ public static final String MIME_APPLICATION_RDF_XML = "application/rdf+xml";
+ public static final String MIME_APPLICATION_JAVA_ARCHIVE = "application/java-archive";
+ public static final String MIME_APPLICATION_RDF_SMIL = "application/smil";
+ public static final String MIME_APPLICATION_SRGS = "application/srgs";
+ public static final String MIME_APPLICATION_SRGS_XML = "application/srgs+xml";
+ public static final String MIME_APPLICATION_VND_MIF = "application/vnd.mif";
+ public static final String MIME_APPLICATION_VND_MSEXCEL = "application/vnd.ms-excel";
+ public static final String MIME_APPLICATION_VND_MSEXCEL_2007 = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+ public static final String MIME_APPLICATION_VND_SPREADSHEET = "application/vnd.oasis.opendocument.spreadsheet";
+ public static final String MIME_APPLICATION_VND_MSPOWERPOINT = "application/vnd.ms-powerpoint";
+ public static final String MIME_APPLICATION_VND_RNREALMEDIA = "application/vnd.rn-realmedia";
+ public static final String MIME_APPLICATION_X_BCPIO = "application/x-bcpio";
+ public static final String MIME_APPLICATION_X_CDLINK = "application/x-cdlink";
+ public static final String MIME_APPLICATION_X_CHESS_PGN = "application/x-chess-pgn";
+ public static final String MIME_APPLICATION_X_CPIO = "application/x-cpio";
+ public static final String MIME_APPLICATION_X_CSH = "application/x-csh";
+ public static final String MIME_APPLICATION_X_DIRECTOR = "application/x-director";
+ public static final String MIME_APPLICATION_X_DVI = "application/x-dvi";
+ public static final String MIME_APPLICATION_X_FUTURESPLASH = "application/x-futuresplash";
+ public static final String MIME_APPLICATION_X_GTAR = "application/x-gtar";
+ public static final String MIME_APPLICATION_X_HDF = "application/x-hdf";
+ public static final String MIME_APPLICATION_X_JAVASCRIPT = "application/x-javascript";
+ public static final String MIME_APPLICATION_X_KOAN = "application/x-koan";
+ public static final String MIME_APPLICATION_X_LATEX = "application/x-latex";
+ public static final String MIME_APPLICATION_X_NETCDF = "application/x-netcdf";
+ public static final String MIME_APPLICATION_X_OGG = "application/x-ogg";
+ public static final String MIME_APPLICATION_X_SH = "application/x-sh";
+ public static final String MIME_APPLICATION_X_SHAR = "application/x-shar";
+ public static final String MIME_APPLICATION_X_SHOCKWAVE_FLASH = "application/x-shockwave-flash";
+ public static final String MIME_APPLICATION_X_STUFFIT = "application/x-stuffit";
+ public static final String MIME_APPLICATION_X_SV4CPIO = "application/x-sv4cpio";
+ public static final String MIME_APPLICATION_X_SV4CRC = "application/x-sv4crc";
+ public static final String MIME_APPLICATION_X_TAR = "application/x-tar";
+ public static final String MIME_APPLICATION_X_RAR_COMPRESSED = "application/x-rar-compressed";
+ public static final String MIME_APPLICATION_X_TCL = "application/x-tcl";
+ public static final String MIME_APPLICATION_X_TEX = "application/x-tex";
+ public static final String MIME_APPLICATION_X_TEXINFO = "application/x-texinfo";
+ public static final String MIME_APPLICATION_X_TROFF = "application/x-troff";
+ public static final String MIME_APPLICATION_X_TROFF_MAN = "application/x-troff-man";
+ public static final String MIME_APPLICATION_X_TROFF_ME = "application/x-troff-me";
+ public static final String MIME_APPLICATION_X_TROFF_MS = "application/x-troff-ms";
+ public static final String MIME_APPLICATION_X_USTAR = "application/x-ustar";
+ public static final String MIME_APPLICATION_X_WAIS_SOURCE = "application/x-wais-source";
+ public static final String MIME_APPLICATION_VND_MOZZILLA_XUL_XML = "application/vnd.mozilla.xul+xml";
+ public static final String MIME_APPLICATION_XHTML_XML = "application/xhtml+xml";
+ public static final String MIME_APPLICATION_XSLT_XML = "application/xslt+xml";
+ public static final String MIME_APPLICATION_XML = "application/xml";
+ public static final String MIME_APPLICATION_XML_DTD = "application/xml-dtd";
+ public static final String MIME_IMAGE_BMP = "image/bmp";
+ public static final String MIME_IMAGE_CGM = "image/cgm";
+ public static final String MIME_IMAGE_GIF = "image/gif";
+ public static final String MIME_IMAGE_IEF = "image/ief";
+ public static final String MIME_IMAGE_JPEG = "image/jpeg";
+ public static final String MIME_IMAGE_TIFF = "image/tiff";
+ public static final String MIME_IMAGE_PNG = "image/png";
+ public static final String MIME_IMAGE_SVG_XML = "image/svg+xml";
+ public static final String MIME_IMAGE_VND_DJVU = "image/vnd.djvu";
+ public static final String MIME_IMAGE_WAP_WBMP = "image/vnd.wap.wbmp";
+ public static final String MIME_IMAGE_X_CMU_RASTER = "image/x-cmu-raster";
+ public static final String MIME_IMAGE_X_ICON = "image/x-icon";
+ public static final String MIME_IMAGE_X_PORTABLE_ANYMAP = "image/x-portable-anymap";
+ public static final String MIME_IMAGE_X_PORTABLE_BITMAP = "image/x-portable-bitmap";
+ public static final String MIME_IMAGE_X_PORTABLE_GRAYMAP = "image/x-portable-graymap";
+ public static final String MIME_IMAGE_X_PORTABLE_PIXMAP = "image/x-portable-pixmap";
+ public static final String MIME_IMAGE_X_RGB = "image/x-rgb";
+ public static final String MIME_AUDIO_BASIC = "audio/basic";
+ public static final String MIME_AUDIO_MIDI = "audio/midi";
+ public static final String MIME_AUDIO_MPEG = "audio/mpeg";
+ public static final String MIME_AUDIO_X_AIFF = "audio/x-aiff";
+ public static final String MIME_AUDIO_X_MPEGURL = "audio/x-mpegurl";
+ public static final String MIME_AUDIO_X_PN_REALAUDIO = "audio/x-pn-realaudio";
+ public static final String MIME_AUDIO_X_WAV = "audio/x-wav";
+ public static final String MIME_CHEMICAL_X_PDB = "chemical/x-pdb";
+ public static final String MIME_CHEMICAL_X_XYZ = "chemical/x-xyz";
+ public static final String MIME_MODEL_IGES = "model/iges";
+ public static final String MIME_MODEL_MESH = "model/mesh";
+ public static final String MIME_MODEL_VRLM = "model/vrml";
+ public static final String MIME_TEXT_PLAIN = "text/plain";
+ public static final String MIME_TEXT_RICHTEXT = "text/richtext";
+ public static final String MIME_TEXT_RTF = "text/rtf";
+ public static final String MIME_TEXT_HTML = "text/html";
+ public static final String MIME_TEXT_CALENDAR = "text/calendar";
+ public static final String MIME_TEXT_CSS = "text/css";
+ public static final String MIME_TEXT_SGML = "text/sgml";
+ public static final String MIME_TEXT_TAB_SEPARATED_VALUES = "text/tab-separated-values";
+ public static final String MIME_TEXT_VND_WAP_XML = "text/vnd.wap.wml";
+ public static final String MIME_TEXT_VND_WAP_WMLSCRIPT = "text/vnd.wap.wmlscript";
+ public static final String MIME_TEXT_X_SETEXT = "text/x-setext";
+ public static final String MIME_TEXT_X_COMPONENT = "text/x-component";
+ public static final String MIME_VIDEO_QUICKTIME = "video/quicktime";
+ public static final String MIME_VIDEO_MPEG = "video/mpeg";
+ public static final String MIME_VIDEO_VND_MPEGURL = "video/vnd.mpegurl";
+ public static final String MIME_VIDEO_X_MSVIDEO = "video/x-msvideo";
+ public static final String MIME_VIDEO_X_MS_WMV = "video/x-ms-wmv";
+ public static final String MIME_VIDEO_X_SGI_MOVIE = "video/x-sgi-movie";
+ public static final String MIME_X_CONFERENCE_X_COOLTALK = "x-conference/x-cooltalk";
+
+ private static HashMap extMapping;
+
+
+ static {
+ extMapping = new HashMap(200) {
+ private void put1(String key, String value) {
+ if (put(key, value) != null) {
+ throw new IllegalArgumentException("Duplicated Mimetype: " + key);
+ }
+ }
+
+ {
+ put1(MIME_APPLICATION_VND_MOZZILLA_XUL_XML, "xul");
+ put1(MIME_APPLICATION_JSON, "json");
+ put1(MIME_X_CONFERENCE_X_COOLTALK, "ice");
+ put1(MIME_VIDEO_X_SGI_MOVIE, "movie");
+ put1(MIME_VIDEO_X_MSVIDEO, "avi");
+ put1(MIME_VIDEO_X_MS_WMV, "wmv");
+ put1(MIME_VIDEO_VND_MPEGURL, "m4u");
+ put1(MIME_TEXT_X_COMPONENT, "htc");
+ put1(MIME_TEXT_X_SETEXT, "etx");
+ put1(MIME_TEXT_VND_WAP_WMLSCRIPT, "wmls");
+ put1(MIME_TEXT_VND_WAP_XML, "wml");
+ put1(MIME_TEXT_TAB_SEPARATED_VALUES, "tsv");
+ put1(MIME_TEXT_SGML, "sgml");
+ put1(MIME_TEXT_CSS, "css");
+ put1(MIME_TEXT_CALENDAR, "ics");
+ put1(MIME_MODEL_VRLM, "vrlm");
+ put1(MIME_MODEL_MESH, "mesh");
+ put1(MIME_MODEL_IGES, "iges");
+ put1(MIME_IMAGE_X_RGB, "rgb");
+ put1(MIME_IMAGE_X_PORTABLE_PIXMAP, "ppm");
+ put1(MIME_IMAGE_X_PORTABLE_GRAYMAP, "pgm");
+ put1(MIME_IMAGE_X_PORTABLE_BITMAP, "pbm");
+ put1(MIME_IMAGE_X_PORTABLE_ANYMAP, "pnm");
+ put1(MIME_IMAGE_X_ICON, "ico");
+ put1(MIME_IMAGE_X_CMU_RASTER, "ras");
+ put1(MIME_IMAGE_WAP_WBMP, "wbmp");
+ put1(MIME_IMAGE_VND_DJVU, "djvu");
+ put1(MIME_IMAGE_SVG_XML, "svg");
+ put1(MIME_IMAGE_IEF, "ief");
+ put1(MIME_IMAGE_CGM, "cgm");
+ put1(MIME_IMAGE_BMP, "bmp");
+ put1(MIME_CHEMICAL_X_XYZ, "xyz");
+ put1(MIME_CHEMICAL_X_PDB, "pdb");
+ put1(MIME_AUDIO_X_PN_REALAUDIO, "ra");
+ put1(MIME_AUDIO_X_MPEGURL, "m3u");
+ put1(MIME_AUDIO_X_AIFF, "aiff");
+ put1(MIME_AUDIO_MPEG, "mp3");
+ put1(MIME_AUDIO_MIDI, "midi");
+ put1(MIME_APPLICATION_XML_DTD, "dtd");
+ put1(MIME_APPLICATION_XML, "xml");
+ put1(MIME_APPLICATION_XSLT_XML, "xslt");
+ put1(MIME_APPLICATION_XHTML_XML, "xhtml");
+ put1(MIME_APPLICATION_X_WAIS_SOURCE, "src");
+ put1(MIME_APPLICATION_X_USTAR, "ustar");
+ put1(MIME_APPLICATION_X_TROFF_MS, "ms");
+ put1(MIME_APPLICATION_X_TROFF_ME, "me");
+ put1(MIME_APPLICATION_X_TROFF_MAN, "man");
+ put1(MIME_APPLICATION_X_TROFF, "roff");
+ put1(MIME_APPLICATION_X_TEXINFO, "texi");
+ put1(MIME_APPLICATION_X_TEX, "tex");
+ put1(MIME_APPLICATION_X_TCL, "tcl");
+ put1(MIME_APPLICATION_X_SV4CRC, "sv4crc");
+ put1(MIME_APPLICATION_X_SV4CPIO, "sv4cpio");
+ put1(MIME_APPLICATION_X_STUFFIT, "sit");
+ put1(MIME_APPLICATION_X_SHOCKWAVE_FLASH, "swf");
+ put1(MIME_APPLICATION_X_SHAR, "shar");
+ put1(MIME_APPLICATION_X_SH, "sh");
+ put1(MIME_APPLICATION_X_NETCDF, "cdf");
+ put1(MIME_APPLICATION_X_LATEX, "latex");
+ put1(MIME_APPLICATION_X_KOAN, "skm");
+ put1(MIME_APPLICATION_X_JAVASCRIPT, "js");
+ put1(MIME_APPLICATION_X_HDF, "hdf");
+ put1(MIME_APPLICATION_X_GTAR, "gtar");
+ put1(MIME_APPLICATION_X_FUTURESPLASH, "spl");
+ put1(MIME_APPLICATION_X_DVI, "dvi");
+ put1(MIME_APPLICATION_X_DIRECTOR, "dir");
+ put1(MIME_APPLICATION_X_CSH, "csh");
+ put1(MIME_APPLICATION_X_CPIO, "cpio");
+ put1(MIME_APPLICATION_X_CHESS_PGN, "pgn");
+ put1(MIME_APPLICATION_X_CDLINK, "vcd");
+ put1(MIME_APPLICATION_X_BCPIO, "bcpio");
+ put1(MIME_APPLICATION_VND_RNREALMEDIA, "rm");
+ put1(MIME_APPLICATION_VND_MSPOWERPOINT, "ppt");
+ put1(MIME_APPLICATION_VND_MIF, "mif");
+ put1(MIME_APPLICATION_SRGS_XML, "grxml");
+ put1(MIME_APPLICATION_SRGS, "gram");
+ put1(MIME_APPLICATION_RDF_SMIL, "smil");
+ put1(MIME_APPLICATION_RDF_XML, "rdf");
+ put1(MIME_APPLICATION_X_OGG, "ogg");
+ put1(MIME_APPLICATION_ODA, "oda");
+ put1(MIME_APPLICATION_MATHML_XML, "mathml");
+ put1(MIME_APPLICATION_MAC_COMPACTPRO, "cpt");
+ put1(MIME_APPLICATION_MAC_BINHEX40, "hqx");
+ put1(MIME_APPLICATION_JNLP, "jnlp");
+ put1(MIME_APPLICATION_ANDREW_INSET, "ez");
+ put1(MIME_TEXT_PLAIN, "txt");
+ put1(MIME_TEXT_RTF, "rtf");
+ put1(MIME_TEXT_RICHTEXT, "rtx");
+ put1(MIME_TEXT_HTML, "html");
+ put1(MIME_APPLICATION_ZIP, "zip");
+ put1(MIME_APPLICATION_X_RAR_COMPRESSED, "rar");
+ put1(MIME_APPLICATION_X_GZIP, "gzip");
+ put1(MIME_APPLICATION_TGZ, "tgz");
+ put1(MIME_APPLICATION_X_TAR, "tar");
+ put1(MIME_IMAGE_GIF, "gif");
+ put1(MIME_IMAGE_JPEG, "jpg");
+ put1(MIME_IMAGE_TIFF, "tiff");
+ put1(MIME_IMAGE_PNG, "png");
+ put1(MIME_AUDIO_BASIC, "au");
+ put1(MIME_AUDIO_X_WAV, "wav");
+ put1(MIME_VIDEO_QUICKTIME, "mov");
+ put1(MIME_VIDEO_MPEG, "mpg");
+ put1(MIME_APPLICATION_MSWORD, "doc");
+ put1(MIME_APPLICATION_MSWORD_2007, "docx");
+ put1(MIME_APPLICATION_VND_TEXT, "odt");
+ put1(MIME_APPLICATION_VND_MSEXCEL, "xls");
+ put1(MIME_APPLICATION_VND_SPREADSHEET, "ods");
+ put1(MIME_APPLICATION_POSTSCRIPT, "ps");
+ put1(MIME_APPLICATION_PDF, "pdf");
+ put1(MIME_APPLICATION_OCTET_STREAM, "exe");
+ put1(MIME_APPLICATION_JAVA_ARCHIVE, "jar");
+ }
+ };
+ }
+
+ public static String getDefaultExt(String mimeType) {
+ String ext = extMapping.get(mimeType.toLowerCase());
+ if (ext == null) {
+ return "";
+ }
+ return "." + ext;
+ }
+
+}