Example usage for org.apache.wicket SharedResources add

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

Introduction

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

Prototype

public final void add(final Class<?> scope, final String name, final Locale locale, final String style,
        final String variation, final IResource resource) 

Source Link

Document

Adds a 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.
 * // w  ww.jav a2  s .  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();
}