/*
(non-Javadoc)

@see
edu.umd.cs.findbugs.classfile.ICodeBase#lookupResource(java.lang.String)
179213
@Override
    public ICodeBaseEntry lookupResource(String resourceName) {

        // Translate resource name, in case a resource name
        // has been overridden and the resource is being accessed
        // using the overridden name.
        resourceName = translateResourceName(resourceName);
        if (!entries.contains(resourceName)) {
            return null;
        }

        try {
            ZipInputStreamCodeBaseEntry z = map.get(resourceName);
            if (z != null) {
                return z;
            }
            ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
            try {
                ZipEntry ze;

                boolean found = false;
                int countDown = 20;
                while ((ze = zis.getNextEntry()) != null && countDown >= 0) {
                    if (ze.getName().equals(resourceName)) {
                        found = true;
                    }
                    if (found) {
                        countDown--;
                        if (map.containsKey(ze.getName())) {
                            continue;
                        }
                        z = build(zis, ze);
                        map.put(ze.getName(), z);
                    }
                    zis.closeEntry();
                }
            } finally {
                zis.close();
            }
            z = map.get(resourceName);
            if (z == null) {
                throw new AssertionError("Could not find " + resourceName);
            }
            return z;
        } catch (IOException e) {
            return null;
        }
    }
1067269
@Override
	public LinkRelation getItemResourceRelFor(Class<?> resource) {

		LookupContext context = LookupContext.forItemResourceRelLookup(entityType);

		return providers.getRequiredPluginFor(context).getItemResourceRelFor(resource);
	}
710536
private DataSource lookupDatasource(JDBCIdentitySource config) {
        DataSource ds;
        try {
            InitialContext ctx = new InitialContext();
            ds = lookupDS(ctx, config.getDatasourcePath());
            if (ds == null) {
                ds = lookupDS(ctx, "java:comp/env/" + config.getDatasourcePath()); //$NON-NLS-1$
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        if (ds == null) {
            throw new RuntimeException("Datasource not found: " + config.getDatasourcePath()); //$NON-NLS-1$
        }
        return ds;
    }
113283
public static CmsResource lookupPage(CmsObject cms, String uri) throws CmsException {

        try {
            CmsResource res = cms.readResource(uri);
            return res;
        } catch (CmsVfsResourceNotFoundException e) {
            String detailName = CmsResource.getName(uri).replaceAll("/$", "");
            CmsUUID detailId = cms.readIdForUrlName(detailName);
            if (detailId != null) {
                return cms.readResource(detailId);
            }
            throw new CmsVfsResourceNotFoundException(
                org.opencms.db.generic.Messages.get().container(
                    org.opencms.db.generic.Messages.ERR_READ_RESOURCE_1,
                    uri));
        }
    }
435932
public static String lookup(String resourceName) {
        String resource = null;

        // 1. Check in the JNDI tree
        Context ctx = null;
        try {
            ctx = (Context) new InitialContext().lookup(JNDI_ENVIRONMENT);
            resource = (String) ctx.lookup(resourceName);
        }
        catch (NamingException ignore) {}

        // 2. Check among system properties
        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through JNDI...");
            try {
                resource = System.getProperty(resourceName);
            }
            catch (Exception ignore) {}
        }

        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through system properties...");
        }
        return resource;
    }
1349276
public Resource getResource(String name, Locale locale) throws IOException {
        return getResource(name, locale, null);
    }
468440
public static Object lookup(String jndiName)
    {
        if(log.isDebugEnabled()) log.debug("lookup("+jndiName+") was called");
        try
        {
            return getContext().lookup(jndiName);
        }
        catch (NamingException e)
        {
            throw new OJBRuntimeException("Lookup failed for: " + jndiName, e);
        }
        catch(OJBRuntimeException e)
        {
            throw e;
        }
    }
452589
@Override
   protected URL findResource(String name) {
      if (resourceCache.containsKey(name)) {
         return resourceCache.get(name);
      }

      for (WeakReference<Bundle> ref : bundles) {
         final Bundle bundle = ref.get();
         if (bundle != null && bundle.getState() == Bundle.ACTIVE) {
            try {
               final URL resource = bundle.getResource(name);
               if (resource != null) {
                  resourceCache.put(name, resource);
                  return resource;
               }
            } catch (Exception ignore) {
            }
         }
      }

      // TODO: Error?
      return null;
   }
207445
@Override
    public URL[] findResources()
    {
        URL[] result = null;

        if (classesToScan != null && !classesToScan.isEmpty())
        {
            result = findResourcesByContextLoader();
        }
        // else
        // {
        // result = findResourcesByClasspath();
        // }
        return result;
    }
174553
@Override
	public Resource getResource(String key)
	{

		Resource resource = new ClasspathResource(key, this.getChildPath(root, key), this);
		return resource;
	}
1341352
public final URL findResource(final String fname) {
		if (!this.isInit()) {
			if (CClassLoader.sl(CClassLoader.DEBUG)) {
				CClassLoader.log("Not initialized, forward to old loader "
						+ fname + " in " + this.getPath(), CClassLoader.DEBUG);
			}

			if ((Thread.currentThread().getContextClassLoader() != null)
					&& (Thread.currentThread().getContextClassLoader() != this)) {
				return Thread.currentThread().getContextClassLoader()
						.getResource(fname);
			}

			return CClassLoader.getRootLoader().getParent().getResource(fname);
		}

		String name = fname;

		if (name.startsWith("/")) {
			name = name.substring(1);
		}

		final CThreadContext context = CThreadContext.getInstance();
		final String cpName = CClassLoader.CCLASSLOADER_NAMESPACE + name;
		List lPriorLoader = (List) context.get(cpName);

		if (lPriorLoader == null) {
			lPriorLoader = new Vector();
			context.set(cpName, lPriorLoader);
		}

		if (lPriorLoader.contains(this.toString())) {
			return null;
		}

		lPriorLoader.add(this.toString());

		if (CClassLoader.sl(CClassLoader.DEBUG)) {
			CClassLoader.log("Searching " + name + " in " + this.getPath(),
					CClassLoader.DEBUG);
		}

		// first check if this resource as a mandatory loader
		URL urlToResource = null;

		if (!this.booAlone) {
			CClassLoader loader = null;

			for (final Iterator it = CClassLoader.mandatoryLoadersMap
					.entrySet().iterator(); it.hasNext();) {
				final Entry entry = (Entry) it.next();
				loader = (CClassLoader) entry.getValue();

				if (loader.resourcesMap.containsKey(name)) {
					if (loader != this) {
						break;
					}
					loader = null;
					break;
				}
				loader = null;
			}

			if (loader != null) {
				urlToResource = loader.getResource(name);
			}

			if (urlToResource != null) {
				context.set(cpName, null);

				return urlToResource;
			}
		}

		final Object to = this.resourcesMap.get(name);
		if (to instanceof URL) {
			// second search in this repository
			urlToResource = (URL) to;
		} else if (to instanceof List) {
			final List l = (List) to;
			urlToResource = (URL) l.get(0);
		}

		if (urlToResource != null) {
			if (CClassLoader.sl(CClassLoader.DEBUG)) {
				CClassLoader.log("Loaded " + name + " in " + this.getPath(),
						CClassLoader.DEBUG);
			}

			context.set(cpName, null);

			return urlToResource;
		}

		// then search in each children
		final List tmpLoader = new ArrayList();

		for (final Iterator it = this.childrenMap.entrySet().iterator(); it
				.hasNext();) {
			final Entry entry = (Entry) it.next();
			final CClassLoader child = (CClassLoader) entry.getValue();

			if (lPriorLoader.contains(child.toString())) {
				continue;
			}

			tmpLoader.add(child);
		}

		for (final Iterator it = tmpLoader.iterator(); it.hasNext();) {
			final Object element = it.next();
			final CClassLoader child = (CClassLoader) element;
			urlToResource = child.getResource(name);

			if (urlToResource != null) {
				return urlToResource;
			}
		}

		// then follow to parents
		if ((this != CClassLoader.getRootLoader())
				&& !this.booDoNotForwardToParent) {
			if (lPriorLoader.contains(this.getParent().toString())) {
				return null;
			} else {
				if (this.getParent() == null) {
					return null;
				}

				return this.getParent().getResource(name);
			}
		} else {
			urlToResource = CClassLoader.getRootLoader().getParent()
					.getResource(name);
			context.set(cpName, null);

			return urlToResource;
		}
	}
639859
public static boolean doesResourceExist(final String location) {
        try {
            return getResourceFrom(location) != null;
        } catch (final Exception e) {
            LOGGER.trace(e.getMessage(), e);
        }
        return false;
    }
279134
@Override
    public ICodeBaseEntry lookupResource(String resourceName) {
        // Translate resource name, in case a resource name
        // has been overridden and the resource is being accessed
        // using the overridden name.
        resourceName = translateResourceName(resourceName);

        File file = getFullPathOfResource(resourceName);
        if (!file.exists()) {
            return null;
        }
        return new DirectoryCodeBaseEntry(this, resourceName);
    }
11618
protected File findFile(final List<File> sourceDirectories, String resourceFileName) throws IOException {
	    for (final File sourceDirectory : sourceDirectories) {
	        final File resourceFile = new File(sourceDirectory, resourceFileName);
	        if (resourceFile.exists()) {
	            return resourceFile;
	        }
	    }
	    
	    throw new IOException("Failed to find resource " + resourceFileName + " in any of the source directories: " + sourceDirectories);
	}
511812
@Override
    protected Enumeration<URL> findResources(String name) {
        URL url = findResource(name);
        Vector<URL> urls = new Vector<>();
        if (url != null) {
            urls.add(url);
        }
        return urls.elements();
    }
603359
public CmsResource getSource(CmsObject cms, CmsResourceFilter filter) throws CmsException {

        try {
            // first look up by id
            return cms.readResource(getSourceId(), filter);
        } catch (CmsVfsResourceNotFoundException e) {
            // then look up by name, but from the root site
            String storedSiteRoot = cms.getRequestContext().getSiteRoot();
            try {
                cms.getRequestContext().setSiteRoot("");
                return cms.readResource(getSourcePath(), filter);
            } finally {
                cms.getRequestContext().setSiteRoot(storedSiteRoot);
            }
        }
    }
903249
public URL getResource(String resourceName, BeanContextChild child)
	{
		if (resourceName == null || child == null)
		{
			throw new NullPointerException();
		}
		if (!contains(child))
		{
			throw new IllegalArgumentException(Messages.getString("beans.6D"));
		}

		return ClassLoader.getSystemResource(resourceName);
	}