322448 Added jetty-dir.css for directory listings

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2214 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-08-16 14:36:39 +00:00
parent a456b2b600
commit 50de9c814e
11 changed files with 15239 additions and 49 deletions

View File

@ -12,6 +12,7 @@ jetty-7.2-SNAPSHOT
+ 321307 HashSessionManager calls passivation listeners.
+ 321730 SelectChannelEndPoint prints to System.err
+ 321735 HttpClient onException called for buffer overflow.
+ 322448 Added jetty-dir.css for directory listings
+ 322683 RewriteHandler thread safety
+ JETTY-912 added per exchange timeout api
+ JETTY-1245 Do not use direct buffers with NIO SSL
@ -30,7 +31,6 @@ jetty-7.1.6.v20100715
+ JETTY-1249 Apply max idle time to all connectors
+ JETTY-1251 Replace then close selector for JVM bugs
jetty-7.1.5.v20100705
+ Update ecj to 3.6 Helios release drop
+ 288194 Add blacklist/whitelist to ProxyServlet and ProxyHandler

View File

@ -16,6 +16,9 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -52,6 +55,8 @@ public class ResourceHandler extends AbstractHandler
{
ContextHandler _context;
Resource _baseResource;
Resource _defaultStylesheet;
Resource _stylesheet;
String[] _welcomeFiles={"index.html"};
MimeTypes _mimeTypes = new MimeTypes();
ByteArrayBuffer _cacheControl;
@ -61,6 +66,7 @@ public class ResourceHandler extends AbstractHandler
/* ------------------------------------------------------------ */
public ResourceHandler()
{
}
/* ------------------------------------------------------------ */
@ -181,6 +187,57 @@ public class ResourceHandler extends AbstractHandler
throw new IllegalArgumentException(resourceBase);
}
}
/* ------------------------------------------------------------ */
/**
* @return Returns the stylesheet as a Resource.
*/
public Resource getStylesheet()
{
if(_stylesheet != null)
{
return _stylesheet;
}
else
{
if(_defaultStylesheet == null)
{
try
{
_defaultStylesheet = Resource.newResource(this.getClass().getResource("/jetty-default.css"));
}
catch(IOException e)
{
Log.warn(e.toString());
Log.debug(e);
}
}
return _defaultStylesheet;
}
}
/* ------------------------------------------------------------ */
/**
* @param stylesheet The location of the stylesheet to be used as a String.
*/
public void setStylesheet(String stylesheet)
{
try
{
_stylesheet = Resource.newResource(stylesheet);
if(!_stylesheet.exists())
{
Log.warn("unable to find custom stylesheet: " + stylesheet);
_stylesheet = null;
}
}
catch(Exception e)
{
Log.warn(e.toString());
Log.debug(e);
throw new IllegalArgumentException(stylesheet.toString());
}
}
/* ------------------------------------------------------------ */
/**
@ -282,11 +339,19 @@ public class ResourceHandler extends AbstractHandler
return;
skipContentBody = true;
}
Resource resource=getResource(request);
Resource resource = getResource(request);
if (resource==null || !resource.exists())
return;
{
if (target.endsWith("/jetty-stylesheet.css"))
{
response.setContentType("text/css");
resource = getStylesheet();
}
else
return;
}
if (!_aliases && resource.getAlias()!=null)
{
Log.info(resource+" aliased to "+resource.getAlias());

View File

@ -16,7 +16,6 @@ package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
@ -100,6 +99,9 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.
*
* aliases If True, aliases of resources are allowed (eg. symbolic
* links and caps variations). May bypass security constraints.
*
@ -141,6 +143,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
private MimeTypes _mimeTypes;
private String[] _welcomes;
private Resource _stylesheet;
private boolean _useFileMappedBuffer=false;
private ByteArrayBuffer _cacheControl;
private String _relativeResourceBase;
@ -151,7 +154,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------ */
@Override
public void init()
throws UnavailableException
throws UnavailableException
{
_servletContext=getServletContext();
ContextHandler.Context scontext=ContextHandler.getCurrentContext();
@ -205,6 +208,29 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
}
}
String css=getInitParameter("stylesheet");
try
{
if(css!=null)
{
_stylesheet = Resource.newResource(css);
if(!_stylesheet.exists())
{
Log.warn("!" + css);
_stylesheet = null;
}
}
if(_stylesheet == null)
{
_stylesheet = Resource.newResource(this.getClass().getResource("/jetty-dir.css"));
}
}
catch(Exception e)
{
Log.warn(e.toString());
Log.debug(e);
}
String t=getInitParameter("cacheControl");
if (t!=null)
_cacheControl=new ByteArrayBuffer(t);
@ -258,9 +284,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
public String getInitParameter(String name)
{
String value=getServletContext().getInitParameter("org.eclipse.jetty.servlet.Default."+name);
if (value==null)
value=super.getInitParameter(name);
return value;
if (value==null)
value=super.getInitParameter(name);
return value;
}
/* ------------------------------------------------------------ */
@ -280,7 +306,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
private int getInitInt(String name, int dft)
{
String value=getInitParameter(name);
if (value==null)
if (value==null)
value=getInitParameter(name);
if (value!=null && value.length()>0)
return Integer.parseInt(value);
@ -296,15 +322,16 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
* @return The resource to serve.
*/
public Resource getResource(String pathInContext)
{
{
Resource r=null;
if (_relativeResourceBase!=null)
pathInContext=URIUtil.addPaths(_relativeResourceBase,pathInContext);
try
{
if (_resourceBase!=null)
if (_resourceBase!=null){
r = _resourceBase.addPath(pathInContext);
}
else
{
URL u = _servletContext.getResource(pathInContext);
@ -318,6 +345,10 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
{
Log.ignore(e);
}
if((r==null || !r.exists()) && pathInContext.endsWith("/jetty-dir.css"))
r=_stylesheet;
return r;
}
@ -325,7 +356,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
@SuppressWarnings("unchecked")
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
throws ServletException, IOException
{
String servletPath=null;
String pathInfo=null;
@ -369,7 +400,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
// Find the resource and content
Resource resource=null;
HttpContent content=null;
try
{
// Try gzipped content first
@ -436,24 +467,24 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
pathInContext+="?"+q;
response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(_servletContext.getContextPath(),pathInContext)));
}
else
{
// ensure we have content
if (content==null)
content=new UnCachedContent(resource);
else
{
// ensure we have content
if (content==null)
content=new UnCachedContent(resource);
if (included.booleanValue() || passConditionalHeaders(request,response, resource,content))
{
if (gzip)
{
response.setHeader(HttpHeaders.CONTENT_ENCODING,"gzip");
String mt=_servletContext.getMimeType(pathInContext);
if (mt!=null)
response.setContentType(mt);
}
sendData(request,response,included.booleanValue(),resource,content,reqRanges);
}
}
if (included.booleanValue() || passConditionalHeaders(request,response, resource,content))
{
if (gzip)
{
response.setHeader(HttpHeaders.CONTENT_ENCODING,"gzip");
String mt=_servletContext.getMimeType(pathInContext);
if (mt!=null)
response.setContentType(mt);
}
sendData(request,response,included.booleanValue(),resource,content,reqRanges);
}
}
}
else
{
@ -541,7 +572,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------ */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
throws ServletException, IOException
{
doGet(request,response);
}
@ -559,11 +590,11 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------ */
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
throws ServletException, IOException
{
resp.setHeader("Allow", "GET,HEAD,POST,OPTIONS");
}
/* ------------------------------------------------------------ */
/**
* Finds a matching welcome file for the supplied {@link Resource}. This will be the first entry in the list of
@ -595,7 +626,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
Map.Entry entry=_servletHandler.getHolderEntry(welcome_in_context);
if (entry!=null && entry.getValue()!=_defaultHolder &&
(_welcomeServlets || (_welcomeExactServlets && entry.getKey().equals(welcome_in_context))))
welcome_servlet=welcome_in_context;
welcome_servlet=welcome_in_context;
}
}
@ -669,9 +700,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------------- */
protected void sendDirectory(HttpServletRequest request,
HttpServletResponse response,
Resource resource,
String pathInContext)
HttpServletResponse response,
Resource resource,
String pathInContext)
throws IOException
{
if (!_dirAllowed)
@ -705,11 +736,11 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------ */
protected void sendData(HttpServletRequest request,
HttpServletResponse response,
boolean include,
Resource resource,
HttpContent content,
Enumeration reqRanges)
HttpServletResponse response,
boolean include,
Resource resource,
HttpContent content,
Enumeration reqRanges)
throws IOException
{
boolean direct;
@ -725,8 +756,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
direct=connector instanceof NIOConnector && ((NIOConnector)connector).getUseDirectBuffers() && !(connector instanceof SslConnector);
content_length=content.getContentLength();
}
// Get the output stream (or writer)
OutputStream out =null;
try{out = response.getOutputStream();}
@ -887,7 +918,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
/* ------------------------------------------------------------ */
protected void writeHeaders(HttpServletResponse response,HttpContent content,long count)
throws IOException
throws IOException
{
if (content.getContentType()!=null && response.getContentType()==null)
response.setContentType(content.getContentType().toString());
@ -990,7 +1021,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
{
return null;
}
/* ------------------------------------------------------------ */
public Buffer getIndirectBuffer()
{

View File

@ -484,7 +484,8 @@ public abstract class Resource
String title = "Directory: "+deTag(decodedBase);
StringBuilder buf=new StringBuilder(4096);
buf.append("<HTML><HEAD><TITLE>");
buf.append("<HTML><HEAD>");
buf.append("<LINK HREF=\"").append("jetty-dir.css").append("\" REL=\"stylesheet\" TYPE=\"text/css\"/><TITLE>");
buf.append(title);
buf.append("</TITLE></HEAD><BODY>\n<H1>");
buf.append(title);

View File

@ -0,0 +1,31 @@
body
{
background-color: #FFFFFF;
margin: 10px;
padding: 5px;
}
h1
{
text-shadow: #000000 -1px -1px 1px;
color: #FC390E;
font-weight: bold;
}
a
{
color: #7036be;
font-weight: bold;
font-style: normal;
text-decoration: none;
font-size:inherit;
}
td
{
font-style: italic;
padding: 2px 15px 2px 0px;
}

View File

@ -0,0 +1,10 @@
0000 0000000000000000000000000000000000000000000000000000000
0001 0000000000000000000000000000000000000000000000000000000
0002 0000000000000000000000000000000000000000000000000000000
0003 0000000000000000000000000000000000000000000000000000000
0004 0000000000000000000000000000000000000000000000000000000
0005 0000000000000000000000000000000000000000000000000000000
0006 0000000000000000000000000000000000000000000000000000000
0007 0000000000000000000000000000000000000000000000000000000
0008 0000000000000000000000000000000000000000000000000000000
0009 0000000000000000000000000000000000000000000000000000000

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
body
{
margin: 10px;
padding: 5px;
}
h1
{
text-shadow: #000000 -1px -1px 1px;
}
a
{
font-weight: bold;
font-style: normal;
text-decoration: none;
font-size:inherit;
}
td
{
font-style: italic;
}

View File

@ -0,0 +1,26 @@
body
{
margin: 10px;
padding: 5px;
}
h1
{
text-shadow: #000000 -1px -1px 1px;
}
a
{
font-weight: bold;
font-style: normal;
text-decoration: none;
font-size:inherit;
}
td
{
font-style: italic;
}