You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by sa...@apache.org on 2011/10/28 11:40:45 UTC

svn commit: r1190225 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom: mime/ mime/impl/axiom/ mime/impl/javamail/ om/impl/

Author: sagara
Date: Fri Oct 28 09:40:44 2011
New Revision: 1190225

URL: http://svn.apache.org/viewvc?rev=1190225&view=rev
Log:
Fixed - AXIOM-396  - Introduced two new method to the MultipartWriter API so that it will write "Content-Disposition" header.   

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/MultipartWriterImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java?rev=1190225&r1=1190224&r2=1190225&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java Fri Oct 28 09:40:44 2011
@@ -68,6 +68,28 @@ public interface MultipartWriter {
      */
     OutputStream writePart(String contentType, String contentTransferEncoding, String contentID)
             throws IOException;
+    /**
+    * Start writing a MIME part. The methods returns an {@link OutputStream} that the caller can
+    * use to write the content of the MIME part. After writing the content,
+    * {@link OutputStream#close()} must be called to complete the writing of the MIME part.
+    * 
+    * @param contentType
+    *            the value of the <tt>Content-Type</tt> header of the MIME part
+    * @param contentTransferEncoding
+    *            the content transfer encoding to be used (see above); must not be
+    *            <code>null</code>
+    * @param contentID
+    *            the content ID of the MIME part (see above)
+    * @param dispositionType
+    *            the disposition type of the MIME part 
+    * @param dispositionParm
+    *            a disposition parameter of the MIME part
+    * @return an output stream to write the content of the MIME part
+    * @throws IOException
+    *             if an I/O error occurs when writing to the underlying stream
+    */
+    OutputStream writePart(String contentType, String contentTransferEncoding,
+            String contentID, String dispositionType, String dispositionParm) throws IOException;
     
     /**
      * Write a MIME part. The content is provided by a {@link DataHandler} object, which also
@@ -85,6 +107,26 @@ public interface MultipartWriter {
      */
     void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID)
             throws IOException;
+    /**
+     * Write a MIME part. The content is provided by a {@link DataHandler} object, which also
+     * specifies the content type of the part.
+     * 
+     * @param dataHandler
+     *            the content of the MIME part to write
+     * @param contentTransferEncoding
+     *            the content transfer encoding to be used (see above); must not be
+     *            <code>null</code>
+     * @param contentID
+     *            the content ID of the MIME part (see above)
+     * @param dispositionType
+     *            the disposition type of the MIME part 
+     * @param dispositionParm
+     *            a disposition parameter of the MIME part
+     * @throws IOException
+     *             if an I/O error occurs when writing the part to the underlying stream
+     */
+    void writePart(DataHandler dataHandler, String contentTransferEncoding,
+            String contentID, String dispositionType, String dispositionParm) throws IOException;
     
     /**
      * Complete writing of the MIME multipart package. This method does <b>not</b> close the

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java?rev=1190225&r1=1190224&r2=1190225&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java Fri Oct 28 09:40:44 2011
@@ -82,7 +82,7 @@ class MultipartWriterImpl implements Mul
     }
     
     public OutputStream writePart(String contentType, String contentTransferEncoding,
-            String contentID) throws IOException {
+            String contentID, String dispositionType, String dispositionParm) throws IOException {
         OutputStream transferEncoder;
         if (contentTransferEncoding.equals("8bit") || contentTransferEncoding.equals("binary")) {
             transferEncoder = out;
@@ -106,16 +106,33 @@ class MultipartWriterImpl implements Mul
             writeAscii(contentID);
             out.write('>');
         }
+        
+        if (dispositionType != null && dispositionParm != null) {
+            writeAscii("\r\nContent-Disposition: ");
+            writeAscii(dispositionType);
+            writeAscii("; ");
+            writeAscii(dispositionParm);
+        }
         writeAscii("\r\n\r\n");
         return new PartOutputStream(transferEncoder);
     }
     
-    public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID)
+    public OutputStream writePart(String contentType, String contentTransferEncoding,
+            String contentID) throws IOException {    	
+        return writePart(contentType, contentTransferEncoding, contentID, null, null);
+    }
+    
+    public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID,String dispositionType, String dispositionParm)
             throws IOException {
-        OutputStream partOutputStream = writePart(dataHandler.getContentType(), contentTransferEncoding, contentID);
+        OutputStream partOutputStream = writePart(dataHandler.getContentType(), contentTransferEncoding, contentID, dispositionType, dispositionParm);
         dataHandler.writeTo(partOutputStream);
         partOutputStream.close();
     }
+    
+    public void writePart(DataHandler dataHandler, String contentTransferEncoding,
+            String contentID) throws IOException {
+        writePart(dataHandler, contentTransferEncoding, contentID, null, null);
+    }
 
     public void complete() throws IOException {
         writeAscii("--");

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/MultipartWriterImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/MultipartWriterImpl.java?rev=1190225&r1=1190224&r2=1190225&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/MultipartWriterImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/MultipartWriterImpl.java Fri Oct 28 09:40:44 2011
@@ -42,14 +42,18 @@ class MultipartWriterImpl implements Mul
         private final String contentID;
         private final WritableBlob blob;
         private final OutputStream parent;
+        private final String dispositionType;
+        private final String dispositionParm; 
 
         public PartOutputStream(String contentType, String contentTransferEncoding,
-                String contentID) {
+                String contentID, String dispositionType, String dispositionParm) {
             this.contentType = contentType;
             this.contentTransferEncoding = contentTransferEncoding;
             this.contentID = contentID;
             blob = new MemoryBlob();
             parent = blob.getOutputStream();
+            this.dispositionType = dispositionType;
+            this.dispositionParm = dispositionParm;
         }
 
         public void write(int b) throws IOException {
@@ -67,7 +71,7 @@ class MultipartWriterImpl implements Mul
         public void close() throws IOException {
             parent.close();
             writePart(new DataHandler(new BlobDataSource(blob, contentType)),
-                    contentTransferEncoding, contentID);
+                    contentTransferEncoding, contentID, dispositionType, dispositionParm);
         }
     }
     
@@ -86,17 +90,29 @@ class MultipartWriterImpl implements Mul
     
     public OutputStream writePart(String contentType, String contentTransferEncoding,
             String contentID) throws IOException {
-        return new PartOutputStream(contentType, contentTransferEncoding, contentID);
+        return new PartOutputStream(contentType, contentTransferEncoding, contentID, null, null);
+    }
+    
+    public OutputStream writePart(String contentType, String contentTransferEncoding,
+            String contentID, String dispositionType, String dispositionParm) throws IOException {
+        return new PartOutputStream(contentType, contentTransferEncoding, contentID,
+                dispositionType, dispositionParm);
     }
 
     public void writePart(DataHandler dataHandler, String contentTransferEncoding,
-            String contentID) throws IOException {
+            String contentID, String dispositionType, String dispositionParm) throws IOException {
         MimeBodyPart mimeBodyPart = new MimeBodyPart();
         try {
             mimeBodyPart.setDataHandler(dataHandler);
             mimeBodyPart.addHeader("Content-ID", "<" + contentID + ">");
             mimeBodyPart.addHeader("Content-Type", dataHandler.getContentType());
             mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
+            mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
+            if (dispositionType != null && dispositionParm != null) {
+                mimeBodyPart.addHeader("Content-Disposition", dispositionType + "; "
+                        + dispositionParm);
+            }
+            
         } catch (MessagingException ex) {
             IOException ex2 = new IOException("Unable to create MimeBodyPart");
             ex2.initCause(ex);
@@ -114,6 +130,11 @@ class MultipartWriterImpl implements Mul
         }
         out.write(CR_LF);
     }
+    
+    public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID)
+            throws IOException {
+        writePart(dataHandler, contentTransferEncoding, contentID, null, null);
+    }
 
     public void complete() throws IOException {
         out.write(DASH_DASH);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java?rev=1190225&r1=1190224&r2=1190225&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java Fri Oct 28 09:40:44 2011
@@ -114,6 +114,27 @@ public class OMMultipartWriter {
     }
     
     /**
+     * Start writing an attachment part of the MIME package. This method delegates to
+     * {@link MultipartWriter#writePart(String, String, String)}, but computes the content transfer
+     * encoding based on the content type and the {@link OMOutputFormat}.
+     * 
+     * @param contentType
+     *            the content type of the MIME part to write
+     * @param contentID
+     *            the content ID of the MIME part
+     * @param dispositionType
+     *            the disposition type of the MIME part 
+     * @param dispositionParm
+     *            a disposition parameter of the MIME part
+     * @return an output stream to write the content of the MIME part
+     * @throws IOException
+     *             if an I/O error occurs when writing to the underlying stream
+     */
+    public OutputStream writePart(String contentType, String contentID, String dispositionType, String dispositionParm) throws IOException {    
+        return writer.writePart(contentType, getContentTransferEncoding(contentType), contentID, dispositionType, dispositionParm);
+    }
+    
+    /**
      * Write a MIME part. This method delegates to
      * {@link MultipartWriter#writePart(DataHandler, String, String)}, but computes the appropriate
      * content transfer encoding from the {@link OMOutputFormat}.
@@ -122,10 +143,14 @@ public class OMMultipartWriter {
      *            the content of the MIME part to write
      * @param contentID
      *            the content ID of the MIME part
+     * @param dispositionType
+     *            the disposition type of the MIME part 
+     * @param dispositionParm
+     *            a disposition parameter of the MIME part             
      * @throws IOException
      *             if an I/O error occurs when writing the part to the underlying stream
      */
-    public void writePart(DataHandler dataHandler, String contentID) throws IOException {
+    public void writePart(DataHandler dataHandler, String contentID, String dispositionType, String dispositionParm) throws IOException {
         String contentTransferEncoding = null;
         if (dataHandler instanceof ConfigurableDataHandler) {
             contentTransferEncoding = ((ConfigurableDataHandler)dataHandler).getTransferEncoding();
@@ -133,7 +158,23 @@ public class OMMultipartWriter {
         if (contentTransferEncoding == null) {
             contentTransferEncoding = getContentTransferEncoding(dataHandler.getContentType());
         }
-        writer.writePart(dataHandler, contentTransferEncoding, contentID);
+        writer.writePart(dataHandler, contentTransferEncoding, contentID, dispositionType, dispositionParm);
+    }
+    
+    /**
+     * Write a MIME part. This method delegates to
+     * {@link MultipartWriter#writePart(DataHandler, String, String)}, but computes the appropriate
+     * content transfer encoding from the {@link OMOutputFormat}.
+     * 
+     * @param dataHandler
+     *            the content of the MIME part to write
+     * @param contentID
+     *            the content ID of the MIME part 
+     * @throws IOException
+     *             if an I/O error occurs when writing the part to the underlying stream
+     */
+    public void writePart(DataHandler dataHandler, String contentID) throws IOException {
+        writePart(dataHandler, contentID, null, null);
     }
 
     /**