Search in sources :

Example 1 with UrlExternalFormComparator

use of org.apache.wicket.util.collections.UrlExternalFormComparator in project wicket by apache.

the class AbstractClassResolver method getResources.

@Override
public Iterator<URL> getResources(final String name) {
    Set<URL> resultSet = new TreeSet<>(new UrlExternalFormComparator());
    try {
        // Try the classloader for the wicket jar/bundle
        Enumeration<URL> resources = Application.class.getClassLoader().getResources(name);
        loadResources(resources, resultSet);
        // Try the classloader for the user's application jar/bundle
        resources = Application.get().getClass().getClassLoader().getResources(name);
        loadResources(resources, resultSet);
        // Try the context class loader
        resources = getClassLoader().getResources(name);
        loadResources(resources, resultSet);
    } catch (Exception e) {
        throw new WicketRuntimeException(e);
    }
    return resultSet.iterator();
}
Also used : UrlExternalFormComparator(org.apache.wicket.util.collections.UrlExternalFormComparator) TreeSet(java.util.TreeSet) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Application(org.apache.wicket.Application) URL(java.net.URL) WicketRuntimeException(org.apache.wicket.WicketRuntimeException)

Example 2 with UrlExternalFormComparator

use of org.apache.wicket.util.collections.UrlExternalFormComparator in project wicket by apache.

the class CompoundClassResolver method getResources.

/**
 * {@inheritDoc}
 * <p>
 * This implementation iterates through all {@link IClassResolver}s added, and combines the
 * results into one {@link Set} of {@link URL}s, and returns an {@link Iterator} for the set.
 * {@link URL}s are unique in the set.
 *
 * @param name
 *            The name of the resource to find.
 * @return An {@link Iterator} of all the {@link URL}s matching the resource name.
 */
@Override
public Iterator<URL> getResources(final String name) {
    Args.notNull(name, "name");
    Set<URL> urls = new TreeSet<URL>(new UrlExternalFormComparator());
    for (IClassResolver resolver : resolvers) {
        Iterator<URL> it = resolver.getResources(name);
        while (it.hasNext()) {
            URL url = it.next();
            urls.add(url);
        }
    }
    return urls.iterator();
}
Also used : UrlExternalFormComparator(org.apache.wicket.util.collections.UrlExternalFormComparator) TreeSet(java.util.TreeSet) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 TreeSet (java.util.TreeSet)2 UrlExternalFormComparator (org.apache.wicket.util.collections.UrlExternalFormComparator)2 Application (org.apache.wicket.Application)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1