changes from review
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
a5817144f6
commit
0f1420fbd7
|
@ -17,23 +17,32 @@ import java.io.IOException;
|
|||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
public class StaticHttpContentFactory implements HttpContent.Factory
|
||||
/**
|
||||
* An {@link HttpContent.Factory} implementation which takes a Resource and fakes this resource as
|
||||
* an entry in every directory. If any request is made for this resources file name, and it is not
|
||||
* already present in that directory then the resource contained in this factory will be served instead.
|
||||
*/
|
||||
public class VirtualHttpContentFactory implements HttpContent.Factory
|
||||
{
|
||||
private final HttpContent.Factory _factory;
|
||||
private final Resource _styleSheet;
|
||||
private final Resource _resource;
|
||||
private final String _contentType;
|
||||
private final String _matchSuffix;
|
||||
|
||||
public StaticHttpContentFactory(HttpContent.Factory factory, Resource styleSheet)
|
||||
public VirtualHttpContentFactory(HttpContent.Factory factory, Resource resource, String contentType)
|
||||
{
|
||||
_factory = factory;
|
||||
_styleSheet = styleSheet;
|
||||
_resource = resource;
|
||||
_matchSuffix = "/" + _resource.getFileName();
|
||||
_contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the stylesheet as a Resource.
|
||||
*/
|
||||
public Resource getStyleSheet()
|
||||
public Resource getResource()
|
||||
{
|
||||
return _styleSheet;
|
||||
return _resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,10 +51,13 @@ public class StaticHttpContentFactory implements HttpContent.Factory
|
|||
HttpContent content = _factory.getContent(path);
|
||||
if (content != null)
|
||||
return content;
|
||||
|
||||
if ((_styleSheet != null) && (path != null) && path.endsWith("/jetty-dir.css"))
|
||||
return new ResourceHttpContent(_styleSheet, "text/css");
|
||||
|
||||
if (matchResource(path))
|
||||
return new ResourceHttpContent(_resource, _contentType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean matchResource(String path)
|
||||
{
|
||||
return (_resource != null) && (path != null) && path.endsWith(_matchSuffix);
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@ import org.eclipse.jetty.http.content.FileMappingHttpContentFactory;
|
|||
import org.eclipse.jetty.http.content.HttpContent;
|
||||
import org.eclipse.jetty.http.content.PreCompressedHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ResourceHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.StaticHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.VirtualHttpContentFactory;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.NoopByteBufferPool;
|
||||
import org.eclipse.jetty.server.Context;
|
||||
|
@ -106,7 +106,7 @@ public class ResourceHandler extends Handler.Wrapper
|
|||
{
|
||||
HttpContent.Factory contentFactory = new ResourceHttpContentFactory(ResourceFactory.of(getBaseResource()), getMimeTypes());
|
||||
contentFactory = new FileMappingHttpContentFactory(contentFactory);
|
||||
contentFactory = new StaticHttpContentFactory(contentFactory, getStyleSheet());
|
||||
contentFactory = new VirtualHttpContentFactory(contentFactory, getStyleSheet(), "text/css");
|
||||
contentFactory = new PreCompressedHttpContentFactory(contentFactory, getPrecompressedFormats());
|
||||
contentFactory = new ValidatingCachingHttpContentFactory(contentFactory, Duration.ofSeconds(1).toMillis(), getByteBufferPool());
|
||||
return contentFactory;
|
||||
|
|
|
@ -47,8 +47,8 @@ import org.eclipse.jetty.http.content.FileMappingHttpContentFactory;
|
|||
import org.eclipse.jetty.http.content.HttpContent;
|
||||
import org.eclipse.jetty.http.content.PreCompressedHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ResourceHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.StaticHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.VirtualHttpContentFactory;
|
||||
import org.eclipse.jetty.logging.StacklessLogging;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
|
@ -668,7 +668,7 @@ public class ResourceHandlerTest
|
|||
{
|
||||
HttpContent.Factory contentFactory = new ResourceHttpContentFactory(ResourceFactory.of(getBaseResource()), getMimeTypes());
|
||||
contentFactory = new FileMappingHttpContentFactory(contentFactory);
|
||||
contentFactory = new StaticHttpContentFactory(contentFactory, getStyleSheet());
|
||||
contentFactory = new VirtualHttpContentFactory(contentFactory, getStyleSheet(), "text/css");
|
||||
contentFactory = new PreCompressedHttpContentFactory(contentFactory, getPrecompressedFormats());
|
||||
contentFactory = new ValidatingCachingHttpContentFactory(contentFactory, 0, getByteBufferPool());
|
||||
return contentFactory;
|
||||
|
|
|
@ -57,8 +57,8 @@ import org.eclipse.jetty.http.content.FileMappingHttpContentFactory;
|
|||
import org.eclipse.jetty.http.content.HttpContent;
|
||||
import org.eclipse.jetty.http.content.PreCompressedHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ResourceHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.StaticHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.VirtualHttpContentFactory;
|
||||
import org.eclipse.jetty.io.ByteBufferInputStream;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.NoopByteBufferPool;
|
||||
|
@ -158,7 +158,7 @@ public class DefaultServlet extends HttpServlet
|
|||
if (getInitBoolean("useFileMappedBuffer", false))
|
||||
contentFactory = new FileMappingHttpContentFactory(contentFactory);
|
||||
|
||||
contentFactory = new StaticHttpContentFactory(contentFactory, styleSheet);
|
||||
contentFactory = new VirtualHttpContentFactory(contentFactory, styleSheet, "text/css");
|
||||
contentFactory = new PreCompressedHttpContentFactory(contentFactory, precompressedFormats);
|
||||
|
||||
int maxCacheSize = getInitInt("maxCacheSize", -2);
|
||||
|
|
|
@ -33,8 +33,8 @@ import org.eclipse.jetty.http.content.FileMappingHttpContentFactory;
|
|||
import org.eclipse.jetty.http.content.HttpContent;
|
||||
import org.eclipse.jetty.http.content.PreCompressedHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ResourceHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.StaticHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.VirtualHttpContentFactory;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.NoopByteBufferPool;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -134,7 +134,7 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory,
|
|||
{
|
||||
HttpContent.Factory contentFactory = new ResourceHttpContentFactory(this, _mimeTypes);
|
||||
contentFactory = new FileMappingHttpContentFactory(contentFactory);
|
||||
contentFactory = new StaticHttpContentFactory(contentFactory, getStyleSheet());
|
||||
contentFactory = new VirtualHttpContentFactory(contentFactory, getStyleSheet(), "text/css");
|
||||
contentFactory = new PreCompressedHttpContentFactory(contentFactory, _resourceService.getPrecompressedFormats());
|
||||
contentFactory = new ValidatingCachingHttpContentFactory(contentFactory, Duration.ofSeconds(1).toMillis(), _byteBufferPool);
|
||||
return contentFactory;
|
||||
|
|
|
@ -39,8 +39,8 @@ import org.eclipse.jetty.http.content.FileMappingHttpContentFactory;
|
|||
import org.eclipse.jetty.http.content.HttpContent;
|
||||
import org.eclipse.jetty.http.content.PreCompressedHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ResourceHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.StaticHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory;
|
||||
import org.eclipse.jetty.http.content.VirtualHttpContentFactory;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.NoopByteBufferPool;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -253,7 +253,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
|
|||
contentFactory = new ResourceHttpContentFactory(this, _mimeTypes);
|
||||
if (_useFileMappedBuffer)
|
||||
contentFactory = new FileMappingHttpContentFactory(contentFactory);
|
||||
contentFactory = new StaticHttpContentFactory(contentFactory, _styleSheet);
|
||||
contentFactory = new VirtualHttpContentFactory(contentFactory, _styleSheet, "text/css");
|
||||
contentFactory = new PreCompressedHttpContentFactory(contentFactory, _resourceService.getPrecompressedFormats());
|
||||
|
||||
int maxCacheSize = getInitInt("maxCacheSize", -2);
|
||||
|
|
Loading…
Reference in New Issue