當前位置: 首頁>>代碼示例>>Java>>正文


Java Resource.exists方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.util.resource.Resource.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.exists方法的具體用法?Java Resource.exists怎麽用?Java Resource.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.util.resource.Resource的用法示例。


在下文中一共展示了Resource.exists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的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: addFolderResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
protected void addFolderResource(final WebAppContext context) throws IOException {
	for (Resource resource : context.getMetaData().getWebInfJars()) {
		String url = resource.toString();
		if (!isClassesDir(url)) {
			continue;
		}
		{
			Resource fragmentResource = resource.getResource("META-INF/web-fragment.xml");
			if (fragmentResource.exists()) {
				// addResource(context, METAINF_FRAGMENTS, resource);
			}
		}

		this.addTldResource(context, resource, "META-INF/fnx.tld");
		this.addTldResource(context, resource, "META-INF/dw.tld");
	}
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:18,代碼來源:EmbedMetaInfConfiguration.java

示例3: getResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
protected Resource getResource(HttpServletRequest request) throws MalformedURLException {
	System.err.println("getResource uri:" + request.getRequestURI());
	// return super.getResource(request);
	// }
	//
	// @Override
	// public Resource getResource(String path) {
	// System.err.println("getResource path:" + path);

	Resource resource = super.getResource(request);
	if (resource == null || !resource.exists()) {
		return resource;
	}

	String path = request.getRequestURI();
	if ("/js/jquery.min.js".equals(path)) {
		try {
			resource = this.append(request, resource, path);
		}
		catch (IOException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}
	return resource;
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:26,代碼來源:HostResourceHandler.java

示例4: addJars

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
/**
 * Add elements to the class path for the context from the jar and zip files found
 * in the specified resource.
 *
 * @param resource the resource that contains the jar and/or zip files.
 */
public void addJars(Resource resource) {
    if (resource.exists() && resource.isDirectory()) {
        String[] files = resource.list();
        for (int f = 0; files != null && f < files.length; f++) {
            try {
                Resource fn = resource.addPath(files[f]);
                String fnlc = fn.getName().toLowerCase(Locale.ENGLISH);
                // don't check if this is a directory, see Bug 353165
                if (isFileSupported(fnlc)) {
                    String name = fn.toString();
                    name = StringUtil.replace(name, ",", "%2C");
                    name = StringUtil.replace(name, ";", "%3B");
                    addClassPath(name);
                    List<Class<?>> classes = getClassesInJar(name);
                    for (Class<?> clazz : classes) {
                        knownClasses.put(clazz.getName(), clazz);
                    }
                }
            } catch (Exception ex) {
                LOG.error(String.format("Exception adding classpath entry from resource %s", resource.getName()), ex);
            }
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:31,代碼來源:BeyondJWebAppClassLoader.java

示例5: getWelcomeFile

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
/**
 * Finds a matching welcome file for the supplied {@link Resource}. This will be the first entry in the list of
 * configured {@link #_welcomes welcome files} that existing within the directory referenced by the <code>Resource</code>.
 * If the resource is not a directory, or no matching file is found, then it may look for a valid servlet mapping.
 * If there is none, then <code>null</code> is returned.
 * The list of welcome files is read from the {@link ContextHandler} for this servlet, or
 * <code>"index.jsp" , "index.html"</code> if that is <code>null</code>.
 * @param resource
 * @return The path of the matching welcome file in context or null.
 * @throws IOException
 * @throws MalformedURLException
 */
private String getWelcomeFile(String pathInContext)
    throws MalformedURLException, IOException
{
    if (_welcomes == null)
        return null;
        
    String welcome_servlet = null;
    for (int i = 0; i < _welcomes.length; i++)
    {
        String welcome_in_context = URIUtil.addPaths(pathInContext, _welcomes[i]);
        Resource welcome = getResource(welcome_in_context);
        if (welcome != null && welcome.exists())
            return _welcomes[i];
            
        if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet == null)
        {
            MappedEntry<?> entry = _servletHandler.getHolderEntry(welcome_in_context);
            if (entry != null && entry.getValue() != _defaultHolder
                && (_welcomeServlets || (_welcomeExactServlets && entry.getKey().equals(welcome_in_context))))
                welcome_servlet = welcome_in_context;
                
        }
    }
    return welcome_servlet;
}
 
開發者ID:lnwazg,項目名稱:kit,代碼行數:38,代碼來源:DefaultServlet.java

示例6: 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

示例7: 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

示例8: findTemplateSource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
@Override
public Object findTemplateSource(String name) throws IOException {
  Resource resource = baseResource.addPath(name);
  if (!resource.exists()) {
    return null;
  }
  return resource;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:9,代碼來源:ResourceTemplateLoader.java

示例9: getResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
/** get Resource to serve.
 * Map a path to a resource. The default implementation calls
 * HttpContext.getResource but derived servlets may provide
 * their own mapping.
 * @param pathInContext The path to find a resource for.
 * @return The resource to serve.
 */
@Override
public Resource getResource(String pathInContext)
{
    Resource r = null;
    if (_relativeResourceBase != null)
        pathInContext = URIUtil.addPaths(_relativeResourceBase, pathInContext);
        
    try
    {
        if (_resourceBase != null)
        {
            r = _resourceBase.addPath(pathInContext);
            if (!_contextHandler.checkAlias(pathInContext, r))
                r = null;
        }
        else if (_servletContext instanceof ContextHandler.Context)
        {
            r = _contextHandler.getResource(pathInContext);
        }
        else
        {
            URL u = _servletContext.getResource(pathInContext);
            r = _contextHandler.newResource(u);
        }
        
        if (LOG.isDebugEnabled())
            LOG.debug("Resource " + pathInContext + "=" + r);
    }
    catch (IOException e)
    {
        LOG.ignore(e);
    }
    
    if ((r == null || !r.exists()) && pathInContext.endsWith("/jetty-dir.css"))
        r = _stylesheet;
        
    return r;
}
 
開發者ID:lnwazg,項目名稱:kit,代碼行數:46,代碼來源:DefaultServlet.java

示例10: doStart

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
@Override
protected void doStart() throws Exception {
  
  Resource resource = Resource.newResource(webapp);
  File file = resource.getFile();
  if (!resource.exists())
      throw new IllegalStateException("WebApp resouce does not exist "+resource);

  String lcName=file.getName().toLowerCase(Locale.ENGLISH);

  if (lcName.endsWith(".xml")) {
      XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL());
      xmlc.getIdMap().put("Server", contexts.getServer());
      xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home","."));
      xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base","."));
      xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath());
      xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath());
      xmlc.getProperties().putAll(properties);
      handler = (ContextHandler)xmlc.configure();
  } else {
    WebAppContext wac=new WebAppContext();
    wac.setWar(webapp);
    wac.setContextPath("/");
  }
  
  contexts.addHandler(handler);
  if (contexts.isRunning())
    handler.start();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:30,代碼來源:VmRuntimeWebAppDeployer.java

示例11: findWebXml

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
@Override
protected Resource findWebXml(WebAppContext context) throws IOException {
    Resource webXml = super.findWebXml(context);
    if ((webXml == null || !webXml.exists()) && context.getClassLoader() != null) {
        webXml = context.getResource("/" + context.getDescriptor());
    }
    return webXml;
}
 
開發者ID:jreznot,項目名稱:diy-remote,代碼行數:9,代碼來源:ClasspathWebXmlConfiguration.java

示例12: getResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
/**
 * @see org.eclipse.jetty.servlet.DefaultServlet#getResource(java.lang.String)
 */
@Override
public synchronized Resource getResource(String pathInContext) {
    for (Resource resourceBase : resourceBases) {
        setResourceBase(resourceBase);
        Resource resource = super.getResource(pathInContext);
        if (resource != null && resource.exists()) {
            return resource;
        }
    }
    return null;
}
 
開發者ID:Governance,項目名稱:overlord-commons,代碼行數:15,代碼來源:MultiDefaultServlet.java

示例13: main

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    Resource keystore = Resource.newClassPathResource("/keystore");
    if (keystore != null && keystore.exists()) {
        // if a keystore for a SSL certificate is available, start a SSL
        // connector on port 8443.
        // By default, the quickstart comes with a Apache Wicket Quickstart
        // Certificate that expires about half way september 2021. Do not
        // use this certificate anywhere important as the passwords are
        // available in the source.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart has been enabled on port 8443");
        System.out.println("You can access the application using SSL on https://localhost:8443");
        System.out.println();
    }

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
開發者ID:sparsick,項目名稱:ansible-docker-talk,代碼行數:65,代碼來源:Start.java

示例14: addTldResource

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
protected void addTldResource(final WebAppContext context, Resource resource, String name) throws IOException {
	Resource tldResource = resource.getResource(name);
	if (tldResource.exists()) {
		// addResource(context, METAINF_TLDS, tldResource);
	}
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:7,代碼來源:EmbedMetaInfConfiguration.java

示例15: main

import org.eclipse.jetty.util.resource.Resource; //導入方法依賴的package包/類
/**
 * Main function, starts the jetty server.
 *
 * @param args
 */
public static void main(String[] args)
{
	System.setProperty("wicket.configuration", "development");

	Server server = new Server();

	HttpConfiguration http_config = new HttpConfiguration();
	http_config.setSecureScheme("https");
	http_config.setSecurePort(8443);
	http_config.setOutputBufferSize(32768);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
	http.setPort(8080);
	http.setIdleTimeout(1000 * 60 * 60);

	server.addConnector(http);

	Resource keystore = Resource.newClassPathResource("/keystore");
	if (keystore != null && keystore.exists())
	{
		// if a keystore for a SSL certificate is available, start a SSL
		// connector on port 8443.
		// By default, the quickstart comes with a Apache Wicket Quickstart
		// Certificate that expires about half way september 2021. Do not
		// use this certificate anywhere important as the passwords are
		// available in the source.

		SslContextFactory sslContextFactory = new SslContextFactory();
		sslContextFactory.setKeyStoreResource(keystore);
		sslContextFactory.setKeyStorePassword("wicket");
		sslContextFactory.setKeyManagerPassword("wicket");

		HttpConfiguration https_config = new HttpConfiguration(http_config);
		https_config.addCustomizer(new SecureRequestCustomizer());

		ServerConnector https = new ServerConnector(server, new SslConnectionFactory(
			sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
		https.setPort(8443);
		https.setIdleTimeout(500000);

		server.addConnector(https);
		System.out.println("SSL access to the examples has been enabled on port 8443");
		System.out
			.println("You can access the application using SSL on https://localhost:8443");
		System.out.println();
	}

	WebAppContext bb = new WebAppContext();
	bb.setServer(server);
	bb.setContextPath("/");
	bb.setWar("src/main/webapp");

	// uncomment next line if you want to test with JSESSIONID encoded in the urls
	// ((AbstractSessionManager)
	// bb.getSessionHandler().getSessionManager()).setUsingCookies(false);

	server.setHandler(bb);

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
	MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
	server.addEventListener(mBeanContainer);
	server.addBean(mBeanContainer);

	try
	{
		server.start();
		server.join();
	}
	catch (Exception e)
	{
		e.printStackTrace();
		System.exit(100);
	}
}
 
開發者ID:pingunaut,項目名稱:wicket-stream-download-example,代碼行數:80,代碼來源:Start.java


注:本文中的org.eclipse.jetty.util.resource.Resource.exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。