1 9 package org.openuss.utility; 10 11 import com.lutris.appserver.server.httpPresentation.*; 12 13 import com.lutris.mime.*; 14 15 17 import java.io.*; 18 19 import java.rmi.*; 20 21 import java.text.*; 22 23 import java.util.*; 24 25 import org.w3c.dom.*; 26 import org.w3c.dom.html.*; 27 28 29 37 public class UploadFileHelper { 38 protected static String FILE_DATE = "Date"; 40 protected static String FILE_NAME = "Filename"; 41 protected static String FILE_TITLE = "Name"; 42 protected static String FILE_FILE = "File"; 43 44 protected String title; 46 protected String filename; 47 protected String date; 48 protected FileObjectWrapper fileObject; 49 50 53 public UploadFileHelper() throws Exception { 54 } 56 57 60 public UploadFileHelper(HttpPresentationComms comms) 61 throws Exception { 62 this(); 63 64 65 calculateData(comms); 67 } 68 69 72 public String getTitle() { 73 return title; 74 } 75 76 79 public void setTitle(String title) { 80 this.title = title; 81 } 82 83 86 public String getDate() { 87 return date; 88 } 89 90 93 public void setDate(String date) { 94 this.date = date; 95 } 96 97 100 public String getFilename() { 101 return filename; 102 } 103 104 107 public void setFilename(String filename) { 108 this.filename = filename; 109 } 110 111 114 public long getSize() { 115 if (fileObject != null) { 116 byte[] data = fileObject.getData(); 118 long fileSize = data.length; 119 120 long result = (fileSize / 1024) + 1; 123 124 return result; 125 } else { 126 return 0; 128 } 129 } 130 131 134 public FileObjectWrapper getFileObject() { 135 return fileObject; 136 } 137 138 141 public void setFileObject(FileObjectWrapper fileObject) { 142 this.fileObject = fileObject; 143 } 144 145 148 protected void calculateData(HttpPresentationComms comms) 149 throws Exception { 150 String contentType = comms.request.getContentType(); 152 153 if (contentType == null) { 154 contentType = ""; 155 } 156 157 ContentHeader contentHdr = new ContentHeader("Content-Type: " + 159 contentType); 160 161 HttpPresentationInputStream input = comms.request.getInputStream(); 163 164 MultipartMimeInput mime = new MultipartMimeInput(input, contentHdr); 166 MultipartMimeInputStream in; 167 168 while ((in = mime.nextPart()) != null) { 170 MimeHeader hdr = in.getHeader("Content-Disposition"); 171 172 if (hdr != null) { 174 String contentName = null; 175 176 ContentHeader chdr = new ContentHeader(hdr); 177 contentName = chdr.getParameter("name"); 178 179 if (contentName.equals(FILE_FILE)) { 181 196 197 int n; 199 byte[] buffer = new byte[1024]; 200 201 ByteArrayOutputStream outByte = new ByteArrayOutputStream(); 202 203 while ((n = in.read(buffer, 0, buffer.length)) > 0) { 204 outByte.write(buffer, 0, n); 205 } 206 207 208 outByte.flush(); 210 211 byte[] data = outByte.toByteArray(); 212 213 if (outByte.size() > 0) { 215 fileObject = new FileObjectWrapper(data); 216 } 217 218 outByte.close(); 219 } 220 221 if (contentName.equals(FILE_TITLE)) { 223 int n; 224 byte[] buffer = new byte[1024]; 225 226 StringBuffer sb = new StringBuffer (); 227 228 while ((n = in.read(buffer, 0, buffer.length)) > 0) { 229 for (int i = 0; i < n; i++) { 230 sb.append((char) (((int) (buffer[i]) + 0x100) & 231 0xff)); 232 } 233 } 234 235 236 title = new String (sb); 238 } 239 240 if (contentName.equals(FILE_DATE)) { 242 int n; 243 byte[] buffer = new byte[1024]; 244 245 StringBuffer sb = new StringBuffer (); 246 247 while ((n = in.read(buffer, 0, buffer.length)) > 0) { 248 for (int i = 0; i < n; i++) { 249 sb.append((char) (((int) (buffer[i]) + 0x100) & 250 0xff)); 251 } 252 } 253 254 255 date = new String (sb); 257 } 258 259 if (contentName.equals(FILE_NAME)) { 261 int n; 262 byte[] buffer = new byte[1024]; 263 264 StringBuffer sb = new StringBuffer (); 265 266 while ((n = in.read(buffer, 0, buffer.length)) > 0) { 267 for (int i = 0; i < n; i++) { 268 sb.append((char) (((int) (buffer[i]) + 0x100) & 269 0xff)); 270 } 271 } 272 273 274 filename = new String (sb); 276 } 277 } 278 279 280 in.close(); 282 } 283 } 284 } | Popular Tags |