Example usage for org.apache.wicket SharedResources get

List of usage examples for org.apache.wicket SharedResources get

Introduction

In this page you can find the example usage for org.apache.wicket SharedResources get.

Prototype

public ResourceReference get(Class<?> scope, String name, Locale locale, String style, String variation,
        boolean strict) 

Source Link

Document

Resolves a ResourceReference for a shared resource.

Usage

From source file:org.cast.cwm.components.DeployJava.java

License:Open Source License

/**
 * Provides a URL to a shared resource for the given jarFile.  If a resource
 * does not exist, it searches the /WEB-INF/lib folder for a file that starts with 
 * the provided name and adds the resource first.
 * /*from   ww w .  j a v  a 2s .c o m*/
 * @param jarName
 * @return
 */
public String getSharedArchiveURL(final String jarName) {
    SharedResources sr = Application.get().getSharedResources();

    // If this jarName is not listed as a shared resource, add it as one.
    if (sr.get(DeployJava.class, jarName, null, null, null, false) == null) {
        ServletContext sc = WebApplication.get().getServletContext();
        String path = "/WEB-INF/lib";
        File jar = findMatchingFile(new Folder(sc.getRealPath(path)), jarName);
        if (jar == null) {
            path = "/WEB-INF/classes";
            jar = findMatchingFile(new Folder(sc.getRealPath(path)), jarName);
        }
        if (jar == null) {
            log.error("No JAR found matching {}, looked in {} and {}", jarName, sc.getRealPath("/WEB-INF/lib"),
                    sc.getRealPath("/WEB-INF/classes"));
        } else {
            log.debug("Adding JAR to Shared Resources: {}", jar.getAbsolutePath());
            ContextRelativeResource resource = new ContextRelativeResource(path + "/" + jar.getName());
            sr.add(DeployJava.class, jarName, null, null, null, resource);
        }
    }

    return urlFor(new PackageResourceReference(DeployJava.class, jarName), null).toString();
}