當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。