org.kohsuke.stapler.framework.adjunct
Class AdjunctManager

java.lang.Object
  extended by org.kohsuke.stapler.framework.adjunct.AdjunctManager

public class AdjunctManager
extends Object

This application-scoped object that exposes djuncts to URL.

Adjuncts are packaging of JavaScript, CSS, and other static assets in jar files with dependency information between them. This allows JavaScript libraries and other static assets to be reused across different projects through Maven/Ivy.

To use AdjunctManager in your application, create one instance, and bind it to URL (like you do any other objects.) The most typical way of doing this is to define it as a field in your top-level object.

 public class MyApplication {
     public final AdjunctManager adjuncts = new AdjunctManager(context,getClass().getClassLoader(),"/adjuncts");
 }
 

How you include an adjunct will depend on your template language, but for example in Jelly you do:

 <st:adjunct includes="org.kohsuke.stapler.bootstrap"/>
 
Or from Groovy you do:
 adjunct "org.kohsuke.stapler.bootstrap"
 

... and this produces a series of style and script tags that include all the necessary JavaScript, CSS, and their dependencies.

Internally, this class provides caching for Adjuncts.

Author:
Kohsuke Kawaguchi
See Also:
Adjunct

Field Summary
 boolean debug
          Hint instructing adjuncts to load a debuggable non-minified version of the script, as opposed to the production version.
 String rootURL
          Absolute URL of the AdjunctManager in the calling application where it is bound to.
 
Constructor Summary
AdjunctManager(javax.servlet.ServletContext context, ClassLoader classLoader, String rootURL)
           
 
Method Summary
protected  boolean allowResourceToBeServed(String absolutePath)
          Controls whether the given resource can be served to browsers.
 void doDynamic(StaplerRequest req, StaplerResponse rsp)
          Serves resources in the class loader.
static AdjunctManager get(javax.servlet.ServletContext context)
           
 Adjunct get(String name)
          Obtains the adjunct.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootURL

public final String rootURL
Absolute URL of the AdjunctManager in the calling application where it is bound to.

The path is treated relative from the context path of the application, and it needs to end without '/'. So it needs to be something like "foo/adjuncts" or more likely, just "adjuncts".


debug

public boolean debug
Hint instructing adjuncts to load a debuggable non-minified version of the script, as opposed to the production version. This is only a hint, and so the semantics of it isn't very well defined. The intention is to assist JavaScript debugging.

Constructor Detail

AdjunctManager

public AdjunctManager(javax.servlet.ServletContext context,
                      ClassLoader classLoader,
                      String rootURL)
Parameters:
classLoader - ClassLoader to load adjuncts from.
rootURL - See rootURL for the meaning of this parameter.
Method Detail

get

public static AdjunctManager get(javax.servlet.ServletContext context)

get

public Adjunct get(String name)
            throws IOException
Obtains the adjunct.

Returns:
always non-null.
Throws:
IOException - if failed to locate Adjunct.

doDynamic

public void doDynamic(StaplerRequest req,
                      StaplerResponse rsp)
               throws IOException,
                      javax.servlet.ServletException
Serves resources in the class loader.

Throws:
IOException
javax.servlet.ServletException

allowResourceToBeServed

protected boolean allowResourceToBeServed(String absolutePath)
Controls whether the given resource can be served to browsers.

This method can be overridden by the sub classes to change the access control behavior.

AdjunctManager is capable of serving all the resources visible in the classloader by default. If the resource files need to be kept private, return false, which causes the request to fail with 401. Otherwise return true, in which case the resource will be served.



Copyright © 2012. All Rights Reserved.