KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > html > CIDLink


1 package SnowMailClient.view.html;
2
3 import SnowMailClient.model.multipart.MimePart;
4 import snow.utils.storage.*;
5 import java.io.*;
6
7 /** used to identify images embedded in a mime tree
8 */

9 public class CIDLink
10 {
11   String JavaDoc CID = "";
12   MimePart mimePart;
13   File file;
14
15   // position in the source (used for replacement)
16
public int posInSource;
17
18   public CIDLink(String JavaDoc cid, int posInSource, MimePart mimePart) throws Exception JavaDoc
19   {
20      this.CID = cid;
21      this.posInSource = posInSource;
22      this.mimePart = mimePart;
23
24      // create a random file
25
file = File.createTempFile("CIDExtracted", ".jpg");
26      file.deleteOnExit();
27
28      writeFile();
29   }
30
31   public String JavaDoc getCID() { return CID; }
32
33   public int getPosInSource() { return posInSource; }
34
35   public String JavaDoc getAbsolutePath() throws Exception JavaDoc
36   {
37     String JavaDoc path = file.getCanonicalPath();
38     // now, convert \ to /
39
//path = path.replace('\\', '/');
40

41     return path;
42   }
43
44   private void writeFile() throws Exception JavaDoc
45   {
46      byte[] cont = mimePart.getByteContent();
47      if(cont==null) throw new Exception JavaDoc("CID "+CID+" has null content");
48      FileUtils.saveToFile(cont, file);
49   }
50
51
52
53 } // CIDLink
Popular Tags