001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.spi.DataFormat; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * MIME Multipart data format 031 */ 032@Metadata(label = "dataformat,transformation", title = "MIME Multipart") 033@XmlRootElement(name = "mime-multipart") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class MimeMultipartDataFormat extends DataFormatDefinition { 036 037 @XmlAttribute 038 @Metadata(defaultValue = "mixed") 039 private String multipartSubType = "mixed"; 040 @XmlAttribute 041 @Metadata(defaultValue = "false") 042 private Boolean multipartWithoutAttachment; 043 @XmlAttribute 044 @Metadata(defaultValue = "false") 045 private Boolean headersInline; 046 @XmlAttribute 047 private String includeHeaders; 048 @XmlAttribute 049 @Metadata(defaultValue = "false") 050 private Boolean binaryContent; 051 052 public MimeMultipartDataFormat() { 053 super("mime-multipart"); 054 } 055 056 @Override 057 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 058 if (getMultipartSubType() != null) { 059 setProperty(camelContext, dataFormat, "multipartSubType", getMultipartSubType()); 060 } 061 if (getMultipartWithoutAttachment() != null) { 062 setProperty(camelContext, dataFormat, "multipartWithoutAttachment", getMultipartWithoutAttachment()); 063 } 064 if (getHeadersInline() != null) { 065 setProperty(camelContext, dataFormat, "headersInline", getHeadersInline()); 066 } 067 if (getIncludeHeaders() != null) { 068 setProperty(camelContext, dataFormat, "includeHeaders", getIncludeHeaders()); 069 } 070 if (getBinaryContent() != null) { 071 setProperty(camelContext, dataFormat, "binaryContent", getBinaryContent()); 072 } 073 } 074 075 public String getMultipartSubType() { 076 return multipartSubType; 077 } 078 079 /** 080 * Specify the subtype of the MIME Multipart. 081 * <p> 082 * Default is "mixed". 083 */ 084 public void setMultipartSubType(String multipartSubType) { 085 this.multipartSubType = multipartSubType; 086 } 087 088 public Boolean getMultipartWithoutAttachment() { 089 return multipartWithoutAttachment; 090 } 091 092 /** 093 * Defines whether a message without attachment is also marshaled into a 094 * MIME Multipart (with only one body part). 095 * <p> 096 * Default is "false". 097 */ 098 public void setMultipartWithoutAttachment(Boolean multipartWithoutAttachment) { 099 this.multipartWithoutAttachment = multipartWithoutAttachment; 100 } 101 102 public Boolean getHeadersInline() { 103 return headersInline; 104 } 105 106 /** 107 * Defines whether the MIME-Multipart headers are part of the message body 108 * (true) or are set as Camel headers (false). 109 * <p> 110 * Default is "false". 111 */ 112 public void setHeadersInline(Boolean headersInline) { 113 this.headersInline = headersInline; 114 } 115 116 public Boolean getBinaryContent() { 117 return binaryContent; 118 } 119 120 /** 121 * A regex that defines which Camel headers are also included as MIME headers 122 * into the MIME multipart. This will only work if headersInline is set to true. 123 * <p> 124 * Default is to include no headers 125 */ 126 public void setIncludeHeaders(String includeHeaders) { 127 this.includeHeaders = includeHeaders; 128 } 129 130 public String getIncludeHeaders() { 131 return includeHeaders; 132 } 133 134 /** 135 * Defines whether the content of binary parts in the MIME multipart is 136 * binary (true) or Base-64 encoded (false) 137 * <p> 138 * Default is "false". 139 */ 140 public void setBinaryContent(Boolean binaryContent) { 141 this.binaryContent = binaryContent; 142 } 143}