You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by th...@apache.org on 2005/06/30 14:06:34 UTC

svn commit: r202543 - /webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java

Author: thilina
Date: Thu Jun 30 05:06:33 2005
New Revision: 202543

URL: http://svn.apache.org/viewcvs?rev=202543&view=rev
Log:
Temporary File Caching ability for Attachments

Modified:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java?rev=202543&r1=202542&r2=202543&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis/attachments/PartOnFile.java Thu Jun 30 05:06:33 2005
@@ -16,51 +16,88 @@
  */
 package org.apache.axis.attachments;
 
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Enumeration;
 
 import javax.activation.DataHandler;
+import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.Multipart;
 import javax.mail.Part;
+import javax.mail.internet.MimeBodyPart;
+
+import org.apache.axis.om.OMException;
 
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
  */
 public class PartOnFile implements Part {
-
+	
 	String fileName;
-
+	
 	Part bodyPart;
-
-	public PartOnFile(Part bodyPart) throws Exception {
+	
+	int size;
+	
+	String contentType;
+	
+	Enumeration headers;
+	
+	String contentID;
+	
+	public PartOnFile(Part bodyPart,String contentID, String repoDir) throws Exception {
 		super();
-		fileName = (new Date()).getTime() + ".tmp";
+		size = bodyPart.getSize();
+		contentType = bodyPart.getContentType();
+		headers = bodyPart.getAllHeaders();
+		// TODO Find a better naming algorithm
+		fileName = repoDir+"/"+(new Date()).getTime() + ".tmp";
 		FileOutputStream outFileStream;
 		outFileStream = new FileOutputStream(fileName);
 		bodyPart.writeTo(outFileStream);
 		outFileStream.close();
 	}
-
+	
+	private Part getPartOnFile() {
+		FileInputStream inFileStream;
+		Part part=null;
+		try {
+			inFileStream = new FileInputStream(fileName);
+			
+			part = new MimeBodyPart(inFileStream);
+		} catch (FileNotFoundException e) {
+			throw new OMException("File Not Found"+e.toString());
+		} catch (MessagingException e1) {
+			throw new OMException("Cannot create MimePart from the Part read from file"+e1.toString());
+		}
+		return part;
+	}
+	
+	public String getContentID()
+	{
+		return contentID;
+	}
 	public int getSize() throws MessagingException {
-		// TODO Auto-generated method stub
-		return 0;
+		return size;
 	}
-
+	
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getLineCount()
 	 */
 	public int getLineCount() throws MessagingException {
-		// TODO Auto-generated method stub
-		return 0;
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -68,230 +105,224 @@
 	 */
 	public String getContentType() throws MessagingException {
 		// TODO Auto-generated method stub
-		return null;
+		return contentType;
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#isMimeType(java.lang.String)
 	 */
 	public boolean isMimeType(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-		return false;
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getDisposition()
 	 */
 	public String getDisposition() throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setDisposition(java.lang.String)
 	 */
 	public void setDisposition(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getDescription()
 	 */
 	public String getDescription() throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setDescription(java.lang.String)
 	 */
 	public void setDescription(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getFileName()
 	 */
 	public String getFileName() throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setFileName(java.lang.String)
 	 */
 	public void setFileName(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getInputStream()
 	 */
 	public InputStream getInputStream() throws IOException, MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		Part part = getPartOnFile();
+		return part.getInputStream();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getDataHandler()
 	 */
 	public DataHandler getDataHandler() throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		Part part = getPartOnFile();
+		return part.getDataHandler();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getContent()
 	 */
 	public Object getContent() throws IOException, MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		Part part = getPartOnFile();
+		return part.getContent();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setDataHandler(javax.activation.DataHandler)
 	 */
 	public void setDataHandler(DataHandler arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setContent(java.lang.Object, java.lang.String)
 	 */
 	public void setContent(Object arg0, String arg1) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setText(java.lang.String)
 	 */
 	public void setText(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setContent(javax.mail.Multipart)
 	 */
 	public void setContent(Multipart arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
+		
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#writeTo(java.io.OutputStream)
 	 */
-	public void writeTo(OutputStream arg0) throws IOException,
-			MessagingException {
-		// TODO Auto-generated method stub
-
+	public void writeTo(OutputStream outStream) throws IOException,
+	MessagingException {
+		Part part = getPartOnFile();
+		part.writeTo(outStream);
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getHeader(java.lang.String)
 	 */
 	public String[] getHeader(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		ArrayList selectedHeader = null;
+		while (headers.hasMoreElements()) {
+			String header = (String) headers.nextElement();
+			if (arg0.equals(header)) {
+				selectedHeader.add(header);
+			}
+		}
+		String[] headerStrings = (String[]) selectedHeader.toArray();
+		return headerStrings;
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#setHeader(java.lang.String, java.lang.String)
 	 */
 	public void setHeader(String arg0, String arg1) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
+		
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#addHeader(java.lang.String, java.lang.String)
 	 */
 	public void addHeader(String arg0, String arg1) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
+		
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#removeHeader(java.lang.String)
 	 */
 	public void removeHeader(String arg0) throws MessagingException {
-		// TODO Auto-generated method stub
-
+		throw new UnsupportedOperationException();
+		
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getAllHeaders()
 	 */
 	public Enumeration getAllHeaders() throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+		return headers;
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getMatchingHeaders(java.lang.String[])
 	 */
 	public Enumeration getMatchingHeaders(String[] arg0)
-			throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+	throws MessagingException {
+		throw new UnsupportedOperationException();
 	}
-
+	
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see javax.mail.Part#getNonMatchingHeaders(java.lang.String[])
 	 */
 	public Enumeration getNonMatchingHeaders(String[] arg0)
-			throws MessagingException {
-		// TODO Auto-generated method stub
-		return null;
+	throws MessagingException {
+		throw new UnsupportedOperationException();
 	}
-
+	
 }