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


Java Resource.newResource方法代码示例

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


在下文中一共展示了Resource.newResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  this.servletConfig = servletConfig;

  //templateCfg.setClassForTemplateLoading(getClass(), "/");
  Resource baseResource;
  try {
    baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
  } catch (MalformedURLException e) {
    throw new ServletException(e);
  }
  templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
  templateCfg.setDefaultEncoding("UTF-8");

  // Sets how errors will appear.
  // During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
  // is better.
  // cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:IndexServlet.java

示例2: getDirectoryResource

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/** Returns a resource for the directory. */
Resource getDirectoryResource(String directory, boolean isInJar,
		File installRootDirectory) {
	if (isInJar) {
		try {
			return JarResource.newJarResource(Resource
					.newResource(Servlet.class.getClassLoader()
							.getResource(directory)));
		} catch (final IOException e) {
		}
		return null;
	} else {
		return Resource.newResource(new File(installRootDirectory,
				directory));
	}
}
 
开发者ID:ZapBlasterson,项目名称:crushpaper,代码行数:17,代码来源:Servlet.java

示例3: getClassPath

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
 * Generate the classpath (as a string) of all classloaders
 * above the given classloader.
 * 
 * This is primarily used for jasper.
 * @return the system class path
 */
public static String getClassPath(ClassLoader loader) throws Exception
{
    StringBuilder classpath=new StringBuilder();
    while (loader != null && (loader instanceof URLClassLoader))
    {
        URL[] urls = ((URLClassLoader)loader).getURLs();
        if (urls != null)
        {     
            for (int i=0;i<urls.length;i++)
            {
                Resource resource = Resource.newResource(urls[i]);
                File file=resource.getFile();
                if (file!=null && file.exists())
                {
                    if (classpath.length()>0)
                        classpath.append(File.pathSeparatorChar);
                    classpath.append(file.getAbsolutePath());
                }
            }
        }
        loader = loader.getParent();
    }
    return classpath.toString();
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:32,代码来源:Loader.java

示例4: createSSLConnectionFactory

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private SslConnectionFactory createSSLConnectionFactory(final KeystoreConfig keystore) {

        final Resource keystoreResource = Resource.newResource(keystore.getURL());

        final SslContextFactory contextFactory = new SslContextFactory();
        contextFactory.setEnableCRLDP(false);
        contextFactory.setEnableOCSP(false);
        contextFactory.setNeedClientAuth(false);
        contextFactory.setWantClientAuth(false);
        contextFactory.setValidateCerts(false);
        contextFactory.setValidatePeerCerts(false);
        contextFactory.setRenegotiationAllowed(false); // avoid vulnerability
        contextFactory.setSessionCachingEnabled(true); // optimization
        contextFactory.setKeyStoreResource(keystoreResource);
        contextFactory.setKeyStorePassword(keystore.getPassword());
        contextFactory.setCertAlias(keystore.getAlias());
        contextFactory.setKeyStoreType(keystore.getType());
        contextFactory.setIncludeCipherSuites("TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
                "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA",
                "SSL_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
                "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"); // check RFC 5430

        final SslConnectionFactory factory = new SslConnectionFactory(contextFactory, "http/1.1");
        return factory;
    }
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:26,代码来源:HttpServer.java

示例5: chop

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
public static Resource chop(final URL baseURL, final String toChop)
		throws MalformedURLException, IOException {
	String base = baseURL.toExternalForm();
	if (!base.endsWith(toChop)) {
		throw new IllegalArgumentException(base + " does not endWith "
				+ toChop);
	}
	base = base.substring(0, base.length() - toChop.length());

	if (base.startsWith("jar:file:") && base.endsWith("!")) {
		// If it was a jar:file:/.../.jar!/META-INF/web-fragment.xml, then
		// 'jar:' & '!' has to go as well:
		base = base.substring(0, base.length() - 1);
		base = "file:" + base.substring("jar:file:".length());
	}
	return Resource.newResource(base);
}
 
开发者ID:logsniffer,项目名称:logsniffer,代码行数:18,代码来源:Util.java

示例6: setupFilesHandler

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private void setupFilesHandler(Reflections reflections) throws IOException {

        // Set up the handler if there's anything to be served:
        URL url = getFilesUrl(reflections);
        if (url != null) {

            // Set up the resource handler:
            ResourceHandler filesHandler = new ResourceHandler();
            Resource resource = Resource.newResource(url);
            filesHandler.setBaseResource(resource);

            this.filesHandler = filesHandler;

            log.info("Set up static file handler for URL: " + url);
        } else {
            log.info("No static file handler configured.");
        }
    }
 
开发者ID:davidcarboni,项目名称:restolino,代码行数:19,代码来源:MainHandler.java

示例7: doStart

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
  // unpack and Adjust paths.
  Resource base = getBaseResource();
  if (base == null) {
    base = Resource.newResource(getWar());
  }
  Resource dir;
  if (base.isDirectory()) {
    dir = base;
  } else {
    throw new IllegalArgumentException();
  }
  Resource qswebxml = dir.addPath("/WEB-INF/quickstart-web.xml");
  if (qswebxml.exists()) {
    setConfigurationClasses(quickstartConfigurationClasses);
  }
  super.doStart();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:20,代码来源:VmRuntimeWebAppContext.java

示例8: getResource

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public Resource getResource(String uriInContext) throws MalformedURLException {
    if (publishedClasspathResources.contains(uriInContext) && getClassLoader() != null) {
        if (uriInContext.startsWith("/"))
            uriInContext = uriInContext.substring(1);

        URL resource = getClassLoader().getResource(uriInContext);
        if (resource == null) {
            throw new RuntimeException("Could not found published resource in classpath");
        }

        return Resource.newResource(resource);
    }

    return super.getResource(uriInContext);
}
 
开发者ID:jreznot,项目名称:diy-remote,代码行数:17,代码来源:ClasspathWebAppContext.java

示例9: getResource

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public final Resource getResource(String pathInContext) {
	ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
	ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
	
	for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
		if (mapping.getServletName().equals(getServletName())) {
			for (String pathSpec: mapping.getPathSpecs()) {
				String relativePath = null;
				if (pathSpec.endsWith("/*")) {
					pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
					if (pathInContext.startsWith(pathSpec + "/")) 
						relativePath = pathInContext.substring(pathSpec.length());
				} else if (pathSpec.startsWith("*.")) {
					pathSpec = StringUtils.stripStart(pathSpec, "*");
					if (pathInContext.endsWith(pathSpec))
						relativePath = pathInContext;
				} else if (pathSpec.equals(pathInContext)) {
					relativePath = pathInContext;
				}
				if (relativePath != null) {
					relativePath = StringUtils.stripStart(relativePath, "/");
					Resource resource = Resource.newResource(loadResource(relativePath));
					if (resource != null && resource.exists())
						return resource;
				}
			}
		}
	}
	
	return null;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:33,代码来源:AssetServlet.java

示例10: createDocsWebApp

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private ContextHandler createDocsWebApp(final String contextPath) throws IOException {
    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);

    // load the docs directory
    final File docsDir = Paths.get("docs").toRealPath().toFile();
    final Resource docsResource = Resource.newResource(docsDir);

    // load the rest documentation
    final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
    if (!webApiDocsDir.exists()) {
        final boolean made = webApiDocsDir.mkdirs();
        if (!made) {
            throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
        }
    }
    final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);

    // create resources for both docs locations
    final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
    resourceHandler.setBaseResource(resources);

    // create the context handler
    final ContextHandler handler = new ContextHandler(contextPath);
    handler.setHandler(resourceHandler);

    logger.info("Loading documents web app with context path set to " + contextPath);
    return handler;
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:30,代码来源:JettyServer.java

示例11: newResource

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
protected Resource newResource(String path) {
	try {
		return Resource.newResource(path);
	}
	catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}

}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:10,代码来源:AbstractClassPathService.java

示例12: addClassPath

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
 * @param classPath Comma or semicolon separated path of filenames or URLs
 *                  pointing to directories or jar files. Directories should end
 *                  with '/'.
 */
public void addClassPath(String classPath)
        throws IOException {
    if (classPath == null) {
        return;
    }

    StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");

    while (tokenizer.hasMoreTokens()) {
        Resource resource = Resource.newResource(tokenizer.nextToken().trim());
        // Add the resource
        if (resource.isDirectory() && resource instanceof ResourceCollection) {
            addClassPath(resource);
        }
        else {
            // Resolve file path if possible
            File file = resource.getFile();
            if (file != null) {
                URL url = resource.getURL();
                addURL(url);
            } else if (resource.isDirectory()) {
                addURL(resource.getURL());
            } else {
                LOG.error("Check file exists and is not nested jar: " + resource);
                throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
            }
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:35,代码来源:BeyondJWebAppClassLoader.java

示例13: addClassPath

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
 * @param classPath Comma or semicolon separated path of filenames or URLs
 *                  pointing to directories or jar files. Directories should end
 *                  with '/'.
 */
public void addClassPath(String classPath)
        throws IOException {
    if (classPath == null) {
        return;
    }

    StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
    while (tokenizer.hasMoreTokens()) {
        Resource resource = Resource.newResource(tokenizer.nextToken().trim());
        // Add the resource
        if (resource.isDirectory() && resource instanceof ResourceCollection)
            addClassPath(resource);
        else {
            // Resolve file path if possible
            File file = resource.getFile();
            if (file != null) {
                URL url = resource.getURL();
                addURL(url);
            } else if (resource.isDirectory()) {
                addURL(resource.getURL());
            } else {
                LOG.error("Check file exists and is not nested jar: " + resource);
                throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
            }
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:33,代码来源:BeyondJTomcatWebAppClassLoader.java

示例14: newResourcesHandler

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private ResourceHandler newResourcesHandler() throws MalformedURLException {
    final ResourceHandler resources = new ResourceHandler();
    final Resource location =
            config.getBoolean("web.static.resources.embedded") ?
                      Resource.newClassPathResource("web", false, false)
                    : Resource.newResource("src/main/resources/web", false);
    resources.setBaseResource(location);
    resources.setCacheControl("no-store");
    return resources;
}
 
开发者ID:alpian,项目名称:tired,代码行数:11,代码来源:WebServer.java

示例15: FavIconHandler

import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
public FavIconHandler() {
    byte[] bytes;
    try {
        URL fav = this.getClass().getClassLoader().getResource("favicon.ico");
        Resource r = Resource.newResource(fav);
        bytes = IO.readBytes(r.getInputStream());
    } catch (IOException e) {
        log.warn("Could not load favicon", e);
        bytes = null;
    }
    favicon = bytes;
}
 
开发者ID:danielflower,项目名称:app-runner-router,代码行数:13,代码来源:FavIconHandler.java


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