当前位置: 首页>>代码示例>>Java>>正文


Java PathResource类代码示例

本文整理汇总了Java中org.eclipse.jetty.util.resource.PathResource的典型用法代码示例。如果您正苦于以下问题:Java PathResource类的具体用法?Java PathResource怎么用?Java PathResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PathResource类属于org.eclipse.jetty.util.resource包,在下文中一共展示了PathResource类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResource

import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
@Override
public Resource getResource(String path) {
    try {
        Resource resource = super.getResource(path);
        if (resource == null) return null;
        if (!(resource instanceof PathResource) || !resource.exists()) return resource;
        File f = resource.getFile();
        if (f.isDirectory() && !path.equals("/")) return resource;
        CacheResource cache = resourceCache.get(f);
        if (cache != null) return cache;
        if (f.length() < CACHE_LIMIT || f.getName().endsWith(".html") || path.equals("/")) {
            cache = new CacheResource((PathResource) resource);
            resourceCache.put(f, cache);
            return cache;
        }
        return resource;
    } catch (IOException e) {
        Data.logger.warn("", e);
    }
    return null;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:22,代码来源:FileHandler.java

示例2: CacheResource

import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
public CacheResource(PathResource pathResource) throws IOException {
    this.file = pathResource.getFile();
    if (this.file.isDirectory()) this.file = new File(this.file, "index.html");
    this.includes = new ArrayList<>(8);
    initCache(System.currentTimeMillis());
    pathResource.close();
    
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:9,代码来源:FileHandler.java

示例3: createdWebAppContext

import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
/**
 * Build web app context used to launch server.
 * May be override by subclasses.
 *
 * @throws Exception May be thrown by web app context initialization (will be wrapped later).
 */
private WebAppContext createdWebAppContext() throws Exception {
	final String path = configuration.getPath();
	final String webapp = configuration.getWebapp();
	final String classpath = configuration.getClasspath();
	final Collection<URL> parentClasspath = configuration.getParentClasspath();
	final String overrideDescriptor = configuration.getOverrideDescriptor ();
	final Resource baseResource = configuration.getBaseResource();

	final ClassLoader threadCl = Thread.currentThread().getContextClassLoader();
	final ClassLoader classLoader;
	if (!parentClasspath.isEmpty()) {
		int nbUrls = parentClasspath.size();
		URL[] urls = parentClasspath.toArray(new URL[nbUrls]);
		classLoader = new URLClassLoader(urls, threadCl);
	} else {
		classLoader = threadCl;
	}

	WebAppContext ctx = new WebAppContext();
	ctx.setClassLoader(classLoader);
	ctx.setContextPath(path);

	if (baseResource == null) {
		// use default base resource
		ctx.setBaseResource(newResource(webapp));
	} else {
		ctx.setBaseResource(baseResource);
	}

	if (overrideDescriptor != null) {
		ctx.setOverrideDescriptor(overrideDescriptor);
	}

	ctx.setConfigurations(new Configuration[]{
			new WebInfConfiguration(),
			new WebXmlConfiguration(),
			new AnnotationConfiguration(),
			new JettyWebXmlConfiguration(),
			new MetaInfConfiguration(),
			new FragmentConfiguration()
	});

	if (isNotBlank(classpath)) {
		// Fix to scan Spring WebApplicationInitializer
		// This will add compiled classes to jetty classpath
		// See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
		// And more precisely: http://stackoverflow.com/a/18449506/1215828
		File classes = new File(classpath);
		PathResource containerResources = new PathResource(classes.toURI());
		ctx.getMetaData().addContainerResource(containerResources);
	}

	ctx.setParentLoaderPriority(true);
	ctx.setWar(webapp);
	ctx.setServer(server);

	// Add server context
	server.setHandler(ctx);

	return ctx;
}
 
开发者ID:mjeanroy,项目名称:junit-servers,代码行数:68,代码来源:EmbeddedJetty.java

示例4: __invoke

import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws Exception {
    final boolean[] once = {false};

    ResourceHandler resourceHandler = new ResourceHandler() {
        @Override
        public Resource getResource(String path) {
            if (!once[0]) {
                once[0] = true;
                Object attr = request.getRequest().getAttribute("**");
                File file;

                if (attr != null) {
                    file = new File(PHttpResourceHandler.this.file, "/" + attr);
                } else {
                    file = new File(PHttpResourceHandler.this.file);
                }

                if (file.exists()) {
                    return new PathResource(file.getAbsoluteFile());
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    };

    resourceHandler.doStart();

    resourceHandler.setResourceBase(file());

    if (cacheControl() != null) {
        resourceHandler.setCacheControl(cacheControl());
    }

    resourceHandler.setRedirectWelcome(redirectWelcome());
    resourceHandler.setPathInfoOnly(pathInfoOnly());
    resourceHandler.setDirectoriesListed(directoriesListed());
    resourceHandler.setDirAllowed(dirAllowed());
    resourceHandler.setAcceptRanges(acceptRanges());
    resourceHandler.setEtags(etags());

    Request baseRequest = Request.getBaseRequest(request.getRequest());

    resourceHandler.handle(
            request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse()
    );
}
 
开发者ID:jphp-compiler,项目名称:jphp,代码行数:51,代码来源:PHttpResourceHandler.java


注:本文中的org.eclipse.jetty.util.resource.PathResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。