home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / www / MimeEntry.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.5 KB  |  87 lines

  1. /*
  2.  * @(#)MimeEntry.java    1.8 95/08/22
  3.  * 
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for NON-COMMERCIAL purposes and without fee is hereby
  8.  * granted provided that this copyright notice appears in all copies. Please
  9.  * refer to the file "copyright.html" for further important copyright and
  10.  * licensing information.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
  15.  * OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
  16.  * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
  17.  * ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.net.www;
  21. import java.net.URL;
  22. import java.io.*;
  23.  
  24. class MimeEntry {
  25.     String name;
  26.     String command;
  27.     String TempNameTemplate;
  28.     MimeEntry next;
  29.     boolean starred;
  30.  
  31.     MimeEntry (String nm, String cmd) {
  32.     this(nm, cmd, null);
  33.     }
  34.     MimeEntry (String nm, String cmd, String tnt) {
  35.     name = nm;
  36.     command = cmd;
  37.     TempNameTemplate = tnt;
  38.     if (nm != null && nm.length() > 0 && nm.charAt(nm.length() - 1) == '/')
  39.         starred = true;
  40.     }
  41.  
  42.     Object launch(java.net.URLConnection urlc, MimeTable mt) {
  43.     if (command.equalsIgnoreCase("loadtofile")) {
  44.         try {
  45.         return urlc.getInputStream();
  46.         } catch(Exception e) {
  47.         return "Load to file failed:\n" + e;
  48.         }
  49.     }
  50.     if (command.equalsIgnoreCase("plaintext")) {
  51.         try {
  52.         StringBuffer sb = new StringBuffer();
  53.         InputStream is = urlc.getInputStream();
  54.         int c;
  55.         try {
  56.             while ((c = is.read()) >= 0)
  57.             sb.append((char) c);
  58.         } catch(IOException e) {
  59.         }
  60.         return sb.toString();
  61.         } catch(IOException e) {
  62.         return "Failure fetching file:\n" + e.toString();
  63.         }
  64.     }
  65.     String message = command;
  66.     int fst = message.indexOf(' ');
  67.     if (fst > 0)
  68.         message = message.substring(0, fst);
  69.     return new MimeLauncher(this, urlc, mt.TempTemplate(),
  70.                 message);
  71.     // new MimeLauncher(this, is, u, mt.TempTemplate()).start();
  72.     // String message = command;
  73.     // int fst = message.indexOf(' ');
  74.     // if (fst > 0)
  75.     // message = message.substring(0, fst);
  76.     // System.out.print("Launched " + message + "\n");
  77.     // return null;
  78.     }
  79.  
  80.     boolean matches(String type) {
  81.     if (starred)
  82.         return type.startsWith(name);
  83.     else
  84.         return type.equals(name);
  85.     }
  86. }
  87.