home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_07.cab / Response.java < prev    next >
Encoding:
Java Source  |  1997-09-04  |  5.3 KB  |  218 lines

  1. /*    ********************************************************************************
  2.     Response.java ******************************************************************
  3.     ********************************************************************************  */
  4.  
  5. package aspcomp;
  6.  
  7. import com.ms.asp.*;
  8. import com.ms.com.*;
  9. import java.io.*;
  10. import java.util.*;
  11.  
  12. /**
  13.  * Cover class for the ASP Response intrinsic.
  14.  */
  15.  
  16. public class Response extends OutputStream
  17. {
  18.  
  19. /*
  20.     Consider: 1) May want an HTTPHeader class that breaks apart the two strings in a 
  21.                  header. We would want static definitions in it for common headers.
  22.               2) May want a CharSet class to deal with character sets.
  23.               3) May want a MIMEType class that breaks apart the two strings there. 
  24.                  We would want static definitions within it for common MIME types.
  25.               4) May want a CacheControl class to deal with cache control settings.
  26.               5) May want a Pics class to deal with PICS settings.
  27. */
  28.  
  29. /*    ********************************************************************************
  30.     Constructor ********************************************************************
  31.     ********************************************************************************  */
  32.  
  33.     public Response(IResponse response) 
  34.     {
  35.         m_IResponse = response;
  36.     }
  37.  
  38.  
  39. /*    ********************************************************************************
  40.     Internal (Private) Variables ***************************************************
  41.     ********************************************************************************  */
  42.  
  43.     private IResponse m_IResponse;
  44.  
  45.  
  46. /*    ********************************************************************************
  47.     External (Public) Methods ******************************************************
  48.     ********************************************************************************  */
  49.  
  50.     public void addHeader(String name, String value) 
  51.     {
  52.         m_IResponse.AddHeader(name, value);
  53.     }
  54.  
  55.     public boolean getBuffered() 
  56.     {
  57.         return m_IResponse.getBuffer();
  58.     }
  59.  
  60.     public void setBuffered(boolean fIsBuffered) 
  61.     {
  62.         m_IResponse.putBuffer(fIsBuffered);
  63.     }
  64.  
  65.     public int getExpires() 
  66.     {
  67.         return VariantToJava.getInt(m_IResponse.getExpires());
  68.     }
  69.  
  70.     public void setExpires(int iExpirationMinutes) 
  71.     {
  72.         m_IResponse.putExpires(iExpirationMinutes);
  73.     }
  74.  
  75.     public Date getExpiresAbsolute() 
  76.     {
  77.         return VariantToJava.getDate(m_IResponse.getExpiresAbsolute());
  78.     }
  79.  
  80.     public void setExpiresAbsolute(Date dateExpire) 
  81.     {
  82.         m_IResponse.putExpiresAbsolute(JavaToVariant.dateToDouble(dateExpire));
  83.     }
  84.  
  85.     public String getCharSet() 
  86.     {
  87.         return m_IResponse.getCharSet();
  88.     }
  89.  
  90.     public void setCharSet(String strCharSet) 
  91.     {
  92.         m_IResponse.putCharSet(strCharSet);
  93.     }
  94.  
  95.     public String getContentType() 
  96.     {
  97.         return m_IResponse.getContentType();
  98.     }
  99.  
  100.     public void setContentType(String strContentType) 
  101.     {
  102.         m_IResponse.putContentType(strContentType);
  103.     }
  104.  
  105.     public String getCacheControl() 
  106.     {
  107.         return m_IResponse.getCacheControl();
  108.     }
  109.  
  110.     public void setCacheControl(String strCacheControl) 
  111.     {
  112.         m_IResponse.putCacheControl(strCacheControl);
  113.     }
  114.  
  115.     public String getStatus() 
  116.     {
  117.         return m_IResponse.getStatus();
  118.     }
  119.  
  120.     public void setStatus(String strStatus) 
  121.     {
  122.         m_IResponse.putStatus(strStatus);
  123.     }
  124.  
  125.     public void appendToLog(String s) 
  126.     {
  127.         m_IResponse.AppendToLog(s);
  128.     }
  129.  
  130.     public boolean isClientConnected() 
  131.     {
  132.         return m_IResponse.IsClientConnected();
  133.     }
  134.  
  135.     public void end() 
  136.     {
  137.         m_IResponse.End();
  138.     }
  139.  
  140.     public void clear() 
  141.     {
  142.         m_IResponse.Clear();
  143.     }
  144.  
  145. //    public void flush() is covered below (overriding OutputStream.flush()).
  146.  
  147.     public void write(String str) 
  148.     {
  149.         m_IResponse.Write(new Variant(str));
  150.     }
  151.  
  152.     public void pics(String str) 
  153.     {
  154.         m_IResponse.Pics(str);
  155.     }
  156.  
  157.     public void redirect(String str) 
  158.     {
  159.         m_IResponse.Redirect(str);
  160.     }
  161.  
  162.     public CookieDictionary getCookies()  
  163.     {
  164.         return new CookieDictionary(m_IResponse.getCookies());
  165.     }
  166.  
  167.  
  168. /*    ********************************************************************************
  169.     External (Public) java.io.OutputStream Interface Methods ***********************
  170.     ********************************************************************************  */
  171.  
  172.     public void write(int i) 
  173.         throws IOException,
  174.                NullPointerException,
  175.                 IndexOutOfBoundsException
  176.     {
  177.         byte [] b = new byte[1];
  178.         b[0] = (byte) i;
  179.         write(b, 0, 1);
  180.     }
  181.  
  182.     public void write(byte[] b) 
  183.         throws IOException,
  184.                NullPointerException,
  185.                IndexOutOfBoundsException
  186.     {
  187.         write(b, 0, b.length);
  188.     }
  189.  
  190.     public void write(byte[] b, int off, int len) 
  191.         throws IOException,
  192.                 NullPointerException,
  193.                 IndexOutOfBoundsException
  194.     {
  195.         SafeArray sa = new SafeArray(Variant.VariantByte, len);
  196.         sa.setBytes(0, len, b, off);
  197.         Variant v = new Variant(sa, true);
  198.         m_IResponse.BinaryWrite(v);
  199.     }
  200.  
  201.     public void close() 
  202.         throws IOException
  203.     {
  204.         // Nothing to do here -- we don't have to close the ASP response stream
  205.     }
  206.  
  207.     public void flush() 
  208.         throws IOException
  209.     {
  210.         // Can only flush if ASP buffering is on
  211.         if (getBuffered() == true)
  212.         {
  213.             m_IResponse.Flush();
  214.         }
  215.     }
  216.  
  217. }
  218.