org.kohsuke.stapler.framework.adjunct
Class AdjunctManager

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

public class AdjunctManager
extends java.lang.Object

This application-scoped object works like a factory for Adjuncts and provides caching.

This object can be UI-bound by stapler, and adjunct CSS and JavaScript can be accessed like

 <link rel="stylesheet" href=".../css/org/example/style" type="text/css" />
 <script                href=".../js/org/example/style"></script>
 

Author:
Kohsuke Kawaguchi

Field Summary
 java.lang.String rootURL
          Absolute URL of the AdjunctManager in the calling application where it is bound to.
 
Constructor Summary
AdjunctManager(javax.servlet.ServletContext context, java.lang.ClassLoader classLoader, java.lang.String rootURL)
           
 
Method Summary
protected  boolean allowResourceToBeServed(java.lang.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(java.lang.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 java.lang.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".

Constructor Detail

AdjunctManager

public AdjunctManager(javax.servlet.ServletContext context,
                      java.lang.ClassLoader classLoader,
                      java.lang.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(java.lang.String name)
            throws java.io.IOException
Obtains the adjunct.

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

doDynamic

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

Throws:
java.io.IOException
javax.servlet.ServletException

allowResourceToBeServed

protected boolean allowResourceToBeServed(java.lang.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.