use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class ContextHandler method getResource.
/* ------------------------------------------------------------ */
/*
*/
public Resource getResource(String path) throws MalformedURLException {
if (path == null || !path.startsWith(URIUtil.SLASH))
throw new MalformedURLException(path);
if (_baseResource == null)
return null;
try {
path = URIUtil.canonicalPath(path);
Resource resource = _baseResource.addPath(path);
if (checkAlias(path, resource))
return resource;
return null;
} catch (Exception e) {
LOG.ignore(e);
}
return null;
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class ResourceContentFactory method load.
/* ------------------------------------------------------------ */
private HttpContent load(String pathInContext, Resource resource, int maxBufferSize) throws IOException {
if (resource == null || !resource.exists())
return null;
if (resource.isDirectory())
return new ResourceHttpContent(resource, _mimeTypes.getMimeByExtension(resource.toString()), maxBufferSize);
// Look for a precompressed resource or content
String mt = _mimeTypes.getMimeByExtension(pathInContext);
if (_precompressedFormats.length > 0) {
// Is there a compressed resource?
Map<CompressedContentFormat, HttpContent> compressedContents = new HashMap<>(_precompressedFormats.length);
for (CompressedContentFormat format : _precompressedFormats) {
String compressedPathInContext = pathInContext + format._extension;
Resource compressedResource = _factory.getResource(compressedPathInContext);
if (compressedResource.exists() && compressedResource.lastModified() >= resource.lastModified() && compressedResource.length() < resource.length())
compressedContents.put(format, new ResourceHttpContent(compressedResource, _mimeTypes.getMimeByExtension(compressedPathInContext), maxBufferSize));
}
if (!compressedContents.isEmpty())
return new ResourceHttpContent(resource, mt, maxBufferSize, compressedContents);
}
return new ResourceHttpContent(resource, mt, maxBufferSize);
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class ResourceContentFactory method getContent.
/* ------------------------------------------------------------ */
@Override
public HttpContent getContent(String pathInContext, int maxBufferSize) throws IOException {
// try loading the content from our factory.
Resource resource = _factory.getResource(pathInContext);
HttpContent loaded = load(pathInContext, resource, maxBufferSize);
return loaded;
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MavenQuickStartConfiguration method deconfigure.
@Override
public void deconfigure(WebAppContext context) throws Exception {
//if we're not persisting the temp dir, get rid of any overlays
if (!context.isPersistTempDirectory()) {
Resource originalBases = (Resource) context.getAttribute("org.eclipse.jetty.resources.originalBases");
String originalBaseStr = originalBases.toString();
//Iterate over all of the resource bases and ignore any that were original bases, just
//deleting the overlays
Resource res = context.getBaseResource();
if (res instanceof ResourceCollection) {
for (Resource r : ((ResourceCollection) res).getResources()) {
if (originalBaseStr.contains(r.toString()))
continue;
IO.delete(r.getFile());
}
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MavenWebInfConfiguration method unpackOverlay.
protected Resource unpackOverlay(WebAppContext context, Overlay overlay) throws IOException {
LOG.debug("Unpacking overlay: " + overlay);
if (overlay.getResource() == null)
//nothing to unpack
return null;
//Get the name of the overlayed war and unpack it to a dir of the
//same name in the temporary directory
String name = overlay.getResource().getName();
if (name.endsWith("!/"))
name = name.substring(0, name.length() - 2);
int i = name.lastIndexOf('/');
if (i > 0)
name = name.substring(i + 1, name.length());
name = name.replace('.', '_');
//add some digits to ensure uniqueness
name = name + (++COUNTER);
File dir = new File(context.getTempDirectory(), name);
//if specified targetPath, unpack to that subdir instead
File unpackDir = dir;
if (overlay.getConfig() != null && overlay.getConfig().getTargetPath() != null)
unpackDir = new File(dir, overlay.getConfig().getTargetPath());
overlay.getResource().copyTo(unpackDir);
//use top level of unpacked content
Resource unpackedOverlay = Resource.newResource(dir.getCanonicalPath());
LOG.debug("Unpacked overlay: " + overlay + " to " + unpackedOverlay);
return unpackedOverlay;
}
Aggregations