View Javadoc
1 /*** 2 * Title: S/MIME Project 3 * Description: Creating S/MIME email transport capabilities. 4 * @Author Vladimir Radisic 5 * @Version 2.0.1 6 */ 7 8 package org.webdocwf.util.smime.test; 9 10 11 import org.webdocwf.util.smime.exception.SMIMEException; 12 import java.io.ByteArrayInputStream; 13 import java.io.File; 14 import java.io.IOException; 15 import java.io.UnsupportedEncodingException; 16 import org.webdocwf.util.smime.util.ConvertAssist; 17 18 19 /*** 20 * Class for storing and generation of resources used in test examples. This 21 * class is intended for simulation of contents generated by program and 22 * attachments for composing email messages. 23 */ 24 public class ExampleGenerator { 25 26 /*** 27 * Location of resource yellow.jpg 28 */ 29 private String yellow = null; 30 31 /*** 32 * Location of resource orange.jpg 33 */ 34 private String orange = null; 35 36 /*** 37 * Location of resource blue.gif 38 */ 39 private String blue = null; 40 41 /*** 42 * Location of resource green.gif 43 */ 44 private String green = null; 45 46 /*** 47 * Location of resource red.gif 48 */ 49 private String red = null; 50 51 /*** 52 * green.gif represented as byte array; 53 */ 54 private int[] pic = { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 55 0x19, 0x00, 0x19, 0x00, 0xb3, 0x00, 0x00, 0x00, 0x66, 56 0x33, 0x00, 0x99, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, 57 0xff, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x19, 62 0x00, 0x00, 0x04, 0x3f, 0x30, 0x00, 0x20, 0xe9, 0xac, 63 0xf8, 0x6a, 0x9b, 0xad, 0xef, 0x60, 0x20, 0x8e, 0x64, 64 0x69, 0x92, 0x1b, 0x98, 0xae, 0xea, 0xb7, 0x7e, 0x67, 65 0x2c, 0xb7, 0x34, 0xfb, 0xd6, 0xf0, 0xac, 0x8f, 0x77, 66 0xef, 0xe2, 0xc0, 0x9d, 0xd0, 0x07, 0x74, 0x19, 0x83, 67 0x42, 0x1d, 0x71, 0x59, 0x3c, 0x5e, 0x92, 0x4a, 0xa7, 68 0x34, 0xd3, 0xa4, 0x41, 0x67, 0xcb, 0xa9, 0x76, 0x7b, 69 0xc5, 0x72, 0x6f, 0x11, 0x00, 0x3b }; 70 71 /*** 72 * Sets value to corresponding resource in html code (in this example it is one 73 * of pictures: red.gif, blue.gif, green.gif, yellow.jpg or orange.jpg). 74 * @param name0 name of desired resource. Can be: "RED", "BLUE", "YELLOW", 75 * "GREEN" or "ORANGE". If wrong value is given to argument, default value is 76 * taken in methods getHtmlStream and getHtmlString (default values are relative 77 * adresses and they can be seen from orginal html file: HtmlTest.html). 78 * @param value0 value which is given to appropriate resource (relative or 79 * absolute path, http://... or file://... url, or virtual_file_name value used 80 * for IputStream resources). 81 */ 82 public void setResourceInExampleHtml(String name0, String value0) { 83 if (name0.equalsIgnoreCase("RED")) 84 red = new String(value0); 85 else if (name0.equalsIgnoreCase("BLUE")) 86 blue = new String(value0); 87 else if (name0.equalsIgnoreCase("GREEN")) 88 green = new String(value0); 89 else if (name0.equalsIgnoreCase("YELLOW")) 90 yellow = new String(value0); 91 else if (name0.equalsIgnoreCase("ORANGE")) 92 orange = new String(value0); 93 } 94 95 /*** 96 * Returns HTML code from storage. 97 * @return HTML code represented as a String 98 */ 99 public String getHtmlString() { 100 101 if (red == null) 102 red = "./pictures/red.gif"; 103 if (blue == null) 104 blue = "./pictures/blue.gif"; 105 if (green == null) 106 green = "./pictures/green.gif"; 107 if (yellow == null) 108 yellow = "./pictures/yellow.jpg"; 109 if (orange == null) 110 orange = "./pictures/orange.jpg"; 111 112 return 113 "<html>" + "\r\n" + 114 "<head>" + "\r\n" + 115 "<meta http-equiv=\"Content-Language\" content=\"hr\">" + "\r\n" + 116 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1250\">" + "\r\n" + 117 "<title>Test Page</title>" + "\r\n" + 118 "</head>" + "\r\n" + 119 "<body background=\"" + yellow + "\">" + "\r\n" + 120 "<p align=\"center\"><font color=\"#800080\" size=\"6\">HTML test for SMIME project</font></p>" + "\r\n" + 121 "<hr>" + "\r\n" + 122 "<p><b>Ordered and unordered lists:</b></p>" + "\r\n" + 123 "<ul>" + "\r\n" + 124 " <li><b>Text a</b>" + "\r\n" + 125 " <ol>" + "\r\n" + 126 " <li><b>No 1</b></li>" + "\r\n" + 127 " <li><b>No 2</b></li>" + "\r\n" + 128 " <li><b>No 3</b></li>" + "\r\n" + 129 " </ol></li>" + "\r\n" + 130 " <li><b>Text b</b></li>" + "\r\n" + 131 " <li><b>Text c</b></li>" + "\r\n" + 132 "</ul>" + "\r\n" + 133 "<div align=\"center\">" + "\r\n" + 134 " <center>" + "\r\n" + 135 " <table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" align=\"left\" height=\"100\">" + "\r\n" + 136 " <tr>" + "\r\n" + 137 " <td background=\"" + orange + "\" width=\"275\"><b>Table1 Row1 Column1</b></td>" + "\r\n" + 138 " <td background=\"" + green + "\" width=\"275\"><b>Table1 Row1 Column2</b></td>" + "\r\n" + 139 " <td background=\"" + orange + "\" width=\"275\"><b>Table1 Row1 Column3</b></td>" + "\r\n" + 140 " </tr>" + "\r\n" + 141 " <tr>" + "\r\n" + 142 " <td background=\"" + green + "\" width=\"275\"><b>Table1 Row1 Column2</b></td>" + "\r\n" + 143 " <td background=\"" + orange + "\" width=\"275\"><b>Table1 Row2 Column2</b></td>" + "\r\n" + 144 " <td background=\"" + green + "\" width=\"275\"><b>Table1 Row2 Column3</b></td>" + "\r\n" + 145 " </tr>" + "\r\n" + 146 " </table>" + "\r\n" + 147 " </center>" + "\r\n" + 148 "</div>" + "\r\n" + 149 "<p> </p>" + "\r\n" + 150 "<p> </p>" + "\r\n" + 151 "<p> </p>" + "\r\n" + 152 "<br><br>" + "\r\n" + 153 "<p>" + "\r\n" + 154 "<b>Specijal characters:&, ©, >, <, ®, ±, ä, Ä, ë, Ë, ö, Ö, ß </b>" + "\r\n" + 155 "</p>" + "\r\n" + 156 "<br><br>" + "\r\n" + 157 "<div align=\"center\">" + "\r\n" + 158 " <center>" + "\r\n" + 159 " <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" align=\"left\">" + "\r\n" + 160 " <tr>" + "\r\n" + 161 " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" src=\"" + blue + "\" width=\"25\" height=\"25\">" + "\r\n" + 162 " Picture1</b></td>" + "\r\n" + 163 " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" src=\"" + green + "\" width=\"25\" height=\"25\">" + "\r\n" + 164 " Picture2</b></td>" + "\r\n" + 165 " <td width=\"165\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" src=\"" + orange + "\" width=\"25\" height=\"25\">" + "\r\n" + 166 " Picture3</b></td>" + "\r\n" + 167 " <td width=\"166\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" src=\"" + red + "\" width=\"25\" height=\"25\">" + "\r\n" + 168 " Picture4</b></td>" + "\r\n" + 169 " <td width=\"166\" bgcolor=\"#FFFFFF\"><b><img border=\"0\" src=\"" + yellow + "\" width=\"25\" height=\"25\">" + "\r\n" + 170 " Picture5</b></td>" + "\r\n" + 171 " </tr>" + "\r\n" + 172 " </table>" + "\r\n" + 173 " </center>" + "\r\n" + 174 "</div>" + "\r\n" + 175 "</body>" + "\r\n" + 176 "</html>"; 177 } 178 179 /*** 180 * Returns HTML code from storage. 181 * @return HTML code represented as a ByteArrayInputStream 182 */ 183 public ByteArrayInputStream getHtmlStream() throws UnsupportedEncodingException { 184 185 ByteArrayInputStream bais = new ByteArrayInputStream( 186 getHtmlString().getBytes("ISO-8859-1")); 187 188 return bais; 189 } 190 191 /*** 192 * Returns zip file generated by program as ByteArrayInputStream 193 * @return zip file represented as ByteArrayInputStream 194 */ 195 public ByteArrayInputStream getZipStream() throws IOException, SMIMEException { 196 197 File zip = new File("./test/Zip8Test1.zip"); 198 199 return new ByteArrayInputStream(ConvertAssist.readFileToByteArray(zip)); 200 } 201 202 /*** 203 * Returns image file green.gif as ByteArrayInputStream 204 * @return gif image represented as ByteArrayInputStream 205 */ 206 public ByteArrayInputStream getGifImage() { 207 208 byte[] temp = new byte[pic.length]; 209 210 for (int i = 0; i != pic.length; i++) 211 temp[i] = (byte) pic[i]; 212 return new ByteArrayInputStream(temp); 213 } 214 215 }

This page was automatically generated by Maven