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