Package org.apache.tomcat.core

Examples of org.apache.tomcat.core.OutputBuffer


  FileInputStream in=null;
  try {
      in = new FileInputStream(file);

      OutputBuffer out=res.getBuffer();
      byte[] buf = new byte[1024];
      int read = 0;
     
      while ((read = in.read(buf)) != -1) {
    out.write(buf, 0, read);
      }
  } catch (FileNotFoundException e) {
      // Figure out what we're serving
      context.getContextManager().handleStatus( req, res, 404);
  } finally {
View Full Code Here


        context.getContextManager().handleStatus( req, res, 404);
        return;
    }
  }

  OutputBuffer buf=res.getBuffer();
  if( sbNote==0 ) {
      //sbNote=req.getContextManager().
      //    getNoteId(ContextManager.REQUEST_NOTE,
      //          "RedirectHandler.buff");
      sbNote=req.getContextManager().
    getNoteId(ContextManager.REQUEST_NOTE,"uft8encoder");
  }

  // we can recycle it because
  // we don't call toString();
  //   StringBuffer buf=(StringBuffer)req.getNote( sbNote );
  //   if( buf==null ) {
  //       buf = new StringBuffer();
  //       req.setNote( sbNote, buf );
  //   }

  UEncoder utfEncoder=(UEncoder)req.getNote( sbNote );
  if( utfEncoder==null ) {
      utfEncoder=new UEncoder();
      utfEncoder.addSafeCharacter( '/' );
  }

  if (! inInclude) {
           if (charset == null || charset.equalsIgnoreCase("ISO-8859-1"))
               res.setContentType("text/html");
           else {
               res.setContentType("text/html; charset=" + charset);
               res.setUsingWriter(true);
           }
      buf.write("<html>\r\n");
      buf.write("<head>\r\n");
      buf.write("<title>");
      buf.write(sm.getString("defaultservlet.directorylistingfor"));
      buf.write(requestURI);
      buf.write("</title>\r\n</head><body bgcolor=white>\r\n");
  }

  buf.write("<table width=90% cellspacing=0 ");
  buf.write("cellpadding=5 align=center>");
  buf.write("<tr><td colspan=3><font size=+2><strong>");
  buf.write(sm.getString("defaultservlet.directorylistingfor"));
  buf.write(requestURI);
  buf.write("</strong></td></tr>\r\n");

  if (! pathInfo.equals("/")) {
      buf.write("<tr><td colspan=3 bgcolor=#ffffff>");
      //buf.write("<a href=\"../\">Up one directory");
     
      String toPath = requestURI;

      if (toPath.endsWith("/")) {
    toPath = toPath.substring(0, toPath.length() - 1);
      }
     
      toPath = toPath.substring(0, toPath.lastIndexOf("/"));
     
      //if (toPath.length() == 0) {
      //toPath = "/";
      //}
      // Add trailing "/"
      toPath += "/";
     
      buf.write("<a href=\"");
      utfEncoder.urlEncode( buf, toPath);
      buf.write( "\"><tt>" );
      buf.write( sm.getString("defaultservlet.upto"));
      buf.write( toPath);
      buf.write("</tt></a></td></tr>\r\n");
  }

  // Pre-calculate the request URI for efficiency

  // Make another URI that definitely ends with a /
  String slashedRequestURI = null;

  if (requestURI.endsWith("/")) {
      slashedRequestURI = requestURI;
  } else {
      slashedRequestURI = requestURI + "/";
  }

  String[] fileNames = file.list();
  boolean dirsHead=true;
  boolean shaderow = false;

  for (int i = 0; i < fileNames.length; i++) {
      String fileName = fileNames[i];

            // Don't display special dirs at top level
      if( (pathInfo.length() == 0 || "/".equals(pathInfo)) &&
         "WEB-INF".equalsIgnoreCase(fileName) ||
         "META-INF".equalsIgnoreCase(fileName) )
        continue;

      File f = new File(file, fileName);

      if (f.isDirectory()) {
    if( dirsHead ) {
        dirsHead=false;
        buf.write("<tr><td colspan=3 bgcolor=#cccccc>");
        buf.write("<font size=+2><strong>");
        buf.write( sm.getString("defaultservlet.subdirectories"));
        buf.write( "</strong>\r\n");
        buf.write("</font></td></tr>\r\n");
    }

                String fileN = f.getName();

                buf.write("<tr");

                if (shaderow) buf.write(" bgcolor=#eeeeee");
    shaderow=!shaderow;
   
                buf.write("><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                buf.write("<tt><a href=\"");
    utfEncoder.urlEncode( buf, slashedRequestURI);
    utfEncoder.urlEncode( buf, fileN);
    buf.write("/\">");
    buf.write(fileN);
    buf.write("/</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    buf.write("</tt>\r\n");
                buf.write("</td><td><tt>&nbsp;&nbsp;</tt></td>");
                buf.write("<td align=right><tt>");
    buf.write(dateFormat.format(new Date(f.lastModified())));
                buf.write("</tt></td></tr>\r\n");
      }
  }

  shaderow = false;
  buf.write("<tr><td colspan=3 bgcolor=#ffffff>&nbsp;</td></tr>");
  boolean fileHead=true;
 
  for (int i = 0; i < fileNames.length; i++) {
      File f = new File(file, fileNames[i]);

      if (f.isFile()) {
    String fileN = f.getName();
   
    if( fileHead ) {
        fileHead=false;
        buf.write("<tr><td colspan=4 bgcolor=#cccccc>");
        buf.write("<font size=+2><strong>");
        buf.write(sm.getString("defaultservlet.files"));
        buf.write("</strong></font></td></tr>");
    }

    buf.write("<tr");

    if (shaderow) buf.write(" bgcolor=#eeeeee");
    shaderow = ! shaderow;
   
    buf.write("><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\r\n");

    buf.write("<tt><a href=\"");
    utfEncoder.urlEncode( buf, slashedRequestURI);
    utfEncoder.urlEncode( buf, fileN);
    buf.write("\">");
    buf.write( fileN );
    buf.write( "</a>");
    buf.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>");
    buf.write("</td>\r\n");

    buf.write("<td align=right><tt>");
    displaySize( buf, (int)f.length());
    buf.write("</tt></td>");

    buf.write("<td align=right><tt>");
    buf.write(dateFormat.format(new Date(f.lastModified())));
    buf.write("</tt></td></tr>\r\n");
      }
     
      buf.write("\r\n");
  }
 
  buf.write("<tr><td colspan=3 bgcolor=#ffffff>&nbsp;</td></tr>");
  buf.write("<tr><td colspan=3 bgcolor=#cccccc>");
  buf.write("<font size=-1>");
  buf.write(ContextManager.TOMCAT_NAME);
  buf.write(" v");
  buf.write(ContextManager.TOMCAT_VERSION);
  buf.write("</font></td></tr></table>");
 
  if (! inIncludebuf.write("</body></html>\r\n");

    //   res.getBuffer().write(buf);
    //   buf.setLength(0);
    }
View Full Code Here

    /** Package
     */
    HttpServletResponseFacade(Response response) {
        this.response = response;
  OutputBuffer oBuffer= response.getBuffer();
  writer = new ServletWriterFacade( oBuffer, response);
    }
View Full Code Here

    void recycle() {
  usingStream = false;
  usingWriter= false;
  if( writer.checkError() ) {
      OutputBuffer oBuffer= response.getBuffer();
      writer = new ServletWriterFacade( oBuffer, response);
  }
  if( osFacade != null ) osFacade.recycle();
    }
View Full Code Here

TOP

Related Classes of org.apache.tomcat.core.OutputBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.