You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2022/11/09 00:45:58 UTC

[ws-axiom] branch master updated: [AXIOM-506] Make the ContentTransferEncodingPolicy configurable in OMOutputFormat

This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d5a278af [AXIOM-506] Make the ContentTransferEncodingPolicy configurable in OMOutputFormat
0d5a278af is described below

commit 0d5a278afa4cd2bac291b3544cbd1c6ab27f89e7
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Wed Nov 9 00:45:49 2022 +0000

    [AXIOM-506] Make the ContentTransferEncodingPolicy configurable
    in OMOutputFormat
---
 axiom-api/pom.xml                                  |  1 -
 .../java/org/apache/axiom/om/OMOutputFormat.java   | 26 +++++++++++++---------
 .../apache/axiom/om/impl/OMMultipartWriter.java    | 14 ++++++++----
 3 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/axiom-api/pom.xml b/axiom-api/pom.xml
index e44b51d69..f2aa1c667 100644
--- a/axiom-api/pom.xml
+++ b/axiom-api/pom.xml
@@ -286,7 +286,6 @@
                                 <!-- Bad API design: a public API shouldn't depend on classes in an impl package in its interface -->
                                 org.apache.axiom.attachments.lifecycle.LifecycleManager -&gt; org.apache.axiom.attachments.lifecycle.impl.FileAccessor,
                                 <!-- TODO(AXIOM-506) -->
-                                org.apache.axiom.om.impl.OMMultipartWriter -&gt; org.apache.axiom.attachments.ConfigurableDataHandler,
                                 org.apache.axiom.util.base64.Base64Utils -&gt; org.apache.axiom.util.activation.DataSourceUtils,
                                 org.apache.axiom.util.base64.Base64Utils -&gt; javax.activation.DataSource,
                                 org.apache.axiom.util.base64.Base64Utils -&gt; javax.activation.DataHandler,
diff --git a/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java b/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
index 5d216b303..65eb96137 100644
--- a/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
+++ b/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
@@ -22,6 +22,7 @@ package org.apache.axiom.om;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.axiom.om.format.xop.ContentTransferEncodingPolicy;
 import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.om.util.StAXWriterConfiguration;
 import org.apache.axiom.soap.SOAPVersion;
@@ -70,16 +71,11 @@ public class OMOutputFormat {
     @SuppressWarnings("deprecation")
     private StAXWriterConfiguration writerConfiguration;
     
-    // The value of this property is a Boolean.  
-    // A missing value indicates the default action, which is Boolean.FALSE
-    // If Boolean.TRUE, attachments that are "non textual" are written out with 
-    // a content-transfer-encoding type of base64.
-    // @See CommonUtils.isTextualPart for the textual part definition.
-    // 
-    // Example:
-    //   An attachment with a content-type of "image/gif" is a non-textual attachment.
-    //   An attachment with a content-type of "application/soap+xml" is an textual attachment
-    //
+    private ContentTransferEncodingPolicy contentTransferEncodingPolicy;
+
+    /**
+     * @deprecated Use {@link ContentTransferEncodingPolicy#USE_BASE64_FOR_NON_TEXTUAL_PARTS} instead.
+     */
     public static final String USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS = 
         "org.apache.axiom.om.OMFormat.use.cteBase64.forNonTextualAttachments";
     
@@ -125,6 +121,7 @@ public class OMOutputFormat {
         ignoreXMLDeclaration = format.ignoreXMLDeclaration;
         autoCloseWriter = format.autoCloseWriter;
         writerConfiguration = format.writerConfiguration;
+        contentTransferEncodingPolicy = format.contentTransferEncodingPolicy;
         if (format.map != null) {
             map = new HashMap<String,Object>(format.map);
         }
@@ -474,4 +471,13 @@ public class OMOutputFormat {
     public void setStAXWriterConfiguration(StAXWriterConfiguration writerConfiguration) {
         this.writerConfiguration = writerConfiguration;
     }
+
+    public ContentTransferEncodingPolicy getContentTransferEncodingPolicy() {
+        return contentTransferEncodingPolicy;
+    }
+
+    public void setContentTransferEncodingPolicy(
+            ContentTransferEncodingPolicy contentTransferEncodingPolicy) {
+        this.contentTransferEncodingPolicy = contentTransferEncodingPolicy;
+    }
 }
diff --git a/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java b/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
index c0d2a9a1c..4c4161fae 100644
--- a/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
+++ b/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
@@ -23,7 +23,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 
-import org.apache.axiom.attachments.ConfigurableDataHandler;
 import org.apache.axiom.blob.Blob;
 import org.apache.axiom.mime.ContentTransferEncoding;
 import org.apache.axiom.mime.ContentType;
@@ -58,10 +57,14 @@ public class OMMultipartWriter {
         
         // TODO(AXIOM-506): make this configurable in OMOutputFormat
         contentTypeProvider = DataHandlerContentTypeProvider.INSTANCE;
-        ContentTransferEncodingPolicy contentTransferEncodingPolicy = ConfigurableDataHandler.CONTENT_TRANSFER_ENCODING_POLICY;
+        ContentTransferEncodingPolicy contentTransferEncodingPolicy = format.getContentTransferEncodingPolicy();
         if (format != null && Boolean.TRUE.equals(
                 format.getProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS))) {
-            contentTransferEncodingPolicy = new CombinedContentTransferEncodingPolicy(contentTransferEncodingPolicy, ContentTransferEncodingPolicy.USE_BASE64_FOR_NON_TEXTUAL_PARTS);
+            if (contentTransferEncodingPolicy == null) {
+                contentTransferEncodingPolicy = ContentTransferEncodingPolicy.USE_BASE64_FOR_NON_TEXTUAL_PARTS;
+            } else {
+                contentTransferEncodingPolicy = new CombinedContentTransferEncodingPolicy(contentTransferEncodingPolicy, ContentTransferEncodingPolicy.USE_BASE64_FOR_NON_TEXTUAL_PARTS);
+            }
         }
         this.contentTransferEncodingPolicy = contentTransferEncodingPolicy;
         
@@ -86,7 +89,10 @@ public class OMMultipartWriter {
     }
 
     private ContentTransferEncoding getContentTransferEncoding(Blob blob, ContentType contentType) {
-        ContentTransferEncoding cte = contentTransferEncodingPolicy.getContentTransferEncoding(blob, contentType);
+        ContentTransferEncoding cte = null;
+        if (contentTransferEncodingPolicy != null) {
+            cte = contentTransferEncodingPolicy.getContentTransferEncoding(blob, contentType);
+        }
         return cte == null ? ContentTransferEncoding.BINARY : cte;
     }