1 17 package org.apache.axis2.attachments; 18 19 import java.io.FileInputStream ; 20 import java.io.FileNotFoundException ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 import java.util.ArrayList ; 26 import java.util.Date ; 27 import java.util.Enumeration ; 28 29 import javax.activation.DataHandler ; 30 import javax.mail.BodyPart ; 31 import javax.mail.MessagingException ; 32 import javax.mail.Multipart ; 33 import javax.mail.Part ; 34 import javax.mail.internet.MimeBodyPart ; 35 36 import org.apache.axis2.om.OMException; 37 38 41 public class PartOnFile implements Part { 42 43 String fileName; 44 45 Part bodyPart; 46 47 int size; 48 49 String contentType; 50 51 Enumeration headers; 52 53 String contentID; 54 55 public PartOnFile(Part bodyPart,String contentID, String repoDir) throws Exception { 56 super(); 57 size = bodyPart.getSize(); 58 contentType = bodyPart.getContentType(); 59 headers = bodyPart.getAllHeaders(); 60 if (repoDir==null) 62 { 63 repoDir="."; 64 } 65 fileName = repoDir+(new Date ()).getTime() + ".tmp"; 66 FileOutputStream outFileStream; 67 outFileStream = new FileOutputStream (fileName); 68 bodyPart.writeTo(outFileStream); 69 outFileStream.close(); 70 } 71 72 private Part getPartOnFile() { 73 FileInputStream inFileStream; 74 Part part=null; 75 try { 76 inFileStream = new FileInputStream (fileName); 77 78 part = new MimeBodyPart (inFileStream); 79 } catch (FileNotFoundException e) { 80 throw new OMException("File Not Found"+e.toString()); 81 } catch (MessagingException e1) { 82 throw new OMException("Cannot create MimePart from the Part read from file"+e1.toString()); 83 } 84 return part; 85 } 86 87 public String getContentID() 88 { 89 return contentID; 90 } 91 public int getSize() throws MessagingException { 92 return size; 93 } 94 95 96 101 public int getLineCount() throws MessagingException { 102 throw new UnsupportedOperationException (); 103 } 104 105 110 public String getContentType() throws MessagingException { 111 return contentType; 113 } 114 115 120 public boolean isMimeType(String arg0) throws MessagingException { 121 throw new UnsupportedOperationException (); 122 } 123 124 129 public String getDisposition() throws MessagingException { 130 throw new UnsupportedOperationException (); 131 } 132 133 138 public void setDisposition(String arg0) throws MessagingException { 139 throw new UnsupportedOperationException (); 140 } 141 142 147 public String getDescription() throws MessagingException { 148 throw new UnsupportedOperationException (); 149 } 150 151 156 public void setDescription(String arg0) throws MessagingException { 157 throw new UnsupportedOperationException (); 158 } 159 160 165 public String getFileName() throws MessagingException { 166 throw new UnsupportedOperationException (); 167 } 168 169 174 public void setFileName(String arg0) throws MessagingException { 175 throw new UnsupportedOperationException (); 176 } 177 178 183 public InputStream getInputStream() throws IOException , MessagingException { 184 Part part = getPartOnFile(); 185 return part.getInputStream(); 186 } 187 188 193 public DataHandler getDataHandler() throws MessagingException { 194 Part part = getPartOnFile(); 195 return part.getDataHandler(); 196 } 197 198 203 public Object getContent() throws IOException , MessagingException { 204 Part part = getPartOnFile(); 205 return part.getContent(); 206 } 207 208 213 public void setDataHandler(DataHandler arg0) throws MessagingException { 214 throw new UnsupportedOperationException (); 215 } 216 217 222 public void setContent(Object arg0, String arg1) throws MessagingException { 223 throw new UnsupportedOperationException (); 224 } 225 226 231 public void setText(String arg0) throws MessagingException { 232 throw new UnsupportedOperationException (); 233 } 234 235 240 public void setContent(Multipart arg0) throws MessagingException { 241 throw new UnsupportedOperationException (); 242 243 } 244 245 250 public void writeTo(OutputStream outStream) throws IOException , 251 MessagingException { 252 Part part = getPartOnFile(); 253 part.writeTo(outStream); 254 } 255 256 261 public String [] getHeader(String arg0) throws MessagingException { 262 ArrayList selectedHeader = null; 263 while (headers.hasMoreElements()) { 264 String header = (String ) headers.nextElement(); 265 if (arg0.equals(header)) { 266 selectedHeader.add(header); 267 } 268 } 269 String [] headerStrings = (String []) selectedHeader.toArray(); 270 return headerStrings; 271 } 272 273 278 public void setHeader(String arg0, String arg1) throws MessagingException { 279 throw new UnsupportedOperationException (); 280 281 } 282 283 288 public void addHeader(String arg0, String arg1) throws MessagingException { 289 throw new UnsupportedOperationException (); 290 291 } 292 293 298 public void removeHeader(String arg0) throws MessagingException { 299 throw new UnsupportedOperationException (); 300 301 } 302 303 308 public Enumeration getAllHeaders() throws MessagingException { 309 return headers; 310 } 311 312 317 public Enumeration getMatchingHeaders(String [] arg0) 318 throws MessagingException { 319 throw new UnsupportedOperationException (); 320 } 321 322 327 public Enumeration getNonMatchingHeaders(String [] arg0) 328 throws MessagingException { 329 throw new UnsupportedOperationException (); 330 } 331 332 } | Popular Tags |