KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > test > ExampleGenerator


1     /**
2  * Title: Oyster Project
3  * Description: Creating S/MIME email transport capabilities.
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8 package org.enhydra.oyster.test;
9
10 import org.enhydra.oyster.exception.SMIMEException;
11 import java.io.ByteArrayInputStream JavaDoc;
12 import java.io.File JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.UnsupportedEncodingException JavaDoc;
15 import org.enhydra.oyster.util.ConvertAssist;
16
17 /**
18  * Class for storing and generation of resources used in test examples. This
19  * class is intended for simulation of contents generated by program and
20  * attachments for composing email messages.
21  */

22 public class ExampleGenerator
23 {
24
25 /**
26  * Location of resource yellow.jpg
27  */

28   private String JavaDoc yellow = null;
29
30 /**
31  * Location of resource orange.jpg
32  */

33   private String JavaDoc orange = null;
34
35 /**
36  * Location of resource blue.gif
37  */

38   private String JavaDoc blue = null;
39
40 /**
41  * Location of resource green.gif
42  */

43   private String JavaDoc green = null;
44
45 /**
46  * Location of resource red.gif
47  */

48   private String JavaDoc red = null;
49
50 /**
51  * green.gif represented as byte array;
52  */

53   private int[] pic = { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61,
54                          0x19, 0x00, 0x19, 0x00, 0xb3, 0x00, 0x00, 0x00, 0x66,
55                          0x33, 0x00, 0x99, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
56                          0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60                          0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x19,
61                          0x00, 0x00, 0x04, 0x3f, 0x30, 0x00, 0x20, 0xe9, 0xac,
62                          0xf8, 0x6a, 0x9b, 0xad, 0xef, 0x60, 0x20, 0x8e, 0x64,
63                          0x69, 0x92, 0x1b, 0x98, 0xae, 0xea, 0xb7, 0x7e, 0x67,
64                          0x2c, 0xb7, 0x34, 0xfb, 0xd6, 0xf0, 0xac, 0x8f, 0x77,
65                          0xef, 0xe2, 0xc0, 0x9d, 0xd0, 0x07, 0x74, 0x19, 0x83,
66                          0x42, 0x1d, 0x71, 0x59, 0x3c, 0x5e, 0x92, 0x4a, 0xa7,
67                          0x34, 0xd3, 0xa4, 0x41, 0x67, 0xcb, 0xa9, 0x76, 0x7b,
68                          0xc5, 0x72, 0x6f, 0x11, 0x00, 0x3b };
69
70 /**
71  * Sets value to corresponding resource in html code (in this example it is one
72  * of pictures: red.gif, blue.gif, green.gif, yellow.jpg or orange.jpg).
73  * @param name0 name of desired resource. Can be: "RED", "BLUE", "YELLOW",
74  * "GREEN" or "ORANGE". If wrong value is given to argument, default value is
75  * taken in methods getHtmlStream and getHtmlString (default values are relative
76  * adresses and they can be seen from orginal html file: HtmlTest.html).
77  * @param value0 value which is given to appropriate resource (relative or
78  * absolute path, http://... or file://... url, or virtual_file_name value used
79  * for IputStream resources).
80  */

81   public void setResourceInExampleHtml(String JavaDoc name0, String JavaDoc value0) {
82     if(name0.equalsIgnoreCase("RED"))
83       red = new String JavaDoc(value0);
84     else if(name0.equalsIgnoreCase("BLUE"))
85       blue = new String JavaDoc(value0);
86     else if(name0.equalsIgnoreCase("GREEN"))
87       green = new String JavaDoc(value0);
88     else if(name0.equalsIgnoreCase("YELLOW"))
89       yellow = new String JavaDoc(value0);
90     else if(name0.equalsIgnoreCase("ORANGE"))
91       orange = new String JavaDoc(value0);
92   }
93
94 /**
95  * Returns HTML code from storage.
96  * @return HTML code represented as a String
97  */

98   public String JavaDoc getHtmlString() {
99
100     if(red == null)
101       red = "./pictures/red.gif";
102     if(blue == null)
103       blue = "./pictures/blue.gif";
104     if(green == null)
105       green = "./pictures/green.gif";
106     if(yellow == null)
107       yellow = "./pictures/yellow.jpg";
108     if(orange == null)
109       orange = "./pictures/orange.jpg";
110
111     return
112       "<html>" + "\r\n" +
113       "<head>" + "\r\n" +
114       "<meta http-equiv=\"Content-Language\" content=\"hr\">" + "\r\n" +
115       "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1250\">" + "\r\n" +
116       "<title>Test Page</title>" + "\r\n" +
117       "</head>" + "\r\n" +
118       "<body background=\"" + yellow + "\">" + "\r\n" +
119       "<p align=\"center\"><font color=\"#800080\" size=\"6\">HTML test for SMIME project</font></p>" + "\r\n" +
120       "<hr>" + "\r\n" +
121       "<p><b>Ordered and unordered lists:</b></p>" + "\r\n" +
122       "<ul>" + "\r\n" +
123       " <li><b>Text a</b>" + "\r\n" +
124       " <ol>" + "\r\n" +
125       " <li><b>No 1</b></li>" + "\r\n" +
126       " <li><b>No 2</b></li>" + "\r\n" +
127       " <li><b>No 3</b></li>" + "\r\n" +
128       " </ol></li>" + "\r\n" +
129       " <li><b>Text b</b></li>" + "\r\n" +
130       " <li><b>Text c</b></li>" + "\r\n" +
131       "</ul>" + "\r\n" +
132       "<div align=\"center\">" + "\r\n" +
133       " <center>" + "\r\n" +
134       " <table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" align=\"left\" height=\"100\">" + "\r\n" +
135       " <tr>" + "\r\n" +
136       " <td background=\"" + orange + "\" width=\"275\"><b>Table1&nbsp;Row1 Column1</b></td>" + "\r\n" +
137       " <td background=\"" + green + "\" width=\"275\"><b>Table1&nbsp;Row1 Column2</b></td>" + "\r\n" +
138       " <td background=\"" + orange + "\" width=\"275\"><b>Table1&nbsp;Row1 Column3</b></td>" + "\r\n" +
139       " </tr>" + "\r\n" +
140       " <tr>" + "\r\n" +
141       " <td background=\"" + green + "\" width=\"275\"><b>Table1&nbsp;Row1 Column2</b></td>" + "\r\n" +
142       " <td background=\"" + orange + "\" width=\"275\"><b>Table1&nbsp;Row2 Column2</b></td>" + "\r\n" +
143       " <td background=\"" + green + "\" width=\"275\"><b>Table1&nbsp;Row2 Column3</b></td>" + "\r\n" +
144       " </tr>" + "\r\n" +
145       " </table>" + "\r\n" +
146       " </center>" + "\r\n" +
147       "</div>" + "\r\n" +
148       "<p>&nbsp;</p>" + "\r\n" +
149       "<p>&nbsp;</p>" + "\r\n" +
150       "<p>&nbsp;</p>" + "\r\n" +
151       "<br><br>" + "\r\n" +
152       "<p>" + "\r\n" +
153       "<b>Specijal characters:&amp;, &copy;, &gt;, &lt;, &reg;, &plusmn;, &auml;, &Auml;, &euml;, &Euml;, &ouml;, &Ouml;, &szlig; </b>" + "\r\n" +
154       "</p>" + "\r\n" +
155       "<br><br>" + "\r\n" +
156       "<div align=\"center\">" + "\r\n" +
157       " <center>" + "\r\n" +
158       " <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" align=\"left\">" + "\r\n" +
159       " <tr>" + "\r\n" +
160       " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" SRC=\"" + blue + "\" width=\"25\" height=\"25\">" + "\r\n" +
161       " Picture1</b></td>" + "\r\n" +
162       " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" SRC=\"" + green + "\" width=\"25\" height=\"25\">" + "\r\n" +
163       " Picture2</b></td>" + "\r\n" +
164       " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" SRC=\"" + orange + "\" width=\"25\" height=\"25\">" + "\r\n" +
165       " Picture3</b></td>" + "\r\n" +
166       " <td width=\"166\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" SRC=\"" + red + "\" width=\"25\" height=\"25\">" + "\r\n" +
167       " Picture4</b></td>" + "\r\n" +
168       " <td width=\"166\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" SRC=\"" + yellow + "\" width=\"25\" height=\"25\">" + "\r\n" +
169       " Picture5</b></td>" + "\r\n" +
170       " </tr>" + "\r\n" +
171       " </table>" + "\r\n" +
172       " </center>" + "\r\n" +
173       "</div>" + "\r\n" +
174       "</body>" + "\r\n" +
175       "</html>";
176   }
177
178 /**
179  * Returns HTML code from storage.
180  * @return HTML code represented as a ByteArrayInputStream
181  */

182   public ByteArrayInputStream JavaDoc getHtmlStream() throws UnsupportedEncodingException JavaDoc {
183
184     ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(
185                                         getHtmlString().getBytes("ISO-8859-1"));
186     return bais;
187   }
188
189
190 /**
191  * Returns zip file generated by program as ByteArrayInputStream
192  * @return zip file represented as ByteArrayInputStream
193  */

194   public ByteArrayInputStream JavaDoc getZipStream() throws IOException JavaDoc, SMIMEException {
195
196     File JavaDoc zip = new File JavaDoc("./test/Zip8Test1.zip");
197
198     return new ByteArrayInputStream JavaDoc( ConvertAssist.fileToByteArray(zip) );
199   }
200
201
202 /**
203  * Returns image file green.gif as ByteArrayInputStream
204  * @return gif image represented as ByteArrayInputStream
205  */

206   public ByteArrayInputStream JavaDoc getGifImage() {
207
208     byte[] temp = new byte[pic.length];
209     for(int i=0; i!=pic.length; i++)
210       temp[i] = (byte)pic[i];
211     return new ByteArrayInputStream JavaDoc(temp);
212   }
213
214 }
Popular Tags